fix(server): attribute V2 turn diffs to the turn-start snapshot #11528
main fromrefs/pull/11528/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
emmsixx(GitHub profile, opens in a new tab) approved these changes
- apps/server/src/orchestration-v2/testkit/ProviderReplayHarness.ts line 395OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -392,3 +392,4 @@392392 Layer.provide(393393 Layer.mergeAll(394394 runFinalizationServiceProvided,395+ checkpointCaptureServiceProvided,apps/server/src/orchestration-v2/runtimeLayer.ts line 256OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -253,3 +253,4 @@253253 Layer.provide(254254 Layer.mergeAll(255255 runFinalizationServiceProvided,256+ checkpointCaptureServiceProvided,
- apps/server/src/orchestration-v2/EffectWorker.ts line 27OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -24,3 +24,4 @@2424 type OrchestrationEffectV2,2525 } from "./EffectOutbox.ts";2626 import { CheckpointRollbackServiceV2 } from "./CheckpointRollbackService.ts";27+import { CheckpointCaptureServiceV2 } from "./CheckpointCaptureService.ts";
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:L
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XXL
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:XXL
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- apps/server/src/storageCleanup.ts line 119OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -116,4 +116,4 @@116116 );117117 }118118119-export const make = Effect.gen(function* () {119+const make = Effect.gen(function* () {
- apps/server/src/storageCleanup.ts line 44OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -41,4 +41,4 @@4141 import * as GitVcsDriver from "./vcs/GitVcsDriver.ts";4242 import { withWorkspaceLease } from "./workspace/workspaceLease.ts";434344-export class StorageCleanup extends Context.Service<44+class StorageCleanup extends Context.Service<
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:L
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XXL
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:XXL
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:L
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XXL
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:XXL
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- apps/server/src/orchestration-v2/CheckpointService.ts lines 119 to 122OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -115,3 +116,7 @@115116116117 const isCheckpointRestoreError = Schema.is(CheckpointRestoreError);117118119+export class CheckpointBaselineCleanupError extends Schema.TaggedError<CheckpointBaselineCleanupError>()(120+ "CheckpointBaselineCleanupError",121+ { scopeId: CheckpointScopeId, ordinalWithinScope: Schema.Number, cause: Schema.Defect() },122+) {}
- apps/server/src/checkpointing/CheckpointDiffQuery.ts line 163OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -160,16 +159,5 @@160- ? (() => {161- // The root scope is shared by every run in this thread. Its162- // runId tracks the latest owner, while ordinal zero stays the baseline.163- const firstScope = projection.checkpointScopes.find(164- (scope) => scope.kind === "root_run",165- );166- return firstScope === undefined167- ? undefined168- : checkpointRefForScopeOrdinal({169- scopeId: firstScope.id,170- ordinalWithinScope: 0,171- });172- })()173- : readyCheckpoints.find((checkpoint) => checkpoint.appRunOrdinal === input.fromTurnCount)174- ?.ref;175- if (fromCheckpointRef === undefined) {159+ const startRef = checkpointStartRef(toCheckpoint.ref);160+ // A captured turn-start snapshot is itself the correct single-turn161+ // baseline, including when the previous turn left no checkpoint.162+ const turnBaselineRef =163+ input.toTurnCount === input.fromTurnCount + 1 &&
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:L
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XXL
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:XXL
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:L
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XXL
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:XXL
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- apps/server/src/orchestration-v2/ProviderRuntimeRecoveryService.ts line 323OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -235,3 +235,6 @@235235 });236236 }237237 for (const run of runs) {238+ const node = projection.nodes.find((candidate) => candidate.id === run.rootNodeId);239+ if (node?.checkpointScopeId != null) {240+ effects.push({
- apps/server/src/vcs/GitVcsDriver.ts line 561OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -551,3 +551,11 @@551551 : {}),552552 });553553554+ // Whether a .git entry (directory or worktree pointer file) exists at the555+ // workspace root or any ancestor — filesystem evidence that repository556+ // metadata is present even when git cannot read it.557+ const hasGitMetadataEntry = (cwd: string) =>558+ Effect.gen(function* () {559+ let directory = cwd;560+ while (true) {561+ if (yield* fileSystem.exists(path.join(directory, ".git"))) {
- apps/server/src/vcs/GitVcsDriver.ts line 602OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -557,0 +582,21 @@582+ timeoutMs: 5_000,583+ maxOutputBytes: 4_096,584+ env: { LC_ALL: "C" },585+ },586+ );587+ if (insideWorkTreeResult.exitCode !== 0) {588+ const detectionFailure = new VcsProcessExitError({589+ operation: "GitVcsDriver.detectRepository.insideWorkTree",590+ command: "git rev-parse",591+ cwd,592+ exitCode: insideWorkTreeResult.exitCode,593+ detail: insideWorkTreeResult.stderr.trim() || "Repository detection failed.",594+ });595+ // "not a git repository" is also emitted when .git metadata exists but596+ // is unusable (unreadable HEAD, broken worktree pointer, unreachable597+ // common dir). Absence is only confirmed when no .git entry exists in598+ // the workspace ancestry — and only when that lookup itself succeeds.599+ if (600+ !insideWorkTreeResult.stderr.includes("not a git repository") ||601+ (yield* hasGitMetadataEntry(cwd).pipe(602+ Effect.catchTag("PlatformError", () => Effect.succeed(true)),
- apps/server/src/vcs/GitVcsDriver.ts lines 593 to 595OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -553,0 +575,21 @@575+ Effect.flatMap((present) =>576+ present577+ ? Effect.succeed(true)578+ : fileSystem.readLink(entry).pipe(579+ Effect.as(true),580+ Effect.catchTag("PlatformError", (error) =>581+ error.reason._tag === "NotFound" ? Effect.succeed(false) : Effect.fail(error),582+ ),583+ ),584+ ),585+ );586+587+ // Whether a .git entry exists along the workspace's physical ancestry —588+ // filesystem evidence that repository metadata is present even when git589+ // cannot read it. Git resolves discovery from the real working directory,590+ // so a symlinked cwd must walk its resolved path, not the lexical one.591+ const hasGitMetadataEntry = (cwd: string) =>592+ Effect.gen(function* () {593+ let directory = yield* fileSystem594+ .realPath(cwd)595+ .pipe(Effect.catchTag("PlatformError", () => Effect.succeed(cwd)));apps/server/src/vcs/GitVcsDriver.ts lines 580 to 582OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -553,0 +562,21 @@562+ GIT_WORK_TREE: undefined,563+ GIT_COMMON_DIR: undefined,564+ GIT_INDEX_FILE: undefined,565+ GIT_OBJECT_DIRECTORY: undefined,566+ GIT_ALTERNATE_OBJECT_DIRECTORIES: undefined,567+ GIT_CEILING_DIRECTORIES: undefined,568+ };569+570+ // Whether the path itself exists, including as a symlink — exists()571+ // resolves the target, so a dangling .git link would look absent even572+ // though the entry is repository metadata.573+ const entryExists = (entry: string) =>574+ fileSystem.exists(entry).pipe(575+ Effect.flatMap((present) =>576+ present577+ ? Effect.succeed(true)578+ : fileSystem.readLink(entry).pipe(579+ Effect.as(true),580+ Effect.catchTag("PlatformError", (error) =>581+ error.reason._tag === "NotFound" ? Effect.succeed(false) : Effect.fail(error),582+ ),
- apps/server/src/vcs/GitVcsDriver.ts line 657OutdatedResolvedby saphid(GitHub profile, opens in a new tab)@@ -556,2 +613,20 @@556613 )(function* (cwd) {557- if (!(yield* isInsideWorkTree(cwd))) {614+ const insideWorkTreeResult = yield* gitCommand(615+ vcsProcess,616+ "GitVcsDriver.detectRepository.insideWorkTree",617+ cwd,618+ ["rev-parse", "--is-inside-work-tree"],619+ {620+ allowNonZeroExit: true,621+ timeoutMs: 5_000,622+ maxOutputBytes: 4_096,623+ env: detectionEnv,624+ },625+ );626+ if (insideWorkTreeResult.exitCode !== 0) {627+ const detectionFailure = new VcsProcessExitError({628+ operation: "GitVcsDriver.detectRepository.insideWorkTree",629+ command: "git rev-parse",630+ cwd,631+ exitCode: insideWorkTreeResult.exitCode,632+ detail: insideWorkTreeResult.stderr.trim() || "Repository detection failed.",
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:L
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XL
- apps/server/src/vcs/GitVcsDriver.ts line 1337OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -1199,11 +1305,13 @@1199130512001306 deleteCheckpointRefs: Effect.fn("GitVcsDriver.checkpoints.deleteCheckpointRefs")(12011307 function* (input) {1308+ // update-ref -d exits 0 for refs that do not exist, so nonzero exits1309+ // are real failures (locks, permissions) and must propagate.12021310 yield* Effect.forEach(12031311 input.checkpointRefs,12041312 (checkpointRef) =>12051313 execute({12061314 operation: "GitVcsDriver.checkpoints.deleteCheckpointRefs",12071315 cwd: input.cwd,12081316 args: ["update-ref", "-d", checkpointRef],1209- allowNonZeroExit: true,1317+ env: repositoryEnv,
- apps/server/src/orchestration-v2/CheckpointService.ts line 479OutdatedResolvedby saphid(GitHub profile, opens in a new tab)@@ -440,3 +470,10 @@440470 });441471 }442472473+ const startRef = checkpointStartRef(checkpointRef);474+ const startRefExists = yield* checkpointStore475+ .hasCheckpointRef({476+ cwd: input.scope.cwd,477+ checkpointRef: startRef,478+ })479+ .pipe(
juliusmarminge closed this
juliusmarminge added labelstriage:keep-open
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed