feat: add Zero exec resume and fork sessions#32
Merged
Conversation
Collaborator
BlockersNone found. Non-Blocking
Looks Good
Verdict: Approve — Clean exec session resume/fork foundation. |
Vasanthdev2004
approved these changes
Jun 3, 2026
Vasanthdev2004
left a comment
Collaborator
There was a problem hiding this comment.
Approved after local validation and behavior review.
gnanam1990
force-pushed
the
feat/m3-resume-fork
branch
from
June 3, 2026 10:28
6ac0b5c to
a422f18
Compare
Collaborator
Author
|
Rebased PR #32 onto latest Kept the new runtime context/list-tools flow and restored session resume/fork preparation, contextual prompt wrapping, session event persistence, and regression coverage. Validation after the rebase:
Please re-review when CI finishes: @Vasanthdev2004 @anandh8x |
anandh8x
approved these changes
Jun 3, 2026
anandh8x
left a comment
Collaborator
There was a problem hiding this comment.
Review: Zero exec resume and fork sessions
No blockers. Clean session lifecycle extension with lineage tracking.
What's good
prepareZeroExecSession— Clean tri-mode (new/resume/fork) with mutual exclusion enforced at both CLI and domain layer- Promise queue —
appendSessionEventchains on a serialized promise for non-blocking ordered writes without locks - Prompt context —
formatZeroExecSessionPrompttruncates at 20 events, 500 chars per event, withredactZeroString— no unbounded context or secret leaks - Fork lineage —
parentSessionId,forkedFromEventId,forkedFromSequencein metadata plussession_forkevent marker provide full fork tree auditability cloneJsonValue— JSON round-trip for deep-copying event payloads to forks (handles undefined gracefully)getLatestSession— Simple delegation tolistSessionswhich sorts byupdatedAtdesc; correct for current scale--resumeomits id — Auto-selects latest session; convenient for sequential continuationcreateSessionTitle— First 80 chars of prompt, handles empty/whitespace- Stream-json integration —
sessionIdadded torun_startevent, protocol doc updated - Event coverage — User message, tool calls/results, provider usage, assistant message, and crash errors all recorded
- Crash resilience —
session_forkappended last, so partial forks (mid-copy crash) are detectable by its absence - Test coverage — 335 lines of tests covering: new session, resume latest, resume by id, fork with override, conflict errors, missing targets, session id in stream-json, event recording, fork lineage metadata
Minor issue
formatZeroExecSessionPromptlabel for resume-of-fork — Line 359:prepared.session.parentSessionId ?? prepared.session.sessionId. For fork mode this correctly shows the parent. But for resume mode on a forked session, it shows the parent's ID ("Continuing Zero session parentId") instead of the fork's own sessionId. Should usesession.sessionIdfor resume mode andsession.parentSessionIdfor fork mode:Non-blocking — cosmetic label only, doesn't affect correctness.const displayId = prepared.mode === 'fork' ? prepared.session.parentSessionId : prepared.session.sessionId;
Observations (non-blocking)
- Promise queue cascading rejection —
appendSessionEventchains ontosessionEventQueue. If one write fails, the queue becomes rejected and the finalawaitin both success and crash paths throws. The secondary throw in thecatchblock is unhandled. Could usesessionEventQueue.catch(() => {})to isolate, but acceptable since session writes are secondary to stdout/stderr output forkSessioncopies events serially viaappendEvent— Each event triggers a metadata rewrite (writeMetadatawith incrementedeventCount). Could be optimized with batch append, but correct and simple for M3- No
--context-eventsoption — Full history truncated to 20 events in prompt. Longer sessions silently lose context. Future enhancement candidate
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.
Summary
zero exec --resume [id]andzero exec --fork <id>into headless runs with persisted user, assistant, tool, usage, and crash eventssessionIdin stream-jsonrun_startevents and update the protocol exampleWhy
This gives headless Zero runs a durable session lifecycle so later CLI and TUI flows can continue prior context or branch from an existing run without losing lineage.
Validation
npx --yes bun test ./tests --timeout 15000npx --yes bun run typechecknpx --yes bun run buildnpx --yes bun run smoke:build./zero exec --helpOPENAI_API_KEY= ./zero exec hi --resume abc --fork def --output-format stream-jsongit diff --check origin/main..HEADReviewers
Please review: @Vasanthdev2004 @anandh8x