feat(engine): persistent interactive sessions — no per-turn respawn (spec 2026-07-02) - #95
Merged
Merged
Conversation
…SS_ENGINE=interactive) One long-lived 'claude -p --input-format stream-json --output-format stream-json' process per session, managed by the daemon: - interactive_engine.py: thread-based reader, FIFO for mid-turn sends, lazy crash-respawn via --resume (context survives), stale-reader epoch guard, oversized-line skip, deterministic stop (reap + join). - wsclient: ORC_HEADLESS_ENGINE=interactive routes headless.prompt to a per-session engine registry under the existing per-session lock; same digest/reset delivery semantics; tail suppression contract preserved; blocking pipe IO kept off the event loop. Default per-turn path and sdk path untouched — env var stays the rollback switch. - daemon: engines stopped on shutdown. - tests: fake_claude.py protocol stand-in (echo/crash/tool modes), 6 engine unit tests (multi-turn same process, FIFO, crash-resume, tool steps, idempotent stop), 2 routing tests (persistent process across prompts, tail suppression). Spike-verified against the real binary: multi-turn context retained on one process, turn-2 latency 2.6s vs ~5-15s per-turn respawn. Review findings addressed: loop-blocking stdin write, stuck turn flag on double write failure, late events after stop, unreaped kill. Suite: 259 passed (2 pre-existing wsclient drain failures, on main too).
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.
Goal
Phase-2 centerpiece of the session-bridge spec (vault:
05 Specs/2026-07-02-interactive-engine-orc-owned-sessions.md, operator-approved): ORC owns a persistentclaude -p --input-format stream-json --output-format stream-jsonprocess per session — the operator's own insight ("the VS Code extension is just a wrapper around this; own the process ourselves").Why
--resumerespawn; blocks stream as they complete.Changes
host-agent/agent_host/interactive_engine.py— subprocess manager: daemon reader thread, FIFO for mid-turn sends, lazy crash-respawn with--resume(context survives via transcript), stale-reader guard, 1MB line skip, deterministicstop().wsclient.py—ORC_HEADLESS_ENGINE=interactiveroutesheadless.promptto a per-session engine registry (same per-session lock, same digest/reset delivery frames, same tail-suppression contract). Default andsdkpaths untouched — the env var remains the instant rollback switch (2026-06-22 lesson: one mechanism at a time).daemon.py— engines stopped on shutdown.fake_claude.pyprotocol stand-in + 8 tests (multi-turn on ONE process, FIFO queueing, crash→resume respawn, tool steps, idempotent stop, routing, suppression). No API calls in CI.Review
Independent review (gpt-5.5) found 4 real concurrency/lifecycle bugs — all fixed: event-loop-blocking stdin write (now
asyncio.to_thread), turn flag stuck after double write failure, late events after stop/recycle, unreaped process + unjoined reader on kill.Test Summary
host-agent: 259 passed; 2 pre-existing
test_wsclient.pydrain failures (identical on main). Backend: untouched (0 files). Ruff clean.Deploy / live gate (after merge — per spec, before flipping the default)
git pull, setORC_HEADLESS_ENGINE=interactiveindeploy/orc-stack/orc-stack.env, kickstart daemon.Built per operator routing: engine core by kimi-k2.7-code:cloud, tests by glm-5.2:cloud, routing + review + fixes by the lead.