Skip to content

docs: design the normal, codemode and shell tool modes - #2141

Merged
eric8810 merged 28 commits into
mainfrom
dim/2135-tool-modes
Nov 25, 2026
Merged

eric8810 merged 28 commits into
mainfrom
dim/2135-tool-modes

Conversation

@eric8810

@eric8810 eric8810 commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

WIP: base-1 of #2015. The access-layer check and its allowlist are still to come.

Refs #2015
Refs #2127

Add docs/design/agent-tool-modes.md and index it. A mode is the unit of
action a Session gives its model: one tool call, one program or one shell
session. The mode decides which declarations a request carries, while the
branch's adopted tool set stays mode-independent, so switching takes
effect with the next request.

Refs #2135
@eric8810 eric8810 added documentation Improvements or additions to documentation design Design decision or contract work labels Nov 24, 2026
A separate default the operator sets is redundant with the switch: a new
Session starts normal, a client sends the mode it last used, and
session.create may name one. Availability falls back to normal instead of
refusing the stored choice.

Refs #2135

@zerob13 zerob13 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.

The Session-level mode and keeping the adopted registry separate from the request projection are sensible. The design needs two guarantees before implementation:

  • Separate top-level admission from Code Mode child admission. The projection declares only codemode, but assigns the same admission set to both call origins. That does not enforce the promised one-program interface. Define separate request-pinned allowlists for top-level and child calls, make child discovery and admission agree, and retain Permission and Approval for each child. Also clarify whether a fresh model request after a tool result uses the new Session mode, and which retry or recovery paths reuse the original pin.
  • Give Stop a path to the task owner. Registering execute does not change the existing Stop handler, which routes to BackgroundExec. A live persistent-shell command is owned by ShellSession. Specify how the operator can stop either kind of task, including after switching modes. In the same assembly section, clarify how the execute-only minimal profile retains its tool when normal mode filters execute.

Static design review at 0ba67d0c; hosted docs/ADR gate passed. No runtime claim.

@yyhhyyyyyy yyhhyyyyyy 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.

Review: PR #2141, first round, head 0ba67d0

Scope: this design adds three mutually exclusive tool modes (normal, codemode, shell), makes the mode a Session property, pins it per request, defines the visible and exposed tool surfaces, and changes the shell tool assembly so execute is registered with ToolRegistry. I reviewed the full PR at 0ba67d0 against merge base 4d081fe and current main 7a0e3d4, and checked the cited code in the current main checkout.

Verdict: REQUEST_CHANGES.

Existing review

I agree with the two boundaries in the existing review at this head: top-level and child admission need separate allowlists, and execute needs a Stop path to its task owner. This review adds the request-path mechanism and the create-field spelling that the design still lacks.

P2 findings

P2 1. The live mode is not applied to the request that AgentLoop builds

Problem: The design says only visible reaches the model request and that a mode switch takes effect with the next request without re-adoption (docs/design/agent-tool-modes.md:145-151). In the current request path, when a branch has an adopted tool part, AgentLoop reads data.settings.tools and binds that stored list unchanged (crates/dim-agent-capabilities/src/agent_loop.rs:1231-1245). ToolRegistry::definitions is read only by ToolBinding::prepare and bind_current when the request has no tool list (crates/dim-agent-capabilities/src/tool_binding.rs:143-151, crates/dim-agent-capabilities/src/tool_registry.rs:314). The registry's live mode is not consulted on the configured-branch path.

Failure scenario: An operator creates a Session in normal and switches it to codemode. The next request still carries the branch's stored full tool list, so the model sees the direct tools beside codemode, which is the behavior section 1.4 says the mode exists to prevent. A switch to shell likewise leaves the file and edit tools declared. session.tool_mode.get reports the new mode, but the model request does not match it.

Evidence: docs/design/agent-tool-modes.md:145-151; crates/dim-agent-capabilities/src/agent_loop.rs:1231-1245; crates/dim-agent-capabilities/src/tool_binding.rs:143-151; crates/dim-agent-capabilities/src/tool_registry.rs:314.

Fix: Name the projection step in the request path and apply it to both configurations, with and without a stored tool list. For example, have ToolRegistry return the visible projection and have AgentLoop/ToolBinding use it when preparing settings.tools, without re-adopting the branch. Add a flow test that switches normal to codemode, asserts the next request declares only codemode, then switches back.

P2 2. The request pins declarations but has no separate callable set

Problem: The table gives codemode exposed = callable and visible = {codemode}, and says tools.list and tools.describe are exposed - {codemode} while tools.call resolves the pinned handler (docs/design/agent-tool-modes.md:139-157). ToolBinding::bind_snapshot stores only the declarations passed in settings.tools (crates/dim-agent-capabilities/src/tool_binding.rs:154-177), and handler reads only that stored map (:180-190). There is no second callable set and no separate top-level check.

Failure scenario: If an implementer follows visible and binds only the declaration list, tools.list for a codemode program is empty and tools.call("read") answers Unknown tool, so the mode cannot call any child tool. If they bind the callable set to keep child calls working, a top-level direct call to read passes the check at :152 because exposed is callable, so the one-program-per-step guarantee is broken. The two outcomes cover both ways the current binding can be changed.

Evidence: docs/design/agent-tool-modes.md:139-157; crates/dim-agent-capabilities/src/tool_binding.rs:154-190; crates/dim-agent-capabilities/src/tool_executor.rs:687-700.

Fix: Pin two sets in the request snapshot: visible for top-level admission and callable for child discovery and child admission. Check a top-level call against visible, a child call against callable, and define tools.list/tools.describe from the child set. Add tests for a hidden top-level call and a child call that is not in visible.

P2 3. The create field has two spellings

Problem: docs/design/agent-tool-modes.md:171-172 says the create field is session.create.toolMode. The diagram at :193 says session.create.mode, and the PR summary also says session.create.mode. The current Create request uses deny_unknown_fields (crates/dim-app-server/src/protocol.rs:573-608), so a client sending the wrong spelling receives invalid params rather than a stored mode.

Failure scenario: A client author follows the diagram and sends mode; the daemon rejects the create request. A client author follows the prose and sends toolMode; the diagram and PR description tell a different field. The two product clients can disagree on the wire name, and a test written from one spelling cannot cover the other.

Evidence: docs/design/agent-tool-modes.md:171-172, :193; crates/dim-app-server/src/protocol.rs:573-608.

Fix: Use one spelling in the wire field, the feature name, the diagram, the PR description, the clients and the tests. The wire field should be the one the daemon actually deserializes.

P2 4. The shell stop route still belongs to BackgroundExec

Problem: The design makes execute an ordinary registered tool (docs/design/agent-tool-modes.md:210-214) and says shell mode can still be stopped (:106). session.exec.stop is handled by BackgroundExec (crates/dim-app-server/src/connection.rs:1527, crates/dim-app-server/src/protocol.rs:1019), while the persistent shell keeps background tasks in its own map and implements dyn ExecStop (crates/dim-agent-capabilities/src/shell_session.rs:1305, :1420, :1564). BackgroundExec has no live task for a shell task and cannot cancel it.

Failure scenario: In shell mode, an execute call with runInBackground returns a task id. session.exec.stop or the task list's stop-all reaches BackgroundExec, which sees the recorded ExecStarted fact but no live task and returns a fault or exec_task_unknown; the shell command keeps running. session.stop interrupts a foreground turn but does not stop a background shell job, especially after the operator switches modes.

Evidence: docs/design/agent-tool-modes.md:106, :210-214; crates/dim-app-server/src/connection.rs:1527; crates/dim-app-server/src/protocol.rs:1019; crates/dim-agent-capabilities/src/shell_session.rs:1305, :1420, :1564.

Fix: Route the stop by task owner. Use the branch's dyn ExecStop service, provided by ShellSession, for shell tasks, or register those tasks with the stop port BackgroundExec already serves. State the route in section 6 and add a flow test that stops an execute background task, including after a mode switch.

P3 findings (optional)

  • The request pin is not carried by the budget-recovery transfer. AgentLoop calls ToolBinding::transfer for a recovery request (crates/dim-agent-capabilities/src/agent_loop.rs:1209-1216), and transfer moves only the tool snapshot (crates/dim-agent-capabilities/src/tool_binding.rs:211-218). If the operator switches mode between the original request and its recovery, the recovery keeps the old declarations without the new mode. Include the pinned mode in the transferred snapshot or rebuild the visible projection for the recovery request.
  • session.tool_mode.update writes the stored record and the live value without stating the order, cancellation behavior or restart result (docs/design/agent-tool-modes.md:187-189). session.language.update documents that it writes the record, replaces the live value and then adopts, and that a failure after the record leaves the new value stored (crates/dim-app-server/src/session_language.rs:134-146, docs/design/contracts/session-access.md:333). Define the same failure and cancellation rule for the mode, otherwise get can report a new chosen mode with an old effective mode and a restart can choose the stored one.
  • The minimal-execution profile is not fully accounted for (docs/design/agent-tool-modes.md:214). install_minimal_execution currently gets S:ToolHost from ShellTools (crates/dim-agent-capabilities/src/defaults.rs:230-250, crates/dim-agent-capabilities/src/shell_tools.rs:138), and ToolRegistry requires that service (crates/dim-agent-capabilities/src/tool_registry.rs:874). If ShellTools only registers execute, the profile needs an owner for the empty host table. Separately, normal hides execute, so a default normal Session in that profile has no tool at all. Name the empty-host binding and state whether the minimal profile is shell-only.
  • The design adds SessionConfig.toolMode and gives ToolRegistry a live mode, but it does not update docs/design/contracts/session-access.md A.3 or docs/architecture/rust-agent/plugins/ToolRegistry.md, while the PR body says no other module's design changes. Add those contract updates or state the supersession and the follow-up owner explicitly.

Cross-PR and main

  • The PR is based on 4d081fe6; current main is 7a0e3d46; it is open, not draft, MERGEABLE, and the two-file diff has no visible conflict with main. The branch is older than main, so cited main code was checked in the current checkout.
  • The design depends on the draft CodeMode and child-tool-batches contracts. Its statement that only those two pages change with the implementation does not cover ToolRegistry, SessionConfig or the Session method contract; see the last P3.
  • No overlap with the storage and owner-contract PRs in the current queue. docs/INDEX.md has one added line and no conflicting edit.

Verification

  • node scripts/adr-check.mjs --base 4d081fe6 passed for the 2 changed files.
  • git diff --check passed. A relative-link scan over the new document resolved all 8 targets.
  • CI at 0ba67d0c: changes and ci-ok succeed; the other jobs are skipped. mergeStateStatus is BLOCKED by the review state.
  • No Rust build or runtime test was run; this is a documentation-only PR.

Unverified

  • The target behavior, the session.tool_mode methods and the hello.features mode flags have no current implementation, so their runtime contract was checked only against the design and the existing request path.
  • The exact ShellSession stop behavior after a mode switch was not exercised; the failure is inferred from the current session.exec.stop routing and the two task stores.
  • The design's cited code line numbers were checked against current main 7a0e3d46, not against the PR's older base.

Comment thread docs/design/agent-tool-modes.md Outdated

- Only `visible` reaches the model request, its token accounting and compaction. `exposed` never
appears in a prompt, a declaration or the usage counter.
- A request pins the mode it was prepared under, together with the callable set it pins today. The

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.

P2: the design says a switch needs no re-adoption and only visible reaches the request, but the current request path uses data.settings.tools from the adopted configuration (crates/dim-agent-capabilities/src/agent_loop.rs:1231-1245). ToolRegistry::definitions is read only by ToolBinding::prepare and bind_current when that list is absent (crates/dim-agent-capabilities/src/tool_binding.rs:143-151). A normal to codemode switch therefore leaves the full adopted declarations in the next request. Name and test the projection step for both configurations.

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.

Fixed in 32ff639. Withdrawn.

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.

Fixed in 32ff639 and still fixed in 6d4011c. Withdrawn.

Comment thread docs/design/agent-tool-modes.md Outdated
| Mode | exposed | visible | entry tool absent from callable |
| --- | --- | --- | --- |
| `normal` | callable − {`codemode`, `execute`} | same as exposed | — |
| `codemode` | callable | {`codemode`} | the Session runs `normal` |

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.

P2: codemode exposes callable but declares only codemode. ToolBinding::bind_snapshot stores only the declarations passed in settings.tools (crates/dim-agent-capabilities/src/tool_binding.rs:154-177), and handler reads only that map (:180-190). If the visible projection is bound, a child tools.call("read") is Unknown; if the callable set is bound, a top-level read passes the check at :152. Pin two sets and check top-level against visible, child against callable.

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.

Still open in 32ff639: the prose now separates visible and delegated, but the flow diagram at :197-200 still admits calls against a single exposed set.

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.

The prose fix from 32ff639 remains: visible and delegated are separate sets. The only remainder is the flow diagram at :220, tracked in thread 4677841873. Withdrawn as a separate thread.

