Repository navigation
Stream App Server finals as delivery-bound Leaf replies - #633
Conversation
leaf-agent
left a comment
There was a problem hiding this comment.
Two inline findings on the website carrier, plus one contract doc left behind.
skills/leaf/scripts/leaf/page-storage.md still describes status.json's stream as holding only "the latest session-, turn-, and event-floor-bound activity observed from a live Codex App Server", "cleared when the turn or observer ends". After this change the record also carries stream.reply — a reply draft the browser renders inside a thread, not activity — and that member deliberately survives turn close: AppServerReplyStream.finish writes state: "failed" and leaves the draft standing so the text stays visible, and only a successful _commit_stream_reply clears it. CLAUDE.md names that file as the one that "defines the complete layout", so both sentences are now wrong about the record they describe. session-lifetime.md got its new row; this one didn't. Happy to push the doc commit if you'd rather not hand-edit it.
leaf-agent
left a comment
There was a problem hiding this comment.
One finding on the new unbound-queued terminal path, inline. It refines rather than repeats the last round's ask: closing a turn there is right in principle, but close_session_turn closes the session's current turn, which in the queued case belongs to the direct turn still running.
Leaf's App Server path could stream activity, but its final answer still had to make a separate reply-helper call. That added another model/tool round trip and left queued or overlapping turns without a stable response destination.
This change makes the App Server final-answer item the canonical Leaf reply whenever an immutable delivery has exactly one plain reply obligation. Direct and queued turns bind through the delivery id, provisional deltas appear in the addressed thread, and the completed text commits through the existing validated reply writer. Delivery identity remains authoritative across Stop hooks, a later turn opening, and observer reconnects; current-turn identity governs only activity and provisional display. Multi-response, version, and receipt obligations retain their explicit operations.
The implementation shares the same delivery envelope, activity projection, conversation rendering, and reply contract between the desktop adapter and the website container. Guidance and protocol references now describe one response rule rather than separate direct-versus-queued behavior.
Validation:
uv run pytest tests— 1,051 passednpm run typecheck --prefix workernpm test --prefix worker— 60 passedmain: page presented in 715 ms, comment acknowledged in 428 ms, Starting at 3.53 s, publication at 11.99 s, first reply visible at 17.09 s, durable reply at 18.39 s; App Server turn start was 47 ms and the container request completed in 110 ms