GeezerVison is showing github.com — fix(server): checkpoints skip a project folder its parent repo ignore… · pingdotgg/t3code@6d266ea
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/CheckpointService.test.ts +78Lines changed: 78 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 8 | 8 | ThreadId, | 9 | 9 | type OrchestrationV2CheckpointScope, | 10 | 10 | VcsProcessTimeoutError, | | 11 | + VcsUnsupportedOperationError, | 11 | 12 | } from "@t3tools/contracts"; | 12 | 13 | import * as DateTime from "effect/DateTime"; | 13 | 14 | import * as Effect from "effect/Effect"; | @@ -103,3 +104,80 @@ it.effect.each([false, true, "interrupt"] as const)( | 103 | 104 | }).pipe(Effect.provide(layerTest)); | 104 | 105 | }, | 105 | 106 | ); | | 107 | + | | 108 | +it.effect( | | 109 | + "skips unsupported baseline and turn checkpoints without swallowing capture failures", | | 110 | + () => | | 111 | + Effect.gen(function* () { | | 112 | + const scope: OrchestrationV2CheckpointScope = { | | 113 | + id: CheckpointScopeId.make("checkpoint-scope:capture-failure"), | | 114 | + threadId: ThreadId.make("thread:capture-failure"), | | 115 | + runId: RunId.make("run:capture-failure:1"), | | 116 | + nodeId: NodeId.make("node:capture-failure:1"), | | 117 | + parentScopeId: null, | | 118 | + providerThreadId: ProviderThreadId.make("provider-thread:capture-failure"), | | 119 | + kind: "root_run", | | 120 | + ordinalWithinParent: 0, | | 121 | + advancesAppRunCount: true, | | 122 | + cwd: "/repo/ignored", | | 123 | + createdAt: DateTime.makeUnsafe("2026-07-28T00:00:00.000Z"), | | 124 | + }; | | 125 | + for (const captureError of [ | | 126 | + new VcsProcessTimeoutError({ | | 127 | + operation: "test.capture", | | 128 | + command: "git", | | 129 | + cwd: scope.cwd, | | 130 | + timeoutMs: 30000, | | 131 | + }), | | 132 | + new VcsUnsupportedOperationError({ | | 133 | + operation: "test.capture", | | 134 | + kind: "git", | | 135 | + detail: "The workspace directory is ignored by its Git repository.", | | 136 | + }), | | 137 | + ]) { | | 138 | + const layerTest = CheckpointService.layer.pipe( | | 139 | + Layer.provide( | | 140 | + Layer.mergeAll( | | 141 | + IdAllocator.layer, | | 142 | + Layer.mock(CheckpointStore.CheckpointStore)({ | | 143 | + isGitRepository: () => Effect.succeed(true), | | 144 | + hasCheckpointRef: () => Effect.succeed(false), | | 145 | + captureCheckpoint: () => Effect.fail(captureError), | | 146 | + }), | | 147 | + ), | | 148 | + ), | | 149 | + Layer.provideMerge(NodeCrypto.layer), | | 150 | + ); | | 151 | + yield* Effect.gen(function* () { | | 152 | + const checkpoints = yield* CheckpointService.CheckpointServiceV2; | | 153 | + const baseline = yield* Effect.result( | | 154 | + checkpoints.captureBaseline({ scope, ordinalWithinScope: 0 }), | | 155 | + ); | | 156 | + const checkpoint = yield* checkpoints.capture({ | | 157 | + scope, | | 158 | + ordinalWithinScope: 1, | | 159 | + runId: scope.runId!, | | 160 | + nodeId: scope.nodeId!, | | 161 | + appRunOrdinal: 1, | | 162 | + capturedAt: scope.createdAt, | | 163 | + }); | | 164 | + | | 165 | + assert.deepEqual( | | 166 | + { baseline: baseline._tag, turn: checkpoint.status, files: checkpoint.files }, | | 167 | + captureError._tag === "VcsUnsupportedOperationError" | | 168 | + ? { baseline: "Success", turn: "missing", files: [] } | | 169 | + : { baseline: "Failure", turn: "error", files: [] }, | | 170 | + ); | | 171 | + if (baseline._tag === "Failure") { | | 172 | + assert.strictEqual(baseline.failure.cause, captureError); | | 173 | + } else { | | 174 | + const materialized = yield* checkpoints.materializeBaselineCheckpoint({ | | 175 | + scope, | | 176 | + ordinalWithinScope: 0, | | 177 | + }); | | 178 | + assert.strictEqual(materialized.status, "missing"); | | 179 | + } | | 180 | + }).pipe(Effect.provide(layerTest)); | | 181 | + } | | 182 | + }), | | 183 | +); |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/CheckpointService.ts +18-9Lines changed: 18 additions & 9 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -284,10 +284,16 @@ export const layer: Layer.Layer< | 284 | 284 | return; | 285 | 285 | } | 286 | 286 |
| 287 | | - yield* checkpointStore.captureCheckpoint({ | 288 | | - cwd: input.scope.cwd, | 289 | | - checkpointRef, | 290 | | - }); | | 287 | + yield* checkpointStore | | 288 | + .captureCheckpoint({ | | 289 | + cwd: input.scope.cwd, | | 290 | + checkpointRef, | | 291 | + }) | | 292 | + .pipe( | | 293 | + Effect.catchTags({ | | 294 | + VcsUnsupportedOperationError: () => Effect.void, | | 295 | + }), | | 296 | + ); | 291 | 297 | }), | 292 | 298 | ).pipe( | 293 | 299 | Effect.mapError( | @@ -394,23 +400,26 @@ export const layer: Layer.Layer< | 394 | 400 | }); | 395 | 401 | } | 396 | 402 |
| 397 | | - const captured = yield* checkpointStore | | 403 | + const captureStatus = yield* checkpointStore | 398 | 404 | .captureCheckpoint({ | 399 | 405 | cwd: input.scope.cwd, | 400 | 406 | checkpointRef, | 401 | 407 | }) | 402 | 408 | .pipe( | 403 | | - Effect.as(true), | | 409 | + Effect.as("ready" as const), | | 410 | + Effect.catchTags({ | | 411 | + VcsUnsupportedOperationError: () => Effect.succeed("missing" as const), | | 412 | + }), | 404 | 413 | Effect.catch((cause) => | 405 | 414 | Effect.logWarning("orchestration V2 checkpoint capture failed", { | 406 | 415 | scopeId: input.scope.id, | 407 | 416 | checkpointRef, | 408 | 417 | cause: String(cause), | 409 | | - }).pipe(Effect.as(false)), | | 418 | + }).pipe(Effect.as("error" as const)), | 410 | 419 | ), | 411 | 420 | ); | 412 | 421 |
| 413 | | - if (!captured) { | | 422 | + if (captureStatus !== "ready") { | 414 | 423 | return makeCheckpoint({ | 415 | 424 | id: checkpointId, | 416 | 425 | scope: input.scope, | @@ -420,7 +429,7 @@ export const layer: Layer.Layer< | 420 | 429 | ordinalWithinScope: input.ordinalWithinScope, | 421 | 430 | appRunOrdinal: input.appRunOrdinal, | 422 | 431 | ref: checkpointRef, | 423 | | - status: "error", | | 432 | + status: captureStatus, | 424 | 433 | files: [], | 425 | 434 | capturedAt: input.capturedAt, | 426 | 435 | }); | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/vcs/GitVcsDriver.test.ts +95Lines changed: 95 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -264,6 +264,9 @@ it.effect("checkpoint capture still fails when a clean filter rejects a file", ( | 264 | 264 | ); | 265 | 265 |
| 266 | 266 | assert.strictEqual(result._tag, "Failure"); | | 267 | + if (result._tag === "Failure") { | | 268 | + assert.strictEqual(result.failure._tag, "VcsProcessExitError"); | | 269 | + } | 267 | 270 | assert.deepEqual(yield* fileSystem.readFile(path.join(cwd, ".git", "index")), originalIndex); | 268 | 271 | assert.isFalse(yield* driver.checkpoints.hasCheckpointRef({ cwd, checkpointRef })); | 269 | 272 | }).pipe(Effect.scoped, Effect.provide(layerGitContract)), | @@ -299,6 +302,98 @@ it.effect("checkpoint capture refuses a truncated nested repository listing", () | 299 | 302 | }).pipe(Effect.scoped, Effect.provide(layerGitContract)), | 300 | 303 | ); | 301 | 304 |
| | 305 | +it.effect("checkpoint capture skips an ignored project while keeping its allowed sibling", () => | | 306 | + Effect.gen(function* () { | | 307 | + const fs = yield* FileSystem.FileSystem; | | 308 | + const path = yield* Path.Path; | | 309 | + const driver = yield* GitVcsDriver.makeVcsDriverShape(); | | 310 | + const parent = yield* fs.makeTempDirectoryScoped({ prefix: "t3-checkpoint-ignored-" }); | | 311 | + const { git } = yield* makeCheckpointFixture(driver, parent); | | 312 | + yield* fs.writeFileString( | | 313 | + path.join(parent, ".gitignore"), | | 314 | + "*\n!.gitignore\n!file.txt\n!keep/\n!keep/**\n", | | 315 | + ); | | 316 | + const ignoredCwd = path.join(parent, "ignored"); | | 317 | + const keepCwd = path.join(parent, "keep"); | | 318 | + yield* fs.makeDirectory(ignoredCwd); | | 319 | + yield* fs.makeDirectory(keepCwd); | | 320 | + yield* fs.writeFileString(path.join(ignoredCwd, "secret.txt"), "private\n"); | | 321 | + yield* fs.writeFileString(path.join(keepCwd, "new.txt"), "new\n"); | | 322 | + const originalIndex = yield* fs.readFile(path.join(parent, ".git", "index")); | | 323 | + const ignoredRef = CheckpointRef.make("refs/t3/checkpoints/ignored"); | | 324 | + const keepRef = CheckpointRef.make("refs/t3/checkpoints/keep"); | | 325 | + | | 326 | + const ignored = yield* Effect.result( | | 327 | + driver.checkpoints.captureCheckpoint({ cwd: ignoredCwd, checkpointRef: ignoredRef }), | | 328 | + ); | | 329 | + yield* driver.checkpoints.captureCheckpoint({ cwd: keepCwd, checkpointRef: keepRef }); | | 330 | + | | 331 | + assert.strictEqual((yield* git(["show", `${keepRef}:keep/new.txt`])).stdout, "new\n"); | | 332 | + assert.strictEqual((yield* git(["ls-tree", "-r", keepRef, "--", "ignored"])).stdout, ""); | | 333 | + assert.isFalse( | | 334 | + yield* driver.checkpoints.hasCheckpointRef({ cwd: parent, checkpointRef: ignoredRef }), | | 335 | + ); | | 336 | + assert.deepEqual(yield* fs.readFile(path.join(parent, ".git", "index")), originalIndex); | | 337 | + assert.strictEqual(ignored._tag, "Failure"); | | 338 | + if (ignored._tag === "Failure") { | | 339 | + assert.strictEqual(ignored.failure._tag, "VcsUnsupportedOperationError"); | | 340 | + } | | 341 | + }).pipe(Effect.scoped, Effect.provide(layerGitContract)), | | 342 | +); | | 343 | + | | 344 | +it.effect.each([ | | 345 | + { tracking: "committed-only", committed: ["committed.txt"], staged: [] }, | | 346 | + { tracking: "staged-only", committed: [], staged: ["staged.txt"] }, | | 347 | + { tracking: "mixed", committed: ["committed.txt"], staged: ["staged.txt"] }, | | 348 | +])( | | 349 | + "checkpoint capture keeps $tracking tracked edits but excludes new files in a project ignored later", | | 350 | + ({ committed, staged }) => | | 351 | + Effect.gen(function* () { | | 352 | + const fs = yield* FileSystem.FileSystem; | | 353 | + const path = yield* Path.Path; | | 354 | + const driver = yield* GitVcsDriver.makeVcsDriverShape(); | | 355 | + const parent = yield* fs.makeTempDirectoryScoped({ prefix: "t3-checkpoint-ignored-later-" }); | | 356 | + const { git, checkpointRef } = yield* makeCheckpointFixture(driver, parent); | | 357 | + const cwd = path.join(parent, "sub"); | | 358 | + yield* fs.makeDirectory(cwd); | | 359 | + for (const file of committed) { | | 360 | + yield* fs.writeFileString(path.join(cwd, file), "committed\n"); | | 361 | + yield* git(["add", `sub/${file}`]); | | 362 | + } | | 363 | + if (committed.length > 0) { | | 364 | + yield* git(["commit", "-m", "track project"]); | | 365 | + } | | 366 | + for (const file of staged) { | | 367 | + yield* fs.writeFileString(path.join(cwd, file), "staged\n"); | | 368 | + yield* git(["add", `sub/${file}`]); | | 369 | + } | | 370 | + const tracked = [...committed, ...staged]; | | 371 | + yield* fs.writeFileString(path.join(parent, ".gitignore"), "sub/\n"); | | 372 | + for (const file of tracked) { | | 373 | + yield* fs.writeFileString(path.join(cwd, file), `${file} working\n`); | | 374 | + } | | 375 | + yield* fs.writeFileString(path.join(cwd, "secret.txt"), "private\n"); | | 376 | + const originalIndex = yield* fs.readFile(path.join(parent, ".git", "index")); | | 377 | + | | 378 | + const captured = yield* Effect.result( | | 379 | + driver.checkpoints.captureCheckpoint({ cwd, checkpointRef }), | | 380 | + ); | | 381 | + | | 382 | + assert.deepEqual(yield* fs.readFile(path.join(parent, ".git", "index")), originalIndex); | | 383 | + if (captured._tag === "Failure") return yield* captured.failure; | | 384 | + assert.strictEqual( | | 385 | + (yield* git(["ls-tree", "-r", "--name-only", checkpointRef, "--", "sub"])).stdout, | | 386 | + tracked.map((file) => `sub/${file}\n`).join(""), | | 387 | + ); | | 388 | + for (const file of tracked) { | | 389 | + assert.strictEqual( | | 390 | + (yield* git(["show", `${checkpointRef}:sub/${file}`])).stdout, | | 391 | + `${file} working\n`, | | 392 | + ); | | 393 | + } | | 394 | + }).pipe(Effect.scoped, Effect.provide(layerGitContract)), | | 395 | +); | | 396 | + | 302 | 397 | it.effect("checkpoint recovery refuses excessive candidates before probing", () => | 303 | 398 | Effect.gen(function* () { | 304 | 399 | const fs = yield* FileSystem.FileSystem; | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/vcs/GitVcsDriver.ts +61-1Lines changed: 61 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -13,6 +13,7 @@ import { ChildProcessSpawner } from "effect/process"; | 13 | 13 | import { | 14 | 14 | GitCommandError, | 15 | 15 | VcsProcessExitError, | | 16 | + VcsUnsupportedOperationError, | 16 | 17 | type VcsSwitchRefInput, | 17 | 18 | type VcsSwitchRefResult, | 18 | 19 | type VcsCreateRefInput, | @@ -965,6 +966,64 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* ( | 965 | 966 | } | 966 | 967 | } | 967 | 968 |
| | 969 | + const workspaceIgnored = (yield* filterIgnoredPaths(input.cwd, ["."])).length === 0; | | 970 | + if (workspaceIgnored) { | | 971 | + // HEAD omits staged-only paths. Seed just this workspace's additions, keeping | | 972 | + // unrelated staged changes and the scratch index's sparse flags untouched. | | 973 | + const additions = yield* execute({ | | 974 | + operation, | | 975 | + cwd: input.cwd, | | 976 | + args: [ | | 977 | + "-c", | | 978 | + "core.quotePath=true", | | 979 | + "diff", | | 980 | + "--cached", | | 981 | + "--raw", | | 982 | + "--no-abbrev", | | 983 | + "--no-renames", | | 984 | + "--no-relative", | | 985 | + "--ignore-submodules=none", | | 986 | + "--no-color", | | 987 | + "--no-ext-diff", | | 988 | + "--no-textconv", | | 989 | + "--ita-visible-in-index", | | 990 | + "--diff-filter=A", | | 991 | + "--", | | 992 | + ".", | | 993 | + ], | | 994 | + maxOutputBytes: WORKSPACE_FILES_MAX_OUTPUT_BYTES, | | 995 | + outputMode: "error", | | 996 | + }); | | 997 | + if (additions.stdout.length > 0) { | | 998 | + // Git's quoted paths round-trip through index-info, including non-UTF-8 names. | | 999 | + yield* execute({ | | 1000 | + operation, | | 1001 | + cwd: input.cwd, | | 1002 | + args: [...indexConfig, "-c", "index.sparse=false", "update-index", "--index-info"], | | 1003 | + stdin: additions.stdout.replace( | | 1004 | + /^:000000 ([0-7]{6}) 0+ ([0-9a-f]+) A\t/gm, | | 1005 | + "$1 $2\t", | | 1006 | + ), | | 1007 | + env: commitEnv, | | 1008 | + }); | | 1009 | + } | | 1010 | + const tracked = yield* execute({ | | 1011 | + operation, | | 1012 | + cwd: input.cwd, | | 1013 | + args: [...indexConfig, "ls-files", "--cached", "-z", "--", "."], | | 1014 | + env: commitEnv, | | 1015 | + maxOutputBytes: 1, | | 1016 | + outputMode: "truncate", | | 1017 | + }); | | 1018 | + if (tracked.stdout.length === 0) { | | 1019 | + return yield* new VcsUnsupportedOperationError({ | | 1020 | + operation, | | 1021 | + kind: "git", | | 1022 | + detail: "The workspace directory is ignored by its Git repository.", | | 1023 | + }); | | 1024 | + } | | 1025 | + } | | 1026 | + | 968 | 1027 | const stageFiles = (exclusions: ReadonlyArray<string>) => | 969 | 1028 | execute({ | 970 | 1029 | operation, | @@ -975,7 +1034,8 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* ( | 975 | 1034 | ...longPaths, | 976 | 1035 | "add", | 977 | 1036 | ...(sparseCheckout ? ["--sparse"] : []), | 978 | | - "-A", | | 1037 | + // add -A rejects ignored directories even when they contain tracked files. | | 1038 | + workspaceIgnored ? "-u" : "-A", | 979 | 1039 | "--", | 980 | 1040 | ".", | 981 | 1041 | ...exclusions, | |
|