Skip to content

🤖 fix: let the turn-end TODO nudge continue with the turn's tools - #7027

Merged
ThomasK33 merged 4 commits into
mainfrom
nudge-kzpb
Oct 20, 2026
Merged

ThomasK33 merged 4 commits into
mainfrom
nudge-kzpb

Conversation

@ThomasK33

@ThomasK33 ThomasK33 commented Oct 19, 2026 •

Copy link
Copy Markdown
Member

Summary

The turn-end TODO nudge no longer limits the nudged turn to todo_write. The nudged turn keeps the tools and tool policy of the turn it follows, and its prompt now asks the agent to finish open items that are still in scope, then update the list.

Background

#6720 added the nudge: when a turn calls todo_write and ends with open items, Xum sends one continuation so the pinned list stays accurate. That continuation got a todo_write-only caller tool policy. Two problems:

  1. Work stayed open. An agent with an open "gate and push" item answered: "Gating and pushing needs bash, and this turn has only todo_write." The work then waited for the next user message or heartbeat.
  2. It missed the prompt cache. The caller policy removed every other tool from the advertised tool block, so the whole prefix missed the cache. In 55 sampled nudge turns (6 workspaces, Opus 5.5), 25 first steps missed and rewrote about 271k tokens each (about $53 extra at 1 h cache-write pricing). Hits happened only when another nudge had run within the 1 h TTL.

Implementation

  • mergeTurnStopContinuation returns only the prompt. TODO_TURN_END_NUDGE_TOOL_POLICY and the optionOverrides path are gone, so the nudge queues with the normal stopContinuationOptions, which already carry the turn's own toolPolicy.
  • New prompt text: first finish the open items that are still in scope, then update the list so it matches what was done; keep items that wait for the user and say why.
  • The collapsed transcript row now reads "Asked the agent to update its TODO list and finish open items", so it discloses that the nudged turn continues work. Rows stored with the 🤖 fix: nudge once at turn end when the todo list is left open #6720 text still render as the compact row (isTodoTurnEndNudgePrompt).

The existing limits stay: one nudge per user turn, none in Plan mode, for sub-agents or delegated workspace turns, and queued input, Stop or a plugin halt still cancel it.

Risks

Prompt injection. Codex's security review asked to keep the nudge todo_write-only (rejected, see the thread). The nudge text is a constant (machineTurnPrompts.ts), so it adds no attacker-controlled input, but the nudged turn sees the same context as the turn before it, including any injected text, and can act on it with the turn's tools for one more turn. Like every turn.stop continuation (plugin ones included), it skips the message-send prompt hooks (skipPromptHooks: true), and Xum has no per-tool approval. This was weighed and accepted by the maintainer.

Downgrade. A build before this PR shows rows with the new nudge text as plain user bubbles (cosmetic). Tracked in #7035.

The nudged turn can now do real work instead of one list edit. A model can read "continue" too broadly and act past a deliberate stop (for example a question to the user). The prompt limits this to items "still in scope" that it "can do now". Cost per nudge can grow with turn length, but the first step now hits the cache.

The separate refactor that stops any caller tool policy from changing the tool block is in its own PR.


Generated with xum • Model: anthropic:claude-opus-5-5 • Thinking: high • Cost: $8.62

The nudge turn used to get a todo_write-only caller policy. That left work
the agent could do open until the next user message, and the smaller tool
block missed the prompt cache (25 of 55 sampled nudge turns rewrote ~271k
tokens). The nudge now keeps the turn's own tools and policy, and its prompt
asks the agent to continue open in-scope items.

---

_Generated with `xum` • Model: `anthropic:claude-opus-5-5` • Thinking: `high` • Cost: `$2.13`_

<!-- mux-attribution: model=anthropic:claude-opus-5-5 thinking=high costs=2.13 -->
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-19T20:33:30.860586Z ce992cc Manual request
🔒 Security Review ✅ Completed 2026-10-19T20:35:03.484817Z ce992cc Manual request

Security findings

Advisory findings (1)

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bfd8ca5341

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/common/utils/machineTurnPrompts.ts Resolved
Comment thread src/common/utils/machineTurnPrompts.ts Resolved
Comment thread src/common/utils/machineTurnPrompts.ts Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛡️ Codex Security Review · Automatically triggered

Here are some automated security review suggestions for this pull request.

Reviewed commit: bfd8ca5341

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

ThomasK33 added a commit that referenced this pull request Oct 19, 2026
The turn-end TODO nudge used to send the nudged turn with a todo_write-only
tool policy (#7027). No e2e lane could see that: the mock app AI never
produced a successful todo_write, so the nudge never fired.

- Mock AI: `[mock:todo-nudge]` writes a TODO list with one item left open and
  ends the turn. The reply to Xum's nudge reads README.md and completes the
  list. A canned successful todo_write now writes the list to disk, as the
  real tool does, before any stream event.
- Exact-step repro (CI's mock repro lane): reads the nudge row from history
  over ORPC and fails when its tool policy narrows the tools. It fails on the
  old code with "expected [todo_write] to equal [bash, file_read, todo_write]".
- Agent story (make test-stories): an agent sends the prompt and checks the
  nudge row and the finished work, pinned by the same exact policy check.

---

_Generated with `xum` • Model: `anthropic:claude-opus-5-5` • Thinking: `high` • Cost: `$8.62`_

<!-- mux-attribution: model=anthropic:claude-opus-5-5 thinking=high costs=8.62 -->
@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: cd3f778117

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: cd3f778117

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

ThomasK33 added a commit that referenced this pull request Oct 19, 2026
The turn-end TODO nudge used to send the nudged turn with a todo_write-only
tool policy (#7027). No e2e lane could see that: the mock app AI never
produced a successful todo_write, so the nudge never fired.

- Mock AI: `[mock:todo-nudge]` writes a TODO list with one item left open and
  ends the turn. The reply to Xum's nudge reads README.md and completes the
  list. A canned successful todo_write now writes the list to disk, as the
  real tool does, before any stream event.
- Exact-step repro (CI's mock repro lane): reads the nudge row from history
  over ORPC and fails when its tool policy narrows the tools. It fails on the
  old code with "expected [todo_write] to equal [bash, file_read, todo_write]".
- Agent story (make test-stories): an agent sends the prompt and checks the
  nudge row and the finished work, pinned by the same exact policy check.

---

_Generated with `xum` • Model: `anthropic:claude-opus-5-5` • Thinking: `high` • Cost: `$8.62`_

<!-- mux-attribution: model=anthropic:claude-opus-5-5 thinking=high costs=8.62 -->

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 616ced9c9d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

Reviewed commit: 616ced9c9d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: 616ced9c9d

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

ThomasK33 added a commit that referenced this pull request Oct 19, 2026
The turn-end TODO nudge used to send the nudged turn with a todo_write-only
tool policy (#7027). No e2e lane could see that: the mock app AI never
produced a successful todo_write, so the nudge never fired.

- Mock AI: `[mock:todo-nudge]` writes a TODO list with one item left open and
  ends the turn. The reply to Xum's nudge reads README.md and completes the
  list. A canned successful todo_write now writes the list to disk, as the
  real tool does, before any stream event.
- Exact-step repro (CI's mock repro lane): reads the nudge row from history
  over ORPC and fails when its tool policy narrows the tools. It fails on the
  old code with "expected [todo_write] to equal [bash, file_read, todo_write]".
- Agent story (make test-stories): an agent sends the prompt and checks the
  nudge row and the finished work, pinned by the same exact policy check.

---

_Generated with `xum` • Model: `anthropic:claude-opus-5-5` • Thinking: `high` • Cost: `$8.62`_

<!-- mux-attribution: model=anthropic:claude-opus-5-5 thinking=high costs=8.62 -->
@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

Reviewed commit: ce992cc235

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: ce992cc235

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@ThomasK33
ThomasK33 added this pull request to the merge queue Oct 20, 2026
Merged via the queue into main with commit bb4aefd Oct 20, 2026
32 of 33 checks passed
ThomasK33 added a commit that referenced this pull request Oct 20, 2026
The turn-end TODO nudge used to send the nudged turn with a todo_write-only
tool policy (#7027). No e2e lane could see that: the mock app AI never
produced a successful todo_write, so the nudge never fired.

- Mock AI: `[mock:todo-nudge]` writes a TODO list with one item left open and
  ends the turn. The reply to Xum's nudge reads README.md and completes the
  list. A canned successful todo_write now writes the list to disk, as the
  real tool does, before any stream event.
- Exact-step repro (CI's mock repro lane): reads the nudge row from history
  over ORPC and fails when its tool policy narrows the tools. It fails on the
  old code with "expected [todo_write] to equal [bash, file_read, todo_write]".
- Agent story (make test-stories): an agent sends the prompt and checks the
  nudge row and the finished work, pinned by the same exact policy check.

---

_Generated with `xum` • Model: `anthropic:claude-opus-5-5` • Thinking: `high` • Cost: `$8.62`_

<!-- mux-attribution: model=anthropic:claude-opus-5-5 thinking=high costs=8.62 -->
@ThomasK33
ThomasK33 deleted the nudge-kzpb branch October 20, 2026 06:47
yermakoffivan pushed a commit to yermakoffivan/mux that referenced this pull request Oct 20, 2026
…der#7029)

## Summary

A per-turn caller tool policy (`SendMessageOptions.toolPolicy`) no
longer removes local tools from the tool block that Xum advertises to
the model. A tool the caller denies stays advertised as a coder#5253 refusal
stub and refuses the call with "Tool 'x' is disabled for this turn." For
every tool that can refuse at execution time, the tool block, and with
it the prompt cache, stays the same across turns with different caller
policies. A few tools cannot be stubs and still drop out when denied:
`memory` (its description holds the memory index), `tool_catalog_search`
(a refused search would hide deferred MCP tools), provider-executed
tools such as native `web_search`, and tools without a local `execute`.

## Background

coder#5253 keeps one tool set across agent switches: Xum advertises the union
of every switchable agent's tools and refuses calls the active agent
denies. But `composeWithCallerPolicy` appended the caller policy to
every switchable agent's policy, so a caller `disable` rule removed the
tool from the union. The tool block changed and the whole prefix missed
the cache.

The turn-end TODO nudge showed the cost: its `todo_write`-only caller
policy made 25 of 55 sampled nudge turns rewrite about 271k tokens each
(coder#7027 removes that policy). Today's remaining producers that hit this
are `xum run` (5 denied UI tools) and ACP (`ask_user_question`),
whenever their turns mix with desktop turns in one workspace. This PR
closes the mechanism for future producers too.

## Implementation

- `agentResolution.ts`: `createCallerPolicyComposers` gives two
compositions. The active policy keeps all caller rules. The switchable
(advertised) policies get only the caller's `require` rules. Sub-agents
and hidden agents now get a one-policy union, so the rule holds there
too. Without a caller policy their tool block is unchanged.
- `toolAssembly.ts`:
- new `callerToolPolicy` option; the refusal text names a caller denial
separately from an agent denial.
- a caller policy that leaves no tools (compaction's `.*` disable) still
sends no tools, not stubs with every schema.
- `tool_catalog_search` is never a refusal stub (like `memory`): a
refused search tool stays absent, so tool search does not defer MCP
tools behind a search that always refuses.
- `mux.load` is withheld unless the active policy allows `file_read`. A
refused `file_read` stub stays bridgeable, and `ToolBridge` offered
`mux.load` by that name alone, so it was a second way to read files.
Agent-switch stubs had the same gap before this PR.
- `turnRequestBuilder.ts`: passes the caller policy to tool assembly.
Workflow-result continuations now send the caller's policy instead of
the composed one, so agent rules do not come back as caller rules.

## Validation

- 7 new tests, all failing on the old code and passing with the change:
in `toolAssembly.test.ts`, a caller deny keeps the block and refuses,
disable-all sends no tools, a refused `file_read` has no `mux.load`, and
a refused `tool_catalog_search` stays absent; in
`agentResolution.test.ts`, root exec and a sub-agent keep the same
advertised names under a caller deny; plus the turn-level
`aiService.test.ts` test below.
- A turn-level test in `aiService.test.ts` sends two real exec turns,
one with a caller `bash` deny, through the real agent resolution and
tool assembly. It checks that both turns advertise byte-identical tools
and that `bash` refuses in the restricted turn. It fails on the old code
because the restricted turn drops `bash`.
- 82 related test files pass (tool assembly, agent resolution, turn
request builder, stream manager, task service, PTC, tool utils, ACP).

## Risks

- Medium, in tool assembly. A caller-denied tool is now visible to the
model as a refusal stub. The model can call it and waste one step. Agent
switches already have this cost.
- Every refusal channel runs the stub's `execute` (direct calls, PTC
bridge). Provider-executed tools, tools without a local `execute`, and
`memory` still get removed, as for agent switches.
- Out of scope: a deny of `code_execution` does not stop PTC (coder#7028,
existed before). `request.assemble` hooks can still replace the tool map
after policy.

---

_Generated with `xum` • Model: `anthropic:claude-opus-5-5` • Thinking:
`high` • Cost: `$8.62`_

<!-- mux-attribution: model=anthropic:claude-opus-5-5 thinking=high
costs=8.62 -->
yermakoffivan pushed a commit to yermakoffivan/mux that referenced this pull request Oct 20, 2026
## Summary

Two e2e guards for the turn-end TODO nudge (coder#7027): an exact-step repro
in CI's mock repro lane and an agent-driven story in the `Stories` lane.
Both fail if the nudged turn gets a tool policy that narrows its tools
again. Stacked on coder#7027.

## Background

coder#7027 removes the `todo_write`-only tool policy of the nudged turn. That
narrowing cost open work (it waited for the next user message) and the
prompt cache (25 of 55 sampled nudges rewrote about 271k tokens). No e2e
lane could have seen it: the mock app AI never produced a successful
`todo_write`, so Xum never sent a nudge in any e2e run.

## Implementation

- **Mock AI** (`mockAiRouter.ts`): `[mock:todo-nudge]` writes a TODO
list with "Verify the fix" left pending and ends the turn. An exact
match on Xum's nudge prompt answers with a `README.md` read and a
completed list.
- **Mock player** (`mockAiStreamPlayer.ts`): a canned successful
`todo_write` now writes the list to the session dir, as the real tool
does, before any stream event. `needsTodoTurnEndNudge` reads it there,
so the real nudge path runs.
- **Repro** `tests/bugbash/repros/todoNudgeKeepsTools.e2e.ts` (tags
`bugbash`, `7027`, `mock-only`): sends the prompt, waits for the nudge
row and the final reply, then reads the nudge row from history over ORPC
(`todoNudgeToolPolicies` in `helpers.ts`). The user turn has no tool
policy, so it requires the row's `toolPolicy` and retry `toolPolicy` to
be null: any narrowing fails it.
- **Story** `tests/stories/todoNudge.e2e.ts`: an agent sends the prompt
and checks the nudge row and the finished work with
`agent.act`/`agent.assert`, pinned by the same exact policy check.

The mock runs no tool and cannot see the policy, so the tests check the
stored policy, not tool execution. The tool-block side (a caller policy
must not change the advertised tools) is covered by turn-level Node
tests in coder#7029: no e2e lane builds real requests with tools on, because
model-driven jobs set `XUM_DISABLE_AGENT_TOOLS=1` and the mock skips
request building.

## Validation

- Bug bash (5 charters, Sonnet 5.5, mock app AI, $1.17; round 2 on the
fixed code, 2 charters, $0.47): one older keyboard bug in tool cards,
filed as coder#7033. Two warnings rejected: the "completed" badge on a
`todo_write` card is the shared tool-call status, by design.
- Mock player test: a stream aborted while its start is held writes no
TODO list, and a finished one writes it; it fails on the old up-front
write.
- Some review replies cite commits from before the stack was rebased
onto coder#7027's fixes; those SHAs are no longer in this branch's history.

- Repro on the host (`make test-bugbash-repros BUGBASH_AI=mock`): passes
on web and phone. With `todoTurnEndNudge.ts` and `agentSession.ts`
restored from `main`, it fails on both targets. With the final assertion
(both stored policies must be null) the failure is `ASSERTION_FAILED:
expected [{"regex_match":"(?!todo_write$).*","action":"disable"}] to be
null`, re-proved on the final head.
- Story in the sandbox (`make test-stories BUGBASH_BUDGET_USD=3`): 5 of
5 stories pass, $0.47 at list price.

---

_Generated with `xum` • Model: `anthropic:claude-opus-5-5` • Thinking:
`high` • Cost: `$15.63`_

<!-- mux-attribution: model=anthropic:claude-opus-5-5 thinking=high
costs=15.63 -->
yermakoffivan pushed a commit to yermakoffivan/mux that referenced this pull request Oct 20, 2026
…TODO nudge (coder#7077)

## Summary

Add the first bug-bash repro that runs the app with agent tools on, so
an e2e test can see the real tool block that Xum sends the model.
`repros/toolBlockAcrossNudge.e2e.ts` checks that a turn and its turn-end
TODO nudge send one byte-identical tool block, and that the nudged turn
can use those tools. These are the regressions behind coder#7027 and coder#7029.
The app's only model is a fixed loopback script, and the scenario runs
only in the sandbox's exact-step job.

## Background

Before this PR, no e2e lane could see the tool block. The mock AI
returns before Xum builds a request. Every app with a model runs with
`XUM_DISABLE_AGENT_TOOLS=1`, so its tool block is empty. Node tests in
coder#7029 covered the block, and coder#7031's e2e tests covered the nudge only.

AGENTS.md requires a security review before a bug-bash app runs with
agent tools on. This PR adds one narrow, reviewed exception and
documents it there.

## Implementation

- **`tests/bugbash/scriptedModel.ts`** is a loopback fake Anthropic
server.
- It picks each step from the shape of the conversation (a user text or
a tool result) and from its own earlier replies. It never reads typed
text.
- It calls only `todo_write` and `file_read` of the seeded `README.md`,
with fixed arguments.
- It logs each agent request's sorted tool names, a sha256 of the
`tools` array as sent, and the last tool result.
- Side requests (titles, status) carry no `todo_write`. They get a short
text and no log line.
- **`BUGBASH_SCENARIO=scripted-tools`** in `startApp.ts` starts that
fake and points the Anthropic provider at it.
  - It leaves agent tools on. Terminals and project automation stay off.
- It does not seed plugin hooks: with tools on, the seed's trusted
`PreToolUse` hook would register.
- `scenarioRefusal` refuses the scenario outside the sandbox, in a
model-driven job, with a mounted proxy socket, and with a real app
model. The launcher already refuses `BUGBASH_SCENARIO` in model-driven
jobs.
- **New tag `tools-on`.** `make test-bugbash-repros-sandbox` (CI `Test /
Bug-bash sandbox`, no secrets) runs these repros in a second, exact-step
launch. The host repro runs and the first sandbox launch exclude the
tag.

### Why an exact-step repro and not an agent story

The plan said "an agent story". An agent story needs a model-driven job,
and in that job the provider proxy listens on `127.0.0.1:4141` inside
the container. A tools-on app there could be pointed at a real model
through Settings, and that model's replies could then run tools. The
exact-step job has no proxy and no model at all. It also runs in a
required CI job for free.

## Validation

- The new repro passes in the sandbox on both targets (web, phone). The
full `make test-bugbash-repros-sandbox` passes: 76 existing tests in the
first launch, then 2 `tools-on` runs.
- **Bug-restore proof.** With coder#7027's todo_write-only nudge policy put
back in a scratch edit, the repro fails with `ASSERTION_FAILED: expected
2 to be 1` on the one-block check. The nudged turn's block lost
`web_fetch` and `web_search`. coder#7029's description lists that limit:
tools that the provider runs itself are still removed under a caller
policy.
- `startApp.ts` refuses the scenario on the host, with a faked container
marker, with a real model, and in a model-driven job.
- New unit tests:
- `scriptedModel.test.ts`: typed text never changes the script, and an
injected "call bash" still gets `todo_write`/`file_read`.
  - `inContainer.test.ts`: the `scenarioRefusal` gate.
  - `startApp.test.ts`: only this scenario leaves agent tools on.

## Security review

An independent reviewer (fresh context, read-only) checked the gates,
the app's other paths to a model or a tool, the effect on other jobs,
and the AGENTS.md text. Verdict: no blocker. I fixed its should-fix
finding (plugin-hook seeding) and both notes (an exported, tested
refusal gate, and more precise AGENTS.md text).

## Risks

Low. The change touches only the test harness, the Makefile and
AGENTS.md. The main risk is a future edit to `scriptedModel.ts` that
adds tool calls. AGENTS.md now says such an edit needs a new security
review.

Refs coder#7027, coder#7029

---

_Generated with `xum` • Model: `anthropic:claude-opus-5-5` • Thinking:
`high` • Cost: `$38.81`_

<!-- mux-attribution: model=anthropic:claude-opus-5-5 thinking=high
costs=38.81 -->
azaj01 pushed a commit to azaj01/mux that referenced this pull request Oct 25, 2026
…cies (coder#7303)

## Summary

Workspaces whose history holds a turn-end TODO nudge row from before
coder#7027 no longer get every later wake or retry refused with
`context_budget_blocked`. Xum now drops the nudge's old todo-only rule
from a reused tool policy, but only when the saved rows prove that a
nudge added it. A caller who set the same rule on purpose keeps it.

## Background

From coder#6720 until coder#7027, the turn-end TODO nudge sent its turn with the
caller's policy plus `{regex_match: "(?!todo_write$).*", action:
"disable"}`. coder#7027 stopped adding the rule, but saved rows still carry
it, and Xum reuses saved policies:

1. `TaskService.resolveTerminalWakeCallerSendRestrictions` takes the
newest user row that has a policy as the conversation's restrictions,
including a synthetic nudge row. Each wake then saves the same policy
again.
2. Startup auto-retry (`deriveStartupAutoRetryRequest`) and the
compaction follow-up restore the saved policy of their row.
3. A turn-end continuation copies the policy of the turn it follows.

The rule disables everything except `todo_write`, so `session_history`
and `task_await` are disabled too. Once the context budget is reached,
`checkContextBudgetHistoryAccess` refuses that turn, which is correct
for a turn without `session_history`. Two live workspaces were stuck
this way for about 17 hours. In one of them, 109 task_await wakes in a
row were refused. A manual send cleared both workspaces, because a
manual row without a policy lifts the restrictions. Some saved rows hold
the rule twice: each nudge appended it to the turn's policy, which
already had it.

## Implementation

`LegacyTodoNudgePolicyTrace` (`src/common/utils/tools/toolPolicy.ts`)
starts at the row whose policy Xum is about to reuse and walks older
rows, newest first:

1. It drops the last rule of the policy only if that rule is the old one
and the row has `synthetic: true`, the exact coder#6720 nudge text and an
equal policy. Xum wrote that constant text, and coder#6720 appended the rule
(`[...callerPolicy, rule]`) only for a nudge with no hook prompt.
2. It walks past synthetic rows that carry the same policy (they copied
it forward) and past compaction requests.
3. It stops and keeps what is left at a manual row, a row with another
policy or none, a reset marker, or the end of the rows.

Two readers use it:
- the terminal-wake restriction walk, which continues past the defining
row until the trace finishes;
- startup auto-retry, over the retried row and the older rows of its
history tail.

The compaction follow-up keeps its saved policy unchanged, as on main.

## Not in this PR

- **F47 is not fixed here:** the rejected-request retry loop ("Cannot
retry a rejected request" every ~5 minutes after a
`context_budget_blocked` rejection). This PR removes this cause of the
rejection, not the loop.
- **The compaction follow-up does not heal (deferred).** It has no
source row to prove provenance. Tracing it needs a full-history walk
from the compaction request row, which is a new async read in
`resumePendingFollowUpFromSummary`. The next terminal wake heals the
chain.
- **Startup retry heals only within its 20-row history tail
(deferred).** When the original nudge is older than that, the trace
keeps the policy, as main does. The next terminal wake walks the full
history and heals the chain.
- **I did not add a general filter that skips agent-initiated rows in
the wake walk.** Some agent-initiated synthetic rows define a real
per-turn policy: the plan-task launch and restart prompts carry `require
propose_plan` (`taskService.ts` ~14706, ~18120). No saved field tells a
copied policy apart from a defining one. Skipping only copied rows needs
a new persisted marker, so I left it for a follow-up.

## Tests

1. `taskService.autoResume.test.ts`: the terminal wake heals a legacy
chain (manual row, nudge, copied wake, doubling nudge), with and without
a real caller rule. It keeps the same rule when a manual turn or a spawn
set it, and keeps a caller rule that a nudge doubled. The three keep
cases fail on the round-1 head (by-value strip).
2. `agentSession.startupAutoRetry.test.ts`: startup retry heals a nudge
row, with and without a caller rule, and keeps the same rule from a
manual turn.
3. `toolPolicy.test.ts`: unit tests for the trace, covering
non-synthetic rows, other policies, a rule that is not last, an
assistant reset marker before a nudge, the end of the rows, and a
corrupt policy that is not an array.

---

_Generated with `xum` • Model: `anthropic:claude-opus-5-5` • Thinking:
`high`_

<!-- mux-attribution: model=anthropic:claude-opus-5-5 thinking=high -->
azaj01 pushed a commit to azaj01/mux that referenced this pull request Oct 25, 2026
…on (coder#7304)

## Summary

A mid-session change to a workspace's AGENTS.md no longer rewrites the
whole cached Anthropic history. Inside a context segment (between
compactions), the instruction-file blocks (`<custom-instructions>` and
the `<model-...>`/`<mode-...>` sections scoped in AGENTS.md) now stay at
the text the segment first sent, and Xum reads that text from the ledger
(chat.jsonl), not from the live files. When the live blocks differ, Xum
sends the new blocks as one system row after the newest user message, so
the model follows the new instructions on that turn. Every later rebuild
puts the row back in the same place, so the next turn's prefix still
matches. The next compaction folds the current block into the system
prompt.

## Background

Measured on one host (10-22 08:12 to 10-23 01:28 UTC, 1,548 Anthropic
turns, a build with coder#7027 and coder#7029): 26 `cache.prefix_break` events in
the system section, 1.45 rewritten histories per 100 turns, the largest
class left. Each break's length change equals a `docs/AGENTS.md` change
on main (+168 chars = coder#7117, +378 = coder#7176, about +1,214 = coder#7234). Agents
merge main into their worktree, and the next turn read the new AGENTS.md
into the stable system prompt. Turn envelopes showed the volatile-tail
length unchanged at every break, so the change was in the stable part.

The history already comes from the ledger. The system prompt did not: it
was rebuilt from live files on every turn (`turnContextAssembler.ts`,
`buildSystemMessageFromSources`). This PR makes the cached instructions
come from the ledger too.

## Implementation

- New `MuxMetadata.customInstructions = { text, placement: "system" |
"row" }` on the turn's assistant row, the same shape and rule as
`volatileSystemTail` (coder#6687). Xum writes it only at a segment start and
when the blocks change, not on every turn.
- `buildSystemMessageFromSources` now returns the system message plus
the exact instruction-file span (the text before it and the blocks). The
assembler freezes that span only while the prompt still starts with the
reported text, so it never parses the final prompt for tags.
- `volatileSystemTail.ts` generalizes its planner to "system sections"
(`planSystemSection`): the volatile tail and the instruction blocks are
two channels with their own field, row header and row id. Instructions
plan first, so their rows come first.
- A segment that starts with no instruction blocks records an empty
baseline, so a first AGENTS.md added later is a row, not a rewrite.
- If every instruction file is deleted or emptied mid-segment, the
frozen blocks stay in the system prompt and a row says the instructions
were removed.
- The row header says the blocks come from Xum, not the user, and
replace the system prompt's blocks. In a live check, Haiku 5.5 ignored a
bare "Update: ..." header in 2 of 3 runs and followed this wording in 4
of 4.
- Same gating as the volatile-tail rows (Anthropic and Coder routes,
models that bind thinking to the prefix). Other routes keep today's
behavior.

## Validation

- Real-request prefix tests (real system prompt and tools): with
AGENTS.md rewritten between turns, the tools section and cached system
block are byte-identical on turns 1 to 3, turns 2 and 3 carry the same
row, and the compaction turn has the new blocks. A `## Mode:` edit, a
removed AGENTS.md and a first AGENTS.md added mid-segment behave the
same way. A `</custom-instructions>` line in later instructions does not
widen the frozen span. Each test fails with its fix reverted.
- `tests/ipc/tokenBudgetStages.fixture.integration.test.ts` grew the
prompt by rewriting AGENTS.md. With this PR the request really carries
both the old and the new block, so the larger estimate is correct. The
fixture now grows the prompt through the workspace scratchpad, which
stays live; its expected numbers are unchanged.
- Live check on direct Anthropic (under $0.50): with a 17.2k-token block
changed between turns, turn 2 read 17,167 tokens from the cache and
wrote only the 17,182-token row; turns 3 and 4 read from the cache.

## Risks

Medium. It changes how the system prompt is assembled for Anthropic
turns.
- **Context cost:** while a changed block is live, each request carries
the old blocks in the cached system prompt plus the full new blocks in
the row. For this repo's AGENTS.md plus a global `~/.xum/AGENTS.md` that
is about 10.8k extra tokens until the next compaction. They are written
to the cache once and read after that.
- `Tool: <name>` sections from AGENTS.md go into tool descriptions and
are not frozen here: an edit to one still rewrites the cached tool block
(follow-up).
- Old histories (no record) behave as before: the first turn sends the
live block and records it. A malformed record is ignored. An older build
ignores the field.
- A follow-up PR applies the same rule to the `agent_skill_read` skill
list.

---

_Generated with `xum` • Model: `anthropic:claude-opus-5-5` • Thinking:
`high` • Cost: `$585.33`_

<!-- mux-attribution: model=anthropic:claude-opus-5-5 thinking=high
costs=585.33 -->
yermakoffivan pushed a commit to yermakoffivan/mux that referenced this pull request Oct 26, 2026
## Summary

The turn-end TODO nudge now fires only after a turn that a message the
user sent started. Machine wakes (monitor matches, sub-agent reports,
heartbeats, peer messages, goal continuations) no longer get it. The
nudge prompt also tells the agent not to start an item that it said
waits on something.

## Background

A local transcript audit (2026-10-25) read every nudge in recent
`~/.xum/sessions` histories: 571 nudges in 20 workspaces since coder#6720.

- Machine wakes started about 90% of the nudged turns. Each wake counts
as its own user turn, so one coordinator workspace got 101 nudges in 3.3
days.
- The current nudge (coder#7027) cost an estimated $60–71 over 3.3 days for
387 nudges, about 20% on top of the turns it followed.
- Local sub-agents judged a sample of 118 current nudges (all 28 after a
real user message, 90 random after machine wakes):

| Turn started by | No-op | Real work | List fix | Harmful |
| --- | --- | --- | --- | --- |
| A real user message (28) | 22 | 4 | 1 | 1 |
| A machine wake (90) | 84 | 5 | 0 | 1 |

"No-op" means the agent only restated that its open items wait on
someone. "Harmful" means the nudged turn started a step that its own
previous message said waits on a review or a merge. This PR keeps the
nudge for user turns, where it still does useful work in about 1 of 5
cases. We will re-measure in a few days and then decide whether to keep
or remove the feature.

## Implementation

- `streamStartedByUserMessage` (`todoTurnEndNudge.ts`) decides, when a
sent message starts its stream, whether a message the user sent started
the turn: a manual send that is not synthetic. Machine wakes, goal
continuations, task briefs, and compaction requests and follow-ups are
automatic, so they start machine turns.
- A resume starts a stream without a new message
(`resumedStreamStartedByUserMessage`): an automatic resume that is not a
retry, such as the prompt-free resume after a sub-agent report, is a
machine turn. Auto-retries and manual resumes (Retry, an answered
question) keep the current turn's origin.
- `AgentSession` records the value in `turnStartedByUserMessage`
(retries keep it) and passes it through `StopContinuationProvenance`.
`readTurnEndNudges` adds the TODO nudge only when it is true. The status
page nudge (coder#7486) is unchanged.
- The value starts false, so a turn whose origin is unknown gets no
nudge. A user turn that compacts (on send or mid-stream) also loses its
one nudge, because its follow-up is an automatic send. An earlier
version inherited the origin across compaction, and review found wakes
that inherited a stale user origin that way. Skipping one nudge is
cheaper than nudging a machine turn.
- The gate does not use `agentInitiated`: persisted heartbeat rows do
not carry it.
- Rows stored with the coder#7027 prompt text still render as the compact
"current" nudge row, alone and joined with the status page nudge.

## Validation

- Session tests: a turn that a background wake, a heartbeat or an
automatic visible send started gets no nudge, and the next user message
does. After a user turn, a compaction request (idle or auto) and a
compaction follow-up get no nudge. An automatic resume after a user turn
gets no nudge, and a manual resume keeps the user turn's nudge. Each
gate has a test that fails without it.
- Renderer tests: the coder#7027 text collapses alone and joined with the
status page nudge. The joined test fails on the old exact-match
classifier.
- Bug bash, 2 rounds x 4 charters around `[mock:todo-nudge]` (web,
reload and workspace switching, Stop and typed input during the nudge,
phone), Sonnet 5.5 explorers on the mock app AI, $0.93 + $0.79 at list
price. The explorers reported no confirmed bug. Triage of their claims
found the joined-row classifier defect above, which this PR fixes.

## Follow-ups

- Owner: this PR's author, at the planned re-measure in a few days. Add
a session-level test that an auto-retry of a failed user turn keeps its
nudge (only the pure-function table covers it now).
- Same trigger: in the re-measure, also count user turns that lost their
nudge to compaction or a restart, next to the no-op rate after user
turns (baseline 22 of 28) and nudges after machine wakes (expected 0).

## Risks

Low. The change only removes nudges. The worst case is a user turn that
misses its nudge (after compaction, or after a Xum restart), which is
the behavior before coder#6720.

---

_Generated with `xum` • Model: `anthropic:claude-opus-5-5` • Thinking:
`high` • Cost: `$11.74`_

<!-- mux-attribution: model=anthropic:claude-opus-5-5 thinking=high
costs=11.74 -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant