Skip to content

fix(agent): show knowledge search from the first deferred step - #5681

Merged
kojiwakayama merged 5 commits into
mainfrom
fix/deferred-knowledge-tool-bootstrap
Dec 4, 2026
Merged

kojiwakayama merged 5 commits into
mainfrom
fix/deferred-knowledge-tool-bootstrap

Conversation

@kojiwakayama

Copy link
Copy Markdown
Contributor

Problem

With toolLoading: "deferred", an agent that has a knowledge scope saw only the skill loader and veryfront__tool_search on its first step. veryfront__search_knowledge was authorized but deferred, so the agent started almost every answer with a tool search for its own knowledge tool.

Cause

  • Hosted runs: src/agent/hosted/chat-runtime-tool-assembly.ts builds the startup tool set (modelVisibleToolNames) from the skill loader, configured bootstrapTools, the optional startup tools and veryfront__tool_search. The knowledge search tool was never added to that set. An existing test asserted that step one showed only ["veryfront__tool_search"], which was the bug itself.
  • Direct runs (agent.generate / agent.stream): no host supplies startup names, so src/agent/runtime/agent-runtime-step.ts used only the trusted skill loader. Knowledge search stayed behind tool search there too.
  • Live steering refresh (default-project-steering-refresh.ts): when it rebuilt the tool inventory, it kept only skill-loader names. After a refresh, the prompt could say knowledge search was unavailable even though its schema was loaded.

Change

  1. Hosted assembly: in deferred mode, when the knowledge source lists veryfront__search_knowledge, the name is added to the optional startup names. That listing has already applied the allow and deny selectors. The existing optional-startup path still requires the name to be in the authorized catalog and respects provider slot reservation. Nothing changes when knowledge is off, the tool is denied, it is outside the allowed tools, or loading is eager.
  2. Direct runtime: when the host supplies no startup names, the agent's own knowledge search joins the optional startup names in deferred mode. A new helper, resolveTrustedKnowledgeToolName in knowledge-tools.ts, picks it by provenance only: the framework knowledge tool in a tool record, or the framework knowledge source behind tools: true. A project tool or source with the same name never qualifies. The step must still authorize the tool, and the provider schema limit must leave room for it. Host-supplied startup names are not changed.
  3. Steering refresh: startup tools already shown at the start of the run, except veryfront__tool_search, stay in the refreshed inventory while the refreshed catalog lists them. This covers configured bootstrapTools as well as knowledge search. Membership is checked against the catalog before the provider schema cap, because deferred mode authorizes the whole catalog. When the assembly supplied no visible-tool list, behaviour is unchanged.
  4. Docs (docs/guides/project-knowledge.md): toolLoading: "deferred" is removed from the knowledge example, and one sentence now says knowledge search is visible from the first step under deferred loading.

Tests

All runs used deno task test:file on a single file.

  • src/agent/hosted/chat-runtime-tool-assembly.test.ts
    • New test: "shows authorized knowledge search on the first deferred step". It covers four cases: knowledge on (visible), and knowledge off, tool denied, and tool outside the allowed tools (all not visible). In every case veryfront__create_file stays behind tool search.
    • One existing assertion is corrected. It used to expect ["veryfront__tool_search"] alone.
    • Without the fix, filtered to knowledge: 9 passed, 2 failed (the new test and the corrected assertion). With the fix: 82 passed (32 steps), 0 failed.
  • src/agent/runtime/agent-runtime-step.test.ts
    • New group: "direct-run knowledge search in deferred mode". It covers:
      • a framework knowledge tool in a tool record (visible);
      • the framework knowledge source behind tools: true (visible);
      • a project tool or source with the same name (deferred);
      • a tool the step excludes (hidden);
      • host-supplied startup names (left as given).
    • Without the fix: the two "visible" cases failed. With the fix: 1 passed (54 steps), 0 failed.
  • src/agent/hosted/default-project-steering-refresh.test.ts
    • New test: knowledge search stays in the refreshed inventory while it is listed, and is dropped once it is not.
    • A third case reserves all but one provider schema slot.
    • Without the membership change, the third case failed: veryfront__search_knowledge was missing. With the change: 1 passed (18 steps), 0 failed.
  • deno fmt and deno lint on the changed files: clean.

Review round

  • Docs claim was wider than the fix. The new guide sentence promised the behaviour for every deferred run, but the first commit only covered hosted runs. Fixed at the cause: the direct runtime path now shows knowledge search too (change 2), so the sentence holds for both paths. A regression test fails without that fix.
  • Refresh checked startup tools against the capped catalog. With a catalog larger than the model's tool limit, a late-sorting startup tool could drop out of the refreshed inventory while its schema stayed loaded. Fixed by checking membership before the cap (change 3), with a regression case.

