Skip to content

Bound native agent knowledge lookups to scoped API pages - #5673

Queued
kwakayama wants to merge 12 commits into
mainfrom
chore/bounded-framework-knowledge-20261204
Queued

kwakayama wants to merge 12 commits into
mainfrom
chore/bounded-framework-knowledge-20261204

Conversation

@kwakayama

@kwakayama kwakayama commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Native managed agents with knowledge: true currently build a local manifest before answering a knowledge tool call. This routes that ordinary hosted path through scoped API search pages, so the SDK does not hydrate the full project manifest for each lookup.

The target comes only from the verified native invocation and its sealed persisted policy. A private single-use grant binds the project, run, agent and API origin; model arguments cannot retarget it. Responses are bounded to 256 KiB with strict schema validation, bounded result counts, a deadline, cancellation and no unbounded fallback after the native path is selected. API #7922 supplies the persisted ROOT lookup behavior.

Scope is the ordinary native knowledge: true path. Explicit custom selectors, exact-document reads and shared-source credentials are separate integration work. Staging latency and inference savings remain unmeasured.

The repair batch moves network-facing lookup tests into the integration suite, fixes native CryptoKey inspection in the generated npm package, and includes that existing integration test in the current-head source coverage collector. The 1024-bit RSA fixture intentionally verifies weak-key rejection; code-scanning alert #489 is triaged as used in tests, with the negative assertion retained.

Validation at b7149e8998: all normal pinned Deno 2.9.7 pre-push checks pass, and required uncommitted/fresh-base reviews are clear. Instrumented local hosted-lookup coverage is 343/375 lines (91.47%) and 156/180 branches; hosted Sonar must verify the new head. The preceding head 43b4cb8 passed CI npm compatibility and installed-package proofs; the two-line coverage repair changes no production code. Current-head CI is pending. Base main is 3000851. No dependency or package version changes.

Follow-up at efb02081e1: merged current main. The validateBoundedFrameworkInput import moved below the @module JSDoc in src/knowledge/index.ts, so the generated knowledge.md API reference keeps its description and example. The installed-agent knowledge integration test now calls knowledge: true with { query } only and asserts the search page returns knowledge/claim.md, because this PR no longer exposes lookup_target to the model.

Bind ordinary native knowledge:true execution to an operator-verified
control-plane ingress and matching signed native project/run/agent token.
Use the persisted run scope at the scoped search endpoint, bound decoded
responses, and refuse native errors without a manifest fallback. Preserve
legacy custom, shared-source and unrelated hosted execution while exposing
an immutable query-only framework tool contract. Verify the native bearer
with private byte parsing and captured WebCrypto so mutable prototype
hooks cannot intercept token segments during validation.

Constraint: Scoped native source inheritance requires API PR 7922
Rejected: Caller credentials or selector JSON as authority | cannot establish persisted ROOT binding
Directive: Preserve explicit native refusal separately from unrelated legacy protocols; custom and source-release bounded execution remain open
Confidence: high
Scope-risk: moderate
Tested: 156 focused test groups with 400 steps; 67 documentation groups with 295 steps; cached frozen typecheck; lint and module/dependency boundaries
Not-tested: Live hosted execution, staging retrieval matrix, SDK publication, custom/shared bounded transfer
Merge main's filesystem cache and reserved-data invalidation fixes into
the published bounded-knowledge branch. Preserve the verified native
knowledge capability and its scoped API requests while incorporating
current snapshot, folder and overlapping-poke handling.

Constraint: Published branch history must remain intact
Rejected: Rebase published feature history | ordinary merge preserves the reviewed source commit
Confidence: high
Scope-risk: moderate
Directive: Keep custom and shared-source bounded retrieval gaps explicit; generated hook lock output remains outside this merge
Tested: Deno 2.9.7; 159 focused groups with 559 steps; cached frozen typecheck; changed-file formatting/lint; module/dependency boundaries; required uncommitted review
Not-tested: Hosted execution, staging retrieval matrix, SDK publication
@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:44:07.869351Z efb0208 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

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

@github-actions

github-actions Bot commented Dec 4, 2026

Copy link
Copy Markdown

@codex review

Copy link
Copy Markdown
Contributor Author

Score: 66/100. Careful, well-tested bounded lookup, but it fails closed with no rollout guard, adds cost to every control-plane request, and narrows the local tool contract.

Strengths

  • The design is tight. The lookup is bound to the signed ingress body, the grant is single-use and stored in a private weak store, model-supplied project_reference/lookup_target are rejected, responses are capped at 256 KiB with strict schemas and pagination checks, and there is a 15 s deadline and the reader is cancelled. hosted-runtime-lookup.test.ts adds 858 lines of coverage, including replay, clone, redirect, cancellation and byte-limit cases.
  • The scope is stated plainly. Custom selectors and shared-source agents stay on the manifest path, and the PR and the guide both say so.

