feat(handoff): transactional notebook discard during context handoff - #19
Open
ofriw wants to merge 16 commits into
Open
feat(handoff): transactional notebook discard during context handoff#19ofriw wants to merge 16 commits into
ofriw wants to merge 16 commits into
Conversation
…ages Epoch is now a predictable sequential integer (1) instead of Date.now(), enabling the generation-based discard mechanism. Rehydration scans generation markers to ignore staged survivors from interrupted discards. DiscardPages lets agents prune stale notebook pages during handoff: prepareNotebookDiscard stages survivors, commitNotebookDiscard advances the epoch only after compaction succeeds. Interrupted discards leave the branch on the prior generation.
…ions Removes the sessionFactory parameter from executeSpawn and registerSpawnTool, replacing mock-based lifecycle tests with pure function tests and real child invocations via a deterministic provider. Simplifies cleanup error handling from WeakMap to UI notify + cause chain. Moves concurrent and abortion tests to real invocations.
…xpansion expected version
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.
Note: This PR was generated by an AI agent. If you'd like to talk with other humans, drop by our Discord!
Why this PR exists
The notebook is the agent's working memory — facts, decisions, architecture notes that survive context restarts. Three problems were compounding:
/new). Agents accumulated noise.What this PR changes for users and agents
Agents can now prune stale notebook pages during handoff →
handoff("next task", discardPages=["stale-page"]). Deletion is transactional with the context restart: if the delete fails, all pages survive and the fresh context gets a warning instead of silently losing data. This means cleaner context resets without/new.The notebook is now "shared memory" — not "grounding". Spawned children store results for the parent. Handoff successors pick up where the last context left off. The system prompt explicitly tells agents: "Use the notebook as a shared memory between spawned agents and across handoff contexts." This unblocks multi-agent pipelines where children and handoff chains coordinate through a shared namespace.
Handoff tool descriptions got simpler — agents were seeing internal implementation detail (~30% heuristic, primer ordering) that they don't need to make good decisions. Now the description says what handoff does and when to use it, not how it works internally.
Spawn tests dropped mocks because mocks weren't catching real bugs. The import ordering issue in handoff/tool.ts (static import of notebook/store broke
createAgentSession) passed all mock-based tests — they never exercised the real SDK. Tests now run against real agent sessions in sandboxed temp dirs. ThesessionFactoryseam is gone. Cleanup failures surface via UI notifications or errorcauseinstead of a WeakMap nobody checked.CI audit is no longer at the mercy of npm's broken fetch library — native
Node.fetch()with manual gzip detection. Three new advisory overrides documented for known transitive protobufjs/brace-expansion paths.The one thing to watch
The two-phase commit protocol for
discardPages(prepare → compact → commit) means Pi's compaction callback must fire for pages to actually be deleted. If compaction is somehow bypassed, pages stay — which is the safe fallback, but worth noting if you see unexpected page retention.Attached is an agent optimized description of the changes in this PR - AGENT_REVIEW.md