A desktop coding agent with free access to frontier models.
TypeScript
fix(archive): keep a resumed touched chain without a base, and its paths, when the policy check fails
ogsamratda64965fa3a9
diff --git a/apps/server/src/session-archive/README.md b/apps/server/src/session-archive/README.mdindex f7ef20ae..a8e94d22 100644--- a/apps/server/src/session-archive/README.md+++ b/apps/server/src/session-archive/README.md@@ -319,7 +319,7 @@ against a loopback sink).- **Key and consent.** A folder base reuses the key from the probe it just made. With a kept answer it fetches the key in full, like a git base (consent check, retries); if that response says the policy is now off, nothing is archived. A folder session's deltas pause (`not_archivable`) while the policy is off and catch up on the first delta after it is on again. The server also refuses `folder` archives from a user whose policy is off (`422 archive_marker_not_allowed`), which stops such a session.- **Touched files.** GET /archives/key also carries `policy.touched_files` (off unless it is the boolean `true`; absent on an older backend). Precedence per session root, in `captureBaseLocked`'s gate: a git repository or a folder inside one (`gitMarkerDetector`, `gitParentDetector`) gets the `.git` archive exactly as before; else, with `all_folders` on, the whole-folder `folder` archive; else, with `touched_files` on and the root passing every folder refusal above, a `touched` chain; else nothing. The same probe, TTL and kept answer serve both flags.- **The touched set.** The collector (in the same capture host, on the worker) reports every workspace-relative path a session touches, before its own denylist: tool paths in the trace (`path`, `filePath`, ... of any event, a child session's messages too; `workspaceRelativePath` drops anything outside the root, another drive or share), watcher events (created, modified, deleted, renamed), the reconcile pass, the end-of-turn artifact scan and a change capture's scan (only against an accepted snapshot: with none, as after a refused start snapshot, a scan compares against nothing and reports nothing). `TouchedPathStore` keeps them per session: in memory until the gate has run (a git, folder or refused session drops them), then appended to `omnirush-archive/touched/<session key>.jsonl` within 2 s, and at `stop()`, so they survive a restart; a torn last line is skipped. At most `MAX_TOUCHED_PATHS` (100,000) per session, one `warn` past it. A stopped or deleted session's file goes; `start()` removes the files of sessions that are not touched chains any more, and sign-out removes them all.- - **Captures.** At the same moments as a git chain's deltas (turn end) and final archives (idle, turn_incomplete, session_deleted, app_quit, app_start). `captureBase` at session start only registers the session (`unchanged`, with `turn_seen`, the completed turns so far). The base (sequence 0, no parent, turn = the completed turns so far: the turn's count, or `turn_seen` for a final archive) comes with the first capture that finds a touched file; before that a capture is `unchanged`. Deltas follow the git chain's rules (sequence n+1, the parent, a turn delta's turn above the parent's, a final archive's equal), and a delta's marker is its parent's.+ - **Captures.** At the same moments as a git chain's deltas (turn end) and final archives (idle, turn_incomplete, session_deleted, app_quit, app_start). `captureBase` at session start only registers the session (`unchanged`, with `turn_seen`, the completed turns so far). For a session already registered (resumed after a restart) it runs no gate and asks no policy: it only updates `turn_seen`, and the chain and its touched set are kept whatever the policy answers then (a failed probe included), like a chain with a base; its captures check the policy. The base (sequence 0, no parent, turn = the completed turns so far: the turn's count, or `turn_seen` for a final archive) comes with the first capture that finds a touched file; before that a capture is `unchanged`. Deltas follow the git chain's rules (sequence n+1, the parent, a turn delta's turn above the parent's, a final archive's equal), and a delta's marker is its parent's.- **What is archived.** `scanTouchedFiles` looks at the session's touched paths and every file the chain holds (to see it go), nothing else: a plain relative path only; walked from the root with `lstat`, each folder on the way a real folder (a symlink or a file in the way: the path is not in the folder); a touched folder is never expanded; a symlink is followed only to a target that is lexically inside the root (as given or as its real path, at most 8 links; its target goes through the same checks), and one pointing outside is skipped (`special`) without anything outside being looked at. The same exclusions as the whole-folder scan: credential files (`isArchiveCredentialPath`, unless `archiveIncludeCredentialFiles`), app state dirs under the root, `__omnirush__` at the root, special files, unreadable files, lone-surrogate names. A file is hashed from the very file `lstat`ed (same `st_dev` and `st_ino`), with the root's hash cache (read and added to, never pruned: the scan sees only part of the root), and pass 2 packs it with the usual checks (`pack.ts`). Any type and size, byte for byte, unscrubbed, sealed like every archive; `workspace.git` is `null`.- **Manifest.** `"scope": "touched"` in the sealed `manifest.json` of every archive of the chain; `files` lists only touched files (the base: every touched file; a delta: the added and modified ones). A path the manifest does not list is not deleted: a delta deletes, in `deleted`, the files an earlier archive of the chain holds that are no longer a regular file in the folder (gone, a folder, a link, reached through a folder that is now a link). A file that cannot be read for now stays in the baseline as it was.- **Policy off.** With `touched_files` off or absent nothing is written for such a folder: `captureBase` is `not_archivable` after the probe, and no touched path is kept. A touched chain's captures pause (`not_archivable`) while it is off and catch up once it is on (the touched set is kept). The server refuses a `touched` create from a user whose policy is off with `422 archive_marker_not_allowed`: the drain drops the session's chain (its jobs, the session stopped, one `warn` line, no retry) and keeps the policy as off for `touched` until it is asked again (`POLICY_TTL_MS`), so no other chain starts meanwhile. The same holds for `folder`.@@ -393,5 +393,5 @@ cd apps/server && bun --conditions=development test src/session-archive- a chain conflict and an unknown kid;- sign-out, and a slow part PUT aborted within a second of `signOut()` (the upload aborted with the credentials still held, nothing completed or sent afterwards) and of `stop()` (the job kept, resumed by the next start);- the app's state dir under the root pruned;- - touched files (`touched_files` on): only the touched files, byte for byte (a PDF read, a binary written), untouched files, credentials and a link out of the folder never, the base at the first capture with a touched file, a delta with the changed files and the deleted one, nothing when only an untouched file changed; a git folder archived as today with no touched paths kept; `all_folders` winning over `touched_files`; the policy off, absent or not a boolean: nothing uploaded or kept; the refused folders never archived; finals (the base from an idle final, `app_quit`, `app_start`) and a restart keeping the chain and its touched paths, a session without a base getting it at app start, a deleted session's paths gone; the chain pausing while the policy is off; `422 archive_marker_not_allowed` dropping the chain once, with no retry, and no other touched chain starting until the policy is asked again;+ - touched files (`touched_files` on): only the touched files, byte for byte (a PDF read, a binary written), untouched files, credentials and a link out of the folder never, the base at the first capture with a touched file, a delta with the changed files and the deleted one, nothing when only an untouched file changed; a git folder archived as today with no touched paths kept; `all_folders` winning over `touched_files`; the policy off, absent or not a boolean: nothing uploaded or kept; the refused folders never archived; finals (the base from an idle final, `app_quit`, `app_start`) and a restart keeping the chain and its touched paths, a session without a base getting it at app start, a deleted session's paths gone; a restart whose key probe fails keeping a chain without a base and its paths, its base catching up with every path once the policy answers; the chain pausing while the policy is off; `422 archive_marker_not_allowed` dropping the chain once, with no retry, and no other touched chain starting until the policy is asked again;- final archives: none without a base or when unchanged; the equal-turn wire values (sequence, parent, turn), chained finals, `trigger` and `reason` in the manifest; a server without final archives (`strictTurns`): one refused create, the chain put back, the turn delta queued behind the final captured again, later turns uploaded, one log line; shutdown finals within the budget, a hanging one cut at it and captured at the next start; the app-start candidates (a final due, the most recent session per folder; not deleted or older than 7 days); a deleted session whose folder is gone.diff --git a/apps/server/src/session-archive/index.test.ts b/apps/server/src/session-archive/index.test.tsindex d410f719..457b0ad3 100644--- a/apps/server/src/session-archive/index.test.ts+++ b/apps/server/src/session-archive/index.test.ts@@ -1063,6 +1063,43 @@ describe("SessionArchiver touched files", () => {expect((await readdir(join(state, ARCHIVE_STATE_DIRECTORY, "touched"))).length).toBe(1);});+ test("a restart whose key probe fails keeps a touched chain without a base and its paths: it catches up once the policy answers", async () => {+ let now = Date.parse("2026-09-23T10:00:00Z");+ const { server, root, state, make } = await touchedSetup({ now: () => new Date(now) });+ const first = make();+ const id = "ses_touched_offline";+ expect(await first.captureBase(id, root, 0)).toEqual({ status: "skipped", reason: "unchanged" });+ await writeFile(join(root, "draft.md"), "draft\n");+ first.recordTouched(id, "draft.md");+ await first.stop();++ // The next start is offline: GET archives/key fails.+ server.apiHook = ({ path }) => (path === "archives/key" ? "network" : undefined);+ now += 60_000;+ const second = make();+ expect(await second.startFinalCandidates()).toEqual([id]);+ expect((await second.captureFinal(id, "app_start")).status).toBe("skipped");+ // The session is resumed: its registration asks nothing again and drops nothing, and what it touches now is kept too.+ const calls = server.calls.length;+ expect(await second.captureBase(id, root, 1)).toEqual({ status: "skipped", reason: "unchanged" });+ expect(server.calls.length).toBe(calls);+ await writeFile(join(root, "chart.svg"), "<svg/>\n");+ second.recordTouched(id, "chart.svg");+ expect(await second.captureDelta(id, root, 2)).toEqual({ status: "skipped", reason: "not_archivable" });+ await second.stop();+ expect(await readdir(join(state, ARCHIVE_STATE_DIRECTORY, "touched"))).toHaveLength(1);++ // Online again, and the kept answer is old: the base carries every path from both runs, numbered with the turns seen.+ server.apiHook = null;+ now += POLICY_TTL_MS;+ const third = make();+ expect(await third.captureFinal(id, "idle")).toMatchObject({ status: "queued", kind: "base", sequence: 0 });+ expect((await third.drain()).uploaded).toBe(1);+ const [base] = server.objects();+ expect(base!.request).toMatchObject({ session_id: id, kind: "base", turn: 1, marker: "touched" });+ expect(await names(base!)).toEqual(["__omnirush__/manifest.json", "chart.svg", "draft.md"]);+ });+test("a touched chain pauses while its policy is off and catches up once it is on again", async () => {let now = Date.parse("2026-09-23T10:00:00Z");const { server, root, subject } = await touchedSetup({ now: () => new Date(now) });diff --git a/apps/server/src/session-archive/index.ts b/apps/server/src/session-archive/index.tsindex f7fc036e..3b38bfa3 100644--- a/apps/server/src/session-archive/index.ts+++ b/apps/server/src/session-archive/index.ts@@ -368,6 +368,7 @@ export class SessionArchiver {* (folderPolicy); with both off nothing is written and only the policy is* read. A touched-files session is only registered here ("unchanged"): its* base comes with the first delta or final archive that has a touched file.+ * One registered before (resumed) runs no gate again.*/captureBase(sessionId: string, root: string, turn = 0): Promise<CaptureResult> {return this.guard("base", sessionId, turn, async () => this.withSession(sessionId, async () => {@@ -375,6 +376,13 @@ export class SessionArchiver {const state = await this.loadSession(sessionId);if (state?.stopped || this.stoppedSessions.has(sessionId)) return { status: "skipped", reason: "stopped" };if (state && state.next_sequence > 0) return { status: "skipped", reason: "exists" };+ // A touched-files chain registered earlier (a resumed session) still waits for its base. Like a+ // chain with one, it keeps its paths whatever the policy answers now: its deltas and finals ask.+ if (state?.marker === TOUCHED_MARKER) {+ if (!state.ended) this.touched.track(sessionId);+ if (state.turn_seen !== turn && generation === this.generation) await this.saveSession({ ...state, turn_seen: turn, updated_at: this.now().toISOString() });+ return { status: "skipped", reason: "unchanged" };+ }return this.captureBaseLocked(sessionId, resolve(root), turn, generation, true);}));}