Skip to content

🤖 fix: keep the prompt cache on the turn-end todo nudge - #7011

Closed
ThomasK33 wants to merge 6 commits into
mainfrom
tk/f10-todo-nudge-keep-tools
Closed

ThomasK33 wants to merge 6 commits into
mainfrom
tk/f10-todo-nudge-keep-tools

Conversation

@ThomasK33

@ThomasK33 ThomasK33 commented Oct 19, 2026 •

Copy link
Copy Markdown
Member

Summary

The turn-end TODO nudge (#6720) no longer breaks the Anthropic prompt cache, and its tool limit no longer leaks into later turns. Before this PR, the nudge turn advertised only todo_write, so the tools section (the first part of the cached prefix) changed, and the next turn changed it back: two full history rewrites per nudge. Now the nudge turn sends the previous turn's tools, system prompt and options unchanged, and every tool except todo_write refuses at execution. One exception: provider-run tools that can open a URL the model picks are omitted on the nudge turn (see below). Report wakes, goal continuations and plugin continuations after a nudge get the caller's tools back. Before, they inherited todo_write only.

Background

Measured on one host after the 10-15 prompt-cache fixes (10-17 16:16 to 10-18 12:58 UTC, about 926 Anthropic turns): 72 of 116 prefix breaks were the tools section flipping between 249 tools and exactly one tool, todo_write. That was about 5.7 of 6.2 rewritten histories per 100 turns in the clean window. Turn envelopes show 1-tool manifests (todo_write) between 249-tool requests.

A second bug showed up live: after a nudge, a sub-agent report wake ran with only todo_write ("Model tried to call unavailable tool 'bash'. Available tools: todo_write."). TaskService.resolveTerminalWakeCallerSendRestrictions adopts the newest user row's toolPolicy as the conversation's restriction. It already skipped compaction rows, whose policy is per-turn, but not the synthetic nudge row.

Implementation

  • Same tools on the nudge turn. splitTodoTurnEndNudgePolicy recognizes the nudge's trailing rule and strips it from the caller policy before agent resolution. Tools, tool search and the memory guidance are then computed exactly as in a normal turn. The nudge sets no toolChoice.
  • Proven nudge turns only. A turn is a nudge only when its own row proves it: synthetic, with exactly the TODO_TURN_END_NUDGE text (the transcript's own test). Any other turn, including a manual send with the same todo_write-only rule, keeps its whole policy, and later turns inherit it. No new persisted field.
  • Refuse at execution. A new executionGate in tool assembly turns every tool except todo_write into a refusing stub with the same definition, before the code_execution bridge is built. It covers direct calls, MCP tools and computer-use tools. On a nudge turn code_execution itself refuses, so no sandbox path (bridged tools, mux.load, mux.task_spawn, mux.events, kernel vars) can run. todo_write is PTC-excluded, so it is always a direct tool. The gate applies only on a proven nudge turn. Its stream policy turns require rules into plain enables, so no required tool that the gate refuses keeps the turn stepping, and forced xAI search is off.
  • No inheritance. The terminal-wake walk keeps only the caller part of a nudge row's policy (readPersistedCallerToolPolicy). AgentSession passes options without the nudge rule to turn.stop hooks, goal advancement and the goal continuation (withoutTodoTurnEndNudge).
  • Old data. The narrowed policy stays in the persisted toolPolicy. Retries and compaction follow-ups of the nudge turn itself still narrow, and older builds keep the old behavior. No new persisted field.

Provider-run tools in the nudge turn

A tool that the provider runs on its own servers has no local execute, so Xum cannot refuse it at execution. The nudge turn keeps only searches that take a query and cannot open a page the model picks: Anthropic web_search, Google google_search and xAI x_search. Every other provider-run tool is omitted on the nudge turn, unknown ones included (fail closed). That drops native fetches (Anthropic web_fetch, Google url_context) and the searches that also open live pages (OpenAI web_search with its open_page action, xAI web_search). A prompt injection could otherwise make the todo-only turn send chat data to a URL it picks.

Cache cost: native fetches exist only where tool hooks cannot run (untrusted projects), so only there does a nudge drop a tool. OpenAI and xAI searches exist in every project, so a nudge on those providers costs one cache miss. Trusted Anthropic and Google projects keep a byte-identical tools block. The nudge turn can now search the web with the kept searches, which it could not before.

Validation

Each test fails with its change reverted:

  • aiService.test.ts: an untrusted Claude 4.6+ nudge drops native web_fetch and keeps native web_search. A trusted normal turn, then the nudge, through the real request path. The tools section, cached system row, system tail and provider options are identical, and no forced tool choice is set. bash, file_edit_insert, memory and an MCP tool are refused, no file is created, and todo_write succeeds.
  • toolAssembly.test.ts: the gate keeps the query-only searches and omits native web_fetch, url_context, OpenAI and xAI web_search and an unknown provider tool. With code_execution on, code_execution is refused on the nudge turn and todo_write still runs. With RLM on, mux.load through code_execution gets the refusal and the kernel loader is never called.
  • taskService.autoResume.test.ts: after a nudge row, a child report wake gets the caller's policy (unrestricted, and a caller that disables bash), and no execution gate.
  • agentSession.turnStopHooks.test.ts: a plugin continuation and a goal continuation after the nudge get no nudge rule.

Risks

Medium-low. The change touches tool assembly for the nudge turn and the wake restriction walk.

  • If a later row hides the nudge row (for example a compaction follow-up), Xum does not recognize the nudge and falls back to the old narrowing: one cache miss, still safe.
  • Known gap, not fixed here: if Xum restarts during a report-resume turn that follows a nudge (a turn that adds no user row), the startup retry takes the nudge row as its source and runs with todo_write only. Compaction rows have the same gap today. Telling "the nudge turn itself" from "a later turn with no new row" is a larger change.

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

The turn-end todo nudge (#6720) advertised only todo_write. The tools block
sits first in the Anthropic prompt cache, so each nudge rewrote the whole
cached history twice: once for the nudge turn and once for the next turn.

The request builder now strips the nudge's trailing rules from the caller
policy before agent resolution, so the nudge turn advertises the same tools,
system prompt and provider options as the turn before it. Tool assembly
enforces the nudge rules at execution through a new execution gate: every
tool except todo_write keeps its definition but returns a refusal before any
side effect, on direct calls, inside code_execution (PTC) and for MCP tools.
Provider-executed tools (native web_search/web_fetch) have no local execute,
so they stay usable; they cannot run commands or edit files.

The nudge rules stay in the persisted toolPolicy, so retried, restarted or
compacted nudges (and older Xum builds) still narrow.

---
_Generated with `xum` • Model: `anthropic:claude-opus-5-5` • Thinking: `high`_
<!-- mux-attribution: model=anthropic:claude-opus-5-5 thinking=high -->

(cherry picked from commit 6e1f806b3244082f413b000a9b2970d4c339c8a5)
The turn-end todo nudge queues its turn with the caller policy plus a
todo_write-only rule. That rule governs the nudge turn alone, but later
turns inherited it:

- TaskService's terminal-wake walk (sub-agent report, workflow and idle
  drain wakes) adopted the nudge row's whole policy as the conversation's
  restriction, so every later wake ran with todo_write only until the next
  manual send.
- AgentSession handed the nudge turn's options to the goal continuation
  and to a plugin turn.stop continuation after the nudge.

With the previous commit's execution gate, these turns would advertise
every tool and refuse all but todo_write. The wake walk now adopts only the
caller part of a nudge row's policy (an empty caller part restricts nothing,
like any synthetic row without a policy), and AgentSession strips the
nudge's rule from the options later turns inherit. The nudge turn itself,
including its retries and compaction follow-ups, keeps the rule.

---
_Generated with `xum` • Model: `anthropic:claude-opus-5-5` • Thinking: `high`_
<!-- mux-attribution: model=anthropic:claude-opus-5-5 thinking=high -->

(cherry picked from commit 1eef5a91d582e01affdec4a967994274ecaee840)
@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-21T01:15:41.399301Z d75be1f New commits
🔒 Security Review ✅ Completed 2026-10-21T01:16:39.443200Z d75be1f New commits

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.

@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: 765000623d

ℹ️ 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/node/services/turnRequestBuilder.ts Resolved
Comment thread src/node/services/turnRequestBuilder.ts Resolved
Review round 1 on #7011:

- The request builder, AgentSession and the TaskService wake walk inferred
  a nudge turn from a policy that ends with the nudge's todo_write-only
  rule. A caller that sent that rule itself was then treated as a nudge, and
  the rule was stripped from what later turns and wakes inherited, so they
  regained bash and file edits. A nudge turn is now proven by its own row:
  synthetic, with exactly the nudge's text (the transcript renders it by the
  same test). The builder and AgentSession read the newest user row that
  carries a tool policy in the request's history; the wake walk checks the
  row it adopts. Any other turn keeps its whole policy.
