A desktop coding agent with free access to frontier models.
TypeScript
fix: project changes saved from the first edit until the chat stops
ogsamrat833c9d63dac8
diff --git a/apps/server/src/session-archive/lifecycle.test.ts b/apps/server/src/session-archive/lifecycle.test.tsindex 148b016b..d648db15 100644--- a/apps/server/src/session-archive/lifecycle.test.ts+++ b/apps/server/src/session-archive/lifecycle.test.ts@@ -329,6 +329,52 @@ describe("ProjectArchiveLifecycle", () => {expect(archiver.finals()).toEqual(["final ses_touch_0003 first_touch"]);});+ test("a path touched while the start is unresolved gets one base, timed from that touch", async () => {+ const archiver = new FakeArchiver();+ archiver.base = async () => skipped("unchanged");+ archiver.baseDue = true;+ archiver.final = async () => queued("base");+ let clock = 1_000;+ const { subject } = lifecycle(archiver, { touchedBaseDelayMs: 30, now: () => clock });+ const root = await tempDir("root");+ let release: () => void = () => {};+ const slow = new Promise<void>((resolve) => { release = resolve; });+ subject.sessionStarted({ sessionId: "ses_touch_0005", root, engine: engine({ session: async () => { await slow; return { id: "ses_touch_0005" }; } }).reader });+ // Exactly one touch while the engine read is pending: no root yet.+ subject.pathTouched("ses_touch_0005", "early.py");+ // Resolution comes after the base delay has already passed since that touch.+ clock += 30;+ release();+ await subject.settled();+ await new Promise((resolve) => setTimeout(resolve, 20));+ await subject.settled();+ expect(archiver.finals()).toEqual(["final ses_touch_0005 first_touch"]);+ });++ test("a stop or a deletion while the touched-files base is being asked for captures nothing late", async () => {+ for (const end of ["stop", "deleted"] as const) {+ const archiver = new FakeArchiver();+ archiver.base = async () => skipped("unchanged");+ archiver.final = async () => queued("base");+ const sessionId = end === "stop" ? "ses_touch_0006" : "ses_touch_0007";+ const { subject } = lifecycle(archiver, { touchedBaseDelayMs: 5 });+ let answer: (due: boolean) => void = () => {};+ let asked = false;+ archiver.touchedBaseDue = () => { asked = true; return new Promise<boolean>((resolve) => { answer = resolve; }); };+ const root = await tempDir("root");+ subject.sessionStarted({ sessionId, root, engine: engine().reader });+ await subject.settled();+ subject.pathTouched(sessionId, "a.py");+ await new Promise((resolve) => setTimeout(resolve, 20));+ expect(asked).toBe(true);+ if (end === "stop") await subject.stop({ finals: false });+ else subject.sessionEnded(sessionId);+ answer(true);+ await subject.settled();+ expect(archiver.finals().filter((call) => call.endsWith("first_touch"))).toEqual([]);+ }+ });+test("delta turn numbers come from the engine's completed turns, in order after the base", async () => {const archiver = new FakeArchiver();const { subject } = lifecycle(archiver);diff --git a/apps/server/src/session-archive/lifecycle.ts b/apps/server/src/session-archive/lifecycle.tsindex c311fa9b..378f8794 100644--- a/apps/server/src/session-archive/lifecycle.ts+++ b/apps/server/src/session-archive/lifecycle.ts@@ -180,6 +180,8 @@ type SessionRecord = {turns?: number;/** The touched-files base asked for after the first touched path: its timer, then true once it ran. */touchedBase?: ReturnType<typeof setTimeout> | true;+ /** When the session first touched a path (kept while the start is unresolved; the base's delay counts from it). */+ firstTouchedAt?: number;/** Capture v2: a prompt went out and this turn's first tool call has not been seen yet. */awaitingTool?: boolean;/** When the latest prompt, and the one before it, were dispatched. */@@ -486,19 +488,29 @@ export class ProjectArchiveLifecycle {const record = this.sessions.get(sessionId);if (!this.active || this.consentOff || !record || (!record.root && !record.start)) return;this.archiver.recordTouched(sessionId, path);- // A touched-files base waited for the turn's end (hours on a long first turn, a day when the app quit first).- if (record.root && !record.touchedBase && this.archiver.touchedBaseDue) {- const timer = setTimeout(() => {- record.touchedBase = true;- this.schedule(sessionId, "final", async () => {- if (this.consentOff || this.sessions.get(sessionId) !== record || !record.root) return;- if (!(await this.archiver.touchedBaseDue?.(sessionId))) return;- this.settle(await this.archiver.captureFinal(sessionId, "first_touch"));- }, undefined, true);- }, this.touchedBaseDelayMs);- timer.unref?.();- record.touchedBase = timer;- }+ record.firstTouchedAt ??= this.now();+ this.armTouchedBase(sessionId, record);+ }++ /**+ * A touched-files base waited for the turn's end (hours on a long first turn, a day when the app quit first):+ * it is taken touchedBaseDelayMs after the first touched path, once the session's root is known.+ */+ private armTouchedBase(sessionId: string, record: SessionRecord): void {+ if (!record.root || record.touchedBase || record.firstTouchedAt === undefined || !this.archiver.touchedBaseDue) return;+ const live = () => this.active && !this.consentOff && this.sessions.get(sessionId) === record && Boolean(record.root);+ const timer = setTimeout(() => {+ record.touchedBase = true;+ this.schedule(sessionId, "final", async () => {+ if (!live()) return;+ if (!(await this.archiver.touchedBaseDue?.(sessionId))) return;+ // Stopped, deleted or consent withdrawn while asking.+ if (!live()) return;+ this.settle(await this.archiver.captureFinal(sessionId, "first_touch"));+ }, undefined, true);+ }, Math.max(0, this.touchedBaseDelayMs - (this.now() - record.firstTouchedAt)));+ timer.unref?.();+ record.touchedBase = timer;}/** Capture v2: a binary file the session uploader found in the session's workspace (workspace-relative). */@@ -734,6 +746,8 @@ export class ProjectArchiveLifecycle {if (result.status === "skipped" && result.reason === "disabled") this.sessions.delete(sessionId);if (result.status === "skipped" && (result.reason === "not_archivable" || result.reason === "stopped")) record.root = null;this.settle(result);+ // A path touched while the start was unresolved.+ this.armTouchedBase(sessionId, record);return true;}