Not verified

  • Typecheck, the full unit and integration suites, and docs checks are left to CI. Local test runs use --no-check, so types were not checked locally.
  • Neighbouring test files that mention knowledge or tool search were not run locally: default-chat-runtime.test.ts, chat-preparation.test.ts, factory.test.ts and the rest of runtime/*.test.ts.
  • Not measured in a running deployment: tool calls per answer before and after.

In deferred tool loading, an agent with a knowledge scope saw only the
skill loader and tool search on its first step, so every answer started
with a search for veryfront__search_knowledge. Add the knowledge search
tool to the optional startup schemas when the knowledge source lists it.
The name still passes the allow and deny selectors and the authorized
catalog check, and the live steering refresh keeps it in the tool
inventory while the refreshed catalog lists it.

Drop toolLoading: "deferred" from the knowledge guide example.
A direct agent run (agent.generate or agent.stream) with a knowledge
scope and deferred tool loading supplies no host bootstrap names, so the
runtime bootstrapped only the trusted skill loader and kept
veryfront__search_knowledge behind tool search.

When the host supplies no names, add the agent's own knowledge search to
the optional startup names. It is chosen by provenance: the framework
knowledge tool in a tool record, or the framework knowledge source behind
tools: true. A project tool or source with the same name never
qualifies. The optional startup path still requires the step to authorize
the tool and the provider schema limit to leave room for it.
The live steering refresh kept a startup tool in the deferred inventory
only if the provider-capped catalog still held it. Deferred mode
authorizes the whole catalog, so a large catalog could drop a late-sorting
startup tool such as knowledge search from the refreshed inventory while
its schema stayed loaded. Check membership against the uncapped catalog.
@github-actions

github-actions Bot commented Dec 4, 2026

Copy link
Copy Markdown

📦 Client bundle boundary

Entrypoint Modules Source size Server leaks
src/index.client.ts 66 371 KiB ✅ 0
src/react/components/Head.tsx 5 74 KiB ✅ 0
src/react/router/index.tsx 5 74 KiB ✅ 0
src/react/context/index.tsx 5 74 KiB ✅ 0
src/react/fonts/index.ts 6 81 KiB ✅ 0
src/react/components/ui/index.ts 111 720 KiB ✅ 0
src/react/components/ui/adapter/contract.ts 1 18 KiB ✅ 0
src/react/components/ui/icons/index.ts 3 17 KiB ✅ 0
src/chat/index.ts 305 2055 KiB ✅ 0
src/chat/ag-ui.ts 61 464 KiB ✅ 0
src/chat/protocol.ts 1 11 KiB ✅ 0
src/chat/types.ts 46 248 KiB ✅ 0
src/chat/message-prep.ts 68 519 KiB ✅ 0
src/markdown/index.ts 6 30 KiB ✅ 0
src/mdx/index.ts 2 2 KiB ✅ 0
src/agent/identity-contracts.ts 1 3 KiB ✅ 0
src/schemas/index.ts 43 222 KiB ✅ 0
src/platform/env.ts 5 55 KiB ✅ 0
src/workflow/claude-code/react/index.ts 9 91 KiB ✅ 0
src/events/index.ts 37 631 KiB ✅ 0
src/events/ag-ui/public.ts 36 624 KiB ✅ 0
src/run-events/index.ts 54 323 KiB ✅ 0

A server module in a client graph aborts hydration in the browser. New leaks fail CI; known leaks are tracked in scripts/lint/client-bundle-baseline.json to burn down.

@kojiwakayama
kojiwakayama marked this pull request as ready for review December 4, 2026 21:29
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 4, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-04T22:13:44.765011Z a21ade3 Manual request
ℹ️ 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.

@github-actions

github-actions Bot commented Dec 4, 2026

Copy link
Copy Markdown

@codex review

Deferred tools-true agents now show their scoped knowledge search up front,
so the factory tests assert one schema at step 0 and a completed scoped call.
Type the refresh test's tool parameters so the schema type stays literal.
@github-actions

github-actions Bot commented Dec 4, 2026

Copy link
Copy Markdown

@codex review

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

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@codecov

codecov Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.26027% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...c/agent/hosted/default-project-steering-refresh.ts 94.11% 1 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

…ools

The steering refresh decided whether tool search was needed from the capped
catalog while retaining startup schemas from the uncapped one. With one
provider slot, knowledge search could take it and drop tool search, leaving
other authorized deferred tools unreachable.

Deferred availability now uses the uncapped refreshed catalog, and retained
startup schemas are best effort: like the startup assembly, they leave room
for tool search and one discovered schema, so tool search wins the slot.
@github-actions

github-actions Bot commented Dec 4, 2026

Copy link
Copy Markdown

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: a21ade3e28

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@kojiwakayama
kojiwakayama added this pull request to the merge queue Dec 4, 2026
@sonarqubecloud

sonarqubecloud Bot commented Dec 4, 2026

Copy link
Copy Markdown

Merged via the queue into main with commit d606e52 Dec 4, 2026
445 checks passed
@kojiwakayama
kojiwakayama deleted the fix/deferred-knowledge-tool-bootstrap branch December 4, 2026 22:48
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