Skip to content

fix(bots): close three ways a Bot gets a shell - #321

Merged
diegojohnsonl merged 4 commits into
feat/botsfrom
fix/bot-shell-escapes
Nov 30, 2026
Merged

diegojohnsonl merged 4 commits into
feat/botsfrom
fix/bot-shell-escapes

Conversation

@diegojohnsonl

@diegojohnsonl diegojohnsonl commented Nov 30, 2026 •

Copy link
Copy Markdown
Collaborator

Why

Goal: a Bot's tools list should actually take Bash away. Only the Claude adapter applies a Bot's tools. A Bot could still get a shell in four ways: move a Bot to another provider, pick an ACP agent's own "yolo" mode, start work in a new thread or a linked environment, or run while its profile couldn't be read.

What changed

Four commits, in order:

  1. Provider and agent mode (only the user moves a Bot to another provider).
    • t3_thread_configure refuses a provider change on a Bot's thread, and any change to another Bot's thread.
    • bot_update refuses a provider change from a Bot.
    • bot_update's card shows Agent mode: X → Y for any agent-mode change.
  2. One provider rule (one rule keeps Bots on the user's chosen provider). refuseBotProviderChange in mcp/botCaller.ts is the single check behind t3_thread_configure, bot_update and bot_create. A Bot can't put a new Bot on another provider. A Bot that omits modelSelection in bot_create gets its own model.
  3. Fail-closed profile (a Bot's turn stops when its profile can't be read). If the Bot store can't be read and the session works inside the Bots root, the turn fails. Every Bot and check-in thread works in its folder there, so recognizing one needs no store read. Other threads run as before.
  4. Fix 3 (a Bot without Bash can't start threads or tasks). The rule has one home in McpToolAccess.ts: the WORK_STARTS list and one check, run before every listed call, whether it runs here or goes to a linked environment.
    • The list: delegate_task, create_threads, t3_thread_launch, t3_thread_transfer fork, schedule_task create or enable, and run_scheduled_task_now.
    • Work in the Bot's own thread stays allowed. Scheduled-task lookups go through ScheduledTaskService and refuse when they can't tell.
    • A forwarded start is always refused.
    • merge_back and status stay allowed.

Scope

To revert Fix 3, run git revert on commit 4 alone. I checked that it reverts cleanly, typechecks and passes its tests.
The user decided these are handled by Bot instructions, not code:

  • A local t3_thread_send or bot_message to a thread that has Bash. Forwarded t3_thread_send isn't on the list either.
  • Project scripts, via t3_project_update and t3_worktree_handoff.

Tradeoffs

  • A tool that starts work must be added to WORK_STARTS. It's one explicit list next to its check, not a per-tool annotation.
  • Without BotService, a listed call from a thread is refused. Production always provides BotService; test harnesses get McpToolAccessTestkit.layerNoBots.
  • I rewrote this unmerged branch so Fix 3 is one commit. The content is identical to the reviewed work plus the new fixes.
  • Poteto principles: Laziness Protocol led to one list and one check, not per-handler guards or per-tool annotations. Fix Root Causes moved the rule out of the handlers, which forwarding skipped. Sequence Work into Verifiable Units led to one commit per fix, each typechecked and tested alone. Test Behavior, Not Implementation led to one table test through the real MCP registration.

Blast Radius

This affects Bot callers of the listed tools, bot_create, and Bot turns when the Bot store fails. Non-Bot callers behave as before; the table test covers them.

Verification

  • The table test, every entry point local and forwarded, fails on the old code at the first forwarded row (linked t3_thread_launch … expected 'ran') and passes now.
  • The bot_create and fail-closed tests fail without their fixes and pass with them.
  • vp run check:changed origin/feat/bots passes: format, lint, knip, graphql, typecheck for 3 packages, and tests in 16 files.

🤖 Generated with Claude Code, Claude Opus 5.5, in T3 Code.

Only the Claude adapter applies a Bot's tools, so moving a Bot's thread to
another provider handed it a shell. t3_thread_configure switched a Bot's
own thread with no card, and bot_update carded a Bot moving any Bot.

- t3_thread_configure refuses a provider or instance change on any Bot's
  thread, and any change to another Bot's thread. A Bot may still change
  its own model within its instance.
- bot_update refuses a provider change from a Bot caller. Other callers
  keep the approval card.
- bot_update adds an "Agent mode: X → Y" line to its card when
  modelSelection changes the agent's own mode. T3 cannot rank those
  modes, so any change asks.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
diegojohnsonl and others added 2 commits November 29, 2026 20:48
bot_create let a Bot put a new Bot on another provider instance, such as
Codex, which ignores the Bot's tools. One helper, refuseBotProviderChange,
now holds the rule for t3_thread_configure, bot_update and bot_create:
only the user moves a Bot to another provider, in the UI.

A Bot that omits modelSelection in bot_create now gets its own model,
not its thread's, so leaving it out never asks for another provider.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
If the Bot store couldn't be read, the turn ran as a plain thread, with
the default tools and Bash. The resolver now fails the turn instead when
the session works inside the Bots root, where every Bot and check-in
thread works. That needs no store read. Other threads still run as plain
threads, so a store fault can't stop ordinary work.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Only the Claude adapter applies a Bot's tools, and a new thread gets the
default set, Bash included. So a Bot without Bash could get a shell by
starting work elsewhere, including through a linked environment.

The rule has one home in McpToolAccess: an explicit list of the tools
and actions that start work (delegate_task, create_threads,
t3_thread_launch, t3_thread_transfer fork, schedule_task create or
enable, run_scheduled_task_now), and one check before each listed call,
whether it runs here or goes to a linked environment.

- Work in the calling Bot's own thread stays allowed, such as an
  mcp_event subscription. The check finds a scheduled task's thread
  through ScheduledTaskService and refuses when it can't tell.
- A forwarded start from a Bot without Bash is always refused.
- merge_back and status stay allowed: merge_back only queues context
  into an existing thread's next turn.
- t3_workflow needs no entry: no thread can call it, and a test holds
  that.

Revert this one commit to undo Fix 3.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@diegojohnsonl
diegojohnsonl merged commit 85f46db into feat/bots Nov 30, 2026
diegojohnsonl added a commit that referenced this pull request Nov 30, 2026
A Bot's session only saw its SOUL.md, roster and tools as they stood when
the session started. Turn start now compares that setup with what the
native session last saw. Anything that changed reaches the provider once,
as one <bot-update> part on the inline-context path, so every provider gets
it with no adapter change.

- The record maps each tracked section to its digest, keyed by the native
  session id in bots.sqlite. It is written only after the provider accepts
  the prompt.
- A session's first turn records the baseline and sends nothing.
- Only the setup a Bot doesn't write itself is tracked: identity, SOUL.md,
  HEARTBEAT.md (primary only), roster, tools, MCP servers and skills.
  NOW.md and MEMORY.md are not tracked.
- The read keeps #321's fail-closed rule.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
diegojohnsonl added a commit that referenced this pull request Nov 30, 2026
A Bot's session only saw its SOUL.md, roster and tools as they stood when
the session started. Turn start now compares that setup with what the
native session last saw. Anything that changed reaches the provider once,
as one <bot-update> part on the inline-context path, so every provider gets
it with no adapter change.

- The record maps each tracked section to its digest, keyed by the native
  session id in bots.sqlite. It is written only after the provider accepts
  the prompt.
- A session's first turn records the baseline and sends nothing.
- Only the setup a Bot doesn't write itself is tracked: identity, SOUL.md,
  HEARTBEAT.md (primary only), roster, tools, MCP servers and skills.
  NOW.md and MEMORY.md are not tracked.
- The read keeps #321's fail-closed rule.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
diegojohnsonl added a commit that referenced this pull request Nov 30, 2026
Merges feat/bots at 488ac5c: #321, #323, #325, #328, #332, #337
and the #327 back-merge.

- #328's card_request and upstream's handoff_request (pingdotgg#44774) both stay:
  in the contracts turn-item unions, the Orchestrator's command routing,
  the run-recovery exclusions, the MCP item summaries, and the web and
  mobile timelines. The handoff request keeps its own item status and
  does not use #328's pending-request record.
- Mobile's ThreadFeed keeps #328's single request-card switch and adds
  the handoff card to it, so the per-type activity-group helpers stay
  removed.
- The budget test leaves out tools hidden outside Bots (#328) and tools
  hidden from threads or limited to linked callers (upstream).
- #321's Bot-starting-work test layer gets the HandoffImport,
  ThreadHandoff and ThreadImportService mocks. Upstream's thread handoff
  and import made the project and orchestrator toolkits require them.
  Git merges the file cleanly, so it isn't flagged.
- Translation catalogs take both sides' keys, ordered as gt generate
  puts them.
- The agent context budget is the measured value: upstream's sizes,
  plus the 46 bytes feat/bots adds to the MCP tool list.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
diegojohnsonl added a commit that referenced this pull request Nov 30, 2026
A Bot's session only saw its SOUL.md, roster and tools as they stood when
the session started. Turn start now compares that setup with what the
native session last saw. Anything that changed reaches the provider once,
as one <bot-update> part on the inline-context path, so every provider gets
it with no adapter change.

- The record maps each tracked section to its digest, keyed by the native
  session id in bots.sqlite. It is written only after the provider accepts
  the prompt.
- A session's first turn records the baseline and sends nothing.
- Only the setup a Bot doesn't write itself is tracked: identity, SOUL.md,
  HEARTBEAT.md (primary only), roster, tools, MCP servers and skills.
  NOW.md and MEMORY.md are not tracked.
- The read keeps #321's fail-closed rule.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
diegojohnsonl added a commit that referenced this pull request Dec 1, 2026
)

* ✨ feat(bots): tell a Bot's running session when its setup changes

A Bot's session only saw its SOUL.md, roster and tools as they stood when
the session started. Turn start now compares that setup with what the
native session last saw. Anything that changed reaches the provider once,
as one <bot-update> part on the inline-context path, so every provider gets
it with no adapter change.

- The record maps each tracked section to its digest, keyed by the native
  session id in bots.sqlite. It is written only after the provider accepts
  the prompt.
- A session's first turn records the baseline and sends nothing.
- Only the setup a Bot doesn't write itself is tracked: identity, SOUL.md,
  HEARTBEAT.md (primary only), roster, tools, MCP servers and skills.
  NOW.md and MEMORY.md are not tracked.
- The read keeps #321's fail-closed rule.

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

* ✨ feat(bots): tell a Bot when someone else changed its NOW.md or MEMORY.md

The Bot works from the copies of NOW.md and MEMORY.md that its session
started with. When someone else edits one of them, the next turn's
<bot-update> now carries one line telling the Bot to re-read that file,
without the file's contents.

- The Bot's own edits don't trigger the notice. When the provider turn
  ends, the session's record takes the Bot's NOW.md and MEMORY.md as
  seen. A new afterProviderTurn hook in finalizeRootRun runs this before
  the run settles, so a queued turn can't start first.
- The recording runs only after the provider accepted that turn's prompt.
- The shared instructions now say to read NOW.md or MEMORY.md fresh before
  editing them.

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

* ♻️ refactor(bots): record what a Bot session saw only when its turn ends

The poteto review found that a prompt the provider dropped after accepting
it lost its update, because the accept-time write had already counted it
as seen. The turn-end write records the same setup plus the Bot's own
edits, so it is now the only write. It is still armed only after the
provider accepts the prompt, and it skips a turn whose prompt was dropped.
A crash mid-turn now re-sends that turn's update once instead.

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

* 💬 feat(bots): tell Bots to hand longer work to delegate_task

Bots now read one more line in their shared instructions, under "Coding
work". It tells them to hand work that takes more than a few tool calls to
delegate_task with a complete brief, say in one sentence what's running,
and end the turn. That keeps the chat for decisions and short results.

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

* ♻️ refactor(bots): cut the Bot setup update to its smallest form

This poteto pass trims the B and C change and its test without changing
what a Bot is told.

- The Tools section and its name list are gone. Claude already reopens its
  query with a new tool set, and other providers don't apply Bot tool
  limits (#326).
- Section hashes use Effect's Hash.string instead of the Digest service,
  which drops the extra layer requirement. The system prompt now reads its
  identity, SOUL.md and roster from the same sections the update compares.
- record logs its own failures, so the turn-end hook is a plain condition.
  A turn with no pending update also arms it, so a slash-command turn
  records the Bot's own edits too.
- The one behavior test reuses the primaryBot fixture and waitForIdle, and
  checks the four prompts in one assertion.

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

* 💡 chore(bots): fix a stale comment and name the Bot in a log line

Review 2 nits N1 and N2. The botUpdateSession comment now matches when the
session is set, and the record warning names the Bot.

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

* 🐛 fix(bots): link a Bot's skills only where its profile resolves

The merge with feat/bots moved #343's skill linking into readBotSetup, so
pendingBotUpdate linked skills on every turn for every provider. A Codex
Bot whose links failed would stop from its second turn. Linking goes back
beside readBotSetup in resolveBotHarnessProfile, as on feat/bots.

The skills notice still compares names from the Bot record. Its test moves
into BotService.test.ts's harness and shrinks to one behaviour test.

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

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
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