A desktop coding agent with free access to frontier models.
TypeScript
perf(capture): finalize git metadata at session end
Task Builder333288ffe3eb
diff --git a/apps/server/src/session-uploader.test.ts b/apps/server/src/session-uploader.test.tsindex 832d11c0..3483ebf8 100644--- a/apps/server/src/session-uploader.test.ts+++ b/apps/server/src/session-uploader.test.ts@@ -544,7 +544,10 @@ describe("session uploader envelope v2", () => {await sessionUploader.stop();const start = uploads.find((item) => item.snapshot_type === "start")!;- const gitBlock = start.workspace.git as {+ const end = uploads.find((item) => item.snapshot_type === "end")!;+ expect(start.workspace.git).toBeNull();+ expect(start.workspace.git_deferred).toBe("session_end");+ const gitBlock = end.workspace.git as {commit: string; branch: string; dirty: boolean; upstream: string | null; ahead: number | null; behind: number | null;remotes: Array<{ name: string; url: string }>; recent_commits: Array<{ sha: string; at: string; subject: string }>;status: Array<{ code: string; path: string }>; diff: string; diff_truncated: boolean;@@ -599,7 +602,8 @@ describe("session uploader envelope v2", () => {sessionUploader.startSession("session-v2-bigdiff-1", "workspace-bigdiff", root);await sessionUploader.stop();- const gitBlock = uploads[0]!.workspace.git as { diff: string; diff_truncated: boolean };+ const end = uploads.find((item) => item.snapshot_type === "end")!;+ const gitBlock = end.workspace.git as { diff: string; diff_truncated: boolean };expect(gitBlock.diff_truncated).toBe(true);expect(Buffer.byteLength(gitBlock.diff)).toBeLessThanOrEqual(MAX_UPLOAD_DIFF_BYTES);expect(gitBlock.diff).toContain("+line 0 ");@@ -2547,13 +2551,14 @@ describe("session uploader scrubber parity: second-sample refinements", () => {await sessionUploader.stop();const start = uploads.find((item) => item.snapshot_type === "start")!;+ const end = uploads.find((item) => item.snapshot_type === "end")!;const content = (path: string) => start.files.find((file) => file.path === path)?.content;// Workspace files: .py, .patch and .diff are source, so a bare name stays and a quoted literal goes.expect(content("app/settings.py")).toBe("import config\npassword = hunter2abc\n");expect(content("fix.patch")).toBe(PATCH.replace('"hunter2abc"', '"[REDACTED]"'));expect(content("notes.diff")).toBe("+password = hunter2abc\n");// The envelope's git diff scrubs the .py section as source, as the file itself.- const gitBlock = start.workspace.git as { diff: string };+ const gitBlock = end.workspace.git as { diff: string };expect(gitBlock.diff).toContain("+password = hunter2abc");expect(gitBlock.diff).not.toContain("[REDACTED]");});diff --git a/apps/server/src/session-uploader.ts b/apps/server/src/session-uploader.tsindex b7898b2c..9f075aff 100644--- a/apps/server/src/session-uploader.ts+++ b/apps/server/src/session-uploader.ts@@ -5571,10 +5571,13 @@ export class SessionUploader {return state.changesHeld && uploading;}- /** Whether anything could have moved since the last accepted snapshot; one `git rev-parse` at most. */- private async hasPendingChanges(state: SessionState): Promise<boolean> {+ /** Whether anything could have moved since the last accepted snapshot. Git history is finalized at session end. */+ private hasPendingChanges(state: SessionState): boolean {if (state.dirtyOverflow || state.watchMode !== "watching" || state.dirty.size > 0 || this.journalHasChanges(state)) return true;- return (await gitHead(state.root)) !== state.lastHead;+ // A commit with no working-tree change is represented by the final Git+ // block. Polling HEAD for every turn made Git a recurring capture cost and+ // did not add files to the workspace snapshot.+ return false;}private deferChange(state: SessionState, trigger: ChangeTrigger, wait: number): void {@@ -5761,7 +5764,12 @@ export class SessionUploader {// Collect the cheap relevance evidence before the listing cap. A late// alphabetical path named by a tool or git status must not disappear// merely because the workspace has many files.- const preGitPaths = targeted ? new Set<string>() : await gitPriorityPaths(state.root);+ // Git status is needed once for the initial cap-priority plan and once+ // for the final snapshot. Change snapshots use watcher, journal and tool+ // evidence instead of spawning Git on every turn.+ const preGitPaths = type === "change"+ ? new Set<string>()+ : await gitPriorityPaths(state.root);const preScanPaths = new Set<string>([...state.relevance.keys(),...state.touchedPaths,@@ -5797,16 +5805,17 @@ export class SessionUploader {if (state.turnStartedAt !== null) state.turnWrittenPaths.set(path, Date.now());}}- // A change capture that found nothing moved stops at one `git rev-parse`- // (a commit changes history without touching a file); the full git block- // with its status, log and diff is read only for a snapshot that goes out.- if (type === "change" && scan.changed !== null && scan.changed.size === 0 && scan.removed === 0 && !this.journalHasChanges(state)- && (await gitHead(state.root)) === state.lastHead) {+ // A change capture with no filesystem or journal evidence has nothing+ // to upload. Git-only history changes are represented by the final+ // session snapshot, where the complete status and diff are collected.+ if (type === "change" && scan.changed !== null && scan.changed.size === 0 && scan.removed === 0 && !this.journalHasChanges(state)) {accepted = true;return false;}- // Its status and diff name the files a capped snapshot must keep.- const git = await collectGitBlock(state.root);+ // The complete Git summary (status, upstream, recent commits and diff)+ // is intentionally collected once, at session end. Earlier snapshots+ // still carry manifests and turn diffs, which are the replay baseline.+ const git = type === "end" ? await collectGitBlock(state.root) : null;const gitPaths = new Set<string>([...preGitPaths,...snapshotPriorityPaths([], git),@@ -5833,6 +5842,7 @@ export class SessionUploader {denied_file_count: deniedCount,root_name: rootName,git: { commit: git?.commit ?? null, branch: git?.branch ?? null, dirty: git ? String(git.dirty) : "false" },+ git_deferred: type !== "end",});const leading: UploadFile[] = [{ path: "__omnirush__/workspace.json", content: metadata, sha256: sha256Hex(metadata) }];if (journal.length > 0) {@@ -5845,7 +5855,13 @@ export class SessionUploader {}const filesScope: "full" | "changed" = type === "start" ? "full" : "changed";const extras: Record<string, unknown> = {- workspace: { root_name: rootName, git, ...(git ? {} : await gitSkippedField()), ...(type === "start" && !git ? await projectArchiveField(state.root) : {}) },+ workspace: {+ root_name: rootName,+ git,+ ...(git ? {} : await gitSkippedField()),+ ...(type === "start" && !git ? await projectArchiveField(state.root) : {}),+ ...(type === "end" ? {} : { git_deferred: "session_end" }),+ },environment,touched_paths: touchedPaths,files_scope: filesScope,@@ -5949,7 +5965,7 @@ export class SessionUploader {state.extras = extraEntries;state.turnManifest ??= turnBaseline(manifest, state.turnStartedAt, [previous]);state.listing = { denied: scan.deniedCount, truncated: scan.manifestTruncated };- state.lastHead = git?.commit ?? null;+ if (git) state.lastHead = git.commit;if (journal.length > 0) this.acknowledgeJournal(state, journal);if (type === "change") state.lastChangeAt = Date.now();return true;