Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/adapters/google-antigravity-replay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,15 @@ function refreshReplaySessionCandidate(key: string, entry: ReplayEntry): void {
}

function deleteExpiredReplaySessions(now: number): void {
for (const [key, entry] of replayCache) if (entry.expiresAtMs <= now) deleteReplaySession(key);
let deleted = false;
for (const [key, entry] of replayCache) {
if (entry.expiresAtMs > now) continue;
deleteReplaySession(key);
deleted = true;
}
// Expiry is a durable mutation too: rewrite the snapshot so opaque thought
// signatures do not remain at rest after their in-memory TTL has elapsed.
if (deleted) markReplayDirty();
}

/**
Expand Down
14 changes: 14 additions & 0 deletions tests/google-antigravity-replay.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,20 @@ describe("durable antigravity replay snapshot", () => {
await flushAntigravityReplay();
});

test("sweeping expired sessions removes them from the durable snapshot", async () => {
const now = Date.now();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Compute the sweep deadline after inserting the session

If the clock advances by more than 1 ms between this timestamp capture and observeAntigravityReplay, the entry expires later than now + TTL + 1, so the sweep removes zero sessions and the new regression test fails nondeterministically under a scheduling pause or slow CI. Capture the reference time after insertion, use a comfortably later sweep time, or inject a fixed clock so the assertion always crosses the actual expiry.

Useful? React with 👍 / 👎.

observeAntigravityReplay(MODEL, SESSION, [fcPart("get_x", { a: 1 }, SIG)]);
await flushAntigravityReplay();
expect(readFileSync(snapshotPath(), "utf8")).toContain(SIG);

expect(sweepExpiredAntigravityReplay(now + 60 * 60 * 1000 + 1)).toBe(1);
await flushAntigravityReplay();

const raw = JSON.parse(readFileSync(snapshotPath(), "utf8")) as { sessions?: unknown[] };
expect(raw.sessions).toHaveLength(0);
expect(readFileSync(snapshotPath(), "utf8")).not.toContain(SIG);
});

test("snapshot cap keeps the most recently active sessions", async () => {
// A (two calls, ~899 serialized bytes) fits under the cap; A+B (~1,347)
// does not, so the cap must pick exactly one session by activity.
Expand Down
Loading