Concerns

  1. Fail-closed with no escape hatch (rollout risk). When the handler enters the context but prepareHostedKnowledgeLookup returns null, createSearchKnowledgeTool throws Verified hosted knowledge binding is required (src/knowledge/index.ts:1422-1428). That happens on a missing OAUTH_PUBLIC_KEY, a pinned key mismatch, a missing x-token, an unexpected tokenUse, or a serviceAccountId that differs from SERVICE_ACCOUNT_VERYFRONT_SERVER_ID. Any of these breaks knowledge for every ordinary knowledge: true hosted agent, and the PR says staging is unmeasured. Gate the new path behind a host flag, or fall back to the existing manifest path when the host prerequisites are absent rather than when the grant is forged. Also log a sanitized reason when the grant is refused. Today every refusal is a silent return undefined, so on-call cannot tell which prerequisite failed.
  2. Cost added to every control-plane request. verifyControlPlaneRequest now always awaits a second operator JWS verification, a full JSON parse of the body, and an RSA JWT import and verify (control-plane-auth.ts:421-440). This also runs for the cancel, resume and project-run-execute handlers, which never consume the grant. Only the agent-stream handler does. Prepare the grant lazily in consume…, or have the stream handler opt in, and reuse the operator verification result that the platformToolDependencies branch already computes.
  3. Two sources of truth for knowledge. The handler activates on runtimeBaseAgent.config.knowledge === true. The grant checks the body's agentConfig.knowledge and accepts undefined. If they diverge (for example, the body carries a selector while the resolved config is true), the result is a hard tool failure instead of the manifest path. Derive both decisions from the same resolved value, or pass the resolved value into the consume step.
  4. Public contract narrowed for local agents too. createAgentKnowledgeTool never sets projectDir, so frameworkSearch is true for local knowledge: true agents as well. Those agents lose lookup_target exact reads and project_reference. The guide documents this, but it is a behavior change outside the hosted fix and has no explicit local regression test or changelog note. Also, the JSON schema caps shard_index at 7 while inputSchema allows up to MAX_SAFE_INTEGER. Align the two.
  5. Conventions.
    • The new code throws plain Errors instead of using defineError registry entries, as AGENTS.md requires.
    • The catch-all Bounded hosted knowledge request failed (${phase}) drops the cause and turns caller aborts into a generic error. Rethrow AbortError when the abort comes from signal.
    • knowledge/index.ts now imports internal-agents/control-plane-auth at runtime through verified-hosted-knowledge-context.ts. That is an inverted layer dependency worth a second look even though the boundary checks pass.
    • hosted-runtime-lookup.audit.md sits in src/ and cites internal API PR numbers, commit SHAs and an "SDK 26646" ID. Move it to the PR description or internal docs.

Recommended before merge: items 1-3. Items 4-5 can follow, but please confirm item 4 is intended.


Generated by Claude Code

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: ee6a0b0f2b

ℹ️ 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".

@kwakayama
kwakayama marked this pull request as draft December 4, 2026 10:44
The new tests exercise signed invocation handlers, process environment and mocked outbound transport. Classify them as integration coverage instead of growing the semantic unit audit exceptions. All assertions remain intact; only the three local imports change.

Constraint: New effectful tests cannot grow the semantic audit migration baseline
Rejected: Add a semantic disposition exception | the suite already exercises integration boundaries
Tested: Relocated integration suite passed 15 steps; semantic audit and formatting passed; required uncommitted review clear
Scope-risk: narrow
@codecov

codecov Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

DNT rewrites the bare CryptoKey reference to its crypto shim, which does not export that constructor. Capture the host constructor through the merged global object and validate its prototype before retaining the native algorithm getter. This preserves secret-safe key inspection and avoids the npm root import crash.

Constraint: DNT supplies crypto without a CryptoKey constructor export
Tested: Pinned Deno 2.9.7 hosted integration suite passed 15 steps; required uncommitted review clear; Node getter check passed
Not-tested: Full npm build is still running at commit time
Scope-risk: narrow
Capture the guarded getter in a separate immutable binding so the complete SDK typecheck retains its non-optional function type inside token verification.

Constraint: Preserve the native getter and fail-closed bootstrap.
Tested: Pinned Deno 2.9.7 src/index.ts typecheck; focused 15-step review suite; formatting and diff checks.
Confidence: high
Scope-risk: narrow
@kwakayama
kwakayama marked this pull request as ready for review December 4, 2026 11:18
@github-actions

github-actions Bot commented Dec 4, 2026

Copy link
Copy Markdown

@codex review

@kojiwakayama
kojiwakayama marked this pull request as draft December 4, 2026 11:26

kwakayama commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor Author

Not merge-ready at b7149e8. Coverage wiring is published and all normal pre-push checks pass, but hosted review identified three runtime fixes still required: bind echoed page parameters to the request, revoke private lookup capability when the run settles, and enforce framework input bounds before every dispatch path. These are being repaired together with failing-before regression tests; this PR is draft during that work. The intentionally weak RSA fixture remains negative-test coverage, separate from those runtime findings.

The hosted knowledge security suite lives outside the unit coverage roots.
Include its genuine execution in the checked-out-source collector so the
existing receipt and Sonar merge receive its coverage on this PR head.

Constraint: The reusable public-pool workflow executes from main, so changing its test list would not repair current PR coverage.
Rejected: Move integration tests into unit roots or weaken coverage exclusions | Preserve the semantic test boundary and existing coverage floor.
Confidence: high
Scope-risk: narrow
Tested: Pinned Deno 2.9.7 hosted integration 15 steps with coverage; actual source coverage reporter; workflow regression RED then 35 steps GREEN; lint and format; uncommitted Astra review clear.
Not-tested: Remote Sonar result awaits normal CI.

@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: 43b4cb8d5c

ℹ️ 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".

Comment thread src/knowledge/hosted-runtime-lookup.ts Resolved
Comment thread src/knowledge/hosted-runtime-lookup.ts Resolved
Comment thread src/knowledge/index.ts Resolved
@kwakayama
kwakayama marked this pull request as ready for review December 4, 2026 11:50
@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. 🎉

Reviewed commit: b7149e8998

ℹ️ 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".

@kwakayama
kwakayama marked this pull request as draft December 4, 2026 11:53
…unds

The framework now validates its advertised bounded inputs before any local,
legacy source or hosted dispatch. Native response echoes are checked against
explicit request values and previously issued opaque cursor defaults, without
decoding cursors or guessing omitted continuation fields.

Private run capabilities revoke on settlement and abort outstanding retrievals.
Native response callbacks retain their scope until body cleanup; settlement
retires lookup access while preserving buffered terminal events.

Constraint: Signed opaque cursors resolve omitted query, limit and shard fields at the API
Rejected: Decode caller cursors or revoke at Response construction | either breaks legitimate native continuations or streaming callbacks
Scope-risk: moderate
Directive: Preserve shared-source dual-authority, raw exact-document paths and cursor-restored shard defaults when integrating this lineage
Tested: Three initial RED regressions; focused integration 9 tests/22 steps and unit 9 tests/43 steps; pinned Deno 2.9.7 typecheck, lint, dependency/module boundaries; focused capture modules 90.5% line coverage
Not-tested: Live staging, provider inference and package publication
Related: #5673
The API restores a continuation's original limit and shard tuple even if a
caller repeats different paging fields. Validate known issued cursors against
that resolved tuple, while keeping query binding and initial or unknown
cursor explicit-field checks intact. Opaque cursor bytes remain untrusted.

Constraint: API lookupKnowledgeManifest gives cursor state precedence over repeated limit and shard fields
Rejected: Treat ignored repeated paging fields as new defaults | rejects valid API continuations
Tested: Source-backed issued-cursor conflicting-limit/shard RED-to-GREEN regression; pinned Deno 2.9.7 focused suite 5 tests/23 steps, typecheck and lint
Directive: Never decode opaque cursor bytes as local authorization or substitute SDK cache state for native current-run authentication
Not-tested: Live staging and publication
Related: #5673 (comment)
A cursor remains authoritative for its paging tuple even when this invocation
has not seen it or the bounded local cache has evicted it. Only a cached
validated tuple can supply local paging expectations on continuation; repeated
request fields cannot replace the API's sealed defaults. Initial request
binding, repeated query checks and raw framework input bounds stay intact.

Constraint: API cursor-state precedence does not depend on SDK cache membership
Rejected: Bind uncached cursor paging to repeated caller fields | refuses valid signed continuations
Tested: Actual framework unknown-cursor and 129-successor eviction RED-to-GREEN regressions; pinned Deno 2.9.7 focused suite 6 tests/25 steps, typecheck and lint
Directive: Keep opaque cursors opaque and rely on native authenticated API validation for uncached paging defaults
Not-tested: Live staging and publication
Related: #5673 (comment)
Integrate the reviewed main credential-sealing lineage before final knowledge compatibility checks.

Constraint: Native knowledge access must retain current ingress credential semantics
Tested: Incoming source has no overlap with the bounded knowledge repair
Directive: Re-run native hosted and credential ingress regression suites before publication
@kojiwakayama
kojiwakayama marked this pull request as ready for review December 4, 2026 22:39
@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. Chef's kiss.

Reviewed commit: efb02081e1

ℹ️ 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
Any commits made after this event will not be merged.
@sonarqubecloud

sonarqubecloud Bot commented Dec 4, 2026

Copy link
Copy Markdown

This branch has not been deployed

No deployments
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.

3 participants