feat: compaction-resilient session state (Claude Code + Codex)#15
Open
gabelul wants to merge 2 commits into
Open
feat: compaction-resilient session state (Claude Code + Codex)#15gabelul wants to merge 2 commits into
gabelul wants to merge 2 commits into
Conversation
added 2 commits
May 25, 2026 23:46
Active project, generated screens, and the PRD draft now survive a host context compaction instead of living only in the conversation. - scripts/stitch-session.mjs: one canonical state writer (CLI + helpers) - hooks/: PreCompact snapshots a transcript backstop and breadcrumb; SessionStart re-orients the model on source=compact via additionalContext - stitch-ideate / stitch-orchestrator: persist state as they go, plus a resume self-check for hosts where the hooks aren't trusted yet (Codex) - on-PATH 'stitch-session' launcher (npm bin + installer symlink) so Codex skills, which can't reference a bundled script, can still write state - .codex-plugin/ manifest so the hooks register under Codex CLI State values are sanitized before context injection, the hooks always exit 0 (never block compaction), and the launcher's main-guard resolves symlinks.
Sharpens the 'honest limitations' framing in both the PR body and the feature doc: the mid-phase reasoning loss isn't 'covered by the transcript backstop', it's a real gap whose proper fix is the exec plans pattern. Adds docs/dev-docs/exec-plans-followup.md with the planned shape: .stitch/session/plan.md with five sections (Purpose / Progress / Surprises / Decision Log / Outcomes), written at decision points via the ss wrapper. Designed not built; the current PR stays scoped. Pattern from https://developers.openai.com/cookbook/articles/codex_exec_plans
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.
Why
The orchestrator/ideate flows run inside a host (Claude Code, Codex) that compacts the conversation when its context window fills. Today most of the work survives by luck — the PRD is on disk, screens live in Stitch's backend — but a long ideation session loses its gathered research, because the PRD only gets written at the final phase. This makes the resilience deliberate instead of accidental, and ports it to Codex too.
How — two layers
State lives outside the conversation. One canonical writer,
scripts/stitch-session.mjs, owns.stitch/session/state.json(active project, generated screens, applied design system, artifact pointers) and a runningprd-draft.md.stitch-ideateflushes after each phase;stitch-orchestratorrecords the project/screens/design-system as it goes.Hooks re-orient after a compaction.
PreCompactsnapshots the raw transcript (owner-only) and aRESUME.mdbreadcrumb;SessionStart(source: compact) injects a "you're mid-flow, re-read this, don't restart" line viaadditionalContext. Both no-op silently when there's no Stitch session and always exit 0.Host support
hooks/hooks.json; skills reach the helper via${CLAUDE_SKILL_DIR}..codex-plugin/plugin.json). Codex firesSessionStart:compacttoo and providesCLAUDE_PLUGIN_ROOTas a compat env var, so the samehooks.jsonworks. Codex skills can't reference a bundled script, so the helper is exposed as an on-PATHstitch-sessioncommand (npmbin+ installer symlink); skills call it through a wrapper that falls back to the Claude Code path, and self-recover viass readwhen hooks aren't trusted yet.Reviewed
OMC code-reviewer (APPROVE) + a Codex second opinion. Security model holds — state values are sanitized before context injection, no path traversal in snapshot filenames, no shell/JSON injection. The symlink main-guard bug (npm
binis a symlink, so a naiveimport.meta.url === argv[1]silently skippedmain()) was caught and fixed withrealpathSync.Verify before merge (live hosts — can't be tested offline)
/compactmid-flow → next turn knows the projectcodex plugin add ., trust the hooks,/compact→ re-orientation fires and${CLAUDE_PLUGIN_ROOT}resolvesHonest limitations
prd-draft.md. Tracked as a follow-up indocs/dev-docs/exec-plans-followup.md; the raw-transcript backstop insnapshots/is the recoverable-but-ugly stopgap until that lands.PostCompactstdout is ignored, so re-orientation rides onSessionStart:compact, notPostCompact.Details:
docs/compaction-resilience.md. Landmines:docs/dev-docs/troubleshooting.md.