Skip to content

fix(assistant): limit discovery session tools to a read-only set - #6253

Closed
florianaltendorfer wants to merge 3 commits into
apache:mainfrom
florianaltendorfer:bounty-6250
Closed

florianaltendorfer wants to merge 3 commits into
apache:mainfrom
florianaltendorfer:bounty-6250

Conversation

@florianaltendorfer

@florianaltendorfer florianaltendorfer commented Oct 23, 2026 •

Copy link
Copy Markdown

Summary

Closes #6250.

The discovery session is registered as a background session and has no tool ceiling. On main, DISCOVERY_EXCLUDED_TOOLS already drops the known assistant write and control tools (MatterAdopt, MatterControl, MemoryIndexWrite, ...). That list is only applied to the assistant catalog, though, and only removes names that are on it. The composer still gives the session the full default Host catalog, including Bash, Edit, Write, subagents and mutating plugin tools.

The fix applies a read-only allowlist to the complete catalog in the Host:

  • The interactive run composer takes an optional session-scoped filterTools and applies it to the complete composed catalog, built-in tools included. execution-composition wires PersonalAssistantService.filterTools into it and into the tool-name listing. Most existing assistant filters only drop assistant names, so those sessions are unchanged. The exception is the quick-discovery worker. Its existing filter keeps only read tools and a few named ones, and it now applies to the built-in tools too. That worker therefore also loses Bash, Edit, Write, AskUserQuestion, Skill, the todo tools and other untyped or mutating built-ins. This matches its read-only role.
  • The initiative module's existing discovery filter keeps the DISCOVERY_EXCLUDED_TOOLS check and also limits assistant tools to the new DISCOVERY_TOOLS allowlist: DiscoveryContext, DiscoveryDraft, MatterOverview and the read-only Memory tools. All other tools go through the same read-only rule as Plan mode (read / web_read category). Read, Grep, Glob, WebFetch, WebSearch and plugin tools declared as read stay. Bash, Edit, Write, subagents, client capabilities and untyped or mutating plugin tools are removed.
  • Without Write, discovery would have no way to produce its operations.json draft, and the heartbeat would fail before judgement. The new DiscoveryDraft tool takes { notes } and writes only the current heartbeat's exploration result file. It rejects calls from any session other than the discovery session, and calls made while no discovery draft is open. The exploration wake prompt now points to it.
  • The AI SDK backend adds memory_remember / memory_extract after the composed catalog, so the session filter never saw them. PersonalAssistantService.admitsMemoryTriggers runs those two names through the same session filter. execution-composition only passes memoryExtraction to the backend when the filter keeps them, so discovery (and the quick-discovery worker, whose filter also drops untyped tools) gets no memory write triggers.

Verification

Extended the existing discovery test in assistant-bot.test.ts. It builds the real interactive composer with the built-in shell and edit tools plus foreign read, mutating and untyped tools, then checks the discovery session's catalog. Bash, Edit, Write and the foreign mutating tools are present without the filter and absent with it. Read, Grep, Glob, the foreign read tool and exactly DISCOVERY_TOOLS remain. The discovery heartbeat then submits its draft through DiscoveryDraft instead of writing the file directly, and the run reaches judgement and delivery. The test also checks that the discovery session does not admit the memory triggers, that the owner conversation still does, and that DiscoveryDraft is rejected outside an open discovery draft. The test fails without the change (including when DiscoveryDraft is dropped from the allowlist) and passes with it. Runtime-host build and typecheck, biome lint and format, npm run test:assistant, and node --test on assistant-bot, assistant-initiative-boundary, execution-model-composition, interactive-run-composer and matter-settlement-context all pass.

Not checked: a real desktop discovery session. Plugin tools are classified by their declared categoryHint, the same trust Plan mode uses.

AI use

Select exactly one:

  • No generative tool made a substantive contribution
  • Generative tooling made a substantive contribution

Tool(s) and scope: Claude Code (Claude Opus) traced the root cause and wrote the change and test.

Checklist

  • Tests cover the change and fail without it
  • Lint, format, typecheck and the affected suites pass locally

Does this PR entail a change in behavior?

  • Yes — described under Summary above
  • No

@github-actions github-actions Bot added the effort/S Under 100 readable lines label Oct 23, 2026

@Astro-Han Astro-Han left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Automated review notice: This comment was posted by an automated review agent. It is not an independent human review and does not replace one.

Reviewed 61873698bd60eb9e9095ad577018ac99ad24e658 against a509747d6779b27ee60e4d1ff044bc6ba8fcc5ca (5 files, +81/−2). I found no P0–P2 issues in this change.

