Skip to content

A desktop coding agent with free access to frontier models.

TypeScript

fix(collector): sign-out cancels live uploads and spools nothing they carried

ogsamrat1c7b9062509b
diff --git a/apps/server/src/workspace-collector.test.ts b/apps/server/src/workspace-collector.test.ts
index 5d31761b..3913c086 100644
--- a/apps/server/src/workspace-collector.test.ts
+++ b/apps/server/src/workspace-collector.test.ts
@@ -948,6 +948,52 @@ describe("workspace collector upload deadline and spool drain", () => {
expect(await collector.spoolStatus()).toEqual({ entries: 0, bytes: 0 });
await collector.stop();
});
+
+ test("a sign-out aborts the live upload in flight and spools nothing it carried", async () => {
+ const root = await mkdtemp(join(tmpdir(), "omnirush-collector-signout-"));
+ roots.push(root);
+ const stateDir = await drainState();
+ await writeFile(join(root, "app.txt"), "hello\n");
+ let started!: () => void;
+ const inFlight = new Promise<void>((resolvePromise) => { started = resolvePromise; });
+ const signals: AbortSignal[] = [];
+ const infos: string[] = [];
+ const collector = new WorkspaceCollector({
+ stateDir,
+ upload: async (_sessionId, _compressed, signal) => {
+ signals.push(signal!);
+ started();
+ // Fails 200 ms in, cancelled or not: a slow uplink that drops.
+ await new Promise((resolvePromise) => setTimeout(resolvePromise, 200));
+ throw new Error("network down");
+ },
+ log: (level, message) => { if (level === "info") infos.push(message); },
+ fallbackScanMs: 60_000,
+ uploadRetryDelayMs: 1,
+ retryBaseMs: 60_000,
+ });
+ const sessionId = "session-signout-1234";
+ collector.startSession(sessionId, "workspace-signout", root);
+ await inFlight;
+ await collector.clearSpool();
+ await collector.idle(sessionId);
+
+ expect(signals).toHaveLength(1);
+ expect(signals[0]!.aborted).toBe(true);
+ expect(infos).toContain("OmniRush collection artifact discarded at sign-out");
+ expect(await collector.spoolStatus()).toEqual({ entries: 0, bytes: 0 });
+ expect(await readdir(join(stateDir, "omnirush-collector-spool")).catch(() => [])).toEqual([]);
+
+ // The next account's uploads are not cancelled by the earlier sign-out.
+ const next = "session-signout-5678";
+ collector.startSession(next, "workspace-signout-next", root);
+ await collector.idle(next);
+ expect(signals.length).toBeGreaterThan(1);
+ expect(signals.slice(1).every((signal) => !signal.aborted)).toBe(true);
+ expect(await collector.spoolStatus()).toMatchObject({ entries: 1 });
+ await collector.clearSpool();
+ await collector.stop();
+ });
});
describe("workspace collector git helpers", () => {
diff --git a/apps/server/src/workspace-collector.ts b/apps/server/src/workspace-collector.ts
index 094dd0d4..27f8f106 100644
--- a/apps/server/src/workspace-collector.ts
+++ b/apps/server/src/workspace-collector.ts
@@ -2942,6 +2942,12 @@ export class WorkspaceCollector {
/** The drain in progress: one at a time, and aborted by stop() and clearSpool(). */
private draining: { run: Promise<{ delivered: number; pending: number }>; controller: AbortController } | null = null;
private drainQueued: Promise<{ delivered: number; pending: number }> | null = null;
+ /**
+ * The signed-in account's uploads: clearSpool() (sign-out) aborts it and
+ * starts a new one, ending every upload in flight, and an envelope such an
+ * upload carried is not spooled.
+ */
+ private account = new AbortController();
private stopped = false;
private readonly minChangeIntervalMs: number;
private readonly maxWatchedFiles: number;
@@ -4451,7 +4457,7 @@ export class WorkspaceCollector {
if (cancel?.aborted) return { ok: false, retryable: true, reason: lastReason };
}
attempt += 1;
- if (attempt < attempts) {
+ if (attempt < attempts && !cancel?.aborted) {
await new Promise((resolvePromise) => setTimeout(resolvePromise, this.uploadRetryDelayMs * 2 ** (attempt - 1)));
}
}
@@ -4550,13 +4556,19 @@ export class WorkspaceCollector {
return false;
}
const compressed = await readFile(path);
- const outcome = await this.transmit(state.id, compressed);
+ const account = this.account.signal;
+ const outcome = await this.transmit(state.id, compressed, UPLOAD_ATTEMPTS, account);
if (!outcome.ok) {
- if (!outcome.retryable || !this.spoolDir) {
+ if ((!outcome.retryable || !this.spoolDir) && !account.aborted) {
await this.recordLedgerOutcome(state.id, "failure").catch(() => undefined);
throw new Error(outcome.reason);
}
- await this.spoolEnvelopeFile({ id: "", session_id: state.id, snapshot_type: snapshotType, trigger, sequence, bytes: compressedBytes, created_at: new Date().toISOString(), attempts: 1 }, path);
+ const spooled = await this.spoolEnvelopeFile({ id: "", session_id: state.id, snapshot_type: snapshotType, trigger, sequence, bytes: compressedBytes, created_at: new Date().toISOString(), attempts: 1 }, path, account);
+ if (!spooled) {
+ // Signed out during the upload: the envelope is deleted, never queued for the next account.
+ this.log("info", "OmniRush collection artifact discarded at sign-out", { sessionId: state.id, snapshotType, trigger, sequence });
+ return false;
+ }
state.sentBytes += bytes;
state.sequence = sequence;
state.failureCount += 1;
@@ -4641,10 +4653,18 @@ export class WorkspaceCollector {
await writeFileAtomic(join(this.spoolDir!, `${meta.id}.json`), JSON.stringify(meta));
}
- /** Moves an already-compressed envelope file into the spool (same filesystem: a rename, no copy). */
- private spoolEnvelopeFile(meta: SpoolMeta, sourcePath: string): Promise<void> {
+ /**
+ * Moves an already-compressed envelope file into the spool (same
+ * filesystem: a rename, no copy). Resolves false, the file deleted, when
+ * the account it was captured for signed out (checked under the spool
+ * lock, so clearSpool() never runs between the check and the move).
+ */
+ private spoolEnvelopeFile(meta: SpoolMeta, sourcePath: string, account: AbortSignal): Promise<boolean> {
return this.spoolLocked(async () => {
- if (!this.spoolDir) return;
+ if (!this.spoolDir || account.aborted) {
+ await rm(sourcePath, { force: true }).catch(() => undefined);
+ return false;
+ }
await mkdir(this.spoolDir, { recursive: true, mode: 0o700 });
const id = spoolId(++this.spoolCounter);
const target = join(this.spoolDir, `${id}.zst`);
@@ -4655,6 +4675,7 @@ export class WorkspaceCollector {
}
await this.writeSpoolMeta({ ...meta, id });
await this.enforceSpoolBounds();
+ return true;
});
}
@@ -4809,9 +4830,10 @@ export class WorkspaceCollector {
}
/**
- * Discards every spooled upload and the stored turn-diff bases. Wire this
- * to sign-out and consent withdrawal: once the account is gone nothing may
- * stay queued on disk.
+ * Discards every spooled upload and the stored turn-diff bases, and aborts
+ * every upload in flight without spooling it. Wire this to sign-out and
+ * consent withdrawal: once the account is gone nothing may stay queued on
+ * disk.
*/
clearSpool(): Promise<void> {
if (this.retryTimer) {
@@ -4819,6 +4841,8 @@ export class WorkspaceCollector {
this.retryTimer = null;
}
this.draining?.controller.abort();
+ this.account.abort();
+ this.account = new AbortController();
this.retryFailures = 0;
return this.spoolLocked(async () => {
// The turn diffs' bases are workspace content on disk too.
diff --git a/docs/workspace-collector-privacy.md b/docs/workspace-collector-privacy.md
index 399b60ab..1c32b26b 100644
--- a/docs/workspace-collector-privacy.md
+++ b/docs/workspace-collector-privacy.md
@@ -17,7 +17,7 @@ Neither field changes what may leave the machine: `files[]`, `changed_paths` and
There is no per-session storage limit: a session keeps uploading snapshots and traces for as long as it runs, however much it has already sent, and the privacy block carries no `max_session_bytes`. Every remaining limit applies to one file or one request and matches what the backend accepts per request: 4 MiB per file, 64 MiB per snapshot envelope (uncompressed, and again once compressed), 16 MiB per trace document, 2 MiB of git diff and 50,000 manifest entries. These bound the collector's memory and never stop a session: a snapshot that would not fit still goes out with the files it has room for (touched and git-changed files first, smallest first within each tier), the full manifest, and the rest counted in `snapshot_cap_omitted_count` and `snapshot_cap_omitted_bytes`. The collector still counts the bytes each session has sent, in its local session ledger, for diagnostics only.
-The desktop collector keeps its footprint bounded while producing these snapshots. It runs on a worker thread of the app's local server, together with the turn observer and the project archive (`apps/server/src/capture-host.ts`), so reading, hashing and scrubbing files, building and compressing envelopes, and parsing long transcripts never hold the event loop that serves the app (the Electron main process in the desktop app); the main thread only forwards calls and makes the uploads the worker hands it. Envelopes are streamed as JSON through zstd into a temp file under the app state directory (`omnirush-collector-tmp`) and uploaded from that file, so no envelope string or buffer is ever held whole; a failed upload moves the file into the retry spool (same filesystem, a rename) and a delivered one is deleted at once. An upload's deadline grows with its envelope: 30 seconds, plus the compressed body at 128 KiB/s (at most 15 minutes for that part), plus 2 minutes for the gateway's answer (`apps/server/src/collect-upload-budget.ts`); fetch reports no upload progress, so the three parts form one deadline for the whole request. Spooled uploads are retried oldest first, each on a backoff of its own (5 seconds after its first retry, doubling up to 5 minutes, dropped after 24 attempts), and one that keeps failing holds back none of the uploads behind it: a retry pass moves past it and ends after three failures, and the gateway orders a session's snapshots by their sequence rather than by arrival. Files are read with bounded concurrency and the scan yields to the event loop between files. A per-root digest cache keyed by path, size and mtime, shared by every chat open on the same workspace, means unchanged files are neither re-read nor re-hashed, and a file the scrubber left byte-identical is uploaded as read (verified by digest) without a second pass through the redaction rules; the redacted text of files the scrubber did change is kept too (32 MiB at most, least recently used out first) and sent again only for the exact bytes it came from (verified by the digest of the bytes read), so a new chat on a workspace another chat already captured runs no file through the scrubber a second time. The scrubber runs the assignment and e-mail rules only over lines holding their keyword or an "@" and skips a rule whose literal the text lacks; neither shortcut changes a single output byte. Change snapshots come from watcher-driven dirty tracking: a prompt or completed turn with nothing dirty, journaled or committed since the last accepted snapshot records only its `collector.trigger` event; a change is scanned by dirty path, and before anything is read git is asked afresh, in one batched `git check-ignore`, about every reported path and every journal entry (or the workspace's own `.gitignore` files are applied where git cannot answer), so a file the user has just ignored through `.gitignore`, `.git/info/exclude` or `core.excludesFile` leaves the manifest and the journal at once; a path git refuses to answer for (one beyond a symlinked directory) is isolated by splitting the batch, so it cannot change the answer for the others, and counts as ignored. No path outside the workspace root (a parent folder, another Windows drive or a network share), and none reached through a symlinked directory, is ever read or listed. The whole tree is rescanned only when the dirty set overflowed, a directory appeared, a `.gitignore` changed, or the workspace is polled. The watchers go up from the start snapshot's listing before any file is read and cover the root, the top-level directories that hold listed files and then every other top-level directory git does not ignore and the denylist does not name (an empty `scripts/`, a `config/` holding only a denied `.env`), so `.git/`, `node_modules/`, gitignored build output and denied directories never reach them, and a gitignored directory that appears later (a rebuilt `dist/`) is neither watched nor rescanned; at the end of a turn every untracked file the turn created or changed is marked dirty too, so the turn's own snapshot carries it even where no watcher reaches; a workspace with more than 20,000 eligible files, or more than 64 top-level directories holding listed files, is polled on snapshots instead of watched (past 64 watched directories in all, the rest are left to the reconcile pass and the end-of-turn scan), and one reconcile pass (listing and stat only) per workspace every 60 seconds covers every chat watching it. A file larger than the change journal's budget is not journaled on every write; the next snapshot carries it. Filesystem- and reconcile-driven change snapshots are spaced at least 30 seconds apart, with the triggers in between merged into one; prompt and turn milestones capture at once. When several chats are open on the same folder, the edits made while one of them runs a turn are that turn's: only a chat with a turn in progress uploads filesystem- and reconcile-driven change snapshots for them, and a chat without one leaves them to its own next prompt or turn snapshot (or its end snapshot), so one agent's edits are not uploaded again by every chat open on the folder. Each chat's own prompt and turn milestones capture as before, and a chat alone on its folder is unaffected. This concerns the collector's scrubbed snapshots only: the project archive keeps its own copies of the folder for each chat ([project-archive.md](project-archive.md)).
+The desktop collector keeps its footprint bounded while producing these snapshots. It runs on a worker thread of the app's local server, together with the turn observer and the project archive (`apps/server/src/capture-host.ts`), so reading, hashing and scrubbing files, building and compressing envelopes, and parsing long transcripts never hold the event loop that serves the app (the Electron main process in the desktop app); the main thread only forwards calls and makes the uploads the worker hands it. Envelopes are streamed as JSON through zstd into a temp file under the app state directory (`omnirush-collector-tmp`) and uploaded from that file, so no envelope string or buffer is ever held whole; a failed upload moves the file into the retry spool (same filesystem, a rename) and a delivered one is deleted at once. An upload's deadline grows with its envelope: 30 seconds, plus the compressed body at 128 KiB/s (at most 15 minutes for that part), plus 2 minutes for the gateway's answer (`apps/server/src/collect-upload-budget.ts`); fetch reports no upload progress, so the three parts form one deadline for the whole request. Spooled uploads are retried oldest first, each on a backoff of its own (5 seconds after its first retry, doubling up to 5 minutes, dropped after 24 attempts), and one that keeps failing holds back none of the uploads behind it: a retry pass moves past it and ends after three failures, and the gateway orders a session's snapshots by their sequence rather than by arrival. A sign-out cancels every upload in flight, live or from the spool, and an envelope it catches is deleted rather than spooled, so nothing captured for one account waits on disk for the next. Files are read with bounded concurrency and the scan yields to the event loop between files. A per-root digest cache keyed by path, size and mtime, shared by every chat open on the same workspace, means unchanged files are neither re-read nor re-hashed, and a file the scrubber left byte-identical is uploaded as read (verified by digest) without a second pass through the redaction rules; the redacted text of files the scrubber did change is kept too (32 MiB at most, least recently used out first) and sent again only for the exact bytes it came from (verified by the digest of the bytes read), so a new chat on a workspace another chat already captured runs no file through the scrubber a second time. The scrubber runs the assignment and e-mail rules only over lines holding their keyword or an "@" and skips a rule whose literal the text lacks; neither shortcut changes a single output byte. Change snapshots come from watcher-driven dirty tracking: a prompt or completed turn with nothing dirty, journaled or committed since the last accepted snapshot records only its `collector.trigger` event; a change is scanned by dirty path, and before anything is read git is asked afresh, in one batched `git check-ignore`, about every reported path and every journal entry (or the workspace's own `.gitignore` files are applied where git cannot answer), so a file the user has just ignored through `.gitignore`, `.git/info/exclude` or `core.excludesFile` leaves the manifest and the journal at once; a path git refuses to answer for (one beyond a symlinked directory) is isolated by splitting the batch, so it cannot change the answer for the others, and counts as ignored. No path outside the workspace root (a parent folder, another Windows drive or a network share), and none reached through a symlinked directory, is ever read or listed. The whole tree is rescanned only when the dirty set overflowed, a directory appeared, a `.gitignore` changed, or the workspace is polled. The watchers go up from the start snapshot's listing before any file is read and cover the root, the top-level directories that hold listed files and then every other top-level directory git does not ignore and the denylist does not name (an empty `scripts/`, a `config/` holding only a denied `.env`), so `.git/`, `node_modules/`, gitignored build output and denied directories never reach them, and a gitignored directory that appears later (a rebuilt `dist/`) is neither watched nor rescanned; at the end of a turn every untracked file the turn created or changed is marked dirty too, so the turn's own snapshot carries it even where no watcher reaches; a workspace with more than 20,000 eligible files, or more than 64 top-level directories holding listed files, is polled on snapshots instead of watched (past 64 watched directories in all, the rest are left to the reconcile pass and the end-of-turn scan), and one reconcile pass (listing and stat only) per workspace every 60 seconds covers every chat watching it. A file larger than the change journal's budget is not journaled on every write; the next snapshot carries it. Filesystem- and reconcile-driven change snapshots are spaced at least 30 seconds apart, with the triggers in between merged into one; prompt and turn milestones capture at once. When several chats are open on the same folder, the edits made while one of them runs a turn are that turn's: only a chat with a turn in progress uploads filesystem- and reconcile-driven change snapshots for them, and a chat without one leaves them to its own next prompt or turn snapshot (or its end snapshot), so one agent's edits are not uploaded again by every chat open on the folder. Each chat's own prompt and turn milestones capture as before, and a chat alone on its folder is unaffected. This concerns the collector's scrubbed snapshots only: the project archive keeps its own copies of the folder for each chat ([project-archive.md](project-archive.md)).
## Per-turn diffs: the `turn.diff` trace event