Skip to content

fix(chat): Keep the tool list stable across Turn origins - #2148

Merged
dcramer merged 5 commits into
mainfrom
fix/stable-slack-tool-list
Oct 15, 2026
Merged

dcramer merged 5 commits into
mainfrom
fix/stable-slack-tool-list

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

In a Slack Conversation, a Turn that a person's Slack message did not start got a shorter tool list. This covers event, automation, Agent invocation (child result), and dashboard Turns. They dropped 11 tools: slackPublicSearch, addReaction, the 4 event automation tools, and the 5 scheduled automation tools. Explicit /skill Turns also dropped loadSkill. The provider caches tools before the system prompt and messages, so each change to the tool list wrote the whole Conversation to the cache again.

Change

  • createTools registers these tools from the Conversation's Slack Location, not from the Source or Actor of the Turn. loadSkill is always registered, and the includeLoadSkill option is gone.
  • A tool can now be disabled for one Turn without leaving the tool list. disableTools(tools, reason) sets disabledReason. The tool adapter rejects calls to a disabled tool, direct or through executeTool, before hooks, action review, and the executor. The Turn context lists disabled tools in a <disabled-tools> block. The reason never goes into a tool description or schema, so the tool list stays the same.
  • The automation tools are disabled unless a person started the Turn with a Slack message (isSlackMessageTurn). Scheduled automation tools get the Slack Actor and Source only on those Turns. The existing checks in the tools still reject other Turns, so a child agent result that carries the person's Actor cannot create or change automations with that person's credentials.
  • slackPublicSearch is disabled without a Slack action token, and addReaction without a message.
  • src/chat/README.md documents the rule: tool registration depends on the Conversation, not on one Turn.

Why tests did not catch it

Tests

  • tool-registration.test.ts: message, scheduled automation, event, and Agent invocation Turns in one Slack Conversation get the same tool names, descriptions, and schemas.
  • pi-tool-adapter.test.ts: a disabled tool keeps the same tool list, and direct and executeTool calls are rejected before the executor runs.
  • slack-schedule-tools.test.ts: an Agent invocation Turn with the person's Slack Actor cannot create or delete automations, even when the tools are called directly.
  • prompt.test.ts: the Turn context lists disabled tools.

Not in scope

  • Automation dispatch Conversations also change the system prompt, so a stable tool list alone does not keep the cache there.
  • Plugin tools cannot set disabledReason yet. No plugin tool changes by Turn today.

Eval recordings will change, because more Turns now send these tools.

via David Cramer.

--

View Junior Session [Sentry]

Tool registration depended on the Source and Actor of each Turn. In a
Slack Conversation, event, automation, Agent invocation, and dashboard
Turns dropped 11 tools: slackPublicSearch, addReaction, the 4 event
automation tools, and the 5 scheduled automation tools. Explicit skill
Turns also dropped loadSkill. The provider caches tools first, so each
switch between origins wrote the whole Conversation to the cache again.

Register these tools from the Conversation Location instead. Each tool
still checks at execution that a person's Slack message started the
Turn, so other Turns cannot act with that person's credentials.

The existing history test only compared two web Turns, and the
registration unit test asserted the drift as expected behavior. Add an
integration test that sends a Slack Turn and then an event Turn in the
same Conversation and compares the provider tools, system prompt, and
message prefix.

Co-Authored-By: David Cramer <[email protected]>
@vercel

vercel Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
junior-docs Ready Ready Preview Oct 15, 2026 4:05pm UTC

Request Review

@github-actions github-actions Bot added the risk: high PR risk score: high label Oct 15, 2026
A Turn that cannot use a tool must not remove it, because a changed tool
list makes the provider write the whole Conversation to its cache again.
#2148 kept these tools registered, but each tool rejected the call in its
own way.

Add one API for this. A tool definition can set `disabledReason`, and
`disableTools` sets it for a group of tools. The tool adapter rejects a
call to a disabled tool before input validation, hooks, action review, or
the tool run, with one standard error. The Turn context lists the disabled
tools and the reasons, so the model knows not to call them. The reason
never goes into the tool description or schema, so the tool list stays
the same.

Use it for the Slack tools that a Turn can lack: the event and scheduled
automation tools need a Turn that a person started with a Slack message,
slackPublicSearch needs an action token, and addReaction needs a message.
The checks inside these tools stay as a second guard.

Co-Authored-By: David Cramer <[email protected]>
The test architecture check rejects new agent-run tests and runtime
config mutation in packages/junior/tests. Cover the stable tool list
with the tool registration and Pi adapter tests instead, and list
disabled tools in a prompt unit test.

Co-Authored-By: David Cramer <[email protected]>
Scheduled automations store a Slack user as creator, so the tools need
the Slack Actor and Slack Source together. Pass both only when the Turn
is a person's Slack message, using the same rule that disables the
tools, and explain why other Turns get neither.
Check disabled tools in one place in the tool adapter, before hooks,
action review, and the executor. Drop the extra checks in
prepareArguments and the executeTool path.

Revert the error text and the extra Actor check in the automation
tools. The adapter rejects disabled calls first, and scheduled
automation tools now get the Actor and Source together, so those
changes did nothing. Add isSlackMessageTurn so the scheduled tools use
the same rule as the disabled reason. Shorten repeated comments.

