Repository navigation
Tell an agent where a misdirected id belongs, from what the log still owes for it - #857
Conversation
`leaf receipt PAGE REQUEST` refused any id that was not a request with only `unknown request 'X'`. The id is a bare string, and nothing about it says which namespace it came from, so an agent holding a comment's or a delivery's id reaches for `receipt` with it; a refusal that repeats the id leaves it nothing to change but the guess. A hosted turn on the site's local verification did exactly that after publishing, and spent thirty seconds on six forms of `leaf receipt` before it gave up. The refusal now reads both answers off the log: what the id is when the log holds it (`'…' is a comment in this page's log, not a request`), and which requests are still open, or that there are none. It is the same recourse #837 gave `--section`. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The receipt refusal was a second hand-written answer to "what is this id?" beside the one #837 gave `--section`, and `--to` had a third that listed the page's messages but never said what else an id was. `logged_id_route` in `validation/admission.py` answers it once — what the log holds a bare id as, and which command takes it — and `--section`, `--to` (reply and resolve), and `receipt` all refuse through it. A request routes to its receipt, a message to `--to` and `--for`, and any other delivered move to `--for`. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
leaf-agent
left a comment
There was a problem hiding this comment.
Following the new message lands on a second dead end.
logged_id_route's fallback names leaf reply <page> --for <event-id> for every kind that isn't a request or a message, and --for does not take most of them. Running the two commands in sequence, on a page whose log holds one resolve:
$ leaf comment <page> --section ce978f1469d72e5dd4f9ac52cb06e608 --text hi
can't anchor in revision r1: no element id 'ce978f1469d72e5dd4f9ac52cb06e608' in this version;
ce978f1469d72e5dd4f9ac52cb06e608 is a resolve in this page's log —
`leaf reply <page> --for <event-id>` addresses a delivered move, while `--section` takes an
element id the page's markup declares
$ leaf reply <page> --for ce978f1469d72e5dd4f9ac52cb06e608 --text hi
event 'ce978f1469d72e5dd4f9ac52cb06e608' no longer requires a reply; read the current delivery
or conversation state
The agent is sent to a writer that refuses the value, and the refusal waiting there is the one this PR exists to remove: it names no route, and it answers an id the log has never held, an element id the markup declares, and a settled move with the same sentence.
The fact that decides --for is not the event's kind but whether the log still owes a response for it. --for is accepted only where the event's current_responses entry is a reply, so resolve, undo, pickup, and receipt never qualify and an action stops qualifying once it is answered. Both invariants the docstring states — "--for takes every kind the log holds but a request", and "every writer that refuses an id asks this, and says where the value belongs" — are claims the code does not hold, and the next reader will act on them.
The writer being routed to already computes the answer and discards it. In cmd_reply, the --for branch reads expected = responses.get(for_event) and then exits with event {for_event!r} no longer requires a reply whenever expected is not a reply. For an open request that expected is {"kind": "receipt", "request": ...} — the receipt route this PR's helper would have named:
$ leaf reply <page> --for 0ce64fc155d5ba41e0e9a5607c63711d --text hi
event '0ce64fc155d5ba41e0e9a5607c63711d' no longer requires a reply; read the current delivery
or conversation state
Reading that refusal out of current_responses — name the receipt, name the version, or say the log does not hold the id at all — closes both faces at the one writer where the obligation is already in hand, and leaves logged_id_route's kind-based reading for receipt_contract_error, whose door signature carries no page_dir to derive an obligation from. That would also make the docstring's second invariant true rather than aspirational. I'm happy to push it if you'd like it in this PR.
The route table read the event's kind, and `--for` does not take most kinds: it takes an id whose `current_responses` entry is a reply, so a `resolve`, an `undo` or an answered action was sent there only to meet `no longer requires a reply` with no route at all. `logged_id` now takes the current responses and names the command that settles what is owed — a reply, a receipt — or says the thread takes a page version, or that nothing is owed. `--section`, `--to` and the `--for` refusal read it; `receipt`, whose door has the log and not the page, names the kind and the open requests and no route. `--to`'s refusal needs the page to read the obligation, so `_message` and `_thread_root` take it. #837's `--section` test answered the agent's own comment, which is owed nothing; it now answers a reader's. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
Right:
|
leaf-agent
left a comment
There was a problem hiding this comment.
Two refusals still end where this PR says they shouldn't.
A message owed nothing loses the writer that takes it. Reading the obligation is right for --for, but --to is keyed on the kind rather than the obligation — it takes every message id in the log, standing obligation or not. So the one case the obligation reading cannot see is a message with nothing owed, which is #837's original fixture: the agent's own comment. On this head:
$ leaf comment <page> --quote 'Ship dark' --text note # -> X
$ leaf comment <page> --section X --text x
can't anchor in revision r1: no element id 'X' in this version; X is a comment in this
page's log, and nothing is owed for it, while `--section` takes an element id the page's
markup declares
$ leaf reply <page> --to X --initiates --text more
replied in X
$ leaf resolve <page> --to X
{"kind": "resolve", ...}
The refusal reports the value as unroutable while two writers take it unchanged — the dead end the PR exists to remove, moved onto the kind the old _foreign_id_recourse was the one to route. The inline suggestion names --to for a message kind; it needs from leaf.schema import MESSAGE_KINDS at the top of the module, which a single-line suggestion can't add. tests/test_interact_anchors.py and tests/test_interact_document.py stay green with it (215 passed), including the new settled-move case.
receipt's "the door hands this the log and not the page" is not true, and it is the reason given for the one writer that still names no route. _receipt_error sits in admission_error's chain between _report_error(page_dir, ...) and _anchored_comment_error(page_dir, ...), both of which read the same page_dir, events = page.page_dir, page.events local at the top of that function. Widening that one signature is the whole change: with receipt_contract_error taking page_dir and passing current_responses(page_dir, events) into logged_id, leaf receipt <page> <comment-id> failed answers
53c0e4215101cdc9045b3f63f23682c1 is a comment in this page's log — `leaf reply <page>
--for 53c0e4215101cdc9045b3f63f23682c1` answers it, not a request; open requests: '0038…'
with only the wording pinned in test_receipt_settles_one_known_request_once to update (and the {held}, not a request composition to reorder). That matters most here: leaf receipt is the command the PR's opening paragraph is about, and it is the one writer left saying only what the id isn't. Leaving it routeless is defensible; recording a constraint that isn't there is what the next reader acts on.
Happy to push both if you'd rather not.
… route `--to` takes any message, obligation or not, so the one id the obligation reading could not route was a message owed nothing: the agent's own comment, which `reply --to <id> --initiates` and `resolve --to` both take. `logged_id` names that route for a message owed nothing, and says nothing is owed only for what no writer takes. The receipt refusal claimed its door hands it the log and not the page. The dispatcher holds the page and every neighbouring contract takes it, so `_receipt_error` passes it on and the refusal reads the obligation like the rest. `requests` reaches `current_responses` on the refusal rather than at import, since `delivery` loads it. Every caller now has the reading, so `logged_id`'s kind-only branch is gone. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
Both taken.
|
leaf-agent
left a comment
There was a problem hiding this comment.
The --to … --initiates route is refused whenever the message's conversation owes a reply, so this commit reinstates the dead end it removes — on the very fixture the new test uses.
logged_id reads the obligation per event, because current_responses is keyed by event id. cmd_reply admits --initiates per conversation: it exits conversation {root_id!r} currently requires a response; use the delivered --for event instead of --initiates when the message's thread root is in reply_roots, and refuses earlier still when that root's response is a version (thread {root_id!r} requires a page version and cannot take a reply). A message is owed nothing as soon as it has been answered, so the route is named precisely where the writer it names refuses the value.
On this head, test_a_section_handed_a_message_owed_nothing_is_sent_to_to's own comment, once the reader answers it:
$ leaf comment <page> --quote 'Ship dark' --text note # -> X
# reader replies to X
$ leaf comment <page> --section X --text more
can't anchor in revision r1: no element id 'X' in this version; X is a comment in this
page's log, and nothing is owed for it — `leaf reply <page> --to X --initiates` replies
to it, while `--section` takes an element id the page's markup declares
$ leaf reply <page> --to X --initiates --text more
conversation 'X' currently requires a response; use the delivered --for event instead of
--initiates
That second refusal names a writer but no value, which leaves the agent where the PR opens: holding an id, told to reach for --for, with nothing to hand it.
The docstring's "--initiates is refused while a response is owed" is the claim that is wrong — it is refused while the conversation owes one, which is not what responses.get(value) reads. The new test pins only the arrangement where the two readings agree (a lone comment, nothing else in its thread), so it cannot see them come apart.
The inline suggestion reads the thread's obligation for a message owed nothing: where the conversation owes a reply it names that event's --for, where the thread takes a version it says so, and --to … --initiates is named only where no writer will refuse it. It needs thread_roots beside the existing from leaf.thread_context import thread_structure, which a suggestion on this hunk can't reach. With it, tests/test_interact_anchors.py and tests/test_interact_document.py stay green — 216 passed, including both new cases — and following the --for the refusal above then names succeeds.
That is the local form. The durable one is that "which writer takes this message id" is now settled in two places from two readings of the same log: here, and in cmd_reply's --initiates guard. The PR's move for --for was to derive the obligation once and let every refusal read it; a message's --initiates admissibility is the same kind of fact and hasn't been given that treatment, so the next writer keyed on it can disagree again. One reading both consume would make that unrepresentable rather than fixed once.
Happy to push either.
…enforces it `--initiates` is refused while a message's *thread* owes a response, whichever message in it is owed one, so a refusal reading the message's own obligation named `--initiates` for a message whose conversation was waiting — and the writer it named refused it. That is two readings of "which writer takes this message", which is the duplication this change exists to end. `thread_obligation` in `validation/admission.py` is the one reading: the response standing on a message's conversation, resolved through `thread_roots`. `logged_id` routes a message through it — `--for` the event the conversation owes, else `--to <id> --initiates` — and `cmd_reply`'s guard refuses on it, naming that same event instead of "the delivered --for event". Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
Taken, and the durable point with it.
|
leaf-agent
left a comment
There was a problem hiding this comment.
A resolved version-response thread still sends the agent to a writer that refuses the value.
thread_obligation reads what a thread owes out of current_responses, while cmd_reply's version guard refuses on the root event's own response field. The two agree while the Ask is standing and come apart once the thread is resolved: current_responses drops the obligation, the authored response: {"kind": "version", ...} stays on the root comment for the page's lifetime, and logged_id falls through to the "nothing is owed" branch. On this head, with lf-options given the version-response seat declare_options_version_response sets up in tests/test_interact_product.py, a proposal comment anchored to it, a version that chooses, and leaf resolve --to <proposal>:
$ leaf comment <page> --section X --text more
can't anchor in revision r2: no element id 'X' in this version; X is a comment in this
page's log, and nothing is owed for it — `leaf reply <page> --to X --initiates` replies
to it, while `--section` takes an element id the page's markup declares
$ leaf reply <page> --to X --initiates --text more
thread 'X' requires a page version and cannot take a reply; incorporate its request in
the next version, or open a separate thread on the same Ask with `leaf comment <page>
--section <ask-id>` if you need an answer first
That is the shape the last round removed for the reply face of this guard, still here because "does this thread take a reply?" is settled from two sources. thread_obligation's docstring — "Every writer that asks 'does this message take --initiates?' asks this" — is the claim that isn't true yet: conversation.py's if root and (root.get("response") or {}).get("kind") == "version" asks it of the root event instead, and a reading that cannot see the version face cannot be the one every writer consults.
The inline suggestion folds the root's authored response into thread_obligation, so the refusal says "its thread takes a page version rather than a reply" and names no route the writer will refuse. With it applied the repro above reports the version, and tests/test_interact_anchors.py, tests/test_interact_document.py and tests/test_interact_product.py stay green (262 passed). The durable half is what it then makes possible: with the version face in the reading, cmd_reply's guard can refuse on thread_obligation like the --initiates guard beside it already does, and the two become unable to disagree.
Second, smaller, and the same shape in miniature: receipt_contract_error recomputes the open requests from the raw log on the lines above the current_responses call that already holds them — _response returns {"kind": "receipt", "request": …} for exactly the requests no receipt names. Suggestion inline.
Happy to push either.
A version-response thread takes a version whether or not one is outstanding: the obligation clears when the thread resolves, and the root's own declaration stays for the page's life. `thread_obligation` read only the obligation, so a resolved thread came back unowed and the refusal named `--initiates` — which `cmd_reply` refuses on that declaration, the dead end again. The reading now carries the declaration too, and `cmd_reply`'s version guard refuses on the reading rather than on the root event, so the two cannot come apart. Dropping the declaration from the reading makes `--initiates` succeed on a resolved version thread, which is what the new test's second arm holds. `receipt_contract_error` also read its open requests off the raw log beside the `current_responses` call that already holds them, since a request with no receipt is exactly what `_response` returns a receipt for. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
Both taken.
|
leaf-agent
left a comment
There was a problem hiding this comment.
logged_id's version branch is the one refusal left that says only what the id isn't, and this commit routes a resolved version thread into it.
Running test_a_resolved_version_thread_is_still_named_a_version_thread's own fixture through the CLI on this head:
$ leaf comment <page> --section <proposal> --text more
can't anchor in revision r2: no element id 'a5534…' in this version; a5534… is a comment in
this page's log — its thread takes a page version rather than a reply, while `--section`
takes an element id the page's markup declares
The test's comment justifies naming none with "the writer a route would have named refuses it". That holds for --initiates — but the refusal waiting there names the recourse itself, and this one drops it:
$ leaf reply <page> --to <proposal> --initiates --text more
thread 'a5534…' requires a page version and cannot take a reply; incorporate its request in
the next version, or open a separate thread on the same Ask with `leaf comment <page>
--section <ask-id>` if you need an answer first
That route is open and the log holds its value: the thread's root carries anchor: {"section": "choice"}, and on that same page leaf comment <page> --section choice is accepted, as is leaf resolve <page> --to <proposal>. So the branch this commit widens is the one place logged_id's own stated invariant — "every writer that refuses an id says what the log holds it as, and where it goes instead" — does not hold, and it now covers the state where two other writers take the value. A standing version obligation already reached it; a resolved thread is the case where nothing is left to wait for, which is what makes it worth closing rather than recording.
The suggestion reads the Ask off the root's own anchor, so the refusal above ends with the concrete route instead: its thread takes a page version rather than a reply; leaf comment <page> --section choice opens a separate thread on the same Ask. With it applied, tests/test_interact_product.py, tests/test_interact_anchors.py, tests/test_interact_document.py and tests/test_interact_contract.py are unchanged at 550 passed — the new test's assertion is a substring and still matches. Happy to push it.
The version branch was the one refusal naming no route, and the writer it declined to name was naming one itself: `cmd_reply`'s version refusal offers a separate thread on the same Ask, as `<ask-id>` for the agent to fill from a page it has just been told it cannot find an id in. The root's own anchor holds that id. `version_thread_recourse` reads it there, and the version branch and both of `cmd_reply`'s version refusals compose their sentence with it, so the route is concrete and stated once. A thread whose root anchors nothing keeps the version half alone. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
Taken, and one step further: the route you found was already being named by
|
leaf-agent
left a comment
There was a problem hiding this comment.
Following the route the version branch now names lands on the refusal the PR opens with.
version_thread_recourse reads the Ask off the root's anchor and names it unconditionally, but that id is the one recourse a refusal composes out of the markup rather than the log, and markup is revision-scoped. The Ask is pinned only while its thread is unresolved — publishing a revision that drops it before then is refused with protected ids present in revision r1 but dropped in index.html (unresolved threads, standing state, or widget retirement still need them): ['choice'] — while the version face thread_obligation gained last round outlives the obligation by design. So the state the branch is widest in is exactly the one where the author is free to retire the Ask. On this head, with test_a_resolved_version_thread_is_still_named_a_version_thread's own fixture plus one further revision that retires the <lf-ask>:
$ leaf comment <page> --section 4c2c2867a500aadf1abcd06236f0dae5 --text more
can't anchor in revision r3: no element id '4c2c2867a500aadf1abcd06236f0dae5' in this version;
4c2c2867a500aadf1abcd06236f0dae5 is a comment in this page's log — its thread takes a page
version rather than a reply; incorporate its request in the next version, or open a separate
thread on the same Ask with `leaf comment <page> --section choice` if you need an answer first,
while `--section` takes an element id the page's markup declares
$ leaf comment <page> --section choice --text 'how long?'
can't anchor in revision r3: no element id 'choice' in this version
The second refusal is the first one again with the recourse dropped. That is worse than the <ask-id> placeholder this commit replaces: a placeholder sends the agent to look for an Ask, a concrete retired id tells it the one it must use. cmd_reply's two version refusals compose the same sentence, so they name it too.
The reading the branch is missing is the page's own: whether this revision still declares the id it is about to name. The suggestion names the Ask only where it does, and otherwise keeps the version half alone, as the branch already does for a root that anchors nothing. It needs page_dir threaded through logged_id to its four call sites and passed at cmd_reply's two direct calls, plus latest_revision beside the existing from leaf.files import list_revisions — which a suggestion on this hunk can't reach.
Verification
The repro is the new test's fixture with a third revision replacing the whole <lf-ask id="plan-choice-decision">…</lf-ask> block with prose, published after leaf resolve --to <proposal>. Retiring it before the resolve is refused by activate_source on the protected id, which is what confines this to the resolved thread.
With the suggestion applied, tests/test_interact_product.py, tests/test_interact_anchors.py, tests/test_interact_document.py, tests/test_interact_contract.py and tests/test_interact_session.py report 740 passed; the one failure and two errors are OSError(30, 'Read-only file system') on test_codex_launch_owns_one_private_app_server, test_app_server_observer_connects_over_a_private_unix_socket and test_a_reader_move_no_carrier_will_pick_up_messages_its_claude_code_session, which are this sandbox's read-only /tmp rather than the change — CI's test check is green on this head.
Happy to push it.
Reading the Ask's id off the root's anchor claimed something the log cannot vouch for. The id is markup: a later revision may retire it once the thread resolves, and whether `--section` takes it is the anchor rule's to say against the active revision, which counts more than whether the id is declared. Every reading of that rule from outside it is one more that can drift. The routes this change names are the ones the log settles — a reply, a receipt, a version, a conversation's standing obligation — each read the way the writer refusing on it reads it. The Ask is not one of them, so the version refusals name it as the recipe `cmd_reply` always gave, now written once as `VERSION_THREAD_RECOURSE` and shared by all three. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
Right, and it moves the line rather than the check. The Ask's id is markup, and whether
|
A hosted turn in the site's local verification published its edit, then spent thirty seconds on six forms of
leaf receipt, handing it a comment's id, a delivery's id and a kind's name in turn. Each got back onlyunknown request 'X', which left it nothing to change but the guess. #837 fixed the same dead end for--sectionafter it failed the deploy gate.Which writer takes a bare id is not a matter of the event's kind but of what the log still owes for it, and
current_responsesalready reads that: a reply, a receipt, a page version, or nothing.logged_idinskills/leaf/scripts/leaf/validation/admission.pyturns that reading into a refusal's recourse: what the log holds the id as, and the command that settles it. A message is the one id whose writer turns on its conversation rather than on itself, since--initiatesis refused while the thread owes a response, whichever of its messages is owed it.thread_obligationis that reading — the response standing on the message's conversation, or the version its root declared, which stays after the obligation clears — andcmd_reply's--initiatesand version guards refuse on the same one rather than deriving their own. Two readings of "which writer takes this message" is the duplication this change exists to end. What each refusal now says:--foronreplyused to answer every id it could not take withno longer requires a reply. A request now names its receipt, a message names--foror--to … --initiatesby what its conversation owes, a resolve says nothing is owed, and an id the log never held says so.--sectionwas routed by kind in Give the printed leaf comment forms their page argument, and route an event id off --section #837, which sent aresolveor an answered action to--for, where it met that same refusal with no route. It now reads the obligation.--toonreply,resolveandeditlisted the page's messages but never said what else an id was.cmd_reply's version refusal was already offering one: a separate thread on the same Ask. All three now share that sentence asVERSION_THREAD_RECOURSE. It names the Ask as the recipe--section <ask-id>rather than by id, because the id is markup — a later revision may retire it, and whether--sectiontakes it is the anchor rule's to say against the active revision, which the log cannot vouch for.receiptsays a misdirected id is not a request, where it goes instead, and which requests are still open, or that there are none — read off the same responses, since a request with no receipt is exactly what one names. The dispatcher already holds the page, so_receipt_errorpasses it through;requestsreachescurrent_responseson the refusal rather than at import, sincedeliveryloads it.The tests that pinned #837's kind-based wording now assert the obligation's route: #837's message case uses a reader's comment, which is owed a reply. New tests hand
--sectionaresolve, which is owed nothing; the agent's own comment, whose--to … --initiatesroute the test then follows; a comment whose thread is owed a reply, where the test follows the--forthe refusal names and checks the--initiatesguard names the same event; and a resolved version thread, where the test checks that both refusals name the same recourse and that it is accepted once filled with the Ask's id. The receipt test covers a comment handed toreceipt, and a request handed toresolve --toand toreply --for.Verified with the everyday suite and pre-commit. Each route is also checked by reverting it: removing the obligation reading, restoring the kind-based fallback, dropping the
--toroute, giving the receipt no obligation, reading a message's own obligation in place of its conversation's, dropping the version declaration from the reading, and dropping the recourse from the version branch each fail the tests that own them, the version declaration on each arm separately.🤖 Generated with Claude Code