Comment thread docs/design/agent-tool-modes.md Outdated
- The model has no tool for this; it is a client method only.

```text
session.create.mode ──▶ SessionConfig.toolMode ──▶ ToolRegistry (live mode)

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.

P2: this diagram says session.create.mode, while :171-172 says session.create.toolMode and the PR summary uses mode. session.create has deny_unknown_fields (crates/dim-app-server/src/protocol.rs:573-608), so one spelling is a rejected request. Use one spelling in the wire field, feature name, diagram, clients and tests.

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.

Still open in 32ff639: the diagram at :197 and the PR description still say session.create.mode, while the prose says session.create.toolMode.

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.

Still open in 6d4011c; same as thread 4677841886. The diagram at :218 and the PR description still say session.create.mode.

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.

Still open in 8ca53c3; same as thread 4677841886. The diagram at :208 and the PR description still say session.create.mode.

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.

Fixed in the document in 82f0b06; same as thread 4677841886. The diagram and prose now say toolMode; the PR description still says session.create.mode.

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.

Fixed in bbbcd67. The diagram, prose and description all use session.create.toolMode.

- The product profile mounts `ShellSession` (branch) and the shell tool in every Session, so a
`shell` or `codemode` Session can use it. `ShellSession` starts no OS process until its first
command, so an unused mode costs a registered part, not a PTY.
- `execute` becomes an ordinary registered tool: the `ShellTools` Session part registers its

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.

P2: registering execute here does not move the stop route. session.exec.stop is handled by BackgroundExec (crates/dim-app-server/src/connection.rs:1527), while ShellSession keeps background tasks in its own map and provides dyn ExecStop (crates/dim-agent-capabilities/src/shell_session.rs:1305, :1420, :1564). A shell execute task cannot be stopped through the existing route. Route by owner and test stop after a mode switch.

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.

Still open in 32ff639: BackgroundExec can find a ShellSession task's shared exec/started record and return a fault before the fallback to ExecStop.

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.

Still open in 6d4011c; the fallback issue is detailed in thread 4677841849. BackgroundExec returns a fault on a live ShellSession task's shared start record before any ExecStop fallback.

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.

Still open in 8ca53c3; same as thread 4677841849. Section 6 is unchanged, and BackgroundExec still returns a fault on a live ShellSession task's shared start record before any ExecStop fallback.

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.

Fixed in 82f0b06; same as thread 4677841849. Section 6 now resolves the live owner before BackgroundExec.

Pin two allowlists per request: visible for top-level model calls and
delegated for Code Mode child calls, so a hidden tool cannot be reached by
naming it directly and discovery agrees with admission. State which retry
and recovery paths keep the pin, and add the stop route for a persistent
shell task plus the minimal profile's shell mode.

Refs #2135
@eric8810

Copy link
Copy Markdown
Collaborator Author

Thanks — both points are now in 32ff639e2.

Top-level versus child admission. The request now pins two allowlists instead of one set: visible for top-level model calls and delegated for Code Mode child calls, and admission picks by the existing parent-call scope (current_parent_call_id). visible is what the request declares; delegated is callable − {codemode} in codemode mode and empty otherwise. A top-level call naming a delegated tool is refused as an unknown tool even though the request bound it, and a child call to codemode is refused, so the one-program interface holds. tools.list / tools.describe / tools.call project and admit exactly delegated, so discovery and admission agree, and each child still passes its own Permission and Approval. Documented in §4 and asserted in §10.

Switch unit and recovery. The pin is per request: a request retried through its own source (budget recovery, restart recovery — binding.transfer) keeps it; a continuation request is a new request and pins the current mode, as does the request after a tool result. A call already admitted finishes. Stated in §3, §4 and §10.

Stop. session.exec.stop now asks the branch's BackgroundExec first and, on an unknown id, the branch's dyn ExecStop (provided by ShellSession), so either kind stops and writes its exec/ended. Both parts stay mounted across a mode switch, so a task started in shell or codemode remains stoppable after switching to normal; session.stop stays the turn's stop. §6 and §10.

Minimal profile. Its Sessions are created with toolMode: shell; normal would filter the only tool it has, so execute stays. §6.

@zerob13 zerob13 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.

The revision makes top-level and delegated allowlists explicit, and the minimal profile now selects shell mode. One existing blocker remains in the proposed route, and the admission check needs to cover the earlier claim step.

  • Route Stop to the live task owner before interpreting shared history. The proposed fallback only runs when BackgroundExec returns unknown. A live ShellSession task already has a shared start record, so BackgroundExec can recognize the ID and return a fault instead. Resolve the live owner first, then use shared history for a completed task. Preserve Stop across a mode switch.
  • Apply the top-level allowlist before claim-side effects. ToolBinding::claim already calls into the bound handler before normal executor admission. Rejected calls should not invoke that hook or register a pending waiter. Keep the existing trusted child-batch binding and per-child permission checks. Also distinguish in-process budget retry, which can reuse the binding, from process restart, where existing rebuild settles rather than reissuing an orphaned request.

Docs/ADR gate passed. Static review only; no runtime or reproduction claim.

@yyhhyyyyyy yyhhyyyyyy 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.

Review: PR #2141, round 2, head 32ff639

Scope: this revision separates top-level and Code Mode child admission, adds a stop fallback for a persistent-shell task, and makes the minimal-execution profile shell by construction. I reviewed the full main...head at 32ff639 against merge base 4d081fe and current main 7a0e3d4, and read every existing thread. Code citations use current main 7a0e3d4.

Verdict: REQUEST_CHANGES.

Prior round

  • P2 1, the live mode is not applied to the request that AgentLoop builds: fixed. The design now says requests read the registry when they are prepared and only visible reaches the model request (docs/design/agent-tool-modes.md:160, :187-188). Withdrawn.
  • P2 2, the request pins declarations but has no separate callable set: fixed in the prose. The table and the origin rule now pin visible and delegated separately (docs/design/agent-tool-modes.md:136-150). The flow diagram still uses exposed; see P2 3 below.
  • P2 3, the create field has two spellings: still open; see P2 4 below.
  • P2 4, the shell stop route still belongs to BackgroundExec: still open; see P2 1 below.
  • P3, the budget-recovery transfer does not carry the pin: addressed for the budget path. The design now says a recovery keeps the pin (docs/design/agent-tool-modes.md:154-159), and the transferred snapshot can carry it. Withdrawn for that path. The restart half is not a current retry; see P3 1 below.
  • P3, session.tool_mode.update has no order or failure rule: still open; see P3 2 below.
  • P3, the minimal profile is not fully accounted for: the mode half is now stated but conflicts with the restore rule; see P2 5 below. The empty ToolHost owner remains; see P3 3 below.
  • P3, the contract documents are not updated: still open; see P3 4 below.

P2 findings

P2 1. The stop fallback is unreachable for a live shell task

Problem: The new route asks BackgroundExec first and the branch's ExecStop only when BackgroundExec does not know the id (docs/design/agent-tool-modes.md:226-235). BackgroundExec::stop does not only know its own live tasks: when its live map has no entry, it queries the branch's shared exec/started history and treats a start record as an owned task (crates/dim-agent-capabilities/src/workspace_tools/background.rs:529-550; task_event sets query.from = None at :659). ShellSession writes the same ExecStarted event for a live shell task (crates/dim-agent-capabilities/src/shell_session.rs:1077, :1187). BackgroundExec therefore finds the start record, finds no exec/ended, and returns the fault at :545-550 instead of TaskError::Unknown, so the fallback to dyn ExecStop never runs.

Failure scenario: In shell or codemode mode, an execute call with runInBackground returns a task id. The operator calls session.exec.stop, which still resolves BackgroundExec (crates/dim-app-server/src/connection.rs:1627-1644). BackgroundExec sees the shared start record and returns "owned task has no terminal or live resource"; the shell command keeps running. The same happens after the Session switches to normal, even though both parts stay mounted.

Evidence: docs/design/agent-tool-modes.md:226-235; crates/dim-agent-capabilities/src/workspace_tools/background.rs:516-557, :644-671; crates/dim-agent-capabilities/src/shell_session.rs:1077, :1187, :1420-1427, :1564; crates/dim-app-server/src/connection.rs:1627-1644.

Fix: Resolve the live owner before interpreting shared history. Ask the branch's dyn ExecStop for a live shell task, or keep a task-owner index; use BackgroundExec's live map for native tasks, and use the shared start and end records only to answer a completed task. Keep both parts mounted across mode switches, as the design already says. Add a flow test that stops a live shell task after switching to normal.

P2 2. Admission runs after claim side effects

Problem: The new origin rule is stated for a call (docs/design/agent-tool-modes.md:146-150), but the first hook that sees a top-level call is ToolBinding::claim. It calls every bound handler's claim before the ToolCall is appended (crates/dim-agent-capabilities/src/tool_binding.rs:241-254; crates/dim-agent-capabilities/src/agent_loop.rs:1703-1722). Section 12 assigns the refusal to ToolExecution (docs/design/agent-tool-modes.md:373), whose admit runs later (crates/dim-agent-capabilities/src/tool_executor.rs:687-724). Because the request binds the union of visible and delegated (docs/design/agent-tool-modes.md:137-138), a hidden tool is in the snapshot and its claim is invoked. This is raised at this head because the new origin rule makes the ordering part of the design.

Failure scenario: In codemode mode, the model emits a top-level ask_user call. visible is only codemode, so the call must be refused. ToolBinding::claim still calls AskUser::claim, which registers a waiter and is visible to the question surface (crates/dim-agent-questions/src/lib.rs:338-373). The call is then refused as outside visible, but the handler side effect already happened. The same applies to any future handler whose claim reserves a resource or registers a waiter.

Evidence: docs/design/agent-tool-modes.md:136-150; crates/dim-agent-capabilities/src/tool_binding.rs:241-254; crates/dim-agent-capabilities/src/agent_loop.rs:1703-1722; crates/dim-agent-capabilities/src/tool_executor.rs:687-724; crates/dim-agent-questions/src/lib.rs:338-373.

Fix: Apply the top-level allowlist before claim side effects: filter the top-level calls against visible before binding.claim, or pass the call origin into claim and skip calls outside visible. Keep the child gate's delegated check and per-child Permission. Add a test with a claim-bearing hidden tool.

P2 3. The diagram still admits against a single exposed set

Problem: The prose now defines visible and delegated and admits by call origin (docs/design/agent-tool-modes.md:136-150), but the flow diagram at :199 still says a call checks the pinned mode against exposed, and :137-138 defines exposed as the union of the two sets, not as an admission set. The index line also says "visible/exposed tool surface" (docs/INDEX.md:13), and the PR description repeats "exposed".

Failure scenario: An implementer follows the diagram and checks a call against the union. In codemode, visible is {codemode} but exposed includes read, so a top-level read call is admitted and the one-program interface is broken. The verification step at :319-321 expects that call to be refused, so the diagram and the test disagree.

Evidence: docs/design/agent-tool-modes.md:137-138, :146-150, :199, :319-321; docs/INDEX.md:13; PR description.

Fix: Draw two origin branches in the diagram: a top-level call admits inside visible, a child call inside delegated. Remove exposed as an admission set or label it only as the binding union. Update the index line.

P2 4. The create field still has two spellings

Problem: The prose says the create field is session.create.toolMode (docs/design/agent-tool-modes.md:175-177), but the diagram at :197 says session.create.mode and the PR description also says mode. The current Create request derives deny_unknown_fields with camelCase (crates/dim-app-server/src/protocol.rs:535-537), so a client that follows the diagram sends a field the daemon rejects.

Failure scenario: A client author follows the diagram or the PR description and sends mode; the daemon returns invalid params and the Session is not created with the chosen mode. A test written from one spelling cannot cover the other.

Evidence: docs/design/agent-tool-modes.md:175-177, :197; crates/dim-app-server/src/protocol.rs:535-537; PR description.

Fix: Use toolMode in the wire field, the feature name, the diagram, the PR description, the clients and the tests. The wire field should be the one the daemon deserializes.

P2 5. The minimal profile's shell-by-construction conflicts with the restore rule

Problem: Section 6 says the minimal-execution profile is shell by construction (docs/design/agent-tool-modes.md:218-219), but section 9 says a record without the field reads as normal (docs/design/agent-tool-modes.md:301-312). An existing minimal-execution Session has no toolMode, so it restores as normal. The profile's Session mounts only execute (tests/integration/tests/minimal_execution.rs:267-270; crates/dim-agent-capabilities/src/defaults.rs:227-251; crates/dim-agent-capabilities/src/shell_tools.rs:100-142). The Skills tool is filtered out by that mount list. normal hides codemode and execute, so its visible set is empty.

Failure scenario: After upgrade, an existing minimal-execution Session restores as normal with no tools. The shell mode's only current product form cannot run a command until an operator selects shell, if a client is available. The design does not say how "shell by construction" applies to create or restore.

Evidence: docs/design/agent-tool-modes.md:218-219, :301-312; crates/dim-agent-capabilities/src/defaults.rs:227-251; crates/dim-agent-capabilities/src/shell_tools.rs:100-142; tests/integration/tests/minimal_execution.rs:267-270.

Fix: State that the minimal profile forces toolMode: shell on create and restore and excepts itself from the absent-is-normal rule, or state that old minimal Sessions become normal and have no tools as an intended migration. Add a restore test.

P3 findings (optional)

P3 1. A restart is not a request retry

Problem: The design says a request retried by a restart recovery keeps its pin (docs/design/agent-tool-modes.md:157, :326-327). On restart, AgentLoop::rebuild restores the open turn; for a request in the Model stage it appends ModelOutputEnd with Failed CAPABILITY_RELOADING (crates/dim-agent-capabilities/src/agent_loop.rs:1146-1169), and the handler ends the turn Failed (:1617-1680). It does not reissue the request. A Tools-stage request is settled by rebuild and ToolExecutor with reload results.

Failure scenario: The verification step cannot be executed as written, and an implementer may add pin persistence for a path that never reissues the request. The budget path is real and keeps the pin; the restart path is not a retry.

Evidence: docs/design/agent-tool-modes.md:157, :326-327; crates/dim-agent-capabilities/src/agent_loop.rs:1146-1169, :1617-1680.

Fix: Say that a budget recovery keeps the pin; after a restart the turn fails and the next request is new, pinning the current mode. Remove restart from the retry list and the flow.

P3 2. session.tool_mode.update still has no order or failure rule

Problem: The design says update writes the stored record and the live value "as session.language.update does" (docs/design/agent-tool-modes.md:191-193), and section 11 says cancellation stops the record write (docs/design/agent-tool-modes.md:361-363). The language path writes the record first, replaces the live cell, then has Prompt adopt; only the adoption is cancellable, and a failure after the record leaves the new value stored (crates/dim-app-server/src/session_language.rs:134-151; docs/design/contracts/session-access.md:333-335). The mode design does not state the order or the result of a failure after the record.

Failure scenario: An interrupted update can leave the record and the live value divergent; get may report the old mode while a restart reads the new stored mode. A client cannot know which value won.

Evidence: docs/design/agent-tool-modes.md:191-193, :361-363; crates/dim-app-server/src/session_language.rs:134-151; docs/design/contracts/session-access.md:333-335.

Fix: Mirror the language order and failure rule, or state the difference. Define what get reports after an interrupted update, and add a cancellation test.

P3 3. The minimal profile still has no ToolHost owner

Problem: The design says ShellTools registers execute with ToolRegistry "instead of providing ToolHost" (docs/design/agent-tool-modes.md:214-217). ToolRegistryPlugin requires S:ToolHost and reads its definitions (crates/dim-agent-capabilities/src/tool_registry.rs:865-901). In the minimal profile, ShellTools is the only host provider (crates/dim-agent-capabilities/src/shell_tools.rs:133-139; crates/dim-agent-capabilities/src/defaults.rs:231-251). If it stops providing the host, the registry has no input.

Failure scenario: The minimal profile fails to assemble, or the registry applies with an empty host only if some unstated owner provides an empty table.

Evidence: docs/design/agent-tool-modes.md:214-219; crates/dim-agent-capabilities/src/tool_registry.rs:865-901; crates/dim-agent-capabilities/src/shell_tools.rs:133-139; crates/dim-agent-capabilities/src/defaults.rs:231-251.

Fix: Name the empty-host owner and how the minimal profile binds it, or keep ShellTools as the minimal profile's host provider while registering execute in both profiles. State the split.

P3 4. The canonical contracts are not updated

Problem: The design adds SessionConfig.toolMode and a live mode in ToolRegistry, but the canonical contracts still list the old SessionConfig fields and ToolRegistry dependencies. The PR body also says no other module's design changes.

Failure scenario: Implementers and clients have two sources: the new design and the old contracts. The contract tests and the design can disagree about the stored field set and the registry's inputs.

Evidence: docs/design/agent-tool-modes.md:178-193; docs/design/contracts/session-access.md:310-339; docs/architecture/rust-agent/plugins/ToolRegistry.md:24-31; PR body.

Fix: Update those contracts or state the supersession and the follow-up owner explicitly.

Cross-PR and main

  • The PR is open, not draft, mergeable, and its head is 32ff639. The merge base is 4d081fe; current main is 7a0e3d4. The branch is older than main, so cited code was read from origin/main 7a0e3d4.
  • docs/INDEX.md is also changed by open PRs #2002 (around line 14) and #1881 (around line 132); this PR adds line 13, so there is no hunk overlap. No other open PR touches docs/design/agent-tool-modes.md.
  • No conflict with current main in the two changed files.

Verification

  • node scripts/adr-check.mjs --base 4d081fe6: passed, 2 changed files.
  • git diff --check: passed.
  • Relative-link scan: 7 links, all resolve.
  • CI at 32ff639: changes and ci-ok succeeded; all other jobs were skipped. I did not wait for CI.
  • No Rust build or runtime test was run; this is a documentation-only PR.

Unverified

  • The stop failure was inferred from the two task stores and the shared history query; no live shell task was executed.
  • The claim side effect was read from ToolBinding::claim, AgentLoop, and the question handler; it was not exercised at runtime.
  • The restart behavior was read from the rebuild and failure paths; it was not run.
  • The minimal profile was not built; the missing ToolHost is inferred from the registry's required service and the current profile assembly.

Comment thread docs/design/agent-tool-modes.md Outdated
`ShellSession`, which provides the branch's `dyn ExecStop`. With `execute` in the product, both
kinds exist in one Session:

- The stop route asks `BackgroundExec` first and, when it does not know the id, the branch's

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.

P2: this fallback is unreachable for a live shell task. BackgroundExec::stop queries the branch's shared exec/started history when its live map has no entry (crates/dim-agent-capabilities/src/workspace_tools/background.rs:529-550), and ShellSession writes the same event for a live task (crates/dim-agent-capabilities/src/shell_session.rs:1077, :1187). It therefore finds the start record, finds no exec/ended, and returns the fault at :545-550 instead of TaskError::Unknown, so dyn ExecStop is never called. Resolve the live owner first, and use the shared history only for a completed task.

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.

Still open in 6d4011c. Section 6 (:252-255) still asks BackgroundExec first. BackgroundExec::stop queries the shared exec/started history when its live map misses (crates/dim-agent-capabilities/src/workspace_tools/background.rs:530-537) and returns the fault at :545-550 when no exec/ended exists; ShellSession writes the same start fact at crates/dim-agent-capabilities/src/shell_session.rs:1077 and :1187. The ExecStop fallback still never runs, so a live shell task cannot be stopped. Resolve the live owner first.

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.

Still open in 8ca53c3. Section 6 (:242-243) is unchanged: BackgroundExec first, ExecStop only on unknown. It still finds the shared exec/started record for a live ShellSession task (crates/dim-agent-capabilities/src/workspace_tools/background.rs:529-550; crates/dim-agent-capabilities/src/shell_session.rs:1077, :1187) and returns the fault at :545-550 instead of TaskError::Unknown, so the fallback never runs. Resolve the live owner first.

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.

Fixed in 82f0b06. Section 6 (:272-274) now resolves the live owner first: the branch's ExecStop for a live shell task, then BackgroundExec for a native process, and history never answers for a live task. The verification at :412-414 covers it.

| `codemode` | {`codemode`} | callable − {`codemode`} | the Session runs `normal` |
| `shell` | {`execute`} | none | the Session runs `normal` |

- Admission is by call origin: a top-level call is admitted only inside `visible`, a child call only

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.

P2: this rule would be checked after the first side effect. ToolBinding::claim calls every bound handler's claim before the ToolCall is appended (crates/dim-agent-capabilities/src/tool_binding.rs:241-254; crates/dim-agent-capabilities/src/agent_loop.rs:1703-1722), while section 12 assigns the refusal to ToolExecution (:373), whose admit runs later (crates/dim-agent-capabilities/src/tool_executor.rs:687-724). Because the request binds the union of visible and delegated (:137-138), a hidden top-level ask_user is in the snapshot; its claim registers a waiter (crates/dim-agent-questions/src/lib.rs:338-373) before the call is refused. Apply the top-level allowlist before claim, or make claim skip calls outside visible.

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.

Not fixed, but the role change removes the trigger. ask_user is now a Session tool declared in every mode (:91-92, :104-108), so the hidden call in the prior example no longer exists and no current hidden tool implements claim. The design still assigns the origin refusal to ToolExecution after ToolBinding::claim (crates/dim-agent-capabilities/src/tool_binding.rs:241-254; crates/dim-agent-capabilities/src/agent_loop.rs:1705-1722), so a future Workspace or Entry tool with a claim would side-effect before refusal. I am downgrading this to optional; state the order or say roles with claims are out of scope.

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.

Still optional at 8ca53c3. ask_user is declared in all three modes (docs/design/agent-tool-modes.md:97-99), so no hidden claim-bearing tool exists; the ordering point remains only for a future hidden tool with a claim. State the order or scope it out.

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.

Fixed in 82f0b06. :184-185 says the origin check runs before a handler's claim, so a refused call registers no waiter and takes no effect.

Comment thread docs/design/agent-tool-modes.md Outdated
```text
session.create.mode ──▶ SessionConfig.toolMode ──▶ ToolRegistry (live mode)
├─ a request pins the mode ──▶ visible ──▶ model request, usage
└─ a call checks the pinned mode ──▶ exposed ──▶ admit or refuse

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.

