fix(sync): don't route the remote-http persistent transcript dir through cleanup (#1802)

The ingest finally ran cleanupStagingDir() unconditionally, but in remote-http
mode stagingDir is the PERSISTENT transcript dir (~/.gstack/transcripts/) that
gstack-brain-sync push must consume. The remote-http branch documents the intent
to skip cleanup, but a finally runs on its return. Gate the call on
!remoteHttpMode so the ownership guard only ever sees .staging-ingest-* dirs.
Pre-gate this dir was deleted outright (broken artifacts handoff); post-#1827 it
produced a false 'prevent data loss' warning every sync.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Garry Tan
2026-06-03 07:19:01 -07:00
parent ef606117a9
commit db825fc7af
2 changed files with 36 additions and 1 deletions
@@ -350,3 +350,30 @@ describe("#1802 checkOwnedStagingDir — ownership matrix", () => {
expect(sync).toMatch(/checkOwnedStagingDir\(stagingDir, gstackHome\)/);
});
});
// ── #1802 D1: remote-http persistent dir must never hit cleanupStagingDir ───
// In remote-http mode `stagingDir` is the PERSISTENT transcript dir
// (makePersistentTranscriptDir, under ~/.gstack/transcripts/) that
// gstack-brain-sync push consumes. The finally runs on the remote-http `return`,
// so the cleanup call there must be gated on `!remoteHttpMode` — otherwise the
// guard refuses it on every sync (false "prevent data loss" warning) and, pre-
// gate, the dir was deleted outright (broken artifacts handoff).
describe("#1802 D1 — remote-http finally gate (static invariant)", () => {
const ingest = fs.readFileSync(
path.join(ROOT, "bin", "gstack-memory-ingest.ts"),
"utf-8",
);
test("finally gates cleanupStagingDir on !remoteHttpMode", () => {
expect(ingest).toMatch(/if \(!remoteHttpMode\) cleanupStagingDir\(stagingDir\)/);
});
test("the only finally-scoped cleanup call is the gated one", () => {
// Locate the finally block and assert it does not contain a bare
// `cleanupStagingDir(stagingDir);` that would run regardless of mode.
const finallyAt = ingest.lastIndexOf("} finally {");
expect(finallyAt).toBeGreaterThan(-1);
const finallySlice = ingest.slice(finallyAt, finallyAt + 800);
expect(finallySlice).not.toMatch(/^\s*cleanupStagingDir\(stagingDir\);/m);
});
});