Skip to content

fix(protocol): protocol:check passes when the published schema drifts - #133090

Merged
steipete merged 1 commit into
mainfrom
steipete/admiring-torvalds-da1e11
Aug 30, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/admiring-torvalds-da1e11

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Resolves a problem where pnpm protocol:check reported success even when the published
Gateway protocol schema had drifted. Its final guard ended with:

git diff --exit-code -- dist/protocol.schema.json apps/shared/.../GatewayModels.swift ...

dist/protocol.schema.json is gitignored (.gitignore:169) and never committed, so
git diff --exit-code on that path exits 0 unconditionally — verified by writing garbage
into 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.sh carried the same dead guard a second time. run_protocol_ci_mirror
snapshotted git diff over dist/protocol.schema.json plus GatewayModels.swift, ran
protocol:gen and protocol:check:swift, then compared before/after. That comparison also
could never fail: protocol:gen writes only the untracked JSON and protocol:check:swift
writes 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 fast
checks-fast-bundled-protocol lane — and that scenario built its own hand-copied
duplicate 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 and
docs/concepts/typebox.md, and a --check mode like protocol-gen-swift.ts has no honest
baseline either: protocol:check regenerates the file in the same command (so
gen-then-check is tautological), and the fast CI lane runs pnpm test:bundled && pnpm protocol:check with 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.mts owns the published document:
buildProtocolSchemaDocument builds the envelope (one copy), and
assertProtocolSchemaDocument rejects a document that lost a required frame definition,
reordered the frame oneOf branches, rewrote the type discriminator mapping, or shipped
an empty method catalog. scripts/protocol-gen.ts builds through that owner, asserts
before writing, and writes via the shared writeGeneratedOutput helper the Swift generator
already 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:check diff list, and
run_protocol_ci_mirror collapses into the two run_step calls that were doing the real
work.

Scope note: this deliberately does not add a --check mode to protocol-gen.ts. Doing so
would 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:check that actually fails on published-schema
drift, 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.json is
byte-identical to before, so there is no wire-format or artifact change; prepack gains the
same contract check, so a degraded registry can no longer be published in the
@openclaw/gateway-protocol tarball.

Line delta, judged: production/tooling -19 in prepush-ci.sh, -12 in the generator,
+103 in the new owner (of which roughly 60 is envelope and types moved out of
protocol-gen.ts and the QA-lab producer); test and test-support -52 in the QA-lab
producer, -14 in its unit test, +134 in the new regression test. Net-neutral on
production once the moves are discounted, with the growth being the contract owner that
replaces a guard which could never fail.

Evidence

The bug, reproduced

$ printf 'GARBAGE' > dist/protocol.schema.json
$ git diff --exit-code -- dist/protocol.schema.json; echo "exit=$?"
exit=0

Regression test fails on pre-fix code. test/scripts/protocol-schema-artifact.test.ts
asserts every path in every git diff --exit-code -- guard in package.json is git-tracked.
Restoring the pre-fix protocol:check fails it, naming the exact path:

- Expected
+ Received
    "tracked": [
      "apps/android/.../GatewayProtocol.kt",
      "apps/android/.../OpenClawProtocolConstants.kt",
      "apps/shared/OpenClawKit/Sources/OpenClawProtocol/GatewayModels.swift",
-     "dist/protocol.schema.json",
    ]

The new guard fails on drift. Injecting a dropped ConnectParams into the generator
and running the real command:

$ pnpm protocol:check
$ node --import ./scripts/tsx.mjs scripts/protocol-gen.ts
Error: published protocol schema contract violated: definition ConnectParams is missing
[ELIFECYCLE] Command failed with exit code 1.

That is the exact drift the old guard waved through. Reverted afterwards.

Test coverage. Seven tests in test/scripts/protocol-schema-artifact.test.ts: the
tracked-guard-path regression, four drift cases against the contract assertion, and a
boundary test that spawns the real generator to a temp --out and proves the bytes it
writes are exactly what the shared owner produces.

Artifact unchanged. The regenerated dist/protocol.schema.json is byte-identical to the
pre-refactor output (diff -q against a snapshot taken before the change).

Commands run locally

  • pnpm protocol:check — exit 0
  • node scripts/check-changed.mjs — exit 0 (format, tsgo scripts + test-root, scripts
    lint, 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 passed
  • Full QA-lab producer end to end:
    node --import ./scripts/tsx.mjs test/e2e/qa-lab/runtime/gateway-protocol-artifacts.ts --artifact-base .artifacts/protocol-artifacts-proof — packs the tarball, installs a fresh
    consumer, deep-compares the published schema against the shared canonical builder, and
    compiles/runs the Swift generated models. Result: status: pass, definitions
    ConnectParams, RequestFrame, ResponseFrame, EventFrame, both AJV validators green.

No UI surface changes, so no screenshots apply.

@clawsweeper

clawsweeper Bot commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation scripts Repository scripts labels Aug 30, 2026
@steipete
steipete marked this pull request as ready for review August 30, 2026 05:15
@openclaw-barnacle openclaw-barnacle Bot added size: M maintainer Maintainer-authored PR labels Aug 30, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 30, 2026
@clawsweeper

clawsweeper Bot commented Aug 30, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 30, 2026, 1:44 AM ET / 05:44 UTC.

ClawSweeper review

What this changes

The 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 readiness

⚠️ Ready for maintainer review - 3 items remain

No 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
Reviewed head: d831b273ae34c80330d1d6e2762e6cfaad5e2092

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused repair with credible package-boundary evidence; the earlier correctness blocker is resolved and only normal exact-head automation completion remains.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; independently, its supplied evidence exercises the real package path by packing the protocol package, installing a fresh consumer, parsing the published schema, and running generated Swift models.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; independently, its supplied evidence exercises the real package path by packing the protocol package, installing a fresh consumer, parsing the published schema, and running generated Swift models.
Evidence reviewed 4 items Prior blocker resolved: The shared builder clones the document after inserting TypeBox schemas, removing symbol-key metadata before comparison; the QA producer compares parsed installed JSON with that normalized canonical document.
Production artifact boundary: The protocol package prepack script runs the generator, while the QA producer packs the package, installs it into a fresh consumer, parses its schema, and validates it against the shared builder.
Current-main necessity: Fetched current main does not contain the PR head and retains the previous generator shape; the PR’s introduced package, generator, and QA files remain distinct from current main.
Findings None None.
Security None None.

How this fits together

Gateway 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]
Loading

Before merge

  • Resolve merge risk (P1) - This changes CI and pre-push protocol enforcement, so the remaining exact-head checks must confirm the new validation path before landing.
  • Resolve merge risk (P1) - Production tooling is net +70 lines; the growth is justified by the single shared contract owner replacing duplicated envelope logic and a guard that could not validate an ignored artifact.
  • Complete next step (P2) - The prior review finding is resolved; this open maintainer-authored PR needs ordinary exact-head CI completion rather than an automated repair branch.
Agent review details

Security

None.

PR surface

Tests +68, Docs 0, Config 0, Other +70. Total +138 across 8 files.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 3 152 84 +68
Docs 1 1 1 0
Config 1 1 1 0
Generated 0 0 0 0
Other 3 132 62 +70
Total 8 286 148 +138

Review metrics

Metric Value Why it matters
Production versus test delta production tooling +132/-62 (net +70); package/docs +2/-2; tests and test support +152/-84 The added shared contract owner is the only material production growth and replaces duplicated schema-envelope logic plus a non-validating guard.

Stored data model

Persistent data-model change detected: serialized state: scripts/protocol-gen.ts, unknown-data-model-change: scripts/protocol-gen.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Validate the updated enforcement path (recommended)
    Allow the exact current-head CI suite to complete and confirm that the revised protocol and pre-push checks succeed before merge.

Technical review

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

Labels

