fix(scratchpad): persist + restore <state> across resume (#713)#730
Merged
Conversation
On interrupt + auto-resume, newt restored the transcript but silently dropped the
scratchpad <state> store (pure in-memory, never persisted), so a resumed
state_get("current_task") returned "no such key" and the model blind-probed for
working memory that was gone (round 0 of the live ornith trace).
Option A (durable): ConversationRecord gains an additive scratchpad: BTreeMap
(serde-default), snapshotted on save into a new conversations-table `scratchpad`
column (DEFAULT '{}', back-filled on open — mirrors #717). restore_conversation_
into_session re-hydrates the live store (clear + replay; restore is a conversation
boundary), and the resume banner announces "restored N <state> key(s)" so the
model reads its task instead of probing.
Provenance-safe: the scratchpad rides the conversations row, never a turn — only
turns feed canonical_encoding_v1, so the content-hash is untouched and existing
chains verify byte-for-byte (proven by scratchpad_round_trips_and_chain_still_verifies).
Scope: the scratchpad only; the plan ledger is a separate follow-up.
Fixes #713
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this PR does
On interrupt + auto-resume, newt restored the transcript but silently dropped the scratchpad
<state>store (pure in-memory, never persisted) — so a resumedstate_get("current_task")returned "no such key" and the model blind-probed for working memory that was gone (round 0 of the live ornith:35b trace).Option A (the issue's durable fix):
ConversationRecordgains an additivescratchpad: BTreeMap(serde-default), snapshotted on save into a newconversations-tablescratchpadcolumn (DEFAULT'{}', back-filled on open — mirrors #717).restore_conversation_into_sessionre-hydrates the live store (clear + replay; restore is a conversation boundary), and the resume banner announces— restored N <state> key(s)so the model reads its task instead of probing.Provenance-safe: the scratchpad rides the conversations row, never a turn — only turns feed
canonical_encoding_v1, so the content-hash is untouched and existing chains verify byte-for-byte.Test plan
4 tests: persist→load round-trip + chain-verify still green (proves content-hash untouched), the TUI save path threads
<state>to the store, restore re-hydrates the live store (state_getresolves, stale key cleared, banner reports count), and the banner empty/singular/plural cases.just checkgreen — newt-core lib 1007, store 53, newt-tui 389; clippy-D warnings+ fmt clean.Out of scope (follow-ups)
The plan-ledger persistence (companion to #714/#718), the recall-excludes-current-conversation fix (#714), the no-result repeat guard (#718).
Fixes #713
🤖 Generated with Claude Code