- A nudge turn's stream policy kept the agent's require rules, so a required
  tool the gate refuses kept the turn stepping. Require rules become plain
  enables in the nudge's stream policy; the advertised tools are unchanged.
- Frontier Grok with xAI search mode "on" forced a paid search on the
  nudge's first step. The nudge turn now forces no search.

---
_Generated with `xum` • Model: `anthropic:claude-opus-5-5` • Thinking: `high`_
<!-- mux-attribution: model=anthropic:claude-opus-5-5 thinking=high -->

@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: 118fec8ec3

ℹ️ 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/node/services/toolAssembly.ts Resolved
Review round 2 on #7011: the nudge gate refused each bridged tool's
execute, but RLM kernel methods reach the host without it. mux.load reads
files through the kernel file loader whenever file_read is bridged, so
code_execution could read workspace files during the nudge.

On a gated turn code_execution itself now returns the gate's refusal, so no
bridge or kernel path runs: mux.load, task_spawn, mux.events, kernel vars
and every bridged tool. It stays advertised, so the tools block is
unchanged. todo_write is PTC-excluded, so it stays a direct tool and the
nudge still works.

---
_Generated with `xum` • Model: `anthropic:claude-opus-5-5` • Thinking: `high`_
<!-- mux-attribution: model=anthropic:claude-opus-5-5 thinking=high -->