Label changes:

  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; independently, its supplied evidence exercises the real package path by packing the protocol package, installing a fresh consumer, parsing the published schema, and running generated Swift models.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P1: The repair closes a fast CI enforcement gap that could otherwise allow a degraded published protocol schema to pass validation.
  • merge-risk: 🚨 automation: The PR changes the package protocol-check command and pre-push verification sequence that enforce generated protocol integrity.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; independently, its supplied evidence exercises the real package path by packing the protocol package, installing a fresh consumer, parsing the published schema, and running generated Swift models.

Evidence

What I checked:

  • Prior blocker resolved: The shared builder clones the document after inserting TypeBox schemas, removing symbol-key metadata before comparison; the QA producer compares parsed installed JSON with that normalized canonical document. (scripts/lib/protocol-schema-document.mts:79, d831b273ae34)
  • Production artifact boundary: The protocol package prepack script runs the generator, while the QA producer packs the package, installs it into a fresh consumer, parses its schema, and validates it against the shared builder. (packages/gateway-protocol/package.json:83, d831b273ae34)
  • Current-main necessity: Fetched current main does not contain the PR head and retains the previous generator shape; the PR’s introduced package, generator, and QA files remain distinct from current main. (package.json:1767, d7bbc64a81ae)
  • Relevant history: History identifies prior generator/packaging and artifact-verifier work, but unavailable promised objects prevented raw-parent line-introduction verification; routing remains a non-attributing history suggestion. (scripts/protocol-gen.ts:38, d831b273ae34)

Likely related people:

  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Vincent Koc: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Let the exact current-head CI checks complete for the changed protocol enforcement path.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (1 earlier review cycle)
  • reviewed 2026-08-30T05:22:25.527Z sha 6ffe180 :: needs changes before merge. :: [P1] Preserve schema normalization before the artifact comparison

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.
@steipete
steipete force-pushed the steipete/admiring-torvalds-da1e11 branch from 6ffe180 to d831b27 Compare August 30, 2026 05:38
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 30, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

Addressing the ClawSweeper review items on head d831b273ae34c80330d1d6e2762e6cfaad5e2092 before landing.

Resolve merge risk (P1) — exact-head CI confirms the new validation path. Green on the exact head: 208 checks pass, 26 skipped, 0 failures. checks-fast-bundled-protocol (the lane that runs pnpm protocol:check) passes, and openclaw/ci-gate passes. All 14 checks-ui-e2e shards pass, including 6/14, which was red on the pre-rebase head purely because that head predated cfddfc2f700 — the rebase, not this change, resolved it.

Resolve merge risk (P1) — production tooling net +70. Justified as stated: scripts/lib/protocol-schema-document.mts is a single shared contract owner that absorbs two duplicated schema envelopes (one in scripts/protocol-gen.ts, one in the QA-lab producer) and replaces a guard that could not validate an ignored artifact. Discounting the moved envelope and types, the change is roughly net-neutral on production lines: -19 in scripts/prepush-ci.sh (a second, equally ineffective before/after guard), -12 in the generator, -52 in the QA-lab producer.

Complete next step (P2). Done — ordinary exact-head CI completed green; no repair branch needed.

Stored data model flag — not applicable. The heuristic reported serialized state: scripts/protocol-gen.ts and asked for migration or upgrade-compatibility proof. There is no persistent data model here: protocol-gen.ts writes dist/protocol.schema.json, a gitignored build artifact regenerated on every run, with no SQLite table, schema version, or on-disk state involved. Upgrade compatibility is proven by byte identity — the regenerated artifact is byte-for-byte identical to the pre-change output (diff -q against a snapshot taken before the change), so no consumer of the published schema sees any change. Stating this as a skip rather than merging past it silently.

Fresh $autoreview (Codex, high reasoning) on the rebased head returned scoped-clean with no accepted or actionable findings.

@steipete
steipete merged commit a644634 into main Aug 30, 2026
239 checks passed
@steipete
steipete deleted the steipete/admiring-torvalds-da1e11 branch August 30, 2026 06:38
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 31, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation maintainer Maintainer-authored PR merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. scripts Repository scripts size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant