Repository navigation
refactor(protocol): generate TypeScript contracts and enforce complete tool policies - #389
Draft
NianJiuZst wants to merge 4 commits into
Draft
NianJiuZst wants to merge 4 commits into
NianJiuZst wants to merge 4 commits into
Conversation
…licies Refs Tencent#388. Derive extension contracts and validators from the Rust catalog, enforce exhaustive handler and execution policies, and preserve evaluation settlement across caller deadlines.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #388 when the agreed implementation is merged.
Draft for design discussion. The architecture, compatibility policy, and rollout still need maintainer agreement.
Problem and resulting behavior
Protocol changes currently require updating Rust payloads, handwritten TypeScript mirrors, JSON Schema files, dispatcher registrations, and method classifications separately. These copies can drift: the old TypeScript error union omitted Rust's
user_aborted, and the checked-in handshake/session-stop schemas omitted fields already sent on the wire.This PR uses the Rust method catalog and payload types as the shared source, generates extension contracts, validates the transport boundary, and requires complete handler and local-policy coverage. Evaluation retains the existing bounded timeout/cancellation behavior; an unresolved evaluation does not retain the session queue indefinitely.
Implementation
Methodusing named fields. Effect-classification rationale remains next toeffect().scripts/protocol.mjsgenerates 41 extension methods, 193 contract definitions, and 105 standalone JSON Schemas. Schemars 1.2.2 exports receiving and sending contracts separately.protocol:generateupdates both generated directories;protocol:checkdetects missing, changed, or unexpected files in either directory without modifying source files.dump-schemaderives method roots from the catalog, skips unconstrained daemon-private payloads by schema/ownership rather than a hardcoded Schemars type name, and supports boolean schema roots. Checked-in schemas includeaudit_enabled, handshake audit responses, andwindow_released.protocol_errorwitheffect_state: "unknown"on mismatch; a malformed result does not prove that the action had no effect. Failed session-start result validation cleans up the allocated session.Generate and check
Standalone schemas are compared from a temporary export. The substantial JSON diff includes regeneration under Schemars 1.x, including ordering and description formatting changes.
Validation — 2026-10-07
Local environment: macOS, Rust 1.94.1, Node 26.10.0, Chrome for Testing 153.0.8010.12. Frontend type/lint/build validation used a clean copy of tracked source with workspace dependencies, excluding unrelated untracked audit files.
protocol:checkcargo test --workspace --locked -- --test-threads=2--workspace --lib --bins --locked -- -D warnings)A separate out-of-tree probe exercised the real daemon → built extension → isolated Chrome path. It used a private daemon home, fresh browser profile, local fixture, and a copy of the extension with only the daemon endpoint redirected to an ephemeral loopback port:
new Promise(() => {})withtimeout_ms: 50: returnstimeout; a subsequent evaluation returns4;session.stopsucceeds.cancel_cleanup_timeout, and the session can then be stopped.Baseline/environment limitations: The local Chrome 153 performance regression fails because
fcp_ms.valueis absent. The same assertion fails on an isolated copy of base commit3f10983c09fcd443c7420830ab984c9d409954bf; performance code is unchanged by these fixes. An initial heavily parallel run also hit startup/CDP timeouts; the complete Rust rerun passed, and the browser rerun cleared those failures. Hosted CI is reported separately by GitHub checks.No new test cases, repro scripts, fixtures, screenshots, or run logs are committed. Existing tests have interface and harness adaptations; additional probe evidence is described here.
Compatibility and remaining design decisions
1.3and minimum compatible protocol1.0remain unchanged. Strict validation is a behavior change; these checks do not establish compatibility with every released peer or all real-browser result shapes.entries: []; Serde readers still accept omission. More precise debug enums and result structures constrain previously permissive shapes.