Repository navigation
Fix hosted Codex response settlement - #497
Conversation
leaf-agent
left a comment
There was a problem hiding this comment.
Two points on the settlement path.
An unstamped final answer commits but never settles. _final_text and _commit_stream_reply treat an agentMessage carrying no phase as the turn's answer — that fallback is the contract test_app_server_events_report_semantic_codex_progress pins, and the adapter durably appends such a message on turn/completed. settles accepts only phase == "final_answer", so against a Codex build that does not stamp the phase the adapter appends the reply while the Stop guard still blocks, and the block message directs the agent to leaf reply — the command the new SKILL.md paragraph tells it not to run. Either instruction loses something: obeying the block drops the streamed answer at commit, since pending is false once the manual reply is the last spoken turn, and obeying the skill leaves the turn blocked. The inline suggestion matches the settle predicate to the commit predicate.
The Stop guard now reads stream.reply rather than the projection. Root CLAUDE.md, under The document starts state; the log changes it, names the stop guard among the consumers of the one activity reading. _stream_answers instead folds the raw status.json record together with the obligations itself, so neither judgment the projection already makes about a live reply applies — activity's WORKING_GRACE quiet test, and browser's downgrade of an active reply to disconnected when present["listening"] is false. The consequence is that settles: true has no expiry. An App Server that goes quiet after item/completed without closing its socket leaves the adapter live, the claim turn open, and the record standing, and every later Stop excuses the same unanswered reader move — the guard is off for that thread rather than deferred. Carrying the reply through activity, beside the obligations it has to be compared against, would give it the same aging as every other live fact.
…#508) `publish-site` deployed release `1f9662ae…` to leaf.page, verified it in Chrome, and then failed the agent pass on what the deployed container itself said ([run 34343130285](https://github.com/max-sixty/leaf/actions/runs/34343130285)): `RuntimeError: https://leaf.page/examples/design-decision/ agent returned an unexpected reply; it replied: I couldn't generate a reply just now. Please send a new message to try again.` The agent had already published the requested heading — the `published` and `replies` checks ahead of it passed — so what stopped the run was the reply, not the deployment. Re-running the same job on the same commit confirmed that: [attempt 2](https://github.com/max-sixty/leaf/actions/runs/34343130285/attempts/2) started twelve minutes later, changed nothing, and went green. ## The gate failed on the deployment answering correctly That reply is `worker/server.py`'s `GENERATION_FAILURE_REPLY`, and the container posts it from exactly one place: `_finish_turn`, when the App Server turn it was following ended with a status other than `completed`. So reaching it means the deployed container noticed a turn that never completed, closed it, and settled the reader's standing ask rather than leaving it open — the behaviour #497 was built to produce. What it reports is the model, not the release. The gate read it as a release defect, which puts every push to `main` behind one live hosted turn generating successfully. That tail is not rare: the three earlier `agent published but did not reply` failures on this step were the same event before #497 gave it a settlement to land in. ## The change The pass now sends the new message that reply asks for, once, and requires that turn to answer. A release that cannot run a hosted turn at all settles the same way twice and still reddens `main`; a single model-side failure does not. Every other ending is still reported on the first ask — a turn that completes without posting a reply settles as `MISSING_REPLY` instead, and a reply that says something else is the deployed agent breaking its own instructions. Both are the agent failing its contract rather than the model failing to run. Two smaller readings follow from that split: - A settled generation failure ends its own wait where it lands. It is posted from where the container closes the turn, so nothing further is coming on that comment — unlike every other reading the wait takes, each of which a live turn can still be passing through. The red run spent five minutes past that reply waiting out `TURN_PATIENCE`. - `TURN_LIMIT` now bounds the pass rather than one ask, and a second ask is only posted while a healthy turn's `TURN_PATIENCE` still fits inside it. The job's budget in `.github/workflows/publish-site.yaml` is unchanged, and the comment stating it stays true. `ask_until_answered` holds the pass so it can be driven without a browser; `ask_for_the_heading` and `await_turn` are the two halves of one ask lifted out of the old body unchanged apart from taking their revision and deadline as arguments. ## Verification - `uv run pytest tests/test_website_server.py` — 29 passed. The three new cases drive both sides of this: the container settling a failed turn, the wait ending on that settlement instead of the budget, and the whole two-ask pass against a page whose first turn stops without replying. Each was checked against a mutation of the code it covers — dropping the retry, reusing the first ask's attempt id, and drifting the settlement text all fail it. - `uv run pre-commit run --files scripts/verify-site.py tests/test_website_server.py scripts/CLAUDE.md` — passed, ruff included. The live path is not reachable from here: Chrome will not launch in this sandbox (`process_singleton_posix.cc:297] Check failed: . socket() failed: Operation not permitted`), so the run above is the evidence for the diagnosis and the unit coverage is the evidence for the change. The step itself only runs on pushes to `main`, and `scripts/verify-site.py` is not in `publish-site`'s trigger paths, so the next push that touches the site payload is what exercises it. ## Relation to #487 and #507 Both are open against other red shapes on this step and neither covers this one: #487 changes `main()` so the agent pass stops re-verifying the release, and #507 changes `await_presentation`'s bound for the reload after the turn. This branch changes what happens between those two — the ask and the wait on it — so the three are independent. Co-authored-by: leaf-agent <[email protected]>
…#1057) On the website, a user's question showed nothing in its thread until the agent's work was done. The host published only the App Server turn's `final_answer` message as the reply, and dropped every `commentary` message so working narration stayed out of the conversation (#497). In a local `scripts/verify_site.py local` run, the reply first appeared at 20.8 s, after the page edit had already published at 16.1 s, although the model wrote a message to the user 2 s into the turn. The turn's first agent message is now the reply's opening, when App Server marks it commentary and only the turn's input and reasoning precede it. It streams into the thread at once. Any other commentary stays private, including narration after a tool call from an agent that skipped the opening. The committed reply is the opening plus the final answer. Only the final answer's completion settles it, so the Stop guard still waits for that, and a turn with no final answer commits nothing. A reconnect mid-turn restores the opening already on screen, and a completed turn's message state is dropped, so an adopted next turn starts clean. The website host and the `leaf codex` adapter share this fold (`AppServerEvents` in `codex.py`). Measured with the same local run afterwards, the reply first appeared at 6.1 s, the edit published at 13.6 s, and the reply committed at 43.1 s. The agent learns the rule from three places: - the delivered `answering.reply` clause in `registry.json`; - `host-codex-app-server.md` "Replies", which the website agent reads in full; - `ANSWER_ASK_INSTRUCTION` in `schema.py`. `docs/how-it-works.html` describes the rule and repeats the delivered clause. Behavior that moved: `test_app_server_events_report_semantic_codex_progress` now opens its turn with a commentary message. That opening streams, and the commentary after it still does not. The test also checks: - what `final_text` commits, with and without a final answer; - what a reconnect restores; - that narration after a tool call is never the opening; - that a completed turn leaves no state behind. The snapshots are regenerated for the changed clause: the handling table, interaction recovery, summary suggestion and hosted delivery. Gaps: - There has been no run on the deployed leaf.page and none through the Cloudflare container path. - There has been no live run of the `leaf codex` terminal adapter. - The early reply depends on the model writing an opening before its first tool call. A model that skips it falls back to the old timing. 🤖 Generated with [Claude Code](https://claude.com/claude-code) > _This was written by Claude Code on behalf of max-sixty_ --------- Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
Dogfooding the App Server-backed Leaf path exposed two user-visible failures: Codex commentary appeared in the Leaf conversation, and the Stop hook blocked the turn before the adapter could commit its final answer. The latter forced the agent back onto a manual
leaf reply, defeating the direct-response path.This keeps commentary in Codex, marks only a completed final-answer item as sufficient evidence for the exact bound Leaf obligation, and lets successful
turn/completedcommit the durable reply. Older App Server messages without a phase stamp follow the same fallback for settlement and commit. The Stop guard consumes the canonical activity projection, which matches task, turn, comment, and conversation identity and ages the evidence by the adapter lease and working grace; failed, partial, empty, disconnected, stale, or mismatched responses remain unanswered. The directleaf_feedbackskill route now tells Codex to answer normally instead of duplicating the adapter withleaf reply.The path was exercised with a real App Server, Codex CLI, and live Leaf page: the final answer streamed incrementally, became exactly one durable reply, and the Codex turn returned to idle without a manual Leaf command. The full Python suite and pre-commit gate pass.