Skip to content

A desktop coding agent with free access to frontier models.

TypeScript

fix(collector): keep files on another Windows drive out of change snapshots

ogsamratfa6a51cce961
diff --git a/apps/server/src/workspace-collector.test.ts b/apps/server/src/workspace-collector.test.ts
index 2297cbef..71b8ed00 100644
--- a/apps/server/src/workspace-collector.test.ts
+++ b/apps/server/src/workspace-collector.test.ts
@@ -3,7 +3,7 @@ import { execFile } from "node:child_process";
import { createHash } from "node:crypto";
import { appendFile, mkdir, mkdtemp, readFile, readdir, rename, rm, stat, symlink, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
-import { basename, join } from "node:path";
+import { basename, join, posix, win32 } from "node:path";
import { promisify } from "node:util";
import { zstdDecompressSync } from "node:zlib";
@@ -34,6 +34,7 @@ import {
redactCollectorText,
redactModeForPath,
stripRemoteUserinfo,
+ workspaceRelativePath,
} from "./workspace-collector.js";
const execFileAsync = promisify(execFile);
@@ -264,6 +265,57 @@ describe("workspace collector privacy", () => {
expect(workspaceFile?.content).toContain('"touched_paths":["touched.ts"]');
expect(JSON.stringify(uploads)).not.toContain("do-not-upload");
});
+
+ test("keeps paths outside the workspace root out of capture: parents, other Windows drives and UNC shares", async () => {
+ // Windows: path.relative returns a path on another drive as it is, which a `../` check let through.
+ const windowsRoot = "C:\\Users\\dev\\omnirush.ai";
+ for (const outside of [
+ "D:\\data\\file.csv",
+ "D:/data/file.csv",
+ "d:\\data\\file.csv",
+ "D:file.csv",
+ "\\\\server\\share\\file.csv",
+ "C:\\Users\\dev\\other\\file.csv",
+ "C:\\Users\\dev\\omnirush.ai-other\\file.csv",
+ "..\\file.csv",
+ "src\\..\\..\\file.csv",
+ windowsRoot,
+ ]) {
+ expect([outside, workspaceRelativePath(windowsRoot, outside, win32)]).toEqual([outside, null]);
+ }
+ expect(workspaceRelativePath(windowsRoot, "C:\\Users\\dev\\omnirush.ai\\src\\app.ts", win32)).toBe("src/app.ts");
+ expect(workspaceRelativePath(windowsRoot, "c:\\users\\dev\\omnirush.ai\\src\\app.ts", win32)).toBe("src/app.ts");
+ expect(workspaceRelativePath(windowsRoot, "src/app.ts", win32)).toBe("src/app.ts");
+ // POSIX.
+ for (const outside of ["/etc/hosts", "../ws-other/file.csv", "..", "/home/dev/ws"]) {
+ expect([outside, workspaceRelativePath("/home/dev/ws", outside, posix)]).toEqual([outside, null]);
+ }
+ expect(workspaceRelativePath("/home/dev/ws", "/home/dev/ws/..notes.md", posix)).toBe("..notes.md");
+ expect(workspaceRelativePath("/home/dev/ws", "src/app.ts", posix)).toBe("src/app.ts");
+
+ // Through the collector: a tool naming a file outside the root reads nothing of it.
+ const base = await mkdtemp(join(tmpdir(), "omnirush-collector-outside-"));
+ roots.push(base);
+ const root = join(base, "workspace");
+ await mkdir(root);
+ await writeFile(join(base, "outside.csv"), "OUTSIDE_FILE_MARKER");
+ await writeFile(join(root, "inside.txt"), "inside");
+ const { uploads, upload } = makeUploads();
+ const collector = new WorkspaceCollector({ upload, changeDebounceMs: 10, fallbackScanMs: 60_000 });
+ const sessionId = "session-outside-1234";
+ collector.startSession(sessionId, "workspace-outside", root);
+ await collector.idle(sessionId);
+ collector.recordTrace(sessionId, "file.read", { path: join(base, "outside.csv") });
+ collector.recordTrace(sessionId, "file.read", { path: "../outside.csv" });
+ collector.recordTrace(sessionId, "file.read", { path: "inside.txt" });
+ collector.flushTrace(sessionId);
+ await new Promise((resolve) => setTimeout(resolve, 40));
+ await collector.stop();
+ expect(uploads.at(-1)?.touched_paths).toEqual(["inside.txt"]);
+ const files = uploads.flatMap((envelope) => envelope.files);
+ expect(files.some((file) => file.content.includes("OUTSIDE_FILE_MARKER"))).toBe(false);
+ expect(files.filter((file) => file.path === "__omnirush__/changes.json").map((file) => file.content).join()).not.toContain("outside.csv");
+ });
});
// --- collector envelope v2 ---------------------------------------------------
diff --git a/apps/server/src/workspace-collector.ts b/apps/server/src/workspace-collector.ts
index 0cb187a6..3fb19824 100644
--- a/apps/server/src/workspace-collector.ts
+++ b/apps/server/src/workspace-collector.ts
@@ -3,7 +3,7 @@ import { execFile, spawn } from "node:child_process";
import { createReadStream, createWriteStream, watch, type FSWatcher, type WriteStream } from "node:fs";
import { lstat, mkdir, open, readFile, readdir, rename, rm, stat, writeFile } from "node:fs/promises";
import { release as osRelease, tmpdir } from "node:os";
-import { basename, dirname, extname, join, relative, resolve, sep } from "node:path";
+import nodePath, { basename, dirname, extname, join, relative, resolve, sep, type PlatformPath } from "node:path";
import { promisify } from "node:util";
import { createZstdCompress } from "node:zlib";
import { minimatch } from "minimatch";
@@ -639,6 +639,24 @@ function portablePath(root: string, path: string): string {
return relative(root, path).split(sep).join("/");
}
+/**
+ * `candidate` (absolute, or relative to the root) as a portable path strictly
+ * inside the workspace root, or null for the root itself, a parent, another
+ * drive or a UNC share. path.relative returns a path on another Windows drive
+ * as it is (`D:\data\x.csv`, portable `D:/data/x.csv`), which a `../` check
+ * lets through; here any absolute result is refused, and the path it
+ * resolves to must start with the root and a separator, as inspectFile
+ * requires of every file it reads. `paths` is the platform's path module
+ * (path.win32 in tests).
+ */
+export function workspaceRelativePath(root: string, candidate: string, paths: PlatformPath = nodePath): string | null {
+ const base = paths.resolve(root);
+ const path = paths.relative(base, paths.resolve(base, candidate));
+ if (!path || paths.isAbsolute(path) || path === ".." || path.startsWith(`..${paths.sep}`)) return null;
+ if (!paths.resolve(base, path).startsWith(base.endsWith(paths.sep) ? base : `${base}${paths.sep}`)) return null;
+ return path.split(paths.sep).join("/");
+}
+
export function collectorPathForUpload(path: string): string {
return redactCollectorText(path).text;
}
@@ -1971,8 +1989,8 @@ async function artifactStats(root: string): Promise<Map<string, ArtifactStat>> {
const stats = new Map<string, ArtifactStat>();
for (const path of await listUntrackedFiles(root)) {
try {
+ if (workspaceRelativePath(root, path) === null) continue;
const absolute = resolve(root, path);
- if (portablePath(root, absolute).startsWith("../")) continue;
const file = await lstat(absolute);
if (!file.isFile() || file.isSymbolicLink()) continue;
stats.set(path, { size: file.size, mtimeMs: file.mtimeMs });
@@ -2338,7 +2356,7 @@ async function readUploadContent(
): Promise<UploadContent | null> {
const absolute = resolve(root, path);
// A directory swapped for a symlink since the scan must not be followed either.
- if (!(await hasRealAncestors(root, path, ancestors))) return null;
+ if (workspaceRelativePath(root, path) === null || !(await hasRealAncestors(root, path, ancestors))) return null;
let file;
try {
file = await lstat(absolute);
@@ -3156,8 +3174,8 @@ export class WorkspaceCollector {
return;
}
const relative = String(filename).replaceAll("\\", "/");
- const path = prefix ? `${prefix}/${relative}` : relative;
- if (!path || path.startsWith("../") || path.startsWith("/") || isCollectorPathDenied(path)) return;
+ const path = workspaceRelativePath(state.root, prefix ? `${prefix}/${relative}` : relative);
+ if (!path || isCollectorPathDenied(path)) return;
if (path === ".gitignore" || path.endsWith("/.gitignore")) {
// New ignore rules can hide or reveal any number of files: forget what
// git answered so far and rescan the tree with the rules as they stand.
@@ -3419,13 +3437,8 @@ export class WorkspaceCollector {
}
private recordTouchedPath(state: SessionState, candidate: string): void {
- let path = candidate.replaceAll("\\", "/");
- if (path.startsWith("/")) {
- path = portablePath(state.root, resolve(path));
- } else {
- path = portablePath(state.root, resolve(state.root, path));
- }
- if (!path || path.startsWith("../") || isCollectorPathDenied(path) || state.touchedPaths.has(path)) return;
+ const path = workspaceRelativePath(state.root, candidate.replaceAll("\\", "/"));
+ if (!path || isCollectorPathDenied(path) || state.touchedPaths.has(path)) return;
state.touchedPaths.add(path);
this.markDirty(state, path);
this.queueChangedPath(state, path);
@@ -3778,9 +3791,8 @@ export class WorkspaceCollector {
private queueChangedPath(state: SessionState, filename: string): void {
if (state.finished) return;
- const absolute = resolve(state.root, filename);
- const path = portablePath(state.root, absolute);
- if (!path || path.startsWith("../") || isCollectorPathDenied(path)) return;
+ const path = workspaceRelativePath(state.root, filename);
+ if (!path || isCollectorPathDenied(path)) return;
// Several events for one path before its capture starts collapse into one read.
if (state.pendingJournal.has(path)) return;
state.pendingJournal.add(path);
@@ -3810,9 +3822,10 @@ export class WorkspaceCollector {
private async captureChangedPath(state: SessionState, path: string): Promise<void> {
if (state.finished) return;
const absolute = resolve(state.root, path);
- // Reached through a symlinked directory: a file outside the workspace (a
- // traced read of `linked/util.ts`), never journaled.
- if (!(await hasRealAncestors(state.root, path))) return;
+ // Outside the root (another drive), or reached through a symlinked
+ // directory: a file outside the workspace (a traced read of
+ // `linked/util.ts`), never journaled.
+ if (workspaceRelativePath(state.root, path) === null || !(await hasRealAncestors(state.root, path))) return;
let entry: ChangeJournalEntry;
try {
const file = await lstat(absolute);
diff --git a/docs/workspace-collector-privacy.md b/docs/workspace-collector-privacy.md
index cb4a8765..81dbf31f 100644
--- a/docs/workspace-collector-privacy.md
+++ b/docs/workspace-collector-privacy.md
@@ -17,4 +17,4 @@ 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. 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 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.
+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. 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.