@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: b0145f1572

ℹ️ 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.

Comment thread src/node/services/toolAssembly.ts Resolved
Review round 3 on #7011: the nudge gate kept every provider-executed tool,
because the provider runs it and Xum cannot refuse it. Where tool hooks
cannot run, Claude 4.6+ gets Anthropic's native web_fetch and Gemini 3 gets
url_context. Both fetch any URL server-side, past local hooks, so a prompt
injection could make the todo-only nudge turn send source or chat data to
an attacker's URL. Before this PR the nudge hid them.

The gate now keeps only an allow-list of provider-executed searches
(Anthropic web_search, Google google_search, OpenAI web_search, xAI
web_search and x_search): they take a query, not a URL the model picks.
Every other provider-executed tool, unknown ones included, is omitted on
the nudge turn (fail closed). Native fetches exist only where hooks cannot
run, so only there does a nudge cost a cache miss; trusted projects use
Xum's local web_fetch, which the gate refuses, and keep the tools block.

---
_Generated with `xum` • Model: `anthropic:claude-opus-5-5` • Thinking: `high`_
<!-- mux-attribution: model=anthropic:claude-opus-5-5 thinking=high -->
…e turn

OpenAI web_search can open live pages (open_page action) and xAI web_search
browses web pages, so a prompt injection could make the todo-only turn reach
a URL the model picks. Keep only query-only searches on the nudge turn.
@ThomasK33

Copy link
Copy Markdown
Member Author

Closing as superseded by #7027 and #7029, which merged on main while this PR was in review.

Residual, not fixed: a nudge row stored by a build from #6720 to before #7027 still has the todo_write-only toolPolicy. If such a row is a workspace's newest user row, a report wake there still adopts it until the next user message. It heals on the next user message, so I am not opening a fix for it.

The security findings from rounds 2 and 3 (code_execution, native fetch and page-opening searches during the nudge) applied only to this PR's execution gate, so they do not apply to main.

@ThomasK33 ThomasK33 closed this Oct 21, 2026
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