The discovery-session filter now runs over the complete tool catalog in both execution composition and tool-name listing, after built-in, client and dynamic plugin tools have been assembled. In assistant/index-initiative/host.ts, assistant tools are limited to DISCOVERY_TOOLS; other tools use the existing Plan-mode read/web-read classification. The restriction is scoped to the stored discovery Session and retains its report/context tools.

Fresh dependencies and patches, normal root npm run build:test, 54 assistant/composer tests, changed-file Biome checks, ASF headers, and the protocol guard passed (epoch 227, no protocol/schema changes). The actual assistant-service/composer regression includes built-in Bash/Edit/Write plus foreign read, mutating and untyped tools. Restoring either the base composer or base initiative module exposes forbidden tools and prevents that regression from completing. This verifies catalog enforcement; I did not run an adversarial live model or a real third-party plugin.

The exact-head CI run required workflow authorization; after checking this source/test-only diff, I authorized that workflow run. Its test result is still pending, so this review does not claim CI is green.

@Astro-Han

Astro-Han commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Automated review notice: This comment was posted by an automated review agent. It is not an independent human review and does not replace one.

CI update for 61873698bd60eb9e9095ad577018ac99ad24e658: attempt 2 failed in ShellRun process crash recovery from running does not redispatch. The fixture reads ready.json with JSON.parse while its child writes that file directly; the reported error is Unexpected end of JSON input at that read. The fixture, npm dependency files and CI workflow are unchanged from this PR's base, whose main CI passed. I have not established a regression caused by this tool-filter change, or independently reproduced this particular CI failure on main.

I reran the failed job once. Attempt 3 has now passed on this same commit. The earlier pending-CI limitation is resolved; the first failure's cause has not been independently reproduced on main.

@Astro-Han Astro-Han left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Automated review notice: This comment was posted by an automated review agent. It is not an independent human review and does not replace one.

Reviewed the complete five-file diff at 2097d051717f51c2b4345ce245812310ab506204 against current main 15d0a0dd1 (84 additions, 7 deletions), and compared the rebased commit series with 61873698. The previous merge conflict is resolved. The rebase preserves main's mandatory filter registration and DISCOVERY_EXCLUDED_TOOLS restriction, then applies the complete-catalog read-only filter. It also retains MatterOverview, whose existing implementation is a read operation, alongside the discovery report/context and permitted Memory tools.

I found no new P0–P2 issue in this revision. The actual assistant service and interactive composer produce a discovery catalog containing Read/Grep/Glob, the foreign read tool, MatterOverview and the allowed report/Memory tools, while excluding Bash/Edit/Write, mutating or untyped foreign tools and assistant mutation tools. Loading only main's composer or only main's initiative module re-exposes Bash and other prohibited tools and makes the same catalog check fail. Those checks run outside the worker callback so a forbidden catalog produces a direct assertion failure rather than a caught callback error followed by a timeout.

A fresh patched install and the normal clean root build:test passed. Of 114 assistant, initiative-boundary, execution-composition, composer and Matter-settlement tests, 113 passed. The remaining live Bash sandbox case fails because this environment reports Command sandbox is required but unavailable on platform linux. An isolated rerun with main's execution-composition implementation produces the same error; this does not establish a regression caused by the PR. Changed-file Biome, diff checks and the protocol guard passed. There is no protocol/schema change, and the current epoch remains 228. The static merge is clean.

Current-head CI 40064218014 initially required fork-workflow authorization. After checking this source/test-only diff, I authorized that CI workflow; its test job is now running. This review does not claim CI success or release readiness. I did not run a live discovery model, a real third-party plugin, native Desktop E2E or the full workspace suite. Plugin tool classification still trusts the declared category, as Plan mode does.

@florianaltendorfer
florianaltendorfer force-pushed the bounty-6250 branch 2 times, most recently from 5aa45ba to fe8b646 Compare October 26, 2026 10:16
@florianaltendorfer

Copy link
Copy Markdown
Author

Automated reply from the contributor's coding agent.

Rebased onto main (conflict in execution-composition.ts). Checking the rebased change turned up two gaps in the allowlist, fixed in fe8b646: with Write, Edit and Bash filtered out, discovery had no way left to write its operations.json draft, so a new DiscoveryDraft tool writes only the current heartbeat's exploration result file; and the backend adds the memory_remember / memory_extract triggers after the session filter, so memoryExtraction is now only passed when the filter keeps them. I've updated the description to match, sorry it lagged behind the push.

@florianaltendorfer

Copy link
Copy Markdown
Author

Automated reply from the contributor's coding agent.

Closing this: #6250 was fixed in #6256, and the TypeScript runtime-host code this PR changed has since been removed from main.

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

Labels

effort/M Under 500 readable lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(assistant): discovery session can mutate conversation memory indexes and adopt unassigned Matters

2 participants