Repository navigation
Unify Leaf agent delivery across transports - #561
Conversation
…nterface # Conflicts: # scripts/verify-site.py # tests/test_website_server.py
leaf-agent
left a comment
There was a problem hiding this comment.
Two pieces of shipped guidance describe the new envelope in ways the code doesn't produce.
version obligations name the wrong operation. SKILL.md and host-codex.md both tell the agent that a response.kind: version obligation is discharged with leaf version stamp. A version note's settles relation accepts only report and work targets ($settlement in skills/leaf/assets/registry.json), and the thread loop in acknowledgments.py clears a version-response conversation only on thread["resolved"] or a later clarification thread on the same seat. So a stamp leaves the obligation standing, and the Stop guard in hooks.unattended_pages then blocks the turn with ANSWER_ASK_INSTRUCTION — which states the actual operation, "revising the page and resolving it". The agent is given contradictory instructions for the same obligation by two surfaces this PR touches.
The worked envelope in docs/how-it-works.html shows an impossible event. The comment carries "subject":{"kind":"conversation","id":"a56486d1"} next to "conversations":[]. _subject in delivery.py returns {"kind":"page"} whenever conversations is empty, so that pair can't occur; thread_roots maps an opening comment to itself, so its membership is ["a56486d1"]. The batch-level conversations does stay [] — thread_digest omits the batch's own messages and the pick is on a page widget — so the prose below the specimen is still right, and only the event's own list is wrong. This is the only worked example of leaf-delivery-v1 on the published site, so it's what an integrator will model the subject/conversations relation from.
leaf-agent
left a comment
There was a problem hiding this comment.
Two points on the finishing commit.
worker/README.md keeps the settlement claim the other two surfaces just dropped. The new sentence — "Only explicit leaf reply, leaf version stamp, and leaf receipt commands settle accepted input" — is the same claim this commit rewrote in SKILL.md and host-codex.md. $settlement in skills/leaf/assets/registry.json admits only report and work targets, so a stamp never clears a reader conversation whose response.kind is version; a revision closed with leaf resolve does, which is what ANSWER_ASK_INSTRUCTION prints when the Stop guard blocks the turn. Left as is, the website surface still tells an integrator the thing the other two now contradict.
The demo waiter reports a wait that ended with nothing as a batch-count error. leaf wait, and the leaf ack re-arm it hands off to, end with empty stdout and the reason on stderr — the page idled under it, ownership moved, a server it won't restart twice. receive now turns that into "received 0 page batches instead of one" and discards stderr, so the docstring directly above it ("the empty result is the symptom and that line is the reason") no longer describes what the method does. test_demo_recording_drives_the_browser_journey is nightly-marked, so this message is what a nightly break gets read from.
leaf-agent
left a comment
There was a problem hiding this comment.
Both fixes confirmed on 62c6c433. The waiter now carries the exit status and stderr into the batch-count error, and test_demo_waiter_preserves_the_reason_a_wait_delivered_nothing puts that path under the everyday gate. tests/test_product_page.py -m "not nightly" (8 passed) and tests/test_website_server.py (54 passed) are green here.
One surface named in that thread is still open, and it is the one that reaches a live reader: CODEX_INSTRUCTIONS in worker/server.py:84 still tells the website agent to "edit and publish the page for a version response". That string is the agent's entire guidance — it is passed as developerInstructions at line 584 and the container loads no skill — so nothing else tells it how to close the ask.
Publishing is half the operation. _response addresses the obligation as {"kind": "version", "conversation": <id>}, and the thread loop in acknowledgments.py clears that conversation only on thread["resolved"] or a later clarification thread on the same seat. So after the agent revises, runs version check, and returns to waiting, the reader's ask is still standing on the hosted page. cmd_resolve already enforces the order — it refuses while the revision doesn't answer the Ask — so publish-then-resolve is the only sequence it accepts, and naming it costs the instructions one clause.
…ntracts (#582) The scheduled complete suite came back **38 failed, 2393 passed, 6 skipped** on [run 34562158190](https://github.com/max-sixty/leaf/actions/runs/34562158190). Ten of those are already repaired by #576, #579 and #580, which merged after that run started. This realigns eight more, all of them tests stating a contract a recent change deliberately replaced without running the nightly file that names it. ## The preview places itself before it hands over focus #551 replaced the thread preview's placement engine with Floating UI and made the lifecycle asynchronous: `deferThreadPreviewFocus` waits on the placement promise and focuses the card from it. Three tests read `document.activeElement` in the same turn as the press that opens it, so they see the page rather than the conversation. Bisecting `test_a_tap_on_a_quote_opens_its_thread` across `013f3c44..692032a` names 24f4efc as the first bad commit, and a probe on `main` shows the conversation arriving on the poll after the press. `conversation_a_press_opened` states that ordering once for the three of them. It keeps each test's own failure message — the wait answers None rather than raising, so a press that opens the wrong conversation still reports which one it opened, which is the whole point of the seam fixture. ## The compact card reveals its reply box on request #574 made the popover compact: Reply appears when asked for or when a draft exists, and the card's accessible name became "Conversation for …". So `test_pressing_the_current_element_mark_keeps_its_contour` waited 30s for a `textarea` the card no longer shows — the paint it asserts is the same either way — and `test_a_drawing_can_be_sent_without_words` looked for a dialog named "Thread for …". That test held the only remaining reading of the old wording. ## Settlement reads `responds` #561 made an agent reply settle a reader's word only by naming it in `responds`, and made `leaf reply` require exactly one of `--for` and `--initiates`. Three fixtures pre-date both: one invokes the CLI with neither flag, and two append a reply event that the projection then reads as unanswered, so the receipt and the neighbouring-page row stay where the test expects them to move on. Other hand-written reply fixtures do not assert settlement and are left alone. ## Verification - Complete `tests/test_render_anchors.py`: **3 failed, 92 passed**. The three are the response-bar and widget-text cases #547 already tracks. - Complete `tests/test_render_drawing.py` and `tests/test_render_controls.py`: **3 failed, 114 passed**. All three fail on `main` without this branch — two are in #547's scope, and `test_each_control_archetype_holds_its_neighbours_still[diff-review]` is a thirty-ninth failure that arrived on `main` after the run above. - `pre-commit run --files` over the three changed files: passed. The rest of the run's failures stand. #547 carries them, and I have refreshed it with what this run and `main` now show. Co-authored-by: leaf-agent <[email protected]>
Leaf’s direct session, Codex queue, App Server, and website paths represented reader input differently. The website adapter could fan one native final response across multiple Leaf conversations, while agent-facing state made it difficult to retrieve one exact conversation.
This replaces those paths with one transport-neutral
leaf-delivery-v1envelope. A delivery contains complete ordered page batches; conversation membership is context rather than a partition key; queued work is addressed by an immutable delivery ID; andleaf conversation readreturns one exact bounded conversation. Native host final messages no longer settle Leaf input. Replies and receipts use explicit response addresses, and durablerespondsscope prevents stale or superseded input from being settled accidentally.The cutover removes the previous thread filters, native-final reply binding, provisional reply machinery, and adapter-specific batch representations. The shipped skill, host references, event/storage specifications, examples, website instructions, and demo driver now use the same interface.
Verification:
uv run pytest tests(1,003 passed), including an everyday regression for empty delivery diagnostics; all 36 site pages regenerated; andscripts/verify-site-agent-local.shcompleted a real two-comment App Server journey through queue, immutable delivery read, exact replies, and both terminal turn events. An Astra design review found no remaining issues after adversarial stale-reply and widget-supersession probes.