Co-Authored-By: David Cramer <[email protected]>
@dcramer
dcramer merged commit 0d1988d into main Oct 15, 2026
48 checks passed
@dcramer
dcramer deleted the fix/stable-slack-tool-list branch October 15, 2026 16:15
dcramer added a commit that referenced this pull request Oct 15, 2026
Child agents doing real work keep hitting the 250 tool-call cap from
#1752. The turn fails, the parent sees "model failed", and the child's
work is lost. The cap was meant to stop runaway loops, and what those
loops really cost was model spend.

- **Spend limit:** each turn can spend `maxTurnCostUsd` of model cost,
$100 by default, across all its execution slices. Retries that Junior
throws away count too. The tool-call cap goes from 250 to 1,000 and only
matters for models without cost data.
- **Wrap up instead of failing:** the first model step past a limit has
its tool calls blocked with the same message as a tool that
`disableTools` (#2148) disabled. The tool list stays the same, so the
provider cache stays valid. The model replies with what it finished,
what is left, and how to continue, and a child agent sends that reply to
its parent as a normal result. Any later tool call in the turn fails it.
The turn checkpoint saves the wrap-up, so a later slice does not wrap up
again.
- **Child limit failures are final:** a non-final attempt used to
rethrow the limit error. The retry then marked the child's Turn as "lost
its worker before it could pause", so the parent never saw the limit.

The $100 default comes from Sentry span cost estimates: one child agent
that made 250 tool calls cost about $50.

Not in this PR:
- One budget shared by the root conversation and its child agents. Each
child agent gets its own budget.
- The root and scheduler path in `task-execution/conversation-turn.ts`,
which still retries limit failures.

The new subagent eval uses a 3-call limit to stand in for a spent
budget.

Context: JUNIOR-96, event `49c00ccc6e12485e9f4b18a97c3010d6`.

<!-- junior-request-attribution:start -->
via **David Cramer**.
<!-- junior-request-attribution:end -->

<!-- junior-session-footer:start -->
<!-- junior-conversation-id:slack%3AC0B595QDZLL%3A1792078672.880799 -->

--

[View Junior
Session](https://junior-prod.sentry.dev/conversations/slack%3AC0B595QDZLL%3A1792078672.880799)
[[Sentry]](https://sentry.sentry.io/explore/conversations/slack%3AC0B595QDZLL%3A1792078672.880799/?project=4510944073809921)

<!-- junior-session-footer:end -->

---------

Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
Co-authored-by: David Cramer <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
dcramer added a commit that referenced this pull request Oct 28, 2026
After an in-turn compaction, Junior refused to call
`createEventAutomation` in a Turn that a person started with a Slack
message. In that Turn the tool was enabled. The model made no tool call.
It said the tool was off for the Turn and asked the person to send the
request again. The retry worked because no compaction ran.

**Root cause.** An earlier Agent invocation Turn correctly had the event
automation tools disabled, so its Turn context had a `<disabled-tools>`
block. The next Turn, started by a person, added no Turn context block.
Active compaction rebuilds runtime context from the newest
`<runtime-turn-context>` block in history (`effectiveRuntimeContext`).
That block was the follow-up block from the earlier Turn. The
replacement history put it first, ahead of the current instruction, as
"These tools are disabled in this Turn". The production request after
compaction had that exact block. It also had no session context
(`<runtime>`, `<context>`, available skills), because the follow-up
block replaced the first Turn's session block as the anchor. This
started when #2148 put disabled tools in follow-up Turn context. Plugin
context and Conversation notes also go stale this way.

**Fix.** The agent now passes the current Turn start to
`compactActiveContextIfNeeded`. Compaction keeps all runtime context
from the current Turn. From earlier Turns it keeps only the latest
session context, without its request sections (`plugin-context`,
`conversation-notes`, `disabled-tools`), and the visible AGENTS.md
instructions. The section tag names moved to `turn-context-tag.ts`, so
prompt assembly and compaction read the same names. The existing split
host context test now has an earlier session Turn and a follow-up Turn
that no person started. On `main` it fails because the session context
is missing.

**Remaining risk.** `compactContextForHandoff` still uses the old
newest-block rule. A handoff in the middle of a Turn can probably keep
stale request context too. I did not verify that, and this PR does not
change handoff. When a resumed record has no Turn start, compaction uses
the old rule.

<!-- junior-request-attribution:start -->
via **David Cramer**.
<!-- junior-request-attribution:end -->

<!-- junior-session-footer:start -->
<!-- junior-conversation-id:slack%3AC0B595QDZLL%3A1793217803.314299 -->

--

[View Junior
Session](https://junior-prod.sentry.dev/conversations/slack%3AC0B595QDZLL%3A1793217803.314299)
[[Sentry]](https://sentry.sentry.io/explore/conversations/slack%3AC0B595QDZLL%3A1793217803.314299/?project=4510944073809921)

<!-- junior-session-footer:end -->

---------

Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
Co-authored-by: David Cramer <[email protected]>

This branch was successfully deployed

1 active deployment
Preview – junior-docs — 8b06fd5a Deployed Oct 15, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: high PR risk score: high

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant