Skip to content

fix(task): keep checkpoint snapshot ids unique across restarts - #1369

Merged
alvinunreal merged 1 commit into
alvinunreal:masterfrom
drakeo338:claude/1368-fix
Sep 30, 2026
Merged

alvinunreal merged 1 commit into
alvinunreal:masterfrom
drakeo338:claude/1368-fix

Conversation

@drakeo338

Copy link
Copy Markdown
Contributor

Fixes #1368.

Checkpoint board snapshot ids were built from the session id and nextSnapshotSequence, which lives only in memory and restarts at 0 in every process. After an OpenCode restart the same id then named different board text than before, so plugins that key persisted state by id sent stale text and missed the prompt cache. Each snapshot state now carries a random per-instance epoch that is part of the id.

Ran the task-session-manager tests on the committed HEAD: 3 failed before the change, all 190 pass after. Lint and typecheck were not run.

The board snapshot id was built from a per-session sequence that starts
at 0 whenever the in-memory state is created, so a restart or a
compaction reset reused ids like parent-1:0 for different boards. Add a
random epoch to the retained state and include it in the id. Ids stay
stable while the state lives, so the prompt cache is unaffected.

Fixes alvinunreal#1368
@greptile-apps

greptile-apps Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

[Medium risk] Changes how checkpoint snapshot identifiers are generated.

The PR appears safe to merge, though a larger epoch would better protect against eventual ID reuse.

Findings

  1. P2 Snapshot epochs can collide ▶

Summary

The PR adds a random epoch to checkpoint-board snapshot IDs so a fresh in-memory state does not normally reuse IDs from before a restart. It also updates ID assertions and adds a restart regression test.

Reviews (1) · Last reviewed commit: "fix(task): keep checkpoint snapshot ids ..."


const current = state.retainedBoardSnapshots.get(sessionID) ?? {
snapshots: [],
epoch: randomBytes(4).toString('hex'),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Snapshot epochs can collide Four random bytes provide only 32 bits of entropy. If the same session's state is recreated enough times, an epoch can repeat; because the snapshot sequence also resets to zero, different board text could then receive an old snapshot ID. A larger epoch would make this risk negligible.

Suggested change
epoch: randomBytes(4).toString('hex'),
epoch: randomBytes(16).toString('hex'),

@alvinunreal
alvinunreal merged commit f3b0fd3 into alvinunreal:master Sep 30, 2026
1 check passed
Jiajun0413 added a commit to Jiajun0413/oh-my-opencode-slim that referenced this pull request Sep 30, 2026
…poch

Master regression from alvinunreal#1369 (which fixed alvinunreal#1368): checkpoint snapshot ids
now carry a per-instance random epoch so ids differ across restarts. The
determinism property test compares two fresh-pipeline renders byte-for-
byte and treats the id envelope as payload, so the deliberate epoch reads
as nondeterminism and the test fails on master (the two Bun checks never
ran on alvinunreal#1369 before merge, so the regression slipped in).

Two-part fix, both test-side:

1. Normalize the epoch segment before comparison — field-delimited: only
   the "id" and "snapshotID" fields of board messages are touched, and
   only the exact 8-hex epoch segment followed by the sequence. Every
   other byte, including all board text, stays pinned; a future random
   segment anywhere else still fails this test.
2. Add randomBytes(...) to the cache-safety tripwire VOLATILE_PATTERNS
   with a reviewed allowlist entry for board-injection.ts — the exact
   blind spot alvinunreal#1369 slipped through. Board text stays deterministic; the
   epoch is restart-scoped identity metadata that never reaches provider
   bytes (snapshotID is dropped by the host converter, pinned by
   board-injection-cache-safety.test.ts).

Coexists with alvinunreal#1369's own test (restart => different ids): different
lifecycles, different files, no overlap.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: checkpoint-compatible board snapshot ids repeat after a plugin restart, busting the prompt cache

2 participants