P2: this line still admits against exposed, which :137-138 defines as the union of visible and delegated. The prose at :146-150 admits a top-level call only inside visible and a child only inside delegated. Following the diagram admits a top-level read in codemode and breaks the one-program interface. Draw the two origin branches separately and remove exposed as an admission set; docs/INDEX.md:13 and the PR description use the same stale term.

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.

Still open in 6d4011c. The diagram at :220 still checks a call against exposed, and docs/INDEX.md:13 and the PR description still use the same term. The prose at :167-171 admits a top-level call only inside visible and a child only inside delegated; the diagram admits a top-level read in codemode. Draw the two origin branches and remove exposed as an admission set.

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.

Still open in 8ca53c3. The prose at :157-161 admits by origin, but the diagram at :210 still checks exposed, which :146-147 defines as the union; the PR description also says "a call is admitted only inside the pinned exposed set". A top-level read in codemode would be admitted. Draw the two origin branches and remove exposed as an admission set.

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.

Fixed in the document in 82f0b06. :169-170 removes exposed as an admission set, :180-185 admits by origin, the diagram at :235-238 branches visible and delegated, and docs/INDEX.md:13 is fixed. The PR description still says "admitted only inside the pinned exposed set", so update the body (the P2 in the review body).

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.

Fixed in bbbcd67. The PR description now uses visible and delegated; no exposed remains.

Comment thread docs/design/agent-tool-modes.md Outdated
- The model has no tool for this; it is a client method only.

