GeezerVison is showing github.com — Merge branch 'main' into feat/sidebar-thread-ports · pingdotgg/t3code@b8fad1e
File treeExpand file treeCollapse file tree Open diff view settings web/src/components/pullRequest
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/ProjectionStore.ts +3-2Lines changed: 3 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -4098,9 +4098,10 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> = | 4098 | 4098 | AND EXISTS ( | 4099 | 4099 | SELECT 1 FROM orchestration_v2_projection_nodes AS node | 4100 | 4100 | WHERE node.thread_id = subagents.child_thread_id | 4101 | | - AND node.run_id IS NULL | | 4101 | + -- Matches nodes_live_idx; +run_id keeps thread_run_idx from scanning settled nodes. | | 4102 | + AND node.status IN ('pending', 'starting', 'running', 'waiting') | | 4103 | + AND +node.run_id IS NULL | 4102 | 4104 | AND node.kind = 'root_turn' | 4103 | | - AND node.status IN ('pending', 'running', 'waiting') | 4104 | 4105 | ) | 4105 | 4106 | UNION | 4106 | 4107 | -- No native subagent outlives the provider process that ran it. | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/project/ProjectEnrichmentService.ts +52-48Lines changed: 52 additions & 48 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -210,63 +210,67 @@ export const make = Effect.fn("ProjectEnrichmentService.make")(function* ( | 210 | 210 | { concurrency: "unbounded", discard: true }, | 211 | 211 | ); | 212 | 212 |
| 213 | | - const requestLane = Effect.fn("ProjectEnrichmentService.requestLane")(function* ( | | 213 | + // Every project read lands here; only an actual enqueue gets a span, the resolve workers trace the work. | | 214 | + const requestLane = Effect.fnUntraced(function* ( | 214 | 215 | lane: EnrichmentWorkLane, | 215 | 216 | workspaceRoot: string, | 216 | 217 | field: "repositoryIdentity" | "faviconPath", | 217 | 218 | ) { | 218 | 219 | if (!(yield* reservePending(lane, workspaceRoot))) return; | 219 | | - if (!(yield* Queue.offer(lane.queue, workspaceRoot))) { | 220 | | - yield* removePending(lane, workspaceRoot); | 221 | | - yield* Effect.logWarning("Project metadata enrichment queue is full", { | 222 | | - workspaceRoot, | 223 | | - field, | 224 | | - }); | 225 | | - } | | 220 | + yield* Effect.gen(function* () { | | 221 | + if (!(yield* Queue.offer(lane.queue, workspaceRoot))) { | | 222 | + yield* removePending(lane, workspaceRoot); | | 223 | + yield* Effect.logWarning("Project metadata enrichment queue is full", { | | 224 | + workspaceRoot, | | 225 | + field, | | 226 | + }); | | 227 | + } | | 228 | + }).pipe(Effect.withSpan("ProjectEnrichmentService.requestLane")); | 226 | 229 | }); | 227 | 230 |
| 228 | | - const peek: ProjectEnrichmentService["Service"]["peek"] = Effect.fn( | 229 | | - "ProjectEnrichmentService.peek", | 230 | | - )(function* (workspaceRoot) { | 231 | | - const [repositoryIdentity, faviconPath] = yield* Effect.all( | 232 | | - [ | 233 | | - Cache.getSuccess(repositoryIdentityCache, workspaceRoot), | 234 | | - Cache.getSuccess(faviconCache, workspaceRoot), | 235 | | - ] as const, | 236 | | - { concurrency: "unbounded" }, | 237 | | - ); | 238 | | - return { | 239 | | - repositoryIdentity: availableValue(repositoryIdentity), | 240 | | - faviconPath: availableValue(faviconPath), | 241 | | - repositoryIdentityResolved: isSuccessfullyResolved(repositoryIdentity), | 242 | | - }; | 243 | | - }); | | 231 | + // peek/request/getAvailable run per project on every shell read, inside the caller's span; own spans were ~0ms noise. | | 232 | + const peek: ProjectEnrichmentService["Service"]["peek"] = Effect.fnUntraced( | | 233 | + function* (workspaceRoot) { | | 234 | + const [repositoryIdentity, faviconPath] = yield* Effect.all( | | 235 | + [ | | 236 | + Cache.getSuccess(repositoryIdentityCache, workspaceRoot), | | 237 | + Cache.getSuccess(faviconCache, workspaceRoot), | | 238 | + ] as const, | | 239 | + { concurrency: "unbounded" }, | | 240 | + ); | | 241 | + return { | | 242 | + repositoryIdentity: availableValue(repositoryIdentity), | | 243 | + faviconPath: availableValue(faviconPath), | | 244 | + repositoryIdentityResolved: isSuccessfullyResolved(repositoryIdentity), | | 245 | + }; | | 246 | + }, | | 247 | + ); | 244 | 248 |
| 245 | | - const request: ProjectEnrichmentService["Service"]["request"] = Effect.fn( | 246 | | - "ProjectEnrichmentService.request", | 247 | | - )(function* (workspaceRoot) { | 248 | | - const [hasRepositoryIdentity, hasFaviconPath] = yield* Effect.all( | 249 | | - [Cache.has(repositoryIdentityCache, workspaceRoot), Cache.has(faviconCache, workspaceRoot)], | 250 | | - { concurrency: "unbounded" }, | 251 | | - ); | 252 | | - yield* Effect.all( | 253 | | - [ | 254 | | - hasRepositoryIdentity | 255 | | - ? Effect.void | 256 | | - : requestLane(repositoryIdentityLane, workspaceRoot, "repositoryIdentity"), | 257 | | - hasFaviconPath ? Effect.void : requestLane(faviconLane, workspaceRoot, "faviconPath"), | 258 | | - ], | 259 | | - { concurrency: "unbounded", discard: true }, | 260 | | - ); | 261 | | - }); | | 249 | + const request: ProjectEnrichmentService["Service"]["request"] = Effect.fnUntraced( | | 250 | + function* (workspaceRoot) { | | 251 | + const [hasRepositoryIdentity, hasFaviconPath] = yield* Effect.all( | | 252 | + [Cache.has(repositoryIdentityCache, workspaceRoot), Cache.has(faviconCache, workspaceRoot)], | | 253 | + { concurrency: "unbounded" }, | | 254 | + ); | | 255 | + yield* Effect.all( | | 256 | + [ | | 257 | + hasRepositoryIdentity | | 258 | + ? Effect.void | | 259 | + : requestLane(repositoryIdentityLane, workspaceRoot, "repositoryIdentity"), | | 260 | + hasFaviconPath ? Effect.void : requestLane(faviconLane, workspaceRoot, "faviconPath"), | | 261 | + ], | | 262 | + { concurrency: "unbounded", discard: true }, | | 263 | + ); | | 264 | + }, | | 265 | + ); | 262 | 266 |
| 263 | | - const getAvailable: ProjectEnrichmentService["Service"]["getAvailable"] = Effect.fn( | 264 | | - "ProjectEnrichmentService.getAvailable", | 265 | | - )(function* (workspaceRoot) { | 266 | | - const available = yield* peek(workspaceRoot); | 267 | | - yield* request(workspaceRoot); | 268 | | - return available; | 269 | | - }); | | 267 | + const getAvailable: ProjectEnrichmentService["Service"]["getAvailable"] = Effect.fnUntraced( | | 268 | + function* (workspaceRoot) { | | 269 | + const available = yield* peek(workspaceRoot); | | 270 | + yield* request(workspaceRoot); | | 271 | + return available; | | 272 | + }, | | 273 | + ); | 270 | 274 |
| 271 | 275 | const readRepositoryIdentity: ProjectEnrichmentService["Service"]["readRepositoryIdentity"] = | 272 | 276 | Effect.fn("ProjectEnrichmentService.readRepositoryIdentity")(function* (workspaceRoot) { | |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/pullRequest/PullRequestCodeTab.tsx +79-37Lines changed: 79 additions & 37 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -176,6 +176,76 @@ function parseSlice(slice: DiffSlice, cacheKey: string, ignoreWhitespace: boolea | 176 | 176 | return parsed; | 177 | 177 | } | 178 | 178 |
| | 179 | +type DiffModel = { | | 180 | + readonly parsedSlices: ReadonlyArray<RenderablePatch | null>; | | 181 | + readonly loadedFiles: ReadonlyArray<Extract<RenderablePatch, { kind: "files" }>["files"][number]>; | | 182 | + readonly sourceFileStats: ReadonlyMap<string, ReturnType<typeof getDiffLineStat>>; | | 183 | +}; | | 184 | +const diffModels = new WeakMap<ReadonlyArray<DiffSlice>, Map<string, DiffModel>>(); | | 185 | +const patchHashes = new WeakMap<DiffSlice, number>(); | | 186 | + | | 187 | +// Hashing, ordering and counting every file of a huge pull request costs a second, and the tab | | 188 | +// renders far more often than its slices change, so the model is kept per slice list. | | 189 | +function diffModel( | | 190 | + slices: ReadonlyArray<DiffSlice>, | | 191 | + keyPrefix: string, | | 192 | + ignoreWhitespace: boolean, | | 193 | +): DiffModel { | | 194 | + let models = diffModels.get(slices); | | 195 | + if (models === undefined) diffModels.set(slices, (models = new Map())); | | 196 | + const cached = models.get(keyPrefix); | | 197 | + if (cached !== undefined) return cached; | | 198 | + const parsedSlices = slices.map((slice) => { | | 199 | + let hash = patchHashes.get(slice); | | 200 | + if (hash === undefined) patchHashes.set(slice, (hash = fnv1a32(slice.patch))); | | 201 | + // The cache key carries the theme, which the tokenizer caches against, and the patch's | | 202 | + // hash: a refreshed page reuses its cursor, so position alone would return a stale parse. | | 203 | + return parseSlice(slice, `${keyPrefix}:${slice.cursor ?? "first"}:${hash}`, ignoreWhitespace); | | 204 | + }); | | 205 | + const model: DiffModel = { | | 206 | + parsedSlices, | | 207 | + loadedFiles: orderDiffFilesLikeTree( | | 208 | + parsedSlices.flatMap((parsed) => | | 209 | + parsed?.kind === "files" ? orderDiffFiles(parsed.files) : [], | | 210 | + ), | | 211 | + ), | | 212 | + sourceFileStats: new Map( | | 213 | + parsedSlices.flatMap((parsed) => | | 214 | + parsed?.kind === "files" | | 215 | + ? parsed.files.map( | | 216 | + (file, index) => | | 217 | + [ | | 218 | + buildFileDiffRenderKey(file), | | 219 | + getDiffLineStat([parsed.sourceFiles[index] ?? file]), | | 220 | + ] as const, | | 221 | + ) | | 222 | + : [], | | 223 | + ), | | 224 | + ), | | 225 | + }; | | 226 | + models.set(keyPrefix, model); | | 227 | + return model; | | 228 | +} | | 229 | + | | 230 | +const threadsByPathCache = new WeakMap< | | 231 | + ReadonlyArray<PullRequestReviewThread>, | | 232 | + ReadonlyMap<string, ReadonlyArray<PullRequestReviewThread>> | | 233 | +>(); | | 234 | + | | 235 | +function reviewThreadsByPath(threads: ReadonlyArray<PullRequestReviewThread>) { | | 236 | + let byPath = threadsByPathCache.get(threads); | | 237 | + if (byPath === undefined) { | | 238 | + const grouped = new Map<string, PullRequestReviewThread[]>(); | | 239 | + for (const thread of threads) { | | 240 | + const list = grouped.get(thread.path); | | 241 | + if (list) list.push(thread); | | 242 | + else grouped.set(thread.path, [thread]); | | 243 | + } | | 244 | + threadsByPathCache.set(threads, (byPath = grouped)); | | 245 | + } | | 246 | + return byPath; | | 247 | +} | | 248 | + | 179 | 249 | interface FileViewedToggleState { | 180 | 250 | readonly enabled: boolean; | 181 | 251 | readonly isViewed: (path: string) => boolean; | @@ -491,20 +561,10 @@ function PullRequestCodeTab({ | 491 | 561 | // Agent context is local, so it does not require host comment permission. | 492 | 562 | const canSelectLines = | 493 | 563 | commit === null && (review.inlineComment || onAddToAgentSelection !== undefined); | 494 | | - // The cache key carries the theme, which is what the tokenizer caches against, so a theme | 495 | | - // change is still a fresh parse. The patch's own hash is part of it too: a refreshed page | 496 | | - // reuses its cursor, and a key of position alone would hand back the parse it replaced. | 497 | | - const parsedSlices = loadedSlices.map((slice) => | 498 | | - parseSlice( | 499 | | - slice, | 500 | | - `pull-request:${scopeKey}:${resolvedTheme}:${ignoreWhitespace}:${slice.cursor ?? "first"}:${fnv1a32(slice.patch)}`, | 501 | | - ignoreWhitespace, | 502 | | - ), | 503 | | - ); | 504 | | - const loadedFiles = orderDiffFilesLikeTree( | 505 | | - parsedSlices.flatMap((parsed) => | 506 | | - parsed?.kind === "files" ? orderDiffFiles(parsed.files) : [], | 507 | | - ), | | 564 | + const { parsedSlices, loadedFiles, sourceFileStats } = diffModel( | | 565 | + loadedSlices, | | 566 | + `pull-request:${scopeKey}:${resolvedTheme}:${ignoreWhitespace}`, | | 567 | + ignoreWhitespace, | 508 | 568 | ); | 509 | 569 | const testFileCount = loadedFiles.filter((file) => | 510 | 570 | isTestChangedFile(resolveFileDiffPath(file)), | @@ -523,33 +583,16 @@ function PullRequestCodeTab({ | 523 | 583 | slice.omittedFileStats.map((file) => [file.path, file] as const), | 524 | 584 | ), | 525 | 585 | ); | 526 | | - const sourceFileStats = new Map( | 527 | | - parsedSlices.flatMap((parsed) => | 528 | | - parsed?.kind === "files" | 529 | | - ? parsed.files.map( | 530 | | - (file, index) => | 531 | | - [ | 532 | | - buildFileDiffRenderKey(file), | 533 | | - getDiffLineStat([parsed.sourceFiles[index] ?? file]), | 534 | | - ] as const, | 535 | | - ) | 536 | | - : [], | 537 | | - ), | 538 | | - ); | 539 | 586 | const fileTreeEntries = diffFileTreeEntries(files); | | 587 | + const threadsByPath = reviewThreadsByPath(detail.reviewThreads); | 540 | 588 | // File membership does not guarantee a rendered hunk for the thread. | 541 | 589 | const placedThreadIds = (() => { | 542 | 590 | const placed = new Set<string>(); | 543 | 591 | // Commit diffs use different line coordinates; list conversations separately. | 544 | 592 | if (commit !== null) return placed; | 545 | 593 | for (const file of files) { | 546 | | - const path = resolveFileDiffPath(file); | 547 | | - for (const thread of detail.reviewThreads) { | 548 | | - if ( | 549 | | - thread.path === path && | 550 | | - thread.line !== null && | 551 | | - isLineInFileDiff(file, thread.side, thread.line) | 552 | | - ) { | | 594 | + for (const thread of threadsByPath.get(resolveFileDiffPath(file)) ?? []) { | | 595 | + if (thread.line !== null && isLineInFileDiff(file, thread.side, thread.line)) { | 553 | 596 | placed.add(thread.id); | 554 | 597 | } | 555 | 598 | } | @@ -576,9 +619,8 @@ function PullRequestCodeTab({ | 576 | 619 | return created; | 577 | 620 | }; | 578 | 621 |
| 579 | | - for (const thread of detail.reviewThreads) { | 580 | | - if (thread.path !== path || thread.line === null) continue; | 581 | | - if (!placedThreadIds.has(thread.id)) continue; | | 622 | + for (const thread of threadsByPath.get(path) ?? []) { | | 623 | + if (thread.line === null || !placedThreadIds.has(thread.id)) continue; | 582 | 624 | groupAt(thread.side, thread.line).threads.push(thread); | 583 | 625 | } | 584 | 626 | if (commit === null) { | |
|