Skip to content

fix(runtime): keep tool_search activations for the Session lifetime - #6028

Merged
Colafornia merged 2 commits into
apache:mainfrom
Master-Frank:cursor/keep-tool-search-activation-6adb
Oct 10, 2026
Merged

Colafornia merged 2 commits into
apache:mainfrom
Master-Frank:cursor/keep-tool-search-activation-6adb

Conversation

@Master-Frank

Copy link
Copy Markdown
Contributor

Summary

tool_search activations lived on the per-send Turn, so the next Turn started with an empty provider tool list and missed the prompt cache. This PR keeps the activation map on the Session backend. tool_search only adds names; Turn end and compaction do not clear them.

A rebuilt backend starts empty. Activations are not written to SQLite. Direction 2 stays with #1382; Direction 3 (request_sandbox_boundary as a stable required tool) is a later PR.

Refs #5879

Verification

  • The later-Turn test fails when the map is per-send (new Map()) and passes when Turns share the Session map.
  • node --test packages/runtime/dist/__tests__/tool-availability.test.js packages/runtime/dist/__tests__/deferred-tools-backend.test.js: 37 passed.
  • npm --workspace @maka/runtime run test:dist: 3751 passed, 13 skipped, 0 failed.
  • biome format / biome lint clean for the changed files.
  • npm --workspace @maka/runtime run typecheck passed.
  • Did not run root npm test, knip, or the Desktop app.

AI use

Select exactly one:

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

Tool(s) and scope: A coding assistant implemented the Session-scoped activation map and wrote the regression tests.

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

@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 range: 560a27c1f..1af20d1b (one commit, first review, no prior findings).

The PR moves the tool_search activation map from the per-send AiSdkTurn to the AiSdkBackend instance, so activations last as long as the backend generation. I traced the lifecycle. RuntimeKernel keeps one backend generation per Session across sends and drops it only on invalidation or disposal, so the fix reaches the Host path. prepare() still drops activations whose contribution key no longer matches (a replaced Plugin generation or an unbound tool), so a shared map cannot surface stale schemas. Boundary filtering still runs after prepare(). Nothing else reads turn.activeTools. The new backend test covers a later Turn and a rebuilt backend, and it fails with a per-send new Map().

No P0-P2 findings.

P3 - concurrent Runs now share activations. The kernel allows concurrent Runs on one Session backend (activeRuns is a set). With this change, a tool_search in Run A also adds the schema to Run B's next step, because computeActive() reads the shared map. Activation still only adds tools, and gating follows the same set, so I found no correctness or authority problem. It is a behavior change, though: before, a sibling Run's provider prefix could not change mid-Run because of another Run. The PR text and code comments do not mention it, and no test covers it. The unchanged unit test name activation maps isolate overlapping and subsequent turns (tool-availability.test.ts:452) now describes a property the backend no longer has. Please mention the cross-Run sharing in the field comment and rename or reword that test.

P3 - possible conflict with #6029. Both PRs edit packages/runtime/src/__tests__/deferred-tools-backend.test.ts in the same hunks: each adds a field to the backend() helper input, and each inserts new tests after the same test. A git merge-tree of the two heads conflicts in that file only. ai-sdk-turn.ts and tool-availability.test.ts auto-merge. The runtime changes work together: the boundary tool from #6029 goes through requiredToolNames and never writes to the activation map that this PR makes Session-scoped. Whichever PR lands second needs a small test-file rebase.

No protocol or persisted-schema files are touched (activations are not written to SQLite), so there is no epoch impact.

Mergeability: merges cleanly into current main (c11a5336). CI on 1af20d1b: label and test pass.

request.orchestration ??
resolveEffectiveOrchestration(deps.backend.header.orchestrationMode, undefined);
this.toolRuntime = deps.createToolRuntime(this);
this.activeTools = deps.sessionActiveTools;

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.

P3: concurrent Runs on the same Session backend now share this map. A tool_search in one Run adds the schema to a sibling Run's next step. This looks intended, but please mention it in the sessionActiveTools comment and reword the unit test activation maps isolate overlapping and subsequent turns, which no longer describes backend behavior.

tool_search activations lived on the per-send Turn, so the next Turn
started with an empty provider tool list and missed the prompt cache.
Share the activation map on AiSdkBackend. tool_search only adds names;
Turn end and compaction do not clear them. A rebuilt backend starts
empty; activations are not persisted.

Refs apache#5879

Generated-by: Cursor
…nt Runs

A Session backend can hold several concurrent Runs. They share the
activation map, so a search in one Run is visible on a sibling Run's next
step. Mention that in the field comment and rename the prepare() isolation
test so it no longer describes backend Turns.

Refs apache#5879

Generated-by: Cursor
@cursor
cursor Bot force-pushed the cursor/keep-tool-search-activation-6adb branch from 1af20d1 to 19f449f Compare October 9, 2026 14:45
cursor Bot pushed a commit to Master-Frank/maka that referenced this pull request Oct 9, 2026
Required names are already on the provider list. Leave them out of the
search inventory and ranking so an exact-name search does not activate a
tool that is already visible.

Align the deferred-tools backend helper with apache#6028 so the two PRs rebase
without a test-file conflict.

Refs apache#5879

Generated-by: Cursor
@Master-Frank

Copy link
Copy Markdown
Contributor Author

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 range: 560a27c1f..1af20d1b (one commit, first review, no prior findings).

The PR moves the tool_search activation map from the per-send AiSdkTurn to the AiSdkBackend instance, so activations last as long as the backend generation. I traced the lifecycle. RuntimeKernel keeps one backend generation per Session across sends and drops it only on invalidation or disposal, so the fix reaches the Host path. prepare() still drops activations whose contribution key no longer matches (a replaced Plugin generation or an unbound tool), so a shared map cannot surface stale schemas. Boundary filtering still runs after prepare(). Nothing else reads turn.activeTools. The new backend test covers a later Turn and a rebuilt backend, and it fails with a per-send new Map().

No P0-P2 findings.

P3 - concurrent Runs now share activations. The kernel allows concurrent Runs on one Session backend (activeRuns is a set). With this change, a tool_search in Run A also adds the schema to Run B's next step, because computeActive() reads the shared map. Activation still only adds tools, and gating follows the same set, so I found no correctness or authority problem. It is a behavior change, though: before, a sibling Run's provider prefix could not change mid-Run because of another Run. The PR text and code comments do not mention it, and no test covers it. The unchanged unit test name activation maps isolate overlapping and subsequent turns (tool-availability.test.ts:452) now describes a property the backend no longer has. Please mention the cross-Run sharing in the field comment and rename or reword that test.

P3 - possible conflict with #6029. Both PRs edit packages/runtime/src/__tests__/deferred-tools-backend.test.ts in the same hunks: each adds a field to the backend() helper input, and each inserts new tests after the same test. A git merge-tree of the two heads conflicts in that file only. ai-sdk-turn.ts and tool-availability.test.ts auto-merge. The runtime changes work together: the boundary tool from #6029 goes through requiredToolNames and never writes to the activation map that this PR makes Session-scoped. Whichever PR lands second needs a small test-file rebase.

No protocol or persisted-schema files are touched (activations are not written to SQLite), so there is no epoch impact.

Mergeability: merges cleanly into current main (c11a5336). CI on 1af20d1b: label and test pass.

Thanks. Concurrent Runs on one Session backend do share the map; a search in one Run is visible on a sibling Run's next step. That is intended (activation only adds schemas). The sessionActiveTools comment now says so, and the prepare() isolation test is renamed so it no longer describes backend Turns.

@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.

Incremental review: 1af20d1b (our last reviewed head) to 19f449f5. The branch was rebased onto current main. git range-diff shows the original commit unchanged (1af20d1b = 5687ef3d), plus one new commit, 19f449f5.

The new commit addresses both earlier P3s.

  • The sessionActiveTools doc comment (ai-sdk-backend.ts) and the AiSdkTurn class comment now state that concurrent Runs on the same backend share the activation map, so a search in one Run is visible on a sibling Run's next step. That makes the cross-Run behavior an explicit, documented choice.
  • The stale unit test is renamed to "distinct activation maps isolate overlapping prepares", which matches what it actually checks (separate maps passed to prepare), not a backend guarantee.
  • The test helper gains extraTools. That is the same field #6029 adds, which is why the two branches now merge cleanly with each other (git merge-tree of both heads is clean).

Findings: None at P0-P3 in the delta. There is still no test that exercises two concurrent Runs sharing activations. That is optional, now that the behavior is documented.

Status: MERGEABLE. The fork CI run on this head was waiting for approval, and I approved it after confirming the PR changes no .github files. Results were pending at posting time. No protocol files, so there is no epoch impact.

@github-actions github-actions Bot added effort/M Under 500 readable lines and removed effort/S Under 100 readable lines labels Oct 10, 2026

@Colafornia Colafornia left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Approved.

Keeping activated tools on the Session backend avoids unnecessary tool-list resets between Turns. The change is small and focused, regression tests cover cross-Turn retention and backend reset, and CI passes. No blocking issues found.

@Colafornia
Colafornia merged commit 49c3ecc into apache:main Oct 10, 2026
1 check passed
Colafornia pushed a commit that referenced this pull request Oct 10, 2026
…ions (#6029)

* fix(runtime): keep request_sandbox_boundary visible in sandboxed Sessions

Host binds the widening tool only when the Session is not Full access, but
tool_search still deferred it. Models then searched for it, activated
neighbors, and missed the prompt cache. Pass it through requiredToolNames
whenever it is bound so the schema stays on the provider list for the
whole Session, without depending on a live boundary prompt.

Refs #5879

Generated-by: Cursor

* fix(runtime): omit required tools from the tool_search inventory

Required names are already on the provider list. Leave them out of the
search inventory and ranking so an exact-name search does not activate a
tool that is already visible.

Align the deferred-tools backend helper with #6028 so the two PRs rebase
without a test-file conflict.

Refs #5879

Generated-by: Cursor

---------

Co-authored-by: Cursor Agent <[email protected]>
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.

4 participants