Skip to content

Stream App Server finals as delivery-bound Leaf replies - #633

Merged
max-sixty merged 7 commits into
mainfrom
codex/streamed-agent-replies
Sep 12, 2026
Merged

max-sixty merged 7 commits into
mainfrom
codex/streamed-agent-replies

Conversation

@max-sixty

@max-sixty max-sixty commented Sep 12, 2026 •

Copy link
Copy Markdown
Owner

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 passed
  • npm run typecheck --prefix worker
  • npm test --prefix worker — 60 passed
  • canonical local browser benchmark after merging current main: 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
  • independent Astra review of Stop-hook, concurrent-turn, reconnect, and historical-stream isolation paths — no findings after fixes

This was written by Codex on behalf of max-sixty

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread worker/server.py Resolved
Comment thread worker/server.py Resolved

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread worker/server.py Resolved
@max-sixty
max-sixty merged commit 602c6b6 into main Sep 12, 2026
7 checks passed
@max-sixty
max-sixty deleted the codex/streamed-agent-replies branch September 12, 2026 16:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants