Skip to content

A play's Edit chat describes the play first, and a reply is routed with the message it answers (closes #3738) - #3747

Merged
malibio merged 6 commits into
mainfrom
issue-3738-play-edit-chat
Oct 12, 2026
Merged

malibio merged 6 commits into
mainfrom
issue-3738-play-edit-chat

Conversation

@malibio

@malibio malibio commented Oct 11, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #3738.

What changes

The opening message describes the play, then asks. create_play_edit_chat builds it from what the play stores, with no model call: the play's description, then each rule by name with its description, its trigger described from the trigger's fields (the play viewer's wording), each condition's and each action's description. Six options, "Explain this play" first.

A reply is routed with the message it answers. Stage 1's follow-up frame has two forms. A request that stands alone gets the frame it always had, byte for byte. A message that leans on the one before it (the answer to a clarification, one of the opening message's options, one or two words, or at most six words with a pronoun, ordinal or yes/no) is framed as a reply to the conversation's last message.

Stage 1 cannot stop a chat that pins a skill.

  • Its prompt names what the chat pins: the pinned node's title and type, and the skill.
  • A route_clarify from Stage 1 goes on to retrieval and Stage 2 with the pinned skill (routing_decision="clarify_pinned").
  • A message that is one of the options the chat's opening message offered is not put to Stage 1 at all, and its candidates are led by the pinned skill. The options hold for the whole chat, and are set aside only while the assistant's last message offered options of its own.
  • A lookup keeps the pinned skill without its write tools, so "Explain this play" is offered get_play and never update_play. The system-run search backstop does not replace a prose answer in such a chat.

A chat that pins nothing routes as before: no prompt line, the same clarify outcome, the same lookup narrowing.

Measured on the built-in model (Gemma 4 E4B)

Isolated daemon, the seeded play "Complete a parent task when all its sub-tasks are done", each message sent as the first reply in a fresh Edit chat:

First reply Stage 1 Result
Change when it runs skipped Play Authoring, get_play, says when it runs and asks what it should change to
Change a condition skipped Play Authoring asks which rule's condition
Change an action skipped Play Authoring asks which rule's action
Add a rule skipped Play Authoring asks what the rule should do
Remove a rule skipped Play Authoring asks which rule of the play
Explain this play skipped (lookup) explained from the rules; no write tool offered
when would this fire? / what does this condition mean? skipped (lookup) answered from the rules; no write tool offered
tell me about this play lookup answered from the rules
I don't understand it clarify_pinned answered in plain language; nothing written

The prompt dump of a first reply carries the Play Authoring instructions, the pinned-node record and the play's rule.

Known and left alone: on "Change a condition" and "Change an action" the skill's question sometimes adds "please provide the name of the play". That is the skill's own behaviour, which the issue excludes. Rewording the pinned-node record was tried against it and made no difference, so it was reverted.

Sent after "Explain this play" in the same chat, each of the five change options also skips Stage 1 and is led by Play Authoring; none asks which play.

Routing measurements, main against this branch

main branch
clarification-then-fallthrough, 3 reps 3/3 3/3
Routing fixture, one full pass 14/19 15/19
Follow-up chats (matrix 9, 8e, 10c, 11d, 12d and their chats), 3 reps 4/14 4/14

The routing difference is one scenario on a single rep and is not claimed as a gain. 11d and 12d were excluded on both sides because their setup turns did not establish state. The measurements found one shift, since fixed: a longer message with a pointing-back word, shown the reply frame, was routed as two tasks; such a word now makes a reply only of a message of at most six words.

Not done

Tests

  • Opening message: one rule (full text), several rules (scheduled trigger, for_each, invariant), no rules, unreadable rules.
  • A pinned chat where Stage 1 would clarify goes on to Stage 2 and its Stage-1 prompt names the pins; the same turn in an unpinned chat ends on the clarification with the unchanged prompt.
  • An offered option skips Stage 1 and is led by the pinned skill; "Explain this play" has no write tool and its prose answer stands.
  • The two frames; a new golden for the Stage-1 request in a pinned chat.
  • bun run test:changed passes.

🤖 Generated with Claude Code

@malibio

malibio commented Oct 11, 2026

Copy link
Copy Markdown
Collaborator Author

Pragmatic Code Review: PR #3747 (closes #3738)

Review Type: Initial review (no prior reviews). Head 3845757ea, 7 files, +1244/-54. Read: the full diff, route() and its callers in agent_loop.rs, the routing helpers it uses, the daemon session setup, ADR-090 §3/§5. No builds or tests were run (test:changed is reported passing on this head).

Summary

The change is a clear net improvement and is well contained. Every pin-specific branch is gated on session.pinned_skills being non-empty or on SkillCandidate.pinned, the opening message is built with no model call, and the tests pin the Stage-1 prompt of an unpinned chat byte for byte. No Critical issues. Two acceptance criteria are still open by the author's own account, and one finding (the picked-option skip applies to more than the opening message's options) should be fixed or consciously accepted before merge.

Requirements Check

# Acceptance criterion Status
1 Opening message describes the play, then asks, six options, no model call ✅ opening_message / describe_rule / describe_trigger; EDIT_OPTIONS has six, "Explain this play" first
2 Built-in model: "Explain this play" and own-words questions answered from the rules, nothing written ✅ Recorded in the PR body. Mechanically enforced only on the lookup path (see finding 4)
3 A short reply that refers back is routed as an answer, in any chat; a standalone request routes as before ❌ Partly. The reply frame is implemented. "Routes as before" is only byte-identical for messages with none of 22 common words; the before/after routing results that would show the rest is safe are not recorded yet (finding 2)
4 Built-in model: each of the five change options reaches play-authoring, none clarified by Stage 1 ✅ Recorded in the PR body; Stage 1 is skipped for them and the pinned skill leads
5 Pinned chat: Stage-1 clarify does not end the turn; Stage 1's request names the pins ✅ clarify_pinned branch, stage1_pins_line, test a_stage1_clarify_does_not_end_a_turn_in_a_chat_that_pins_a_skill
6 A chat that pins nothing routes exactly as before ✅ Verified by reading: no pins line, same clarify return, read_only_candidates and lookup_is_searched unchanged without a pin, led_by_pinned_skills unreachable. The only difference is the reply frame, which criterion 3 asks for in every chat
7 Prompt dump of the first reply shows the skill and the play's rule ✅ Stated in the PR body (not re-verified here)
8 One first reply through a hosted OpenAI-compatible model, result recorded ❌ Not run (no key), as the PR body says
9 Tests: one rule, several rules, pinned clarify, unpinned clarify ✅ All four present, plus no rules, unreadable rules, option skip, read-only explain, both frames, new golden
10 quality:fix and test:changed pass ✅ Reported by the author; not re-run

Issue technical note "run the routing scenarios before and after, three repetitions, and record both": ❌ still being produced.

Code Review Findings

🟡 Important

1. The Stage-1 skip and the forced pinned lead apply to any options the last assistant message offered, not only the opening message's
📁 packages/agent/src/local_agent/agent_loop.rs:5648-5657, 5892-5898; packages/daemon/src/services/local_agent_service.rs options_last_offered (~2824-2842)

options_last_offered returns the options of whatever assistant message precedes the user's latest. store_assistant_message writes clarify.options there for every clarification (line 1414), so in a pinned chat the options of a later Stage-2 clarification become offered_options too. ADR-090 §5 and the issue scope the rule to "the opening message's own options".

Failure scenario, verified by reading (not run): in a play's Edit chat the user changes topic, "add a task to review this play". Node Creation asks "Which project?" with options "Website" / "Mobile". The user picks "Website". Before this PR the reply was an answer to a clarification, so Stage 1 saw the blended conversation and wrote a query for creating a task. Now picked_option fires: Stage 1 is skipped, the retrieval query is the bare word "Website" (RouteDecision::Query(message)), and led_by_pinned_skills puts Play Authoring in the lead over whatever was retrieved. Node Creation may not be a candidate at all, so create_node is off the scoped surface. This contradicts §5's "A user who changes topic mid-chat still gets the skills retrieval finds for the new request".

The on-topic case (Play Authoring asks "Which rule?" and the user picks a rule name) benefits from the same code, so the generalisation is not wrong everywhere.

Recommendation: either (a) restrict the skip and the forced lead to options that came from the system-written opening message, or from a turn the pinned skill led; or (b) keep the skip for later options but retrieve on suppressed_clarify_retrieval_query(session, user_message) and do not force the lead for them. Add a test for an option offered by a non-pinned skill's clarification in a pinned chat. Principle: least astonishment; the code should match the decision it cites.

2. leans_on_the_last_message puts many standalone requests in the reply frame, and nothing recorded yet shows they route as before
📁 packages/agent/src/local_agent/routing.rs leans_on_the_last_message (~575-598); packages/agent/src/local_agent/agent_loop.rs:2172-2177

