Repository navigation
improvement(mothership): shadow-check worker stream frames against the contract schemas - #10354
Conversation
…e contract schemas Takes the regenerated mothership-stream-v1 contract, whose types are now inferred from zod schemas. Frames the worker sends this server (the live leg and the run replay) go through parseIngestedStreamEventEnvelope: the existing validator still decides every frame, and the contract schema runs beside it. A disagreement in either direction increments copilot.stream_contract.disagreements (direction, event type, capped kind/phase) and logs the zod issue paths, once per distinct disagreement per ten minutes; a failure of the check itself is logged under the same limit. Synthetic file-preview frames are skipped by their previewPhase. The browser and the outbox reader are unchanged. Tests pin a representative set of frames the validator accepts and the schema rejects, one per kind of gap. The run replay reader validates replay-end payloads with the synced MothershipStreamV1ReplayEndPayloadSchema instead of a local copy of the same shape, and the shadow reuses the contract parser's event-type set.
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
|
There was a problem hiding this comment.
All reported issues were addressed across 11 files
Reply with feedback, questions, or to request a fix.
Turn on auto-fix | Re-trigger cubic
[Low impact] The PR appears safe to merge; no new actionable issues were found. SummaryAdds a server-side comparison between the existing worker-frame validator and the generated Zod schemas without changing which frames are accepted.
|
…d dedupe The shadow skipped any accepted frame carrying a payload previewPhase, so a worker frame with a stray previewPhase hid its schema rejection. It now skips only a frame the contract check rejects, which is exactly one the validator accepted as a synthetic file-preview frame; the previewPhase test stays as the cheap prefilter. A test pins the stray-field case. The log dedupe is an lru-cache (max 256, ttl the ten-minute window, read against Date.now) instead of a hand-rolled TTL map, still reporting the repeats skipped since the last line. Takes the regenerated protocol contract, whose tool deadlines are positive integers, and documents the new metric recorder and direction type with TSDoc.
|
@cubic-dev-ai review this PR |
@waleedlatif1 I have started the AI code review. It will take a few minutes to complete. |
Summary
Takes the regenerated
mothership-stream-v1contract, whose types are now inferred from Zod schemas (the worker side is the companion PR)Frames the worker sends this server (the live leg and the run replay) go through
parseIngestedStreamEventEnvelope. The existing validator still decides every frame, and the contract schema runs beside it. Behaviour is unchanged.A disagreement in either direction:
copilot.stream_contract.disagreements, labelled by direction, event type and kind/phase;A failure of the check itself is logged under the same limit.
Synthetic file-preview frames are skipped. The browser and the Redis outbox reader are unchanged. The shadow lives in its own server-only module, so none of it reaches the client bundle
run-replay.tsvalidates the replay-end payload with the syncedMothershipStreamV1ReplayEndPayloadSchemainstead of a local copyThis is phase A of making the schema the single validator. Phase B switches server ingest to the schema only after the counter has stayed at zero
schema_rejectson hosted traffic. The schema is stricter than today's per-type checks (required fields, enum values), and a rejected frame ends the turn.Type of Change
Testing
contract-shadow.test.ts: a representative frame for each kind of gap (accepted today, rejected by the schema). Each asserts the verdict and returned object are unchanged and the counter and log fire. Further tests cover the opposite direction, agreement (includingreplay_endon a live leg), skipped synthetic frames, the dedupe window, and a throwing meter logging oncesafeParseper frame, about the cost of the frame'sJSON.parse(0.2–1.3 µs on the server)check:contract-sync)tsc --noEmitandbun run lintclean; vitest overlib/mothershippasses; test-pattern, test-type and audit checks pass/simplifyChecklist
Companion: simstudioai/mothership#1008