Skip to content

graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs

Python

Keep rotated transcripts with their saved conversations

justrach3237e0e7837c
diff --git a/apps/native/electron/attachment-lifetime-frontend.cjs b/apps/native/electron/attachment-lifetime-frontend.cjs
index f0e79d58..e76c669a 100644
--- a/apps/native/electron/attachment-lifetime-frontend.cjs
+++ b/apps/native/electron/attachment-lifetime-frontend.cjs
@@ -58,12 +58,19 @@ async function runAttachments({win,origin,temp,output,requests,workspace,send,cl
const savedFile=path.join(savedDirectory,savedName);
const transcriptFile=savedFile.replace(/\.session\.json$/,'.transcript.jsonl');
assert.ok(fs.existsSync(transcriptFile),'The real harness must have written its companion transcript');
+ // Seed a rotated generation from the real transcript; rotation itself is covered by harness tests.
+ const rotatedFile=savedFile.replace(/\.session\.json$/,'.transcript.1.jsonl');
+ fs.copyFileSync(transcriptFile,rotatedFile);
const archiveName='attachment-archive-check';
fs.copyFileSync(savedFile,path.join(savedDirectory,archiveName+'.session.json'));
fs.copyFileSync(transcriptFile,path.join(savedDirectory,archiveName+'.transcript.jsonl'));
+ fs.copyFileSync(rotatedFile,path.join(savedDirectory,archiveName+'.transcript.1.jsonl'));
const archiveResponse=await fetch(origin+'/api/sessions?'+new URLSearchParams({root:workspace,name:archiveName}),{method:'DELETE'});
assert.equal(archiveResponse.status,200,'Archive the copied real checkpoint through the production route');
assert.equal(fs.existsSync(path.join(savedDirectory,archiveName+'.transcript.jsonl')),false);
+ assert.equal(fs.existsSync(path.join(savedDirectory,archiveName+'.transcript.1.jsonl')),false);
+ const archivedRotated=path.join(savedDirectory,'archived',archiveName+'.transcript.1.jsonl');
+ assert.ok(fs.readFileSync(archivedRotated,'utf8').includes(path.basename(aged)));
const archivedTranscript=path.join(savedDirectory,'archived',archiveName+'.transcript.jsonl');
assert.ok(fs.readFileSync(archivedTranscript,'utf8').includes(path.basename(aged)),'Archived replay must retain its image reference');
assert.ok(fs.existsSync(path.join(savedDirectory,'archived',archiveName+'.session.json')));
@@ -74,12 +81,14 @@ async function runAttachments({win,origin,temp,output,requests,workspace,send,cl
await click('button[aria-label^="Delete "]');
await until(()=>!fs.existsSync(savedFile),'session removed after its writer exits');
assert.equal(fs.existsSync(transcriptFile),false,'Deleting a saved chat must also remove its full transcript');
+ assert.equal(fs.existsSync(rotatedFile),false,'Deleting a saved chat must remove its rotated transcript');
await new Promise(resolve=>setTimeout(resolve,250));
assert.equal(fs.existsSync(savedFile),false,'An exiting chat worker must not recreate its deleted session');
fs.writeFileSync(path.join(output,'attachment-session-deleted.png'),(await wc.capturePage()).toPNG());
assert.ok(fs.existsSync(archivedTranscript),'Deleting the original chat must preserve its independent archive');
+ assert.ok(fs.existsSync(archivedRotated),'Deleting the original must preserve the archived rotated transcript');
assert.ok(fs.existsSync(aged),'An independent archived replay still needs the original image pixels');
- report.passed.push('real sidebar delete retires its writer and removes checkpoint plus transcript; production archive preserves both replay files');
+ report.passed.push('real sidebar delete retires its writer and removes checkpoint plus both transcript generations; production archive preserves all replay files');
report.passed.push('synthetic clipboard event through real GUI paste/upload/ACP: aged draft survives, removed and closed drafts release files, sent PNG reaches model and stays available for replay');
fs.writeFileSync(path.join(output,'attachment-requests.json'),JSON.stringify(calls,null,2));
}
diff --git a/apps/native/lib/session-files.test.ts b/apps/native/lib/session-files.test.ts
index a81a639d..c7c31a3b 100644
--- a/apps/native/lib/session-files.test.ts
+++ b/apps/native/lib/session-files.test.ts
@@ -80,6 +80,35 @@ test("a symlinked companion never grants authority to remove a user original", (
} finally { f.dispose(); }
});
+test("both transcript generations follow their checkpoint through archive and deletion", () => {
+ const f = fixture();
+ try {
+ const rotated = path.join(f.root, "saved.transcript.1.jsonl");
+ writeFileSync(rotated, '{"content":"oldest image reference"}\n');
+ const archived = archiveSavedSession(f.file);
+ const archivedRotated = archived.replace(/\.session\.json$/, ".transcript.1.jsonl");
+ expect(readFileSync(archivedRotated, "utf8")).toContain("oldest image reference");
+ expect(existsSync(rotated)).toBe(false);
+ deleteSavedSession(archived);
+ expect(existsSync(archivedRotated)).toBe(false);
+ expect(existsSync(archived.replace(/\.session\.json$/, ".transcript.jsonl"))).toBe(false);
+ expect(existsSync(archived)).toBe(false);
+ } finally { f.dispose(); }
+});
+
+test("a rotated-only archive reserves the whole stem and cannot be overwritten", () => {
+ const f = fixture(false);
+ try {
+ const directory = path.join(f.root, "archived"); mkdirSync(directory);
+ const previous = path.join(directory, "saved.transcript.1.jsonl");
+ writeFileSync(previous, "previous archive");
+ const archived = archiveSavedSession(f.file);
+ expect(path.basename(archived)).not.toBe("saved.session.json");
+ expect(readFileSync(previous, "utf8")).toBe("previous archive");
+ expect(existsSync(archived.replace(/\.session\.json$/, ".transcript.1.jsonl"))).toBe(false);
+ } finally { f.dispose(); }
+});
+
test.skipIf(process.platform === "win32" || process.getuid?.() === 0)("an unwritable archive preserves the checkpoint and its transcript", () => {
const f = fixture(), archive = path.join(f.root, "archived");
diff --git a/apps/native/lib/session-files.ts b/apps/native/lib/session-files.ts
index e0f02986..44037c84 100644
--- a/apps/native/lib/session-files.ts
+++ b/apps/native/lib/session-files.ts
@@ -2,7 +2,8 @@ import { randomUUID } from "node:crypto";
import { constants, copyFileSync, existsSync, linkSync, lstatSync, mkdirSync, unlinkSync } from "node:fs";
import path from "node:path";
-const SESSION_EXT = ".session.json", TRANSCRIPT_EXT = ".transcript.jsonl";
+const SESSION_EXT = ".session.json";
+const TRANSCRIPT_EXTENSIONS = [".transcript.jsonl", ".transcript.1.jsonl"] as const;
/** The harness appends the full transcript beside the resumable checkpoint.
* Both are saved conversation data, even when compaction removes older turns
@@ -10,13 +11,15 @@ const SESSION_EXT = ".session.json", TRANSCRIPT_EXT = ".transcript.jsonl";
export function savedSessionFiles(file: string): string[] {
if (!file.endsWith(SESSION_EXT)) throw new Error("Invalid saved session path");
const files = [file];
- const transcript = file.slice(0, -SESSION_EXT.length) + TRANSCRIPT_EXT;
- try {
- const stat = lstatSync(transcript);
- if (!stat.isFile()) throw new Error("Saved transcript is not a regular file");
- files.push(transcript);
- } catch (error) {
- if ((error as NodeJS.ErrnoException).code !== "ENOENT") throw error;
+ for (const ext of TRANSCRIPT_EXTENSIONS) {
+ const transcript = file.slice(0, -SESSION_EXT.length) + ext;
+ try {
+ const stat = lstatSync(transcript);
+ if (!stat.isFile()) throw new Error("Saved transcript is not a regular file");
+ files.push(transcript);
+ } catch (error) {
+ if ((error as NodeJS.ErrnoException).code !== "ENOENT") throw error;
+ }
}
if (!lstatSync(file).isFile()) throw new Error("Saved session is not a regular file");
return files;
@@ -33,15 +36,16 @@ export function archiveSavedSession(file: string): string {
const directory = path.join(path.dirname(file), "archived");
mkdirSync(directory, { recursive: true });
const stem = path.basename(file).slice(0, -SESSION_EXT.length);
- const extensions = sources.map(source => source.endsWith(SESSION_EXT) ? SESSION_EXT : TRANSCRIPT_EXT);
+ const sourceStem = file.slice(0, -SESSION_EXT.length);
+ const extensions = sources.map(source => source.slice(sourceStem.length));
let targetStem = stem;
- if (extensions.some(ext => existsSync(path.join(directory, targetStem + ext)))) targetStem += `.${randomUUID()}`;
+ if ([SESSION_EXT, ...TRANSCRIPT_EXTENSIONS].some(ext => existsSync(path.join(directory, targetStem + ext)))) targetStem += `.${randomUUID()}`;
const targets = extensions.map(ext => path.join(directory, targetStem + ext));
const created: string[] = [];
try {
// Exclusive links cannot overwrite an earlier archive, even if another
// process creates a destination after the collision check. Link every
- // companion before retiring either source, so a failure preserves the pair.
+ // companion before retiring any source, so a failure preserves the bundle.
for (let i = 0; i < sources.length; i++) {
try { linkSync(sources[i], targets[i]); }
catch (error) {
diff --git a/docs/adr/0117-clipboard-files-follow-consumer-ownership.md b/docs/adr/0117-clipboard-files-follow-consumer-ownership.md
index 7396acbe..24b06dbd 100644
--- a/docs/adr/0117-clipboard-files-follow-consumer-ownership.md
+++ b/docs/adr/0117-clipboard-files-follow-consumer-ownership.md
@@ -37,9 +37,9 @@ including writers already closing after tab disposal. EOF gives the worker its
final save; a mutation gate prevents replacement writers until the file operation
finishes. Otherwise exit autosave can recreate a deleted reference and invalidate
the evidence used to decide that an attachment has no remaining consumers.
-The resumable checkpoint and its full companion transcript are one saved-chat
-lifetime: deleting removes both, while archiving moves both under a shared
-archive name without overwriting an older pair. An independent archive remains
+The resumable checkpoint and both current and rotated companion transcripts are
+one saved-chat lifetime: deleting removes all, while archiving moves them under
+a shared archive name without overwriting or mixing with an older bundle. An independent archive remains
a consumer of its image references.
## Consequences