Any follow-up of one or two words, or containing it, that, this, one, first, last, no, same, both, ..., gets the new frame. Several of those are ordinary words in requests that stand alone: "add a note that Bob called", "create a task for this week", "what did I finish last week?", "how many tasks have no owner?", "list tasks". The doc comment accepts this and relies on the frame's "when it does not stand alone" clause. That is a reasonable design, but it is the widest part of the PR (every follow-up turn in every chat), and criterion 3's "a request that stands alone routes as before" then rests entirely on measurement.

Recommendation: before merge, record the before/after routing results the issue asks for, and make sure the scenarios include standalone follow-ups that contain these words. If any regress, the cheapest tightening is dropping that (mostly a conjunction or relative pronoun) and treating this/last/first/no/one as pointing back only when the message is short. Principle: a heuristic with system-wide reach needs evidence proportional to its reach.

🟢 Suggestions

3. In a pinned chat no lookup gets the system-run search backstop, including lookups that are not about the pinned node
📁 packages/agent/src/local_agent/agent_loop.rs:3676-3682, 3741, 4016

lookup_is_searched is false for every lookup once the chat pins a skill. For "when would this fire?" that is right. For "find what I wrote about rate limiting" asked in the same chat, a prose reply with no tool call now stands, where an unpinned chat would run the search. A side effect on line 4016-4026: a route_clarify call emitted on a lookup turn is no longer dropped in a pinned chat. Suspicion only, not measured. Consider narrowing to "the pinned skill leads the turn", or record the trade in ADR-090 §5 with the docs push.

4. Only the lookup path makes explaining a play read-only
📁 packages/agent/src/local_agent/routing.rs read_only_candidates (1543-1562); agent_loop.rs:5780-5794

"Explain this play" and lookup-shaped questions lose update_play mechanically. "I don't understand it" goes through clarify_pinned to Stage 2 with the full play-authoring surface; that nothing was written there is the model's behaviour (measured in the PR body), not a guarantee. Acceptable given the skill asks before writing; worth stating in the ADR amendment so the guarantee is not overread. Worth noting as a positive: once a pinned skill is stripped of its write tools it always clears the gate, so the "return candidates as retrieved" fallback can no longer hand write tools to a lookup in a pinned chat.

5. Author text goes into the stored markdown message unescaped
📁 packages/daemon/src/services/play_edit_chat.rs describe_rule, describe_trigger, one_line (~243-330)

