Skip to content

perf(mcp): disclose retained-view guidance on demand - #9353

Closed
kaoru0822-kitauji wants to merge 10 commits into
mainfrom
codex/mcp-context-guidance
Closed

kaoru0822-kitauji wants to merge 10 commits into
mainfrom
codex/mcp-context-guidance

Conversation

@kaoru0822-kitauji

@kaoru0822-kitauji kaoru0822-kitauji commented Nov 8, 2026 •

Copy link
Copy Markdown
Collaborator

inspect_analysis_view advertises 17,453 bytes of cross-domain instructions. Keep shared source/Evidence/paging rules inline (1,026 bytes, 94.1% smaller) and serve selectors through the existing guidance tools.

Part of #9347 / #5861. Stacked on #9351, including its latest verification commit. Compiled documentation shares guidance digest/index/locator/capacity ownership. Hot/cold discovery searches the same content and includes it in policy identity. Canonical validation, Evidence, family exclusions and complete exports remain authoritative. No skill-source or managed skill inventory changes.

Deferred and combined verification

Head 9fd5eca98; Node 24.22.1 / npm 11.16.0 / macOS arm64, real MCP JS SDK 2.3.1 clients.

  • 12 public stdio configurations pass: legacy/modern × full/compact/off outputs × full/hot-cold catalogs, with pairwise full/compact inputs. Full-output unscoped startup is observed deferred; compact/off output intentionally compose eagerly. Module observations prove discovery stays deferred and the first domain call materializes.
  • Listings remain stable through materialization. Root-union guidance replies have the correct protocol framing. Successes, no-match union members, malformed inputs, canonical rejection independent of compact-advertisement constraints, errors without structured success payloads, repeated discovery and notifications are checked.
  • 22 public stdio cases pass in total. Four additional cases cover a malformed first domain call followed by valid guidance, and lazy-module evaluation failure followed by repeated calls/discovery, over legacy/full and modern/hot-cold. Failed startup returns the generic diagnostic with no structured success payload; listings remain stable and discovery stays responsive.
  • Two cancellation/reconnection cases pass: hold the real lazy module, cancel one request, complete a peer, export exactly the peer's analysis Evidence, remove the source, read retained facts, reconnect with fresh visibility, reject stale retained references, and read the original portable Evidence.
  • Two prompt-first cases pass: retrieval first on legacy, completion first on modern. Prompt discovery stays deferred, canonical prompt arguments remain validated, and tool/prompt listings stay stable through materialization. Exported Evidence stays empty until an authored API analysis; live completion then returns exactly its retained Evidence ID. Union guidance remains callable afterward.
  • Two bundle-failure cases pass: copied shipped runtimes with linked locked dependencies exercise stale_locator, stale_continuation, and both tools' bundle_unavailable members over legacy/full and modern/hot-cold. A malformed locator still gives invalid_request without structured success data. Restoring exact bundle bytes restores the original digest and locator; SDK output validation and listings stay correct throughout. Faults affect only temporary runtime copies; these cases are not fresh npm installations.
  • 24 HTTP/schema cases pass: full catalog schema validity, canonical validation under compact/off advertisements, and HTTP refresh/DELETE/reconnection. Both explicit legacy and SDK auto negotiation verify hot/cold union guidance before and after session reset. HTTP intentionally composes the legacy server; auto correctly falls back to 2025-11-25, including unsolicited refresh notifications.
  • 53 source cases pass in the current-main qualification below (deferred server, guidance and progressive catalog); fix(mcp): record deferred schemas before protocol framing #9351's 35 stdio cases also pass there, including independent eager/deferred catalog comparisons.
  • Two selected cases fail on pinned main 72d5e72e6 with the original missing-result SDK error. They fail before the new guide lookup.
  • Fresh installed tarball passes four stock-SDK workflows: SDK 2.3.1 legacy/full (2025-11-25, 246 tools) and modern/hot-cold (2026-07-28, 5 → 9 tools), plus independently installed SDK 1.32.2 legacy clients with both full and hot/cold catalogs. SDK 1's default output validator, unsolicited refresh notification and explicit relisting also pass. Root-union guidance is the first materializing call; compiled section retrieval, both union members, malformed-input errors, stable listings, authored OpenAPI facts, source deletion, retained reads and Evidence links all pass. The package has its own 150 production dependencies, without a worktree dependency symlink. The SDK 1 compatibility probes use a separate client installation and 30 s / 3 GiB process-family guards with 1-GiB Node heaps; neither guard fired. They are manual qualification, not a new CI dependency. Install scripts and optional dependencies were disabled; native providers were not exercised. Packed runtime is from 229ebd49d (subsequent changes only extend lifecycle/HTTP tests); tarball SHA-1 bf3d7148d20e36a2d0cda330080e73a974e3a58f.
  • Review correction at 9fd5eca98: the exact-module handoff now promises retained facts and source locations, matching the workflow's actual result. It no longer promises original code. Six focused cases pass (guidance search, MCP retrieval, full/hot-cold compiled retained-facts workflows), plus check:fast.
  • The latest full 22-case focused run, four guidance/MCP-boundary checks, two acceptance workflows, check:fast and touched formatting/diff checks pass. The task-specific first-result routing oracle remains; the broad query independently verifies both workflow and selector guidance and the latter's explicit handoff. Earlier build, documentation, test-discovery and HTTP checks remain recorded in the pinned qualifications below.

Combined CI: manual qualification run 42559394989 targets exact stacked head 17e8deebfd0d66c01295d5159d21937864f85a0c (#9351 + #9353). It completed with 39 successful jobs, three failed jobs (one guidance-search assertion plus dependent aggregate gates), two skipped jobs, and one cancelled Apple artifact job. All 22 deferred-schema cases passed on Linux. The ambiguous-query ordering assertion is corrected at ed307b8d5, with an explicit workflow handoff in the compiled JavaScript selector guide and separate broad-query and task-specific routing checks. Validation at ed307b8d5 passed 22 deferred cases, four guidance/MCP-boundary cases, two acceptance workflows and check:fast. The subsequent wording correction was checked with six guidance/MCP/acceptance cases and check:fast; the full 22-case matrix was not repeated for that prose-only change. Full current-head CI has not been rerun. The standalone source/Python jobs intentionally skip on full tier; they are not counted as passes. The Apple job hit its 15-minute workflow bound during native/process regressions; its coverage remains incomplete and no timeout was raised. This run is the feature branch, distinct from the locally qualified current-main combination below.

Current-main qualification: combined feature 454d7121f plus pinned main c78c8aed4, exact merged tree f00ecd00409b2f85345d3fb20481f0f835f031ca, in a separate unpublished worktree with a fresh locked install. All 79 MCP boundary cases and 53 source cases pass, together with build, check:fast and docs:check. The initial direct run passed 28 cases but two suites could not collect because generated .cache/mcp-tool-catalog.json test metadata was missing; the focused runner prepared it and both suites then passed all 51 cases without test changes or repeating the 28 passes. This qualifies upstream compatibility locally; it does not claim combined CI or change either PR's base.

The matrix uses the repository's official SDK/Ajv validation fixture to share compiled validators, without dropping schema constraints. Context measurements below use the stock SDK default validator. The 12 cases are representative, not an exhaustive 24-cell product. Modern protocol behavior is exercised over stdio; HTTP uses its supported legacy protocol, including automatic fallback.

Review corrections

  • Discovery anchor: inserting guidance before the existing anchor's heading redirected old links. The anchor now immediately precedes its original hot/cold heading. Documentation checks pass; no related cleanup remains.
  • Independent section context: extracted sections could refer to text not returned by their locator. Each affected section now states its parent kind, valid selectors, capture selection and refusal conditions, or an explicit guidance query for further detail. The browser-manifest exception sits with the manifest rules. Admission owners were checked, and all four revised sections were independently searched/read through the compiled CLI. No related cleanup remains.
  • Compact schema invariant: the test incorrectly made omission of an offset constraint part of the compact contract. Valid inputs must now pass every advertised profile; exact negative-schema rejection is required for full inputs, while canonical server rejection remains required for both. Safer compact schemas can retain constraints. The complete 20-case public qualification and check:fast pass; no related cleanup remains.
  • Controlled-gate acknowledgement: marker-only polling could hide an early request failure behind a timeout. The cancellation test now uses the shared awaitAcknowledgement owner to race the marker against the actual request and a deadline, and joins the marker observer with all launched work after release in finally. Both real cancellation/reconnection cases pass in the full 20-case qualification; no related cleanup remains.
  • Modern clients need a subscriptions/listen tool-list subscription (or the SDK convenience handler); registering a handler alone does not receive modern changes. The protocol distinction is now documented and exercised.

Context measurements

Pinned main 72d5e72e6 against measured implementation 229ebd49d. Later test additions and the JavaScript guidance handoff are not a fresh token benchmark. Full initial name/description/input-schema context remains 70,308 → 67,164 estimated tokens, 246 tools. Full tools/list result JSON: 4,407,654 → 4,391,167 bytes; output schemas still dominate.

Task: inspect an authored OpenAPI document, delete it, then read GET /items twice from retained Evidence. Candidate costs include guidance search/read and their hot/cold discovery. Latest qualification reran two fresh candidate sessions using the original harness/fixture; parent/view Evidence IDs match the pinned baseline and authored method/path/source pointers.

Catalog Baseline token estimate Candidate including guidance Wall s CPU s Sampled family peak MiB
full 74,792 72,719 4.288 → 4.192 5.448 → 5.614 1,198.8 → 1,168.8
hot/cold 10,819 9,336 2.254 → 2.215 3.100 → 3.119 870.8 → 883.8

tiktoken 0.14.0 / o200k_base estimates count distinct input definitions, instructions, fixed question, every argument and text reply. Output schemas are separate transport costs. Actual model usage, repeated-turn prompt assembly, caching and agent selection are unmeasured. Hot/cold initial guidance-search documentation adds four estimated tokens.

Processes were fresh; filesystem caches were warm and unflushed. Baseline and follow-up samples are not contemporaneous. CPU sums waited-for harness/server children; family RSS is sampled at 50 ms and can miss short-lived peaks. Guards: 60 s / 3 GiB, 1-GiB Node heaps; none hit, normal cleanup completed. Single shared-host samples establish no latency or memory improvement. Earlier failed guidance pilots led to #9351 and remain excluded from successful-task measurements.

Scope decision: not applicable; existing documentation/discovery. Real deep providers, other OSes and application-specific automatic refresh remain unverified. Full defaults remain unchanged; large output-schema transport cost remains.

Author readiness

Human owner: @kaoru0822-kitauji

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

@greptile-apps

greptile-apps Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5 Tier: plus

[Medium impact] The reviewed changes appear safe to merge.

Summary

The PR moves format-specific inspect_analysis_view instructions into guidance fetched on demand.

  • Retained-view callers fetch format-specific instructions when they need them.
  • Deferred MCP clients keep protocol-correct tool schemas.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Compiled tool guidance] --> C[Shared guidance index]
  B[Installed workflow guides] --> C
  C --> D[search_guidance]
  D --> E[Section locator]
  E --> F[read_guidance_section]
  A --> G[Tool discovery keywords]
Loading

Reviews (8) · Last reviewed commit: "docs(mcp): scope module guidance to reta..." · Reviewed by Greptile

Comment thread docs/reference/mcp-contracts.md Resolved
Comment thread src/contracts/analysisViewGuidance.ts Resolved

Copy link
Copy Markdown
Collaborator Author

Lane A cross-stack audit at 17e8deebfd0d66c01295d5159d21937864f85a0c: there is a verified guidance-routing CI regression to resolve before treating the stack as green.

Both Portable tests and Test shard 5/6 fail tests/boundary/guidanceSearch.test.ts > finds and retrieves the selected section from the generated package bundle. Query exact JavaScript module now returns first heading inspect_analysis_view: JavaScript modules and facts, while the existing oracle requires Read a module without repeating analysis. The logs report one failed test, not a timeout or provider failure.

Source-derived cause: compiled selector guides are now indexed alongside packaged workflow guides, changing their ranking/ownership relationship. I am not claiming the newly selected guide is factually wrong. Please establish the intended workflow-versus-selector routing rule and make its regression coverage explicit; resolve the producing rule or strengthen an obsolete oracle rather than merely dropping the first-result assertion. Lane A #9352 extends this same first-result retrieval test, so the combined stack needs both workflow and selector lookups checked. No Lane B file or branch was modified in this audit.

Comment thread src/contracts/analysisViewGuidance.ts Resolved
Base automatically changed from codex/mcp-deferred-union-schemas to main November 12, 2026 13:50

Copy link
Copy Markdown
Collaborator Author

Maintenance claim for this session (2026-11-12): I am updating this PR in a fresh isolated worktree, merging current main a8527d4 into codex/mcp-context-guidance, reviewing existing feedback and preserving its focused scope. I will push normally after checking the remote head and refresh validation evidence. Please coordinate here before concurrent edits to this branch.

Copy link
Copy Markdown
Collaborator Author

Coordination from session backlog-c4-01a1d00b: the latest user request is to repair all existing kaoru0822-kitauji PRs and mark technically ready PRs ready. I found active maintenance claims on this PR and the other backlog branches, so this session will not push competing branch updates. We are independently auditing current-head CI/reviews, checking the shared Setup TS2741 baseline against main a8527d4, and monitoring readiness. Please retain your branch repair ownership; I will coordinate any concrete additional findings here before editing. The trusted readiness script exempts account ID208281322; no human declaration will be fabricated.

@morluto morluto added area: mcp MCP server, transport, and tool registration performance Performance regressions, scaling limits, and bounded-resource work labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: mcp MCP server, transport, and tool registration performance Performance regressions, scaling limits, and bounded-resource work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants