GeezerVison is showing github.com — perf(server): background PR discovery no longer delays git status aft… · pingdotgg/t3code@bdb8d5d
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/ThreadPullRequestService.ts +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -20,6 +20,7 @@ import * as Stream from "effect/Stream"; | 20 | 20 |
| 21 | 21 | import * as BackgroundPolicy from "../background/BackgroundPolicy.ts"; | 22 | 22 | import * as GitManager from "../git/GitManager.ts"; | | 23 | +import * as GitVcsDriver from "../vcs/GitVcsDriver.ts"; | 23 | 24 | import * as ProjectStore from "./ProjectStore.ts"; | 24 | 25 | import * as PullRequestService from "../pullRequest/PullRequestService.ts"; | 25 | 26 | import * as RepositoryIdentityResolver from "../project/RepositoryIdentityResolver.ts"; | @@ -347,6 +348,7 @@ export const make = Effect.gen(function* () { | 347 | 348 |
| 348 | 349 | const worker = yield* makeDrainableWorker((request: RefreshRequest) => | 349 | 350 | synchronize(request).pipe( | | 351 | + Effect.provideService(GitVcsDriver.BackgroundGitWork, true), | 350 | 352 | Effect.catchCauseIf( | 351 | 353 | (cause) => !Cause.hasInterruptsOnly(cause), | 352 | 354 | (cause) => | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/ThreadSettlementService.ts +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -31,6 +31,7 @@ import * as PullRequestService from "../pullRequest/PullRequestService.ts"; | 31 | 31 | import * as ServerSettings from "../serverSettings.ts"; | 32 | 32 | import { forkParked } from "../serverActivation.ts"; | 33 | 33 | import * as TerminalManager from "../terminal/Manager.ts"; | | 34 | +import * as GitVcsDriver from "../vcs/GitVcsDriver.ts"; | 34 | 35 | import * as ProjectStore from "./ProjectStore.ts"; | 35 | 36 | import { sourceControlDefinitions } from "../sourceControl/sourceControlDefinitions.ts"; | 36 | 37 | import * as Orchestrator from "./Orchestrator.ts"; | @@ -556,6 +557,7 @@ export const make = Effect.gen(function* () { | 556 | 557 | threadId?: ThreadId, | 557 | 558 | ) => | 558 | 559 | sweep(mergedPullRequest, threadId).pipe( | | 560 | + Effect.provideService(GitVcsDriver.BackgroundGitWork, true), | 559 | 561 | Effect.catchCauseIf( | 560 | 562 | (cause) => !Cause.hasInterruptsOnly(cause), | 561 | 563 | (cause) => | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/vcs/GitVcsDriver.ts +5Lines changed: 5 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -301,6 +301,11 @@ export interface GitRemoteStatusOptions { | 301 | 301 | readonly refreshUpstream?: boolean; | 302 | 302 | } | 303 | 303 |
| | 304 | +/** Set by background discovery so its Git commands run in their own small lane, not the user's. */ | | 305 | +export const BackgroundGitWork = Context.Reference<boolean>("t3/vcs/BackgroundGitWork", { | | 306 | + defaultValue: () => false, | | 307 | +}); | | 308 | + | 304 | 309 | export class GitVcsDriver extends Context.Service< | 305 | 310 | GitVcsDriver, | 306 | 311 | { | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/vcs/GitVcsDriverCore.test.ts +50Lines changed: 50 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -14,6 +14,7 @@ import * as FileSystem from "effect/FileSystem"; | 14 | 14 | import * as Fiber from "effect/Fiber"; | 15 | 15 | import * as Layer from "effect/Layer"; | 16 | 16 | import * as Path from "effect/Path"; | | 17 | +import * as Queue from "effect/Queue"; | 17 | 18 | import * as PlatformError from "effect/PlatformError"; | 18 | 19 | import * as Ref from "effect/Ref"; | 19 | 20 | import * as Result from "effect/Result"; | @@ -129,6 +130,55 @@ const makeDriverReleasingLock = ( | 129 | 130 | return { driver, failures }; | 130 | 131 | }); | 131 | 132 |
| | 133 | +it.effect("runs background Git in its own lane so user commands never queue behind it", () => | | 134 | + Effect.gen(function* () { | | 135 | + const gate = yield* Deferred.make<void>(); | | 136 | + const starts = yield* Queue.unbounded<string>(); | | 137 | + const spawner = ChildProcessSpawner.make((command) => | | 138 | + Effect.gen(function* () { | | 139 | + yield* Queue.offer( | | 140 | + starts, | | 141 | + ChildProcess.isStandardCommand(command) ? String(command.args[0]) : "", | | 142 | + ); | | 143 | + return ChildProcessSpawner.makeHandle({ | | 144 | + ...makeSuccessfulHandle("ok"), | | 145 | + exitCode: Deferred.await(gate).pipe(Effect.as(ChildProcessSpawner.ExitCode(0))), | | 146 | + }); | | 147 | + }), | | 148 | + ); | | 149 | + const driver = yield* makeGitVcsDriverCore().pipe( | | 150 | + Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner), | | 151 | + Effect.provide(layerServerConfig), | | 152 | + ); | | 153 | + const run = (args: ReadonlyArray<string>) => | | 154 | + driver.execute({ operation: "test.gitLane", cwd: "/repo", args: [...args] }); | | 155 | + const background = yield* Effect.forEach( | | 156 | + Array.from({ length: 12 }), | | 157 | + () => run(["background"]), | | 158 | + { | | 159 | + concurrency: "unbounded", | | 160 | + }, | | 161 | + ).pipe(Effect.provideService(GitVcsDriver.BackgroundGitWork, true), Effect.forkChild); | | 162 | + const foreground = yield* Effect.forEach(Array.from({ length: 4 }), () => run(["foreground"]), { | | 163 | + concurrency: "unbounded", | | 164 | + }).pipe(Effect.forkChild); | | 165 | + | | 166 | + yield* TestClock.adjust("2 seconds"); | | 167 | + const started = yield* Queue.takeAll(starts); | | 168 | + assert.deepStrictEqual([...started].toSorted(), [ | | 169 | + "background", | | 170 | + "background", | | 171 | + "foreground", | | 172 | + "foreground", | | 173 | + "foreground", | | 174 | + "foreground", | | 175 | + ]); | | 176 | + yield* Deferred.succeed(gate, undefined); | | 177 | + assert.equal((yield* Fiber.join(background)).length, 12); | | 178 | + assert.equal((yield* Fiber.join(foreground)).length, 4); | | 179 | + }).pipe(Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))), | | 180 | +); | | 181 | + | 132 | 182 | describe("Git output collection", () => { | 133 | 183 | // Git writes in arbitrary chunk sizes; one byte per chunk splits every | 134 | 184 | // multibyte character across reads. | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/vcs/GitVcsDriverCore.ts +7-1Lines changed: 7 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -63,6 +63,7 @@ const branchBaseConfigKey = (branch: string) => `branch.${branch}.t3-merge-base` | 63 | 63 | */ | 64 | 64 | const legacyBranchBaseConfigKey = (branch: string) => `branch.${branch}.gh-merge-base`; | 65 | 65 | const gitProcesses = Semaphore.makeUnsafe(8); | | 66 | +const backgroundGitProcesses = Semaphore.makeUnsafe(2); | 66 | 67 | const WORKTREE_REMOVE_TIMEOUT_MS = Duration.toMillis(Duration.minutes(5)); | 67 | 68 | const DEFAULT_MAX_OUTPUT_BYTES = 1_000_000; | 68 | 69 | const OUTPUT_TRUNCATED_MARKER = "\n\n[truncated]"; | @@ -1123,7 +1124,12 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function* | 1123 | 1124 | (execution) => | 1124 | 1125 | input.timeoutMs === null || (input.timeoutMs ?? DEFAULT_TIMEOUT_MS) > DEFAULT_TIMEOUT_MS | 1125 | 1126 | ? execution | 1126 | | - : gitProcesses.withPermits(1)(execution), | | 1127 | + : Effect.gen(function* () { | | 1128 | + const lane = (yield* GitVcsDriver.BackgroundGitWork) | | 1129 | + ? backgroundGitProcesses | | 1130 | + : gitProcesses; | | 1131 | + return yield* lane.withPermits(1)(execution); | | 1132 | + }), | 1127 | 1133 | Effect.withSpan(input.operation, { | 1128 | 1134 | kind: "client", | 1129 | 1135 | attributes: { | |
|