one_line collapses whitespace, which stops a description breaking the list. It does not neutralise markdown: a rule name containing **, a for_each containing a backtick, or a description containing [text](nodespace://<other id>) render as authored. Suspicion, not verified: if mention edges are derived from message content, a link in a rule description would record a mentions edge from the opening message to that node. The title already has [/] removed for this reason; applying the same treatment to rule text would be consistent. Low risk: the text is the user's own, on a local database. The Stage-1 line is fine: titles and types go through stage1_prompt_name (one line, 60 characters).

6. "Its rules can't be read" can be followed by the rules
📁 packages/daemon/src/services/play_edit_chat.rs opening_message (~210-236)

rules_readable is false whenever PlayFields::from_properties fails, for any field. readable_from_properties still decodes rules when the rules themselves are fine, and the loop then lists them under "Its rules can't be read as they are stored." Derive the sentence from whether the rules decoded, not from the whole struct.

Nitpicks

  • Nit: agent_loop.rs comments at ~5810 and ~5910, scripts/eval/types.ts:132 and scripts/aichat.ts:273 list the routing_decision values and do not include clarify_pinned.
  • Nit: led_by_pinned_skills gives every pinned skill the same top.next_up() score, so with two pins the lead goes to the last one (the tie rule its own comment cites). One pin today; say so or step each.
  • Nit: in an_offered_option_is_never_ambiguous_in_a_chat_that_pins_a_skill, authoring < research compares two Option<usize>; it holds only because an earlier assert proves authoring is Some. Unwrap both for a test that fails for the right reason.
  • Nit: describe_trigger duplicates the frontend's describeTrigger wording in Rust with only a comment tying them. A shared fixture of trigger → sentence pairs used by both test suites would catch drift.

Standards check

No literal node_type comparisons in product code (target_type == "*" is the selector wildcard, not a type; the "play" literals are in tests). No compatibility code: set_session_pinned_skills is renamed with no alias left behind. No issue numbers in new comments. No dead code or lint suppressions. f32::next_up is stable on the pinned 1.97.0 toolchain. Sessions are created per turn, so offered_options cannot go stale between turns.

Recommendation: REQUEST CHANGES

Small and specific: resolve finding 1 (restrict or soften the option skip for options the pinned skill did not offer, with a test), and record the routing before/after results for finding 2. The hosted OpenAI-compatible check (criterion 8) stays open and needs either a run or an explicit decision to close the issue without it. Findings 3 to 6 and the nits are optional.

@malibio malibio left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Automated pragmatic-code-review: REQUEST CHANGES (posted as a comment — GitHub blocks self-approval). Full findings in the review comment above.

@malibio

malibio commented Oct 12, 2026 •

Copy link
Copy Markdown
Collaborator Author

Address-review summary

Commits since the review: 1372acf04, 46073a54a.

Addressed

  • Option skip too broad (finding 1). Only the opening message's options skip Stage 1, and only on the reply that answers it (opening_options_answered). A later message that happens to match an option is routed like any other.
  • Reply heuristic breadth (finding 2). Measured, and it was a real shift: "Also the search indexer, that one's twenty-one days" was routed query on main in 3/3 runs and multi on the branch in 3/3. A pointing-back word now makes a reply only of a message of at most six words; a longer one names its own subject. On the rebuilt daemon that message routes query 3/3 again.
  • Finding 4 (only the lookup path is mechanically read-only) is stated in the architecture docs, so the guarantee is not overread.
  • Finding 6 and the nits. Of two pinned skills the first pinned leads; a play is "unreadable" only when stored rules did not decode; clarify_pinned added to the decision lists in the eval types and aichat.ts.

Skipped

  • Finding 3 (no system-run search backstop for any lookup in a pinned chat). Code unchanged; the trade is recorded in the architecture docs' pinned-skills section, as the review offered. Narrowing it to turns the pinned skill leads is worth doing if an off-topic lookup in an Edit chat is seen to go unanswered.
  • Finding 5 (rule text reaches the stored message as markdown). Code unchanged: the text is the user's own, on a local database, and the review rated it low risk. Whether a link in a rule description records a mention from the opening message was not checked.

Routing measurements (Gemma 4 E4B, isolated daemon)

main branch
clarification-then-fallthrough, 3 reps 3/3 3/3
Routing fixture, one full pass 14/19 15/19
Follow-up chats (matrix 9, 8e, 10c, 11d, 12d and their chats), 3 reps 4/14 4/14

The one-scenario routing difference is ambiguous-client-contacts on a single rep; not a claimed gain. The follow-up comparison is limited: 11d and 12d were excluded on both sides because their setup turns did not establish state, on main as well. Per-turn routing decisions are otherwise identical between the sides apart from the message above.

Edit chat on the final head, each as the first reply in a fresh chat: "Change when it runs" and "Add a rule" skip Stage 1 and are led by Play Authoring; "Explain this play", "when would this fire?" and "what does this condition mean?" are lookups with no write tool offered and are answered from the rules; "I don't understand it" is clarify_pinned and is answered. One turn (the first after model load) failed with a backend decode error and passed when sent again.

Not done

The hosted OpenAI-compatible check is filed as #3750.

Re-Review Decision

Decision: RE-REVIEW NEEDED

Rationale: two Important findings were addressed with changes to routing logic (which replies skip Stage 1, and which messages are framed as replies).

@malibio

malibio commented Oct 12, 2026

Copy link
Copy Markdown
Collaborator Author

Pragmatic Code Review: PR #3747 (closes #3738)

Review Type: Re-Review. Scope: 3845757ea..46073a54a (commits 1372acf04, 46073a54a), 7 files. Read: the diff, route() and stage1_query in agent_loop.rs, opening_options_answered and its call site, PlayFields::readable_from_properties / stored_field, ADR-090 §3/§5, and the author's uncommitted docs edits. No builds or tests were run (the machine's build slot was held); the routing measurements below are the author's and were not reproduced.

Summary

Both Important findings are fixed in code, and the fixes are small and match what they claim. No Critical issues and nothing blocking. Two things are left for the author to weigh: the option skip is now narrower than the on-topic case needs (new finding A), and the six-word cap still leaves the first review's own example sentences in the reply frame (finding 2, residual).

Previous Review Summary

Count
Previous findings (2 Important, 4 Suggestions, 4 Nits) 10
Addressed in code 6 (findings 1, 2, 6; three nits)
Addressed in docs only, as the review offered 2 (findings 3, 4)
Not addressed, reasonably skipped 2 (finding 5; the describe_trigger drift nit)
New issues from the two commits 4 (1 Important, non-blocking; 3 Suggestions/Nits)

Status of previous findings

# Finding Status
1 Stage-1 skip and forced pinned lead applied to any last-offered options ✅ Fixed. opening_options_answered (local_agent_service.rs:2834-2844) returns options only when the chat is exactly [assistant, user]. The "Website" scenario now has empty offered_options, so picked_option is None and the reply takes the answer-to-a-clarification path. Covered by the extended test at local_agent_service.rs:4791-4808. See new finding A for what the narrowing costs.
2 leans_on_the_last_message reach, no before/after evidence ✅ Addressed. Measured, a real regression found (query to multi, 3/3) and fixed with a six-word cap on the pointing-back rule (routing.rs:591-607); the failing sentence is pinned in the unit test. Residual below.
3 No search backstop for any lookup in a pinned chat 🟡 Code unchanged; the trade is stated in the pinned-skills section of prompt-skill-system.md ("The cost is a lookup on another topic asked in that chat"). Acceptable: the review offered this. The docs edit is uncommitted and has to be pushed with the merge.
4 Only the lookup path is mechanically read-only ✅ Stated in the same docs section.
5 Rule text reaches the stored message as unescaped markdown 🟡 Skipped, reasonably (the user's own text, local database). The one open question, whether a nodespace:// link in a rule description records a mentions edge from the opening message, is still unchecked.
6 "Its rules can't be read" followed by the rules ✅ Fixed for the reported case, with a test. One edge left (new finding C).
Nit clarify_pinned missing from decision lists ✅ Added in both agent_loop.rs comments, scripts/aichat.ts and the scripts types file.
Nit Two pins: the last one led ✅ Fixed. led_by_pinned_skills steps scores from the last pinned to the first (routing.rs:1320-1326); verified by reading for both orderings of the pinned scores, and tested.
Nit Option<usize> comparison in the test ✅ Both unwrapped with expect.
Nit describe_trigger duplicates the frontend wording Not addressed. Optional.

New findings

🟡 Important (non-blocking)

A. An opening option picked on any turn after the first loses both protections, and that flow is unmeasured
📁 packages/daemon/src/services/local_agent_service.rs:2834-2844; packages/agent/src/local_agent/agent_loop.rs:5648-5650, 5894-5898

The fix for finding 1 went further than the review's option (a): the options count only on the reply to the opening message, not for the opening message's options in general. So "Explain this play" followed by "Change a condition" in the same chat (the flow the first option exists to invite) puts the second message to Stage 1 and does not force the pinned lead. led_by_pinned_skills' own doc comment records what retrieval does with that message by itself: Graph Editing 0.938 ahead of Play Authoring 0.870, "and the reply asked which play was meant". The message is three words with no pointing-back word and follows a Replied turn, so it also gets the standalone frame. The pins line and clarify_pinned may well carry it; every measured Edit-chat turn in the PR and the address summary is a first reply in a fresh chat, so nothing shows either way. ADR-090 §5 says an opening option "is never ambiguous in that chat", which is wider than the first reply. Also unverified: whether the UI still shows the opening message's option chips after the first turn.

Recommendation: measure the two-turn flow once (Explain, then each change option). If it holds, say "first reply only" in ADR-090 §5 with the docs push. If it does not, widen opening_options_answered to return the opening message's options whenever the assistant's last message offered none of its own; the "Website" case stays excluded because that message has options. Principle: a fix should not reintroduce the measured failure it was built against on the adjacent path; code and the decision it cites should agree.

🟢 Suggestions

B. Finding 2 residual: the cap fixes the measured sentence, not the review's examples
📁 packages/agent/src/local_agent/routing.rs:591-607, 4619-4645

All five standalone examples the first review named are still framed as replies: "add a note that Bob called", "create a task for this week", "what did I finish last week?", "how many tasks have no owner?" (six words each) and "list tasks" (two). The doc comment says so honestly, and the author reports identical per-turn decisions across the routing fixture and follow-up chats, so this is accepted on the evidence given. Two cheap additions: put one or two of those sentences through a follow-up turn in the next measurement pass, and pin the boundary in the unit test (a six-word and a seven-word message with the same pointing-back word). Today the standing cases are nine and ten words, so changing the constant to 7 or 8 fails no test.

Related, pre-existing: words are split on every non-alphanumeric character, so "twenty-one" contributes the pointing-back word "one" ("add twenty-one tasks" leans), and contractions count double toward the cap ("what's the first one's status?" is seven words and does not lean).

C. A play with an empty rule list and another undecodable field is still called unreadable
📁 packages/daemon/src/services/play_edit_chat.rs:213-221

readable = !stored || !fields.rules.is_empty(). With "rules": [] stored and, say, "enabled": "yes", stored is true and the decoded list is empty, so the message says "Its rules can't be read as they are stored." where "It has no rules yet." is correct. It needs two conditions at once, so it is rare. An empty stored array is readable by definition: treat it as such, or have nodespace-types expose whether the rules decoded so the sentence does not infer it from the list length.

Nitpicks

  • Nit: agent_loop.rs:2174. With options now set only on the first reply of a pinned chat, and that reply skipping Stage 1, the is_offered_option clause in stage1_query has no production path that reaches it (YAGNI). Drop it, or keep it knowingly for a future unpinned chat with an opening message.
  • Nit: docs, prompt-skill-system.md, the "A question is recognised on the message alone" bullet still lists "one of the options the last message offered" among the reply-frame triggers. It is now the opening message's options only.
  • Nit: opening_options_answered identifies the opening message by position ([assistant, user]). A first turn that fails and is sent again makes a third message, so the retried option is routed through Stage 1. It degrades safely (clarify_pinned); worth one clause in the doc comment since the address summary reports exactly such a failed first turn.

Standards check

No literal node_type comparisons, no compatibility code, no lint suppressions, no issue numbers in new comments. PlayFields::stored_field and PLAY_RULES_FIELD are existing nodespace-types exports reused, not redefined. The session field's meaning changed and its doc comment, setter comment and all three call-site comments changed with it. Criterion 8 (hosted OpenAI-compatible check) is tracked as open issue #3750; whether #3738 closes without it is the owner's call.

Recommendation: APPROVE

Both blocking findings from the first review are fixed, with tests, and the two commits introduce no correctness or safety regression. Finding A is the one to act on before or shortly after merge: one measurement of the Explain-then-change flow decides whether it is a docs sentence or a three-line widening. B, C and the nits are optional. Three docs files are uncommitted in the docs checkout and should be pushed just before bun run merge.

@malibio malibio left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Automated pragmatic-code-review (re-review): APPROVE (posted as a comment — GitHub blocks self-approval). Full findings in the review comment above.

@malibio

malibio commented Oct 12, 2026

Copy link
Copy Markdown
Collaborator Author

Address-review summary (re-review)

Commit since the re-review: b528dc2e4.

Addressed

  • A. An opening option picked after the first turn. Measured, and the finding held. In fresh Edit chats on Gemma 4 E4B, each change option sent after "Explain this play":

    Second reply Before b528dc2e4 After
    Change when it runs Stage 1, Play Authoring only; fine skipped, Play Authoring leads
    Change a condition Stage 1, led by Graph Editing, "Which play would you like to change a condition on?" skipped, Play Authoring leads, asks which rule's condition
    Change an action Stage 1, led by Graph Editing, "Which play…?" skipped, Play Authoring leads, asks which rule
    Add a rule Stage 1, led by Play Workflow State; asked what the rule should do skipped, Play Authoring leads, same question
    Remove a rule Stage 1, Play Authoring leads; asks which rule skipped, Play Authoring leads, same question

    The widening is the one the review proposed: the opening message's options stay on offer unless the assistant's last message offered options of its own (opening_options_on_offer). The "Website" case stays excluded, and a failed first turn sent again now keeps its option too. Tests cover the second reply, the later clarification with its own options, and a chat the user opened.

  • C. Empty stored rule list with another undecodable field now reads "It has no rules yet.", with a test.

  • B, in part. The six-word boundary is pinned in the unit test (a six-word message that leans, the same message one word longer that does not).

  • Docs nits. The reply-frame bullet names the opening message's options; the pinned-skills section says the options hold for the whole chat and when they are set aside.

Skipped

  • B, the rest. The review's five standalone sentences of six words or fewer are still shown the reply frame. That frame asks for the last message to be read in only when the request does not stand alone, and the routing fixture and follow-up chats showed no decision change on such turns. Splitting hyphenated words and contractions differently is left as it was before this PR.
  • Nit: the is_offered_option clause in stage1_query. Kept: it is what frames a picked option as a reply in a chat with an opening message and no pinned skill, which routes through Stage 1.
  • Nit: shared trigger-wording fixture between Rust and the frontend. Optional, and wider than this PR.

Tests

Agent and daemon unit tests: 1,431 pass. bun run test:changed is running on b528dc2e4; its result follows in the next comment.

Re-Review Decision

Decision: RE-REVIEW NEEDED

Rationale: the rule for which turns skip Stage 1 changed again. It is the change the re-review proposed and it is measured, but it is routing logic addressing an Important finding.

@malibio

malibio commented Oct 12, 2026

Copy link
Copy Markdown
Collaborator Author

Pragmatic Code Review: PR #3747 (closes #3738)

Review Type: Re-Review (second). Scope: 46073a54a..b528dc2e4, one commit, 4 files. Read: the diff, opening_options_on_offer and its call site in run_ai_chat_turn, the consumer in route() (picked_option, stage1_query, led_by_pinned_skills, with_pinned_skills), PlayFields::stored_field / readable_from_properties, and the pinned-skills section of prompt-skill-system.md in the docs working tree. No builds or tests were run (the build slot was held); the two-turn measurements are the author's and were not reproduced.

Summary

The commit does what the last review proposed, no more. Finding A is fixed by the widening that review suggested, C is fixed, and the six-word boundary from B is now pinned. I found no correctness or safety regression. What remains is one narrow, unmeasured collision case and a few stale comments.

Previous Review Summary

Count
Findings open after the re-review (A, B, C, three nits) 6
Addressed in code 3 (A, C, the retried-first-turn nit)
Addressed in part 1 (B: boundary pinned in the unit test)
Addressed in docs 1 (the reply-frame bullet)
Skipped with a stated reason 1 (the is_offered_option clause in stage1_query)
New issues from this commit 0 Critical, 0 Important, 2 Suggestions, 3 Nits

Status of previous findings

# Finding Status
A An opening option picked after the first turn lost the Stage-1 skip and the pinned lead ✅ Fixed. opening_options_on_offer (local_agent_service.rs:2838-2855) returns the opening message's options whenever the first message is the assistant's, the last is the user's, and the most recent later assistant message offered no options. The author measured the failure first (Graph Editing led "Change a condition" and "Change an action" after "Explain this play") and the fix after.
B Six-word cap leaves short standalone requests in the reply frame 🟡 Partly. routing.rs:4629, 4641 pin the boundary: the same message leans at six words and not at seven. The five standalone sentences are still framed as replies; accepted on the author's evidence, as before.
C Empty stored rule list with another undecodable field called unreadable ✅ Fixed (play_edit_chat.rs:218-220), with a test. Verified by reading: stored_field reads null as absent, an empty array is "none stored", a non-array value or an array that does not decode is still "can't be read".
Nit is_offered_option in stage1_query unreachable Kept, with a reason (an unpinned chat with an opening message). Acceptable; no such chat exists today, so it stays untested in production.
Nit Docs bullet named "the last message's options" ✅ Fixed in the docs working tree (prompt-skill-system.md:96).
Nit A retried first turn lost its option ✅ Covered by the widening: [opening, user, user] has no later assistant message, so the options stand.

Is the widening safe? (the consumer in route())

Checked each case against agent_loop.rs:5648-5657 and 5892-5898:

  • Later clarification that offered options ("Website" / "Mobile"): asked_since is true, the options are empty, picked_option is None, and the reply takes the answer-to-a-clarification path. Finding 1 from the first review stays fixed. Tested.
  • Prose question with no options ("Which rule?"): the options are on offer, but picked_option fires only when the message equals one of the six option strings (is_offered_option is an exact match after trimming, case and closing punctuation). Any other answer is routed exactly as before this commit. The test's second assertion exercises this shape, since "Which rule?" carries no options.
  • A chat the user opened: the first message is the user's, so the result is empty. A chat with an opening message and no pin gets the options but picked_option is gated on pinned_chat; only the reply frame applies. Tested for the role check.
  • Delete confirmation: answered before this code runs (run_ai_chat_turn:796-809), unaffected.
  • Topic change, then an option typed later: the user typed one of the chat's own options word for word; leading with the pinned skill is the intended reading, and retrieved skills stay among the candidates (led_by_pinned_skills reorders, it drops nothing).

New findings

🟢 Suggestions

1. One collision is left: an option string typed as the answer to an optionless clarification from another skill
📁 packages/daemon/src/services/local_agent_service.rs:2844-2850; packages/agent/src/local_agent/agent_loop.rs:5640, 5648-5650

asked_since reads only whether the last assistant message carried options. A route_clarify with a question and no options from a non-pinned skill ("What should the task be called?") leaves the opening options on offer, so an answer that happens to equal one of them ("Add a rule") skips Stage 1, retrieves on those three words and is led by Play Authoring, where before this commit it was routed as the answer to a clarification. It needs an off-topic request, an optionless clarification and a literal match with one of six strings, so it is unlikely. If it is ever seen, the one-line tightening is picked_option requiring !answering_a_clarification: the first reply is unaffected because prior_turns_from_history leaves the opening message out. Not measured either way; no action needed for merge. Principle: least astonishment.

2. The widened rule is tested where it is computed, not where it is consumed
📁 packages/agent/src/local_agent/agent_loop.rs:16018-16044

an_offered_option_is_never_ambiguous_in_a_chat_that_pins_a_skill still runs the option as the first reply. The skip does not depend on prior turns, so this is low risk, but a route-level case with an earlier exchange in the session (an "Explain this play" turn, then "Change when it runs") would pin the flow this commit exists for: one generation, the pinned skill leading, retrieval on the option alone. The daemon test also has no case for the options coming back on offer after a clarification with options was answered and followed by a plain reply. Optional.

Nitpicks

  • Nit: agent_loop.rs:6370-6371. set_session_offered_options' doc comment still says "for a session whose turn answers that message"; the field's own comment in agent_types.rs was updated and this one was not.
  • Nit: local_agent_service.rs:4802-4803. The comment says "Explain this play", then "Add a rule", but the first message this test sent was "Change a condition".
  • Nit: local_agent_service.rs:4830. user_opened is built from next[1], next[2], next[1] by index, so it depends on the order of everything above it. Naming the two messages, or building them directly, would make the case fail for its own reason. Related, not from this commit: the test doc comment at agent_loop.rs:16014 still says "the chat's last message offered".

Standards check

No literal node_type comparisons, no compatibility code, no lint suppressions, no issue numbers in new comments. opening_options_answered is renamed with no alias left behind. The docs edits (prompt-skill-system.md, ai-chat-node.md, playbook-system.md) are still uncommitted in the docs checkout and should be pushed just before bun run merge. Criterion 8 (hosted OpenAI-compatible check) remains tracked as #3750; closing #3738 without it is the owner's call.

Recommendation: APPROVE

Finding A is fixed with the change the last review proposed, backed by a before/after measurement, and the first review's "Website" case stays excluded. C is fixed. Nothing in this commit blocks the merge; the two suggestions and the nits are optional.

@malibio malibio left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Automated pragmatic-code-review (second re-review): APPROVE (posted as a comment — GitHub blocks self-approval). Full findings in the review comment above.

@malibio

malibio commented Oct 12, 2026

Copy link
Copy Markdown
Collaborator Author

Address-review summary (second re-review)

Commit since the second re-review: the head commit, "Address re-review: correct three comments and name the test's messages".

Addressed

  • The three nits: set_session_offered_options' doc comment, the test comment that named the wrong first message, and the test doc comment that still said "last message". The user-opened case in the daemon test now names its two messages and asserts their roles instead of relying on indices.

Skipped

  • Suggestion 1 (an option string typed word for word as the answer to an optionless clarification from another skill). Left as is: it needs an off-topic request, an optionless clarification and a literal match with one of six strings, and the review asked for no action before merge. The one-line tightening it names is the fix if it is ever seen.
  • Suggestion 2 (a route-level test with an earlier exchange). The skip does not read prior turns, and the two-turn flow is covered where the options are computed and by the live measurement in the previous summary.

Tests

bun run test:changed passed on b528dc2e4 (scripts tier and the Rust workspace). The head commit changes comments and one test's setup; daemon unit tests pass (399).

Re-Review Decision

Decision: NO RE-REVIEW NEEDED

Rationale: the second re-review approved with no Critical or Important findings, and the only change since is comments and a test's setup.

malibio and others added 6 commits October 12, 2026 09:31
- The Stage-1 skip and the pinned lead apply to the reply to a chat's
  opening message only; a later clarification's options are its asker's
- A play's rules are called unreadable only when they did not decode
- Of two pinned skills the first one pinned leads a picked option
- clarify_pinned is listed among the routing decisions

Skipped: the lookup backstop stays off for every lookup in a pinned chat
(the trade is recorded in the docs); rule text is not escaped in the
opening message (the author's own text, and a link in it is a mention).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ssage

Measured on the built-in model, a longer message shown the reply frame was
routed as two tasks on every run.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e whole chat

Measured on the built-in model, a change option sent after "Explain this
play" was put to Stage 1 and answered with a question about which play.
A stored empty rule list is a play with no rules, not unreadable ones.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@malibio
malibio force-pushed the issue-3738-play-edit-chat branch from 347719c to 393888f Compare October 12, 2026 07:31
@malibio
malibio merged commit dbaa7f8 into main Oct 12, 2026
@malibio
malibio deleted the issue-3738-play-edit-chat branch October 12, 2026 07:32
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.

A play's Edit chat: describe the play first, let the user ask about it, and route a reply with the message it answers

1 participant