```text
session.create.mode ──▶ SessionConfig.toolMode ──▶ ToolRegistry (live mode)

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.

P2: this diagram says session.create.mode, while the prose at :175-177 says session.create.toolMode, and the PR description also says mode. Create derives deny_unknown_fields with camelCase (crates/dim-app-server/src/protocol.rs:535-537), so the spelling is a rejected request. Use toolMode in the diagram, the PR description, the clients and the tests.

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.

Still open in 6d4011c. The diagram at :218 still says session.create.mode, while the prose at :197 says session.create.toolMode; the PR description still says session.create.mode. Create derives deny_unknown_fields with camelCase (crates/dim-app-server/src/protocol.rs:536-537), so one spelling is a rejected request. Use toolMode everywhere.

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.

Still open in 8ca53c3. The prose at :186-188 says session.create.toolMode, the diagram at :208 says session.create.mode, and the PR description says session.create.mode. Create derives deny_unknown_fields with camelCase (crates/dim-app-server/src/protocol.rs:536-537), so one spelling is an invalid-params request. Use toolMode everywhere.

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.

Fixed in the document in 82f0b06. :211-214 says session.create takes toolMode and Create carries tool_mode, and the diagram at :235 says session.create.toolMode. The PR description still says session.create.mode, so update the body (the P2 in the review body).

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.

Fixed in bbbcd67. The description and the diagram both say toolMode; session.create.mode is gone.

Comment thread docs/design/agent-tool-modes.md Outdated
declaration and handler with `ToolRegistry` instead of providing `ToolHost`, and still resolves
the calling branch's `ShellSession` per call. The registry's registration already carries what a
host tool needs: declaration, handler, risk, mount-list filtering and per-Session lifetime.
- The minimal-execution profile is `shell` by construction: its Sessions set `toolMode: shell`,

@yyhhyyyyyy yyhhyyyyyy Nov 24, 2026 •

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.

P2: this conflicts with the restore rule at :301-312: a record without toolMode reads as normal, and normal hides execute. The minimal profile's Session mounts only execute (tests/integration/tests/minimal_execution.rs:267-270), so an existing minimal Session restores with no tools. State that the profile forces shell on create and restore and excepts itself from the absent-is-normal rule, or document the loss as intended.

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.

Still open in 6d4011c. Section 6 (:239-240) says the minimal profile is shell by construction, while section 9 (:331-333) says a record without the field restores as normal. The minimal Session mounts only execute (tests/integration/tests/minimal_execution.rs:267-277; crates/dim-agent-capabilities/src/defaults.rs:227-252), and normal hides execute, so an existing minimal Session restores with no visible tools. State that the profile forces shell on create and restore and excepts itself from the absent-is-normal rule, or state the loss as intended.

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.

Still open in 8ca53c3. Section 6 (:229-230) still says the minimal profile is shell by construction, while section 9 (:327-329) and section 5 (:186) say a record without the field is normal. The minimal Session mounts only execute (tests/integration/tests/minimal_execution.rs:267-277), and normal hides it (:97, :151), so a restored minimal Session has no visible tools. State the create/restore exception or the intended loss.

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.

Fixed in 82f0b06. :257-260 sets shell on create and on restore when the record lacks the field, :378-379 excepts the minimal profile, and :407-408 verifies it.

Read the surface rule for the assembled product profile: the normal list,
the codemode delegation and the shell's single tool. The list is a reading
of the rule, not a second source.

Refs #2135
@eric8810

Copy link
Copy Markdown
Collaborator Author

Added the concrete lists for the assembled product profile (§2, "The product profile's tool list") and to the issue:

Mode Declared Delegated to Code Mode
normal read, write, edit, glob, grep, exec, exec_stop, wait, recall, skill, branch, settings, ask_user, goal_update, events, schedule, wakeup, loop, image_understand, agent, plugin, web_fetch —
codemode codemode the normal list and execute
shell execute —

web_search (when a search service is usable) and every MCP tool follow the same rule. The table is a reading of the §4 rule; a mount list, an Agent profile, an absent part or a disabled source narrows it.

A mode replaces the Workspace tools; the Session tools, the extension tools
and the MCP tools stay in every mode. Each owner declares a tool's role at
registration, so a new tool joins the rule without editing the design, and
the shell and codemode modes keep the interaction surface the operator
needs.

Refs #2135
@eric8810

Copy link
Copy Markdown
Collaborator Author

Changed the mode sets from a tool list to a role rule, after the review on enumeration:

  • Workspace tools (today read, write, edit, glob, grep, exec, exec_stop) read, write or run in the workspace; a shell command does the same job, so the mode replaces them.
  • Session tools (everything else, extension and MCP tools included) talk to the operator or another line, schedule the Session's future, or fetch information and configuration. They stay in every mode — a shell Session keeps ask_user, branch, agent, schedule, recall, skill, settings, web_fetch and MCP tools, and a codemode Session declares them too.
  • codemode and execute are entries, declared only in their own mode; a codemode program may still call execute.

Each owner declares a tool's role when it registers it; a tool that declares none is a Session tool. The doc no longer lists each mode's final set, and a new tool needs no edit to this design.

The surface rule, admission split and verification are updated accordingly (§2, §4, §10).

@yyhhyyyyyy yyhhyyyyyy 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.

Review: PR #2141, round 3, head 6d4011c

Scope: this revision replaces the per-mode tool lists with a Workspace/Session/Entry role table, so codemode and shell declare every Session tool beside their entry tool. I reviewed the full main...head at 6d4011c against merge base 4d081fe and current main eacc672, and read every existing thread. Code citations use current main eacc672.

Verdict: REQUEST_CHANGES.

Prior round

  • P2 1, the stop fallback is unreachable: still open; covered by the existing review at 32ff639 and thread 4677841849.
  • P2 2, admission runs after claim side effects: the role change removes the concrete trigger, so I downgrade it; covered by the existing review at 32ff639 and thread 4677841864.
  • P2 3, the diagram admits against exposed: still open; see below.
  • P2 4, the create field has two spellings: still open; see below.
  • P2 5, the minimal profile conflicts with the restore rule: still open; see below.
  • P3 1, restart is treated as a request retry: still open; covered by the existing review at 32ff639.
  • P3 2, session.tool_mode.update has no order or failure rule: still open; see below.
  • P3 3, the minimal profile has no ToolHost owner: still open; see below.
  • P3 4, the canonical contracts are not updated: still open; see below.

Existing review

I agree with the existing review at 32ff639 on the stop fallback, the top-level claim order, and the restart distinction; all three remain at this head, and thread 4677841849 states the stop detail. I do not repeat them below.

P2 findings

P2 1. The flow diagram still admits against the union set

Problem: The prose defines visible and delegated and admits by call origin (docs/design/agent-tool-modes.md:167-171), but the diagram at :220 still says a call checks the pinned mode against exposed. Line :155 defines exposed as the union of the two sets, so the diagram admits a top-level call inside the union. docs/INDEX.md:13 and the PR description repeat the term.

Failure scenario: An implementer follows the diagram and checks a call against the union. In codemode, visible is the Session tools plus codemode, but exposed also contains read; a top-level read call is admitted and the one-program interface is broken. The verification at :343-345 expects that call to be refused.

Fix: Draw two origin branches: a top-level call admits inside visible, a child call inside delegated. Remove exposed as an admission set or label it only as the binding union. Update the index line and the PR description.

P2 2. The create field still has two spellings

Problem: The prose says the create field is session.create.toolMode (:197), while the diagram at :218 says session.create.mode; the PR description also says session.create.mode. Create derives deny_unknown_fields with camelCase (crates/dim-app-server/src/protocol.rs:536-537), so one spelling is a rejected request.

Failure scenario: A client author follows the diagram or the PR description and sends mode; the daemon rejects the create request as invalid params. A client that omits the field to avoid the rejection gets the default mode instead of the operator's choice. A test written from one spelling cannot cover the other.

Fix: Use toolMode in the diagram, the PR description, the clients and the tests.

P2 3. The minimal profile's shell-by-construction still conflicts with the restore rule

Problem: Section 6 says the minimal-execution profile is shell by construction (:239-240), but section 9 says a record without toolMode restores as normal (:331-333). An existing minimal Session has no toolMode; it mounts only execute (tests/integration/tests/minimal_execution.rs:267-277; crates/dim-agent-capabilities/src/defaults.rs:227-252). normal hides execute, so the restored Session has no visible tools.

Failure scenario: After upgrade, an existing minimal-execution Session restores as normal with no tools. The profile's only tool is hidden until an operator selects shell from a client, and the design does not say whether that is intended.

Fix: State that the profile forces toolMode: shell on create and restore and excepts itself from the absent-is-normal rule, or state that old minimal Sessions become normal with no tools as an intended migration. Add a restore test.

P2 4. The new role rule has no channel for host tools

Problem: Section 2 says each owner declares its tool's role when it registers the tool (:94-96), and section 4 relies on that so a new Workspace tool added by WorkspaceTools or ShellTools joins the rule (:115-116). Host tools are not registered. ToolDriver::definitions returns only ToolDefinition (crates/dim-agent-capabilities/src/host.rs:1203-1225), ToolRegistryPlugin maps those definitions to ToolContribution {definition, handler} (crates/dim-agent-capabilities/src/tool_registry.rs:905-914), and ToolDefinition has no role (crates/dim-agent-types/src/tool.rs:401-424). The design bans the role from the model-facing declaration (:96). Section 11 still says the two tool names belong to the registry (:375-376), and section 12 raises no requirement (:394-399).

Failure scenario: A new Workspace tool is added to WorkspaceTools. It has no stated way to declare Workspace, so the implementer either hardcodes the seven current names in ToolRegistry, and the new tool is treated as Session and stays declared in codemode and shell, or adds a role to ToolDefinition, which changes the persisted declaration and the model request, contradicting :96 and session-boundary A.5 (docs/design/contracts/session-boundary.md:637).

Fix: State the host-port channel, for example a ToolDriver role method like concurrency and a role registration option for registered tools, and update sections 11 and 12 to raise the requirement. The current concurrency option is the precedent for a non-declaration property (docs/design/contracts/session-boundary.md:637).

P3 findings (optional)

P3 1. Section 1.4 still argues for hiding the direct tools

Problem: Section 1.4 says a mode exists only if the model faces one unit of action, and that with both codemode and the direct tools the model uses the direct tools (:74-77). Section 2 now keeps every Session tool declared in codemode and shell (:91-92, :104-108, :158-162), so the model does face direct Session tools beside the entry tool.

Failure scenario: An implementer follows section 1.4 and removes the Session tools in codemode or shell, contradicting section 4 and dropping ask_user, or a reviewer cannot tell which set is intended.

Fix: Narrow the claim to workspace tools: the mode hides the Workspace tools and keeps the Session tools.

P3 2. session.tool_mode.update still has no order or failure rule

Problem: The design says update writes the stored record and the live value as session.language.update does (:212-214), and section 11 says cancellation stops the record write (:385-387). The language path writes the record first, replaces the live cell, then has Prompt adopt; only the adoption is cancellable, and a failure after the record leaves the new value stored (crates/dim-app-server/src/session_language.rs:134-151; docs/design/contracts/session-access.md:335-336).

Failure scenario: An interrupted update can leave the record and live value divergent; get may report the old mode while a restart reads the new stored mode.

Fix: Mirror the language order and failure rule, or state the difference and what get reports after an interrupted update.

P3 3. The minimal profile still has no ToolHost owner

Problem: Section 6 says ShellTools registers execute with ToolRegistry instead of providing ToolHost (:235-238). ToolRegistryPlugin requires S: ToolHost and reads its definitions (crates/dim-agent-capabilities/src/tool_registry.rs:865-914). In the minimal profile, ShellTools is the only host provider (crates/dim-agent-capabilities/src/shell_tools.rs:100-142; crates/dim-agent-capabilities/src/defaults.rs:227-252). Section 11 also says assembly is untouched (:380-381), while section 6 changes the product and minimal profiles.

Failure scenario: The minimal profile fails to assemble, or the registry applies with an empty host only if some unstated owner provides one.

Fix: Name the empty-host owner and how the minimal profile binds it, or keep ShellTools as the minimal profile's host provider while registering execute in both profiles. Correct the assembly claim in section 11.

P3 4. The canonical contracts are not updated

Problem: The design adds SessionConfig.toolMode, a live mode in ToolRegistry and a role table, but the canonical contracts still list the old SessionConfig fields and the registry's operations. See docs/design/contracts/session-access.md:310-339 and docs/architecture/rust-agent/plugins/ToolRegistry.md:24-31. The PR body says no other module's design changes.

Failure scenario: Implementers and clients have two sources: the new design and the old contracts. The contract tests and the design can disagree about the stored field set, the registry's inputs and the role mechanism.

Fix: Update those contracts or state the supersession and the follow-up owner explicitly.

Cross-PR and main

  • Merge base 4d081fe; current main eacc672. git merge-tree --write-tree origin/main HEAD is clean. No conflict in the two changed files.
  • Open PRs #2002 (INDEX line 17) and #1881 (INDEX line 134) do not overlap this PR's INDEX line 13. No other open PR touches docs/design/agent-tool-modes.md.
  • Open target-contract PR #2103 (ToolRegistry) says callers keep which tools a request declares and its operations have no role or mode table; this design puts the projection and the live mode in ToolRegistry. Open PR #2099 (CodeMode) says the program sees only the request's pinned declarations; this design's delegated includes tools not in visible. Reconcile these if they land.
  • Open PRs #2102 and #2098 edit docs/design/contracts/session-access.md where toolMode will need a row.

Verification

  • node scripts/adr-check.mjs --base origin/main: passed, 2 changed files.
  • git diff --check origin/main...HEAD: passed.
  • Relative-link scan: 6 links in the new page plus the INDEX entry, all resolve.
  • CI at 6d4011c: changes and ci-ok succeeded; all other jobs were skipped. I did not wait for CI.
  • No Rust build or runtime test was run; this is documentation only.

Unverified

  • The stop failure was inferred from the shared-history query and the two task stores; no live shell task was executed.
  • The role channel gap is read from the current ToolHost, ToolContribution and ToolDefinition shapes; no implementation was attempted.
  • The claim ordering has no current trigger; P3 1 is based on the handler contract.
  • The minimal profile was not built; the empty visible set and the missing ToolHost are inferred from the mount list and the registry's required service.

Comment thread docs/design/agent-tool-modes.md Outdated
looks things up, or coordinates its own lines, so those tools stay in every mode.

Tools fall into two roles, and the two entry tools stand apart. Each owner declares its tool's role
when it registers the tool; a tool that declares none is a Session tool. The role is not a field of

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.

P2: the new role rule has no stated channel for host tools. Section 2 says each owner declares its role when it registers the tool, but host tools are not registered: ToolDriver::definitions returns only ToolDefinition (crates/dim-agent-capabilities/src/host.rs:1203-1225), ToolRegistryPlugin maps those definitions to ToolContribution {definition, handler} (crates/dim-agent-capabilities/src/tool_registry.rs:905-914), and ToolDefinition has no role (crates/dim-agent-types/src/tool.rs:401-424). Section 11 still says the two tool names belong to the registry (:375-376) and section 12 raises no requirement (:394-399). A new Workspace tool added to WorkspaceTools therefore has no stated way to declare Workspace: the implementer either hardcodes the seven names in ToolRegistry, so the new tool is a Session tool and stays declared in codemode and shell, or adds the role to ToolDefinition, which sends it to the model and changes the persisted declaration, contradicting :96 and session-boundary A.5 (docs/design/contracts/session-boundary.md:637). State the host-port channel (for example a ToolDriver role method like concurrency, plus a registration option for registered tools) and update sections 11 and 12.

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.

Fixed in 8ca53c3. The Workspace/Session/Entry role table is removed; section 2 now declares only the entry tool and ask_user/recall, and section 4 defines the sets by exclusion, so a new host or registered tool joins normal, codemode delegation and shell hiding without a role channel. Withdrawn.


### 1.4 The modes are exclusive

A mode exists only if the model faces one unit of action. With both `codemode` and the direct tools

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.

P3: this paragraph still argues that a mode exists only if the model faces one unit of action, and that with both codemode and the direct tools the model uses the direct tools (:74-77). Section 2 now keeps every Session tool declared in codemode and shell (:91-92, :104-108, :158-162), so the model does face direct Session tools beside the entry tool. Narrow the claim to workspace tools, or state why Session tools do not dilute the unit of action. As written, an implementer following this paragraph would remove ask_user and the other Session tools that section 2 deliberately keeps.

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.

Fixed in 8ca53c3. Section 2 now hides every work tool in codemode and shell, so section 1.4's one-unit-of-action argument matches the tables; the direct tools are no longer declared beside the entry. Withdrawn.

@eric8810

Copy link
Copy Markdown
Collaborator Author

A non-normative reading of the role rule for today's product profile (the rule in §2/§4 is the contract; a new tool joins by its role):

Workspace (7) — replaced by the mode: read, write, edit, glob, grep, exec, exec_stop

Session (15 built-in, plus extensions) — stays in every mode: wait, recall, skill, branch, settings, ask_user, goal_update, events, schedule, wakeup, loop, image_understand, agent, plugin, web_fetch; plus web_search when a search service is usable, plus every MCP tool

Entry (2) — declared only in its own mode: codemode, execute

Mode Declared A Code Mode program may call Hidden
normal the 7 Workspace + the 15 Session (+ dynamic) = 22 — codemode, execute
codemode codemode + the 15 Session (+ dynamic) = 16 every tool except codemode = 7 Workspace + 15 Session + execute (+ dynamic) = 23 —
shell execute + the 15 Session (+ dynamic) = 16 — the 7 Workspace

Consequences worth reviewing: a shell Session keeps the whole interaction surface (ask_user, branch, agent, schedule, recall, skill, settings, web_fetch, MCP) and replaces only the workspace actions; a codemode Session declares the same interaction surface and hides the workspace actions from the model while a program can call all of them plus execute.

@eric8810

Copy link
Copy Markdown
Collaborator Author

This supersedes the list in my previous comment. The rule is now: a mode declares its entry tool and the three dialogue tools — ask_user, recall, goal_update — because a mode cannot replace talking to the operator, reading a compacted conversation or closing a goal. Everything else is work.

Mode Declared A program may call Hidden
normal every tool except codemode and execute — codemode, execute
codemode codemode, ask_user, recall, goal_update every tool except codemode —
shell execute, ask_user, recall, goal_update — every other tool

So codemode loses no reach: skills, images, web, MCP, lines, agents, schedules and settings are all callable inside a program; they are just not declared. shell is deliberately minimal: the shell plus the dialogue, no skill, image, web, MCP, line, agent, schedule, settings or plugin tool. Adding one back is a decision on that table.

A new tool is work by default (declared in normal, callable in codemode, hidden in shell); a tool that belongs to the dialogue is added to the table.

A mode declares its entry tool plus ask_user, recall and goal_update: a
shell cannot ask the operator, read a compacted conversation or close a
goal. Everything else is work — declared in normal, callable from a
codemode program, hidden in shell — so codemode loses no reach and shell
is deliberately the shell plus the dialogue.

Refs #2135
@eric8810

Copy link
Copy Markdown
Collaborator Author

Final cut: shell = execute, ask_user, recall; codemode = codemode, ask_user, recall; normal = everything else. Only these two conversation tools stay; every other capability is the entry tool's job or another mode.

A mode declares its entry plus ask_user and recall. Everything else is
the entry's job: codemode calls it from the program, and shell leaves it
to another mode.

Refs #2135

@zerob13 zerob13 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.

Define Goal's lifecycle when a session enters Shell mode. The new Shell surface hides goal_update, but the existing Goal continuation instructs the model to use that tool when the goal is done or blocked. The mode contract neither pauses an active Goal on transition nor says what session.goal.set does while already in Shell. Define that behavior and its acceptance cases so the model is not prompted to use an unavailable completion route. This does not require adding another tool if the product contract explicitly pauses or refuses Goal in this mode and describes resumption.

The exact-head documentation gate passed; there is no runtime implementation validation here. The earlier reviews already cover live Stop ownership, tool admission, and minimal-profile restoration.

@yyhhyyyyyy yyhhyyyyyy 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.

Review: PR #2141, round 4, head 8ca53c3

Scope: the two new commits remove the Workspace/Session/Entry role table and declare only each mode's entry tool plus ask_user and recall. I reviewed the full main...head at 8ca53c3 against merge base 4d081fe and current main 5930539, and read every thread.

Verdict: REQUEST_CHANGES.

Prior round

  • Fixed in 8ca53c3: the host-tool role channel (P2). Section 2 no longer assigns a role per tool; the sets are exclusion rules, so a new host or registered tool joins normal, codemode delegation and shell hiding with no extra channel. Withdrawn in thread 4679383390.
  • Fixed in 8ca53c3: the section 1.4 argument (P3). Section 2 now hides the work tools, so the one-unit-of-action premise matches the tables. Withdrawn in thread 4679383406.
  • Still open: the stop fallback (P2, thread 4677841849); the diagram's exposed admission (P2, thread 4677841873); the create field spelling (P2, thread 4677841886); the minimal profile restore (P2, thread 4677841896). The claim-order thread remains optional (4677841864): ask_user is declared in all three modes, so there is no current hidden claim.

P2 findings

P2 1. The flow diagram and the PR description still admit against the union set

Problem: Section 4 defines visible and delegated and admits a top-level call only inside visible and a child only inside delegated (docs/design/agent-tool-modes.md:157-161). The diagram at :210 still says a call checks the pinned mode against exposed, which :146-147 defines as the union. The PR description says "a call is admitted only inside the pinned exposed set", and docs/INDEX.md:13 repeats "visible/exposed".

Failure scenario: An implementer follows the diagram or the description and checks a call against the union. In codemode, visible is only codemode, ask_user and recall, but exposed also contains read; a top-level read call is admitted and the one-program interface is broken. The verification at :338-340 expects that call to be refused.

Fix: Draw the two origin branches: a top-level call admits inside visible, a child call inside delegated. Remove exposed as an admission set or label it only as the binding union. Update the PR description and the index line.

P2 2. The create field still has two spellings

Problem: The prose says the create field is session.create.toolMode (:186-188), while the diagram at :208 says session.create.mode; the PR description also says session.create.mode. Create derives deny_unknown_fields with camelCase (crates/dim-app-server/src/protocol.rs:536-537), so one spelling is an invalid-params request.

Failure scenario: A client author follows the diagram or the description and sends mode; the daemon rejects the create request. A client that omits the field to avoid the rejection gets normal instead of the operator's choice. A test written from one spelling cannot cover the other.

Fix: Use toolMode in the diagram, the PR description, the clients and the tests. Add the field to Create as tool_mode, which serializes as toolMode.

P2 3. The minimal profile's shell-by-construction still conflicts with the restore rule

Problem: Section 6 says the minimal-execution profile is shell by construction and its Sessions set toolMode: shell (:229-230), while section 9 says a record without the field restores as normal (:327-329) and section 5 says absent means normal (:186). The minimal Session mounts only execute through its mount list (tests/integration/tests/minimal_execution.rs:267-277; crates/dim-agent-capabilities/src/defaults.rs:231-252). normal hides execute (:97, :151), so the restored Session has no visible tools.

Failure scenario: After upgrade, an existing minimal-execution Session restores as normal with an empty visible set. The profile's only tool is hidden until an operator selects shell from a client, and the design does not say whether that is intended. The restore flow at :351-352 and the minimal flow at :354-355 cannot both hold for an old minimal record.

Fix: State that the profile forces toolMode: shell on create and restore and excepts itself from the absent-is-normal rule, or state that old minimal Sessions become normal with no tools as an intended migration. Add a restore test.

P3 findings (optional)

P3 1. The minimal profile still has no ToolHost owner

Problem: Section 6 says ShellTools registers execute with ToolRegistry instead of providing ToolHost (:225-228). ToolRegistryPlugin requires a ToolHost (crates/dim-agent-capabilities/src/tool_registry.rs:865-921), and in the minimal profile ShellTools is the only host provider (crates/dim-agent-capabilities/src/shell_tools.rs:100-142; crates/dim-agent-capabilities/src/defaults.rs:231-252). Section 11 also says assembly is untouched (:375-376).

Failure scenario: The minimal profile fails to assemble, or the registry applies with no host only if some unstated owner provides one.

Fix: Name the empty-host owner and how the minimal profile binds it, or keep ShellTools as the minimal profile's host provider while registering execute in both profiles. Correct the assembly claim in section 11.

P3 2. session.tool_mode.update still has no order or failure rule

Problem: The design says update writes the stored record and the live value as session.language.update does (:189-191), and section 11 says cancellation stops the record write (:380-382). The language path writes the record first, replaces the live cell, then has Prompt adopt; only the adoption is cancellable, and a failure after the record leaves the new value stored (crates/dim-app-server/src/session_language.rs:134-151; docs/design/contracts/session-access.md:335).

Failure scenario: An interrupted update can leave the record and live value divergent; get may report the old mode while a restart reads the new stored mode.

Fix: Mirror the language order and failure rule, or state the difference and what get reports after an interrupted update.

P3 3. The canonical contracts are not updated, and CodeMode's declaration rule now conflicts

Problem: The design adds SessionConfig.toolMode, a live mode in ToolRegistry and a mode projection, but the canonical contracts still list the old SessionConfig fields and give the registry no mode operation (docs/design/contracts/session-access.md:310-315; docs/architecture/rust-agent/plugins/ToolRegistry.md:24-31; the target contract in PR #2103 has no mode operation either). Section 9 says CodeMode changes in one respect, the tool's availability (:324-326), but docs/design/plugins/CodeMode.md:67 says codemode is declared beside the other adopted tools; this design declares only codemode, ask_user and recall, so the declaration set is a second change.

Failure scenario: Implementers and clients have two sources: the new design and the old contracts. A CodeMode implementation that follows its contract declares the work tools beside codemode, which is exactly what the mode is meant to prevent.

Fix: Update those contracts or state the supersession and the follow-up owner explicitly. Add the declaration-set change to section 9 and the PR description.

P3 4. Restart is still treated as a request retry

Problem: Section 4 says a request retried through its own source, including a restart recovery, keeps the pin (:168-170), and the verification repeats it (:344-346). On a process restart the loop rebuilds from the committed timeline and settles the in-flight request rather than reissuing it (crates/dim-agent-capabilities/src/agent_loop.rs:559), as the existing review at 32ff639 distinguishes for the budget path.

Failure scenario: An implementer adds restart handling that tries to reuse a pin for a request that no longer exists, instead of settling the orphaned work.

Fix: Distinguish in-process budget recovery, which can reuse the binding, from process restart, where the existing rebuild settles.

P3 5. The declaration-count wording and the normal feature rule contradict the tables

Problem: Section 2 says a mode declares its entry tool and two conversation tools (:92-93), but normal has no entry tool. Section 7 says "A mode declares one tool" (:250), but codemode and shell declare three. Section 8 says a mode whose hello.features entry is absent is unavailable (:312-314), while section 4 advertises only session.tool_mode.codemode and session.tool_mode.shell (:178-180), so normal has no entry and the rule would disable the default.

Failure scenario: A reader removes the two conversation tools or hides normal from the picker, or cannot tell which set the tables describe.

Fix: Say "codemode and shell declare their entry tool and two conversation tools; normal declares the work tools", "A mode's entry is one tool", and "normal is always available; only codemode and shell can be unavailable".

P3 6. Section 7's "Missing" labels overstate the gap, and the PR description is stale

Problem: Section 7 marks the codemode and execute descriptions as missing (:267, :280), but both exist (crates/dim-codemode/src/session.rs:14-28; crates/dim-agent-capabilities/src/shell_tools.rs:31-38). What is missing is examples and, for codemode, loop-bound and partial-result guidance. It also marks codemode stop as missing (:264-265), but cancellation already cancels the child token, collects effects and returns the may-have-completed warning (crates/dim-codemode/src/interpreter.rs:189-231); if the gap is a dedicated stop route rather than cancellation, say that. The PR description still lists approval wording and a mode-aware environment block as follow-ups, but section 7 no longer lists them.

Failure scenario: An implementer rewrites an existing description or plans work the design dropped; the PR description and the design disagree about scope.

Fix: Say what is actually missing, and update the PR description's follow-up list to match section 7.

P3 7. The index line still calls the mode a user-scope choice

Problem: docs/INDEX.md:13 describes the mode as "one user-scope choice", but the design keeps it on the Session with no daemon-wide default (:184) and makes the remembered choice client state (:192-194). The design's scopes are process, Session and branch; "user-scope" is a fourth scope the design removed.

Failure scenario: A reader takes the index as the summary and implements a user-level setting, which section 5 says not to maintain.

Fix: Say "one Session-level choice" or "the operator's choice per Session".

Cross-PR and main

  • Merge base 4d081fe; current main 5930539. git merge-tree --write-tree origin/main HEAD is clean. No conflict in the two changed files.
  • Open PRs #2002 (INDEX line 17) and #1881 (INDEX line 134) do not overlap this PR's INDEX line 13. No other open PR touches docs/design/agent-tool-modes.md.
  • Open target-contract PR #2103 (ToolRegistry) has no live mode or mode projection; #2099 (CodeMode) says the program sees the request's pinned declarations, which this design splits into visible and delegated; #2102 and #2098 edit docs/design/contracts/session-access.md where toolMode will need a row. Reconcile these if they land.
  • No other open PR changes docs/design/agent-tool-modes.md or the contract files cited above.

Verification

  • node scripts/adr-check.mjs --base origin/main: passed, 2 changed files.
  • git diff --check origin/main...HEAD: passed.
  • Relative-link scan: all links in the two changed pages resolve.
  • CI at 8ca53c3: changes and ci-ok succeeded; all other jobs were skipped. I did not wait for CI.
  • No Rust build or runtime test was run; this is documentation only.

Unverified

  • The 12 kB description and 20 kB with schemas figures were not measured.
  • I did not enumerate every category in section 2's "codemode loses no reach" sentence against the registered tool table.
  • The minimal profile was not assembled; the empty visible set and the missing ToolHost are read from the mount list and the registry's required service.
  • The stop failure was inferred from the shared-history query and the shell start facts; no live shell task was executed.
  • The claim-order point has no current trigger; ask_user is visible in every mode.

Comment thread docs/design/agent-tool-modes.md Outdated

## 7. What the entry tools must provide

A mode declares one tool, so that tool must carry everything the mode promises. The items below are

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.

P3: this says a mode declares one tool, but section 2 declares the entry tool plus ask_user and recall for codemode and shell (:92-99). The requirements below are for the entry tool, so say "A mode's entry is one tool" or "Each mode declares one entry tool". As written, a reader could remove the two conversation tools this PR just added.

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.

Fixed in 92bad9b, still fixed in 82f0b06. :281 now says "A mode's entry is one tool". Withdrawn.

@eric8810

Copy link
Copy Markdown
Collaborator Author

Added the three mechanism requirements discussed:

  • Content blocks on return. A program that returns a child result (or its content) gets its image blocks rebuilt into the outer result; only blocks a child result returned are accepted, text blocks become text, everything else stays JSON text.
  • Ordering. Child calls honor ToolConcurrency: issue order, Concurrent may overlap, an Exclusive call waits for the calls before it and holds back the ones after it.
  • Async lifetime. Work handed to its owner (background tasks, subscriptions, timers, lines, members) survives the program and its cancellation.

Mode sets are now codemode + skill and shell + execute/ask_user/recall; normal declares everything except the two entries.

A codemode program can return a child result and have its image blocks
rebuilt into the outer result; child calls follow ToolConcurrency; work
handed to an owner outlives the program. codemode declares codemode and
skill, shell declares execute, ask_user and recall.

Refs #2135
@eric8810

Copy link
Copy Markdown
Collaborator Author

Correction: codemode needs no extra ordering. ToolConcurrency orders the calls of one batch, and each child call is its own batch of one, so the class has nothing to order there; the program's await/parallel structure is the order. Handlers own their invariants — the file tools keep the per-path lock — and exec keeps none, which is the same cross-turn/background race as before. The design and the verification now say that instead of asking the gate to serialize.

ToolConcurrency orders one batch, and a child call is its own batch of
one, so the program's await and parallel structure are the order. The
file tools keep their per-path lock; exec keeps none, as across turns.

Refs #2135
Child calls need no ordering rule; the program is the order. The design
does not state one.

Refs #2135

@yyhhyyyyyy yyhhyyyyyy 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.

Review: PR #2141, round 15, head 9ecf4d4

Scope: one commit since 1274e4c, docs: reconcile the goal settle with the turn-start pin (23 insertions, 17 deletions). The PR adds docs/design/agent-tool-modes.md (531 lines) and one docs/INDEX.md line. I re-read the full origin/main...HEAD diff, every live thread, review 6051079899 and its three replies, and checked the cited code in the worktree at 9ecf4d4 against origin/main 08d4b00.

Verdict: APPROVE.

Prior opinions

All four round 14 items are fixed; withdraw them.

  • P2, the applied input pinned the old mode in section 2 and section 10: fixed. Section 2's Settle says an applied input was already handed over and is not withdrawn, and its turn pins the mode in force when it starts (docs/design/agent-tool-modes.md:130-135). Section 10 says a turn that already started keeps the old pin and one applied but started after the switch pins shell and carries the pause text (:450-456). Sections 4 (:215-219) and 12 (:523-524) state the same. The code matches: an Append input is released at once (crates/dim-agent-capabilities/src/input_queue.rs:109-142, :182-195), and a released input cannot be withdrawn (:168-180); the turn starts at crates/dim-agent-capabilities/src/agent_loop.rs:227-247, and a deferred or recovered turn reaches the same start (:1373-1381, :1522-1535, :559-710, :479-530).
  • P3 1, the normal-mode clause was not qualified by the mount list: fixed at docs/design/agent-tool-modes.md:143-146 with "when it is mounted". Withdraw.
  • P3 2, the pause text's mode and the registration qualification: fixed. Section 2 names the pause text as an Append input with a mode phrase (:130-133), and section 4 scopes the history claim to an update and names the registration window (:217-219). Withdraw.
  • P3 3, the registration transition did not take the mode gate: fixed. Section 2 has ToolRegistry take the Session's mode gate around the effective-mode change and Goal's settle (:124-126), and section 12 requires the gate for the registration (:517-519). Withdraw.
  • Zerob13's P2 on 4689615101, the applied driving input whose turn has not started: the remaining section 2 and section 10 contradiction is fixed, so withdraw our "partly fixed" note.
  • Zerob13's P2 on 4689679165, the applied Goal input waiting for its turn: fixed. The trigger is not withdrawn, its turn pins the mode in force when it starts, and both section 10 acceptance cases now describe the same outcome. Withdraw.

Optional P3. The registration gate has no acceptance case

Problem: Section 2 (docs/design/agent-tool-modes.md:124-126) and section 12 (:517-519) now serialize a set/resume against a registration transition with the Session's mode gate, but section 10's registration flow (:454-456) covers only a held continuation. The update's flow at :447-449 is scoped to the update's settle and publish.

Failure scenario: A test author follows section 10 and writes no case for a resume that arrives while execute registers. A regression that drops the gate or the effective-mode recheck passes the documented acceptance cases, and a resume that commits after the registration's settle drives a shell turn with an active goal and no goal_update.

Evidence: docs/design/agent-tool-modes.md:124-126, :447-456, :517-519.

Fix: Add one flow sentence: a resume that commits before the registration's effective-mode change is paused and its unapplied trigger withdrawn; one that arrives while the gate is held waits and is refused. Optional.

Cross-PR and main

  • git merge-tree --write-tree origin/main HEAD is clean at 08d4b00; the INDEX line does not overlap the open #2002 or #1881 hunks.
  • #2149 is still relevant: its fold can decline a Goal pause without an error. The design's update failure rule (docs/design/agent-tool-modes.md:136-137, :258-262) needs Goal's settle to report that decline as a failure so the update stops before the record write. This is a Goal owner requirement, not a defect in this document.
  • #2099, #2100, #2102 and #2103 remain the intended "with the implementation" contract changes.

Verification

  • node scripts/adr-check.mjs --base origin/main: passed, 2 changed files.
  • Relative-link scan of the changed page: 15 relative links, all resolve, including appserver/child-tool-batches.md#26-app-server-code-mode-gate.
  • git diff --check origin/main...HEAD: passed.
  • git merge-tree --write-tree origin/main HEAD: clean.
  • CI at 9ecf4d4: changes and ci-ok succeeded; the other jobs were skipped. I did not wait.
  • No Rust build or runtime test; documentation only.

Unverified

  • The Goal settle implementation, the InputQueue timing and the turn-start pin were read, not exercised.
  • The 12 kB and 20 kB declaration figures and the PR body's xtask-check claim.

Threads

  • Reply on 4689720672: fixed in 9ecf4d4.
  • Reply on 4689615101: fixed in 9ecf4d4.
  • Reply on 4689679165: fixed in 9ecf4d4.
  • Reply on 4682647158: gate fixed; the optional acceptance case remains.
  • Reply on 4682647191: pause text fixed.
  • Reply on 4683602368: mount qualification fixed.

Comment thread docs/design/agent-tool-modes.md Outdated
the `goal_update` instruction starts in `shell`. Switched after it is applied, a turn that already
started keeps the old pin and finishes under it; one that was applied but starts after the switch
pins `shell` and carries the pause text. The same settle runs when `execute` registers and makes
`shell` effective without an update; a held continuation released in that window can reach one

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.

Optional: this closes the set/resume race on registration with the mode gate, but section 10:447-449 is scoped to the update's settle and publish, and this registration sentence covers only a held continuation. Add a registration flow for a resume that commits before the effective-mode change (paused, unapplied trigger withdrawn) and one that waits on the gate and is refused. Without it, the new gate has no acceptance case.

@eric8810

Copy link
Copy Markdown
Collaborator Author

@zerob13 9ecf4d4 reconciles §2's Settle and §10's flow with the turn-start pin: an applied input is not withdrawn, its turn pins the mode when it starts, a turn that already started keeps the old pin, and one that starts after the switch pins shell with the pause text. The pause text is an Append input with a mode phrase, and the registration transition takes the mode gate. yyhhyyyyyy approved at 03:18. Could you take another look?

@eric8810
eric8810 requested a review from zerob13 November 25, 2026 03:24
@eric8810

Copy link
Copy Markdown
Collaborator Author

Re-requested review. The pending thread is zerob13's applied-input pin note; 9ecf4d4 reconciles §2/§10 with the turn-start pin (an applied input is not withdrawn, its turn pins at start, a turn that already started keeps the old pin, one that starts after the switch pins shell with the pause text). yyhhyyyyyy approved 9ecf4d4; CI is green.

@Simon-He95 Simon-He95 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.

Direction and architecture

Reviewed head 9ecf4d4b. The design keeps the mode where its state lives: the Session owns the choice and its stored record, ToolRegistry projects the live surface, the Loop pins the turn, and Goal's owner carries the shell transition. No Timeline fact or new service is introduced; the mode is configuration like session.language. That follows the ownership and data-face rules and adds no second business layer.

The App Server change is additive: session.create.toolMode, session.tool_mode.get/update, and two hello.features keys. No existing field is renamed or removed, and v3 clients (dim-electron) can omit toolMode, so their sessions stay normal. The intentional product change is that normal no longer declares codemode, so an existing v4 Session loses codemode until the operator selects it; §9 states this, and the linked issue/release note should carry it as well.

Residual, not blocking: the registration window in §2/§4 is an accepted one-turn hazard, and §10 still has no acceptance case for a set/resume that races a registration transition (the previous Optional thread). §2 states the intended behavior; one flow case would make it testable.

Approving the direction at this head. zerob13's outstanding change request predates the turn-start pin reconciliation; it should be re-checked before merge.

The App Server cannot call Goal: Goal depends on it, not the reverse.
Goal registers a settle handler with an internal tool-mode transition
service in the Session; the update and the registration transition call
it under the mode gate, so neither owner depends on the other.

Refs #2135
@eric8810

Copy link
Copy Markdown
Collaborator Author

Structural fix in 7bfbbd3: the App Server cannot call Goal directly — Goal depends on the App Server, not the reverse. Goal now registers its settle handler with an internal tool-mode transition service in the Session; session.tool_mode.update and the registration transition call it under the mode gate before the record write and before the registry publishes. Neither owner depends on the other, and there is no new public service: the transition service is in-process only.

@yyhhyyyyyy yyhhyyyyyy 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.

Review: #2141 docs: design the normal, codemode and shell tool modes

Reviewed head 7bfbbd3d against origin/main d2603dd8; merge base 4d081fe6. The diff adds docs/design/agent-tool-modes.md and one docs/INDEX.md line, 538 insertions. Verdict: REQUEST_CHANGES.

The design defines three Session tool modes and their Goal interaction. This round adds the Session's internal tool-mode transition service so Goal's settle handler has a caller on an update and on a registration.

P2: the registration settle order is stated two ways

Problem: section 2 says ToolRegistry takes the mode gate and calls the transition service's settle before it publishes the effective mode (docs/design/agent-tool-modes.md:126-128). Section 12 still tells Goal to settle "on the registry's published effective mode" (:513-515) and tells ToolRegistry to "Publish the effective mode to its readers so Goal settles on a registration transition" and then to "call the transition service on a registration before publishing" (:522-524). The Goal requirement takes a post-publish value; section 2 makes a pre-publish call. For a registration, section 2 names no effective mode passed to the service, so the handler has no stated input.

Failure scenario: an implementer follows the section 12 Goal text and wires the handler to the published value. The registry calls the service before publishing, the handler reads the old mode, sees no transition to shell, and does not pause. The registry then publishes shell; a held continuation starts one shell turn with an active goal, no pause text and no goal_update declaration. An implementer who publishes first to make the handler see shell reopens the broader window the pre-publish settle is meant to close.

Fix: pass the effective mode and the cause as data to the service on a registration, settle before publishing, and rewrite :513-515 and the first clause of :522-523 to say the handler receives that mode instead of reading the published value. Keep the one-turn window only for a turn that starts between the entry tool's registration and the settle.

P3 notes (optional)

  1. The transition service has no provider, operation shape, handler lifetime or no-handler rule. Section 2 says Goal registers its handler in apply (:121-122); section 11 calls the service internal (:486-487, :499-500); section 12 requires ToolRegistry to call it (:524). Nothing says who provides it, how the handler is removed when its part unloads or reloads, what an update does with no handler registered, or whether a registration settle failure blocks the publish. Failure scenario: a stale handler from a replaced Goal generation is called into a closed part, or no handler exists and shell becomes effective without the pause. Fix: name the provider and one operation such as settle(mode, cause), bind registration to the part's active lifetime, and state the no-handler and failure rules.
  2. The round 15 acceptance gap remains: section 10 has no registration flow for a resume that commits before the effective-mode change or waits on the gate and is refused. Optional.

Prior opinions

The earlier fixes remain in place and were checked again at this head. The pre-change signal removed in 42d7197 is back as the transition service, and the registration ordering above is what remains. No earlier P3 blocks.

Cross-PR and main

  • git merge-tree --write-tree against origin/main d2603dd8 and the open heads ff9825d2 (#1881), ebeb05f5 (#2002), 672fb9bf (#2174), bbe02f4d (#2177) and b1387a0b (#2178) is clean.
  • node scripts/adr-check.mjs --base origin/main passes.

Verification

  • Docs-only change; no runtime test applies.
  • CI at this head: changes and ci-ok pass; the other jobs are skipped.

Unverified

  • The ordering is read from the document; no implementation exists to probe.

Comment thread docs/design/agent-tool-modes.md Outdated
[Goal](plugins/Goal.md).
- **ToolRegistry.** Publish the effective mode to its readers so Goal settles on a registration
transition; provide the Session's mode gate the update holds, the registration takes and Goal's
`set`/`resume` take; call the transition service on a registration before publishing. The

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.

The registration order is stated two ways. This clause calls the transition service before publishing, and section 2:126-128 says the same, but the Goal requirement at 513-515 settles on the registry's published effective mode and this bullet opens with publish so Goal settles. An implementer following the Goal text wires the handler to the published value, so a pre-publish call reads the old mode and never pauses; following this clause, the handler has no effective mode argument. Pass the effective mode and cause as data, settle before publishing, and make 513-515 and 522-523 say that.

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.

Still present at 2a48829. Section 2:121-135 now passes the mode and cause as data, and section 12:529-531 calls settle before publishing, but the Goal bullet at section 12:520-522 still says "on a registration, on the registry's published effective mode." That is the remaining half of the contradiction; rewrite it to take the shell mode and the registration cause that ToolRegistry passes before it publishes.

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.

Fixed in 8f64766. Section 12:518-521 now has the Goal handler take (mode, cause) as data and settle before the registry publishes for a registration; section 2:129-135 holds the mode gate from before the settle through the publish, and the section 10 registration flow states the same order. Withdrawing the P2.

Comment thread docs/design/agent-tool-modes.md Outdated
hands Goal the pending mode and Goal checks that it would be effective.

- **Update.** The Session's tool-mode transition service (internal, in-process) carries the settle
handlers. Goal registers its handler in `apply`; `session.tool_mode.update` calls it with the

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.

The service has no provider, operation shape, handler lifetime or no-handler rule. Section 11 calls it internal (486-487, 499-500) and section 12 requires ToolRegistry to call it (524), but nothing says who provides it, how the handler is removed on part unload or reload, what an update does without a handler, or whether a registration settle failure blocks the publish. Failure: a stale handler from a replaced Goal generation is called into a closed part, or no handler exists and shell becomes effective unpaused. Name the provider and one operation such as settle(mode, cause), bind registration to the part's active lifetime, and state the no-handler and failure rules. Optional.

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.

Fixed in 2a48829. Section 2:121-125 names ToolRegistry as the provider, settle(mode, cause) with update and registration causes, handler removal on unload or reload, the no-handler no-op, and the failure rule; section 12:529-531 restates the registration call. Withdrawing the P3.

@zerob13 zerob13 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.

Re-reviewed 7bfbbd3. The internal transition service separates the owners cleanly. The remaining acceptance item is one coherent Goal-to-Shell transition consistent with #2135, unless that product contract is explicitly revised.

  • For an implicit Shell transition when execute registers, §2 (docs/design/agent-tool-modes.md:121–131) calls settle before publication but also allows a held continuation to escape into Shell; §12 reads the published mode. The acceptance case should show the Goal pause and withdrawal of held work before the first effective Shell projection. The original registration concern is tracked in this thread.
  • For already-applied work deferred by compaction or rebuild, the new flow at :452–460 explicitly pins Shell, whereas #2135 says it finishes in the previous mode. The pause also needs to be consumed before the first new Shell request's history cutoff, not merely appended. Verify both observable paths under the agreed contract.

Documentation CI passed; these are static design findings. I am not proposing a particular Shell tool list in this review.

A registration calls settle(shell, registration) before it publishes, so
the handler takes the mode and cause as data and never reads the
published value. The service names its provider, operation, handler
lifetime, no-handler and failure rules; the registration acceptance flow
is in section 10.

Refs #2135
@eric8810

Copy link
Copy Markdown
Collaborator Author

2a4882e fixes the round at 11:04.

Registration order (P2). A registration now calls settle(shell, registration) — mode and cause as data — before it publishes, and the handler never reads the published value. §12's Goal and ToolRegistry requirements say that; the one-turn window is scoped to a turn that starts between the registration and the settle.

Service shape (P3 1). ToolRegistry provides the internal ToolModeTransition service with one operation, settle(mode, cause) for update or registration. Goal registers one handler in apply; the registry removes it with the part's registration on unload or reload. No handler means success with no change (no active Goal). An update failure blocks the record write; a registration failure keeps the projection at normal and records a fault.

Registration acceptance (P3 2). §10 has the registration flow: a resume that commits before the call is paused and withdrawn; one that waits on the gate is refused after the publish.

@yyhhyyyyyy yyhhyyyyyy 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.

Review: #2141 docs: design the normal, codemode and shell tool modes

Reviewed head 2a488298 against origin/main d2603dd8; merge base 4d081fe6. The diff adds docs/design/agent-tool-modes.md (543 lines) and one docs/INDEX.md line, 544 insertions. Verdict: REQUEST_CHANGES.

The design defines three Session tool modes and their Goal interaction. Round 16 requested changes on the registration settle order. This round names ToolRegistry as the provider of the internal ToolModeTransition service and gives the handler the mode and cause as data before the registry publishes. That closes the service-definition and section 10 acceptance gaps I raised as optional P3s.

P2: the Goal requirement still settles on the published mode

Problem: section 2:121-135 now says the handler takes the mode and cause as data and does not read the published value, and section 12:529-531 says ToolRegistry calls settle(shell, registration) before publishing. The Goal bullet at section 12:520-522 still says "on a registration, on the registry's published effective mode." The document therefore still gives the Goal owner the post-publish value and ToolRegistry a pre-publish call.

Failure scenario: an implementer follows the Goal bullet and wires the handler to the published value. ToolRegistry calls the service before publishing, the handler reads the old mode, sees no transition to shell, and does not pause. The registry then publishes shell; a held continuation starts one shell turn with an active goal, no pause text and no goal_update declaration. An implementer who publishes first to make the handler see shell reopens the broader window the pre-publish settle is meant to close.

Fix: rewrite the registration clause to take the shell mode and the registration cause that ToolRegistry passes before it publishes, and check that mode in the handler. All three passages then state one order.

Prior opinions

  • Round 16 P3, service definition: fixed in 2a48829 (section 2:121-125, section 11:491-494, section 12:529-531). Withdrawn.
  • Round 16 P3, section 10 registration acceptance gap: fixed by the new flow at section 10:456-458. Withdrawn.
  • The round 16 P2 remains only in section 12:520-522. No other prior P3 blocks.

Cross-PR and main

  • git merge-tree --write-tree against origin/main d2603dd8, #2177 c6044223 and #2178 b1387a0b is clean; the trees for #2177 and this PR also merge cleanly.
  • node scripts/adr-check.mjs --base origin/main passes (2 changed files).

Verification

  • Docs-only change; no runtime test applies.
  • CI at this head: ci-ok and changes pass; the other jobs are skipped.

Unverified

  • The ordering is read from the document; no implementation exists to probe.

Comment thread docs/design/agent-tool-modes.md Outdated
general lifecycle reads the effective mode. Take the Session's mode gate around `set` and
`resume` and re-check the effective mode at their commit boundary. Settle on
every transition to an effective `shell`: on an update, before the record write; on a
registration, on the registry's published effective mode. Fan out from the Goal Session part to

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.

Section 2:121-135 and the ToolRegistry bullet at 529-531 now settle with the mode and cause as data before publishing, but this Goal clause still says "on a registration, on the registry's published effective mode." An implementer following it wires the handler to the published value, so the pre-publish call reads the old mode and never pauses; publishing first to make it visible reopens the window. Take the shell mode and the registration cause that ToolRegistry passes before it publishes. P2.

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.

Fixed in 8f64766. The Goal bullet no longer reads the published effective mode; it receives shell with the registration cause before the publish, and the turn-start read takes the mode gate. Withdrawing the P2.

The Goal requirement still said a registration settles on the registry's
published effective mode. It now takes (shell, registration) from the
service before the registry publishes, like the other two passages.

Refs #2135
@eric8810

Copy link
Copy Markdown
Collaborator Author

88929a5 fixes the round-17 P2.

The Goal requirement now takes (mode, cause) from the service: update with the pending mode before the record write, registration with shell before the registry publishes. It never reads the published value, so §2, §12's Goal bullet and §12's ToolRegistry bullet state one order.

The registration holds the gate from before the settle through the
publish, and the turn-start read takes the same gate, so no turn pins
shell before the pause and the withdrawals commit. The pause text's
Append order puts it before the first request's history cutoff.

Refs #2135
@eric8810

Copy link
Copy Markdown
Collaborator Author

@zerob13 8f64766 closes both acceptance points.

Implicit registration transition. The registry now holds the Session's mode gate from before settle(shell, registration) through the publish, and the Loop's turn-start read takes the same gate. No turn can pin the effective shell projection before the pause text and the withdrawals are committed, so the one-turn escape is gone. The §10 registration flow shows the pause and withdrawal before the first effective shell projection.

Applied work deferred by compaction or rebuild. The design pins at turn start: a turn that already started keeps the old pin; one that was applied but starts after the switch pins shell, and the pause text is an Append input committed before the publish, so it precedes that turn's first request history cutoff. I updated #2135 to match this (it previously said the applied work finishes in the previous mode).

@yyhhyyyyyy yyhhyyyyyy 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.

Review: #2141 docs: design the normal, codemode and shell tool modes

Reviewed head 8f647665 against origin/main 1ca651ba; merge base 4d081fe6. The diff adds docs/design/agent-tool-modes.md (546 lines) and one docs/INDEX.md line, 547 insertions. Verdict: APPROVE.

The design defines three Session tool modes and their Goal interaction. Round 17 requested changes on one P2: the Goal bullet at section 12 still settled "on the registry's published effective mode" while section 2 settled before publishing. This round closes that contradiction.

P2 is closed

Section 12:518-521 now has the Goal handler receive (mode, cause) as data, with update carrying the pending mode and registration carrying shell, and settle before the record write for an update and before the registry publishes for a registration. It states that the handler never reads the published value. Section 2:129-135 gives the same order: ToolRegistry holds the Session's mode gate from before settle(shell, registration) through the publish, and the Loop's turn-start read takes the same gate, so a turn that starts waits and pins shell only after the pause text and the withdrawals commit. Section 4:221-226 and the section 10 registration flow at :464-467 state the same order.

What holds

  • The update path is unchanged and consistent: settle(pending, update) runs before the record write, then the live value is replaced (section 2:126-128, section 5:265-269). A failure before the record write leaves the mode pair unchanged with the committed pause in place.
  • The pause text is an Append input committed before the publish, so a turn that starts in shell has it before its first request's history cutoff (section 2:136-141, section 12:528-530).
  • The round 16 service definition remains: ToolRegistry provides the internal ToolModeTransition service, settle(mode, cause) has the update and registration causes, the handler follows the part's lifetime, a missing handler is a no-op, and a failure blocks the record write or the publish (section 2:121-125, section 11:491-496, section 12:531-534).
  • The section 10 registration acceptance flow remains at :457-459.

Prior opinions

  • Round 17 P2, the Goal bullet settled on the published effective mode: fixed in 8f64766; withdrawn.
  • Round 16 P3s, service definition and section 10 registration acceptance: fixed in 2a48829 and still fixed at this head; withdrawn.
  • No other earlier P3 blocks.

Cross-PR and main

  • git merge-tree --write-tree against origin/main 1ca651ba, #1881 ff9825d2, #2177 c6044223, #2178 b1387a0b and #2002 b9248bb2 is clean.
  • git diff --check is clean.

Verification

  • node scripts/adr-check.mjs --base origin/main: ADR freeze passed for 2 changed files.
  • All relative links in the changed document resolve.
  • Docs-only change; no runtime test applies.
  • CI at this head: ci-ok and changes pass; the other jobs are skipped.

Unverified

  • The ordering is read from the document; no implementation exists to probe.

@zerob13 zerob13 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.

Re-reviewed 8f647665. The pending-mode input and owner text now agree, so the implicit registration finding is closed. The original transition still has two observable acceptance conditions:

  • An already-applied Normal continuation should keep its prior mode even when compaction or rebuild defers turn creation. The current example (docs/design/agent-tool-modes.md:460–467) pins Shell in that case, contrary to the acceptance row in #2135. Reconcile the two rather than requiring a particular implementation.
  • The first new Shell request should include the mode pause in history. The owner text (:522–530) orders pause commitment before publication, but the replay path can start a request before the pause is applied and selected. State how that observable ordering is preserved when delivery lags commitment, and retain dispatcher progress while the turn waits.

Both are carry-forward design findings, not additional acceptance requirements. The documentation CI passed.

An applied input keeps its mode through compaction and rebuild, so a
continuation applied under normal finishes under normal. The applied
record carries the mode; shell turns wait for the committed pause text
to be adopted before their first request. The issue's acceptance rows
now match.

Refs #2135
@eric8810

Copy link
Copy Markdown
Collaborator Author

@zerob13 c92409c reconciles both points.

Applied input keeps its mode. The pin is now recorded when the InputQueue applies the input, not when the turn starts. An already-applied Normal continuation keeps normal through compaction or rebuild; the applied record carries the mode (optional field, absent reads as normal, the only mode before the feature). The design and #2135's acceptance rows now say the same thing.

Pause in the first shell request. The pause text is an Append input committed before the live mode. A turn that pins shell waits for that committed pause to be adopted before its first request, so the request's history cutoff includes it; the Dispatcher keeps running while the turn waits. The §10 flow and §12's Loop requirement state this.

@eric8810
eric8810 requested a review from zerob13 November 25, 2026 12:18

@yyhhyyyyyy yyhhyyyyyy 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.

Review: #2141 docs: design the normal, codemode and shell tool modes

Reviewed head c92409ce against origin/main 1ca651ba; merge base 4d081fe6. The full diff is 2 files, 551 insertions. Verdict: REQUEST_CHANGES.

The design defines three Session tool modes and their Goal interaction. Round 19 moves the mode pin from turn start to input application: section 4, section 9 and the section 10 flow now record the effective mode when the InputQueue applies an input, and the applied record gains an optional toolMode. The direction is coherent and matches the earlier application-time request.

P2: three references still pin at turn start

Problem: section 2's Settle bullet still says "Its turn pins the mode in force when it starts (§4)" (docs/design/agent-tool-modes.md:141). Section 10 says an input "that was applied but starts after the switch pins shell" (:465-466). Section 12 still says "Turn-start reads take the gate" (:535). These contradict the new rule in section 4 (:221-232) and the flow at :446-448: the InputQueue records the mode at application, an applied input keeps its mode, and a switch after application does not change it. Section 9 stores the mode on the applied record (:404-405).

Failure scenario: a Goal continuation is applied while the mode is normal; the operator switches to shell before the turn starts. Section 4 and :446-448 say the turn finishes under normal; :141 and :465-466 say it pins shell. An implementer following the stale lines starts a shell turn for an active goal without the pause text or goal_update. The gate sentence at :535 compounds this: if only turn-start reads take the gate, an input applied during the registration settle records the old mode instead of waiting, so section 2's application-time guarantee at :132 does not hold.

Fix: rewrite :141 to say the applied record carries the mode and the turn keeps it; rewrite :465-466 so an input applied before the switch keeps the old pin and one applied after the switch pins shell and waits for the pause text; change :535 to say the InputQueue application read takes the gate.

Prior opinions

  • Round 18 P2, the Goal requirement settling on the published mode: fixed and withdrawn.
  • Round 16 P3s, service definition and section 10 registration acceptance: remain fixed.
  • The earlier turn-start pin sentence in the prior threads is superseded by this commit; the direction is intended, and only the three stale references above remain.

Cross-PR and main

  • git merge-tree --write-tree against origin/main 1ca651ba, #1881 ff9825d2, #2178 b1387a0b and #2002 eda24338 is clean.
  • All relative links in the changed document resolve.

Verification

  • node scripts/adr-check.mjs --base origin/main: ADR freeze passed for 2 changed files.
  • Docs-only change; no runtime test applies.
  • CI at this head: ci-ok and changes pass; the other jobs are skipped.

Unverified

  • The ordering is read from the document; no implementation exists to probe.

Comment thread docs/design/agent-tool-modes.md Outdated
precedes the next turn (Goal state alone does not enter the model context), and withdraws the
input it queued — the `set`/`resume` trigger and any automatic continuation — when the InputQueue
has not applied it. An applied input was already handed over; the settle does not withdraw it.
Its turn pins the mode in force when it starts (§4).

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.

This still pins at turn start. Section 4:221-232 now records the effective mode when the InputQueue applies the input, section 9:404-405 stores it on the applied record, and section 10:446-448 says a switch after the application does not change it. The same leftover appears at section 10:465-466, where an input applied before a switch is said to pin shell, and at section 12:535, where turn-start reads take the gate instead of the application read at section 2:132. A continuation applied under normal and switched to shell before it starts would pin normal in section 4 and shell here; the shell variant runs an active goal without the pause text or goal_update. Rewrite all three to the applied record. P2.

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.

Fixed in 0e6d305. Section 2:143 now says the applied record carries the mode and the turn keeps it; section 10:467-468 says an input applied before the switch keeps its pin and one applied after pins shell; section 12:544-546 records at application for the Loop. Withdrawing the P2.

@zerob13 zerob13 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.

Re-reviewed c92409ce. Persisting the applied input's mode and requiring the first new Shell request to consume the pause are improvements. The remaining conflicting pin references are already covered by the peer review. There is one distinct design blocker in the new application gate (docs/design/agent-tool-modes.md:467–469): InputQueue applies inline on the serial Dispatcher, while settlement can wait for a withdrawal on that same Dispatcher (input_queue.rs:273–289,313–353). If input application waits on the gate there, the withdrawal cannot finish and the gate cannot be released. State the progress guarantee without prescribing the implementation: while an application is pending, withdrawal and pause can still be delivered, the switch completes, and the first new Shell request includes the pause. This is a static design finding; documentation CI passed.

Rewrite the three turn-start leftovers to the applied record, and state
the progress guarantee around the registration gate: a pending
application does not block the withdrawal or the pause, the switch
completes, and the first new shell request includes the pause.

Refs #2135
@eric8810

Copy link
Copy Markdown
Collaborator Author

0e6d305 addresses both reviews.

Three stale pins (P2). §2's Settle now says the applied record carries the mode and the turn keeps it; §10 says an input applied before the switch keeps its pin and one applied after pins shell and waits for the pause; §12's ToolRegistry no longer says turn-start reads take the gate.

Application gate progress (zerob13). The design now states the guarantee, not the implementation: while the switch runs, a pending application does not block the withdrawal or the pause — both are still delivered, the switch completes, and the first new shell request is prepared only after the pause is applied. The InputQueue records the mode at its serial position on the Dispatcher, not by waiting on the gate.

@yyhhyyyyyy yyhhyyyyyy 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.

Review: #2141 docs: design the normal, codemode and shell tool modes

Reviewed head 0e6d3050 against origin/main 0d823c1b; merge base 4d081fe6. The diff adds docs/design/agent-tool-modes.md and one docs/INDEX.md line, 556 insertions. Verdict: APPROVE.

The design defines three Session tool modes and their Goal interaction. Round 19 requested changes on one P2: the pin had moved to input application, but section 2:141, section 10:465-466 and section 12:535 still pinned at turn start. This round records the effective mode when the InputQueue applies an input and keeps it on the applied record everywhere.

P2 is closed

Section 2:143 now says the applied record carries the mode and the turn keeps it. Section 10:467-468 says an input applied before the switch keeps its pin and one applied after the switch pins shell and waits for the pause text. Section 12:544-546 records at application, at its serial position, for the Loop. Section 4:223-235, section 5:265 and section 9:407-408 state the same pin point, and the gate is now scoped to the update, the registration publish and set/resume only. The three stale turn-start references are gone.

Optional P3: the pending-application rule has no owner for the update side

Problem: the registration paragraph says a pending application does not block the switch and completes after it (section 2:132-136) and section 12:536-540 repeats it, but no owner requirement makes that ordering happen: section 4:223-224 and the Loop bullet at section 12:544-546 say only that the InputQueue records at its serial position on the Dispatcher. The update path has no pending-application rule at all (section 2:126-128, section 5:268-271, section 10:459-461). Because the application read no longer takes the mode gate, serial position orders inputs among themselves, not against a Session-method update or a registry-side registration switch.

Failure scenario: an input is being applied while session.tool_mode.update or a registration switch runs. It can read the old live value and record after the live replacement, so the turn runs under normal after the operator chose shell, or an implementation can make it wait. Two implementations can disagree at the same boundary, and the registration promise that a pending application is ordered after the switch has no stated mechanism.

Fix: state one application-ordering rule for both paths, for example that the application reads the live value at its record point and one that records after the live replacement pins shell, or keep the application read under the mode gate while the switch runs. Optional.

Prior opinions

  • Round 19 P2, three references pinned at turn start: fixed in 0e6d305; withdrawn.
  • Round 18 P2 and the round 16 P3s remain fixed.
  • No other earlier P3 blocks.

Cross-PR and main

  • git merge-tree --write-tree against origin/main 0d823c1b, #2002 eda24338, #1881 ff9825d2 and #2178 b1387a0b is clean.
  • git diff --check is clean.

Verification

  • node scripts/adr-check.mjs --base origin/main: ADR freeze passed for 2 changed files.
  • All relative links in the two changed files resolve.
  • Docs-only change; no runtime test applies.
  • CI at this head: ci-ok and changes pass; the other jobs are skipped.

Unverified

  • The ordering is read from the document; no implementation exists to probe.

@zerob13 zerob13 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.

Approved at 0e6d3050. Deferred and rebuilt turns retain the mode recorded at input application. The design also now requires the Dispatcher to keep delivering withdrawal and pause while an application is pending, and the first new Shell request waits for that pause to be adopted. This resolves my previous change request. The exact-head documentation checks passed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

design Design decision or contract work documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants