Repository navigation
fix(protocol): protocol:check passes when the published schema drifts - #133090
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 30, 2026, 1:44 AM ET / 05:44 UTC. ClawSweeper reviewWhat this changesThe PR replaces an ineffective diff check for an ignored generated Gateway JSON Schema with a shared schema-document contract used by generation and package-artifact verification. Merge readinessNo blocking findings. The prior schema-normalization blocker is fixed on the current head; this remains a useful, maintainer-authored protocol-tooling repair and current main still has the ineffective ignored-artifact guard. Priority: P1 Review scores
Verification
How this fits togetherGateway protocol schemas and method metadata are assembled into a JSON document shipped in the protocol package. Generation, CI, pre-push checks, and the package-artifact QA producer consume that document before native and external clients use it. flowchart LR
A[Gateway schema registry] --> C[Protocol document builder]
B[Gateway method metadata] --> C
C --> D[Schema contract assertion]
D --> E[Generated JSON Schema]
E --> F[Packaged protocol artifact]
C --> G[Artifact verification]
Before merge
Agent review detailsSecurityNone. PR surfaceTests +68, Docs 0, Config 0, Other +70. Total +138 across 8 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep one normalized schema-document builder and contract assertion shared by generation and artifact verification, then land after exact-head CI confirms the updated enforcement path. Do we have a high-confidence way to reproduce the issue? Yes. The prior command guarded an ignored path, and current main still retains that path in the protocol-check flow; the PR body also supplies a focused before/after reproduction and the source confirms the affected entrypoint. Is this the best way to solve the issue? Yes. A shared normalized document owner is preferable to diffing an untracked artifact or retaining a duplicate QA envelope; the current head also resolves the earlier raw-TypeBox-versus-JSON comparison defect. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against d7bbc64a81ae. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
dist/protocol.schema.json is gitignored and never committed, so the trailing `git diff --exit-code` guard in protocol:check exited 0 unconditionally. The Swift and Kotlin halves work because those files are tracked; the JSON half read as verification while it could not fail, leaving schema drift to the slow QA-lab scenario. scripts/prepush-ci.sh carried the same dead guard: its before/after diff covered only the untracked artifact and a file that protocol:check:swift never writes. The artifact is a build output with no committed baseline, so it gets a contract check instead of a diff. scripts/lib/protocol-schema-document.mts owns the published document; protocol-gen builds through it, asserts required frame definitions, frame ordering, discriminator mapping, and a non-empty method catalog before writing through the shared generated-output helper. The QA-lab verifier drops its duplicate envelope copy and compares the packed tarball against that same owner. The generated artifact is byte-identical to before.
6ffe180 to
d831b27
Compare
|
Addressing the ClawSweeper review items on head Resolve merge risk (P1) — exact-head CI confirms the new validation path. Green on the exact head: 208 checks pass, 26 skipped, 0 failures. Resolve merge risk (P1) — production tooling net +70. Justified as stated: Complete next step (P2). Done — ordinary exact-head CI completed green; no repair branch needed. Stored data model flag — not applicable. The heuristic reported Fresh |
|
Merged via squash.
|
…penclaw#133090) dist/protocol.schema.json is gitignored and never committed, so the trailing `git diff --exit-code` guard in protocol:check exited 0 unconditionally. The Swift and Kotlin halves work because those files are tracked; the JSON half read as verification while it could not fail, leaving schema drift to the slow QA-lab scenario. scripts/prepush-ci.sh carried the same dead guard: its before/after diff covered only the untracked artifact and a file that protocol:check:swift never writes. The artifact is a build output with no committed baseline, so it gets a contract check instead of a diff. scripts/lib/protocol-schema-document.mts owns the published document; protocol-gen builds through it, asserts required frame definitions, frame ordering, discriminator mapping, and a non-empty method catalog before writing through the shared generated-output helper. The QA-lab verifier drops its duplicate envelope copy and compares the packed tarball against that same owner. The generated artifact is byte-identical to before.
What Problem This Solves
Resolves a problem where
pnpm protocol:checkreported success even when the publishedGateway protocol schema had drifted. Its final guard ended with:
dist/protocol.schema.jsonis gitignored (.gitignore:169) and never committed, sogit diff --exit-codeon that path exits 0 unconditionally — verified by writing garbageinto the file and watching the guard still pass. The Swift and Kotlin halves work because
those files are tracked; the JSON half read as verification while it could not fail.
scripts/prepush-ci.shcarried the same dead guard a second time.run_protocol_ci_mirrorsnapshotted
git diffoverdist/protocol.schema.jsonplusGatewayModels.swift, ranprotocol:genandprotocol:check:swift, then compared before/after. That comparison alsocould never fail:
protocol:genwrites only the untracked JSON andprotocol:check:swiftwrites nothing at all.
The consequence was that JSON-schema drift only surfaced in the QA-lab scenario
qa/scenarios/runtime/gateway-protocol-artifacts.yaml, never in the fastchecks-fast-bundled-protocollane — and that scenario built its own hand-copiedduplicate of the generator's root envelope, so it was largely comparing one of our copies
against the other rather than the tarball against a canonical document.
Why This Change Was Made
The artifact is deliberately a build output with no committed baseline, so a
regenerate-then-diff guard has nothing to diff against. Tracking a 3.3 MB generated file
inside the ignored
dist/tree contradicts both the gitignore comment anddocs/concepts/typebox.md, and a--checkmode likeprotocol-gen-swift.tshas no honestbaseline either:
protocol:checkregenerates the file in the same command (sogen-then-check is tautological), and the fast CI lane runs
pnpm test:bundled && pnpm protocol:checkwith no build, so a fresh checkout would fail on a missing artifact.So the JSON artifact gets a contract check instead of a diff. New
scripts/lib/protocol-schema-document.mtsowns the published document:buildProtocolSchemaDocumentbuilds the envelope (one copy), andassertProtocolSchemaDocumentrejects a document that lost a required frame definition,reordered the frame
oneOfbranches, rewrote thetypediscriminator mapping, or shippedan empty method catalog.
scripts/protocol-gen.tsbuilds through that owner, assertsbefore writing, and writes via the shared
writeGeneratedOutputhelper the Swift generatoralready uses. The QA-lab verifier imports the same owner, so its tarball comparison is
finally canonical-vs-published, and its duplicate envelope is gone.
The dead paths are removed: the untrackable path leaves the
protocol:checkdiff list, andrun_protocol_ci_mirrorcollapses into the tworun_stepcalls that were doing the realwork.
Scope note: this deliberately does not add a
--checkmode toprotocol-gen.ts. Doing sowould add a third guard to the same family — one that either always passes (run after
generation) or always fails (fresh checkout with no
dist/).User Impact
Maintainers and contributors get a
protocol:checkthat actually fails on published-schemadrift, in the fast CI lane rather than only in the slow QA-lab scenario, with an actionable
message naming what the document lost. The generated
dist/protocol.schema.jsonisbyte-identical to before, so there is no wire-format or artifact change;
prepackgains thesame contract check, so a degraded registry can no longer be published in the
@openclaw/gateway-protocoltarball.Line delta, judged: production/tooling
-19inprepush-ci.sh,-12in the generator,+103in the new owner (of which roughly 60 is envelope and types moved out ofprotocol-gen.tsand the QA-lab producer); test and test-support-52in the QA-labproducer,
-14in its unit test,+134in the new regression test. Net-neutral onproduction once the moves are discounted, with the growth being the contract owner that
replaces a guard which could never fail.
Evidence
The bug, reproduced
Regression test fails on pre-fix code.
test/scripts/protocol-schema-artifact.test.tsasserts every path in every
git diff --exit-code --guard inpackage.jsonis git-tracked.Restoring the pre-fix
protocol:checkfails it, naming the exact path:The new guard fails on drift. Injecting a dropped
ConnectParamsinto the generatorand running the real command:
That is the exact drift the old guard waved through. Reverted afterwards.
Test coverage. Seven tests in
test/scripts/protocol-schema-artifact.test.ts: thetracked-guard-path regression, four drift cases against the contract assertion, and a
boundary test that spawns the real generator to a temp
--outand proves the bytes itwrites are exactly what the shared owner produces.
Artifact unchanged. The regenerated
dist/protocol.schema.jsonis byte-identical to thepre-refactor output (
diff -qagainst a snapshot taken before the change).Commands run locally
pnpm protocol:check— exit 0node scripts/check-changed.mjs— exit 0 (format,tsgoscripts + test-root, scriptslint, script erasability, boundaries, coercion guard, SDK surface)
node scripts/run-vitest.mjs run test/scripts/protocol-schema-artifact.test.ts test/e2e/qa-lab/runtime/gateway-protocol-artifacts.test.ts— 17 tests passednode --import ./scripts/tsx.mjs test/e2e/qa-lab/runtime/gateway-protocol-artifacts.ts --artifact-base .artifacts/protocol-artifacts-proof— packs the tarball, installs a freshconsumer, deep-compares the published schema against the shared canonical builder, and
compiles/runs the Swift generated models. Result:
status: pass, definitionsConnectParams, RequestFrame, ResponseFrame, EventFrame, both AJV validators green.No UI surface changes, so no screenshots apply.