cl_ws-driven-state
Use when changing a Canary Lab state producer or its event wiring, including routes, background jobs, MCP writes, direct file edits and run results. Trace each change to all UI and agent consumers without manual refresh; pair with cl_live-state-sync for consumer recovery.
- License 许可
- MIT
- 最近更新
- 2026-11-14
- Stars
- ★ 4
- Forks
- 0
01 前言 Front Matter
- name
- cl_ws-driven-state
- metadata
- { "internal": true }
- description
- Use when changing a Canary Lab state producer or its event wiring, including routes, background jobs, MCP writes, direct file edits and run results. Trace each change to all UI and agent consumers without manual refresh; pair with cl_live-state-sync for consumer recovery.
03 SKILL.md 正文
WS-Driven State — Every Mutation Emits an Event
If the server already emits the event and only the client fails to react →
cl_live-state-sync.
The product requirement is no manual refresh. Push is the fast path, backed by
automatic recovery in cl_live-state-sync. When an authoritative fact changes,
publish through its owning store/event bridge or the shared writer, then refresh
every dependent consumer. A listener that updates only test source does not update
the coverage ledger derived from those tests.
Forgetting this is the primary cause of "I had to refresh to see X."
The full event chain
Authoritative change (route / job / MCP tool / watched file / run result)
→ owning store bridge or shared writer publishes the change
├─ Browser: WorkspaceEventBus (apps/web-server/src/shared/workspace-events.ts)
│ → apps/web-server/src/shared/ws/workspace-stream.ts broadcasts JSON
│ → apps/web/src/shared/api/workspace-socket.ts parses the frame
│ → apps/web/src/shared/state/use-workspace-data.ts invalidates affected topics
│ → every dependent reader refetches → component renders current state
└─ Agent: supported notification / wait / change-read path
→ connected workflow receives relevant changes with missed-change recovery
Trace agent delivery separately from the browser WebSocket. Reuse existing task streams/store bridges where they own the state; do not add duplicate publishers. For direct filesystem or linked-source edits, cover the actual observed path and recover missed events. Reconnect/resync and bounded reconciliation are required where a dropped signal could otherwise leave a consumer stale indefinitely.
Existing event types
| Event type | What it signals | Client action |
|---|---|---|
feature-created/deleted/renamed, features-changed |
Suite identity or metadata changed | Refresh features and follow a rename in selected views |
tests-changed, tests-dirty-changed |
Test files or their integrity status changed | Invalidate tests and coverage; refresh derived feature evidence |
discovery-repair-changed |
Test discovery repair state changed | Refresh its owning consumer |
envsets-changed |
Envset added/removed for a feature | Refresh features and dependent setup state |
coverage-changed |
Source docs, summary, mappings or coverage-job state changed | Invalidate coverage and refresh derived stage evidence |
robustness-changed |
Robustness Lab job changed | Invalidate the robustness reader |
verification-config-changed |
Verify config saved (route or MCP tool) | Invalidate verification for the selected feature |
journal-changed |
A run's journal file changed | Invalidate the journal reader for its runId |
draft-created/updated/deleted |
Wizard draft mutations | Draft context reducer |
evaluation-export-* |
Evaluation export task lifecycle | Export task context |
version-changed |
Registry latest moved, or an update job finished |
Refresh version |
flights-changed |
A Flight state changed | Invalidate flight artifact readers; the list rides /ws/flights |
agent-jobs-changed, pre-flight-changed |
Agent/pre-flight job changed | Refresh the owning job consumer or pre-flight list |
notifications-changed |
Notification state changed | Invalidate notifications |
project-config-changed, getting-started-changed |
Workspace settings or onboarding state changed | Invalidate the owning settings/onboarding reader |
Pick the narrowest type that fits. features-changed is a catch-all for the feature
list; coverage-changed is scoped to coverage headlines. Prefer scoped events — they
avoid unnecessary re-fetches across all features.
The client-action column describes required consumers, not proof of current
wiring. This is a grouped map, not a substitute for the authoritative
WorkspaceEvent union in
apps/web-server/src/shared/workspace-events.ts and its handlers before changing
a type. Run streams and summary watchers also carry state: trace those into
coverage proof readers even when no WorkspaceEvent directly represents a run.
Checklist — adding a new mutation
Before closing a change to any producer, watcher or event bridge:
-
Which facts and consumers change? Include derived counts, freshness, evidence, open details, notifications and connected agents. Enumerate all entry points, including direct file/linked-target changes and standalone runs. Only skip delivery when there is no UI or agent consumer.
-
Which event type fits?
Use an existing type if it covers the change (see table above). If nothing fits, add a new type (steps below). -
Wire the owning publisher. Inject the real
WorkspaceEventPublisherinto the shared writer or store bridge inserver.ts. A route/runner/tool needs the dependency only when it publishes directly; do not bypass an existing bridge. -
Publish after authoritative state changes. Prefer the existing store bridge or shared writer so all entry points share delivery. A failed data write must not announce success; a persisted failed job/result is itself a state change.
-
Add the type to both sides if it's new:
apps/web-server/src/shared/workspace-events.ts—WorkspaceEventunionapps/web/src/shared/api/workspace-socket.ts— clientWorkspaceEventunion
-
Handle it in
use-workspace-data.tsand inspect the fetch-owning consumers:- For feature-list changes: call
refreshFeatures() - Invalidate the appropriate topics through the shared invalidation bus
- Each dependent reader subscribes and refetches; a component re-render alone does not re-run a fetch whose effect dependencies did not change
- Wire and verify agent delivery separately; a UI broadcast does not enter Claude/Codex model context by itself
- For feature-list changes: call
-
Wire real dependencies and verify consumers. Test the registered route, shared writer or watcher with its production event bridge, then test an already open consumer without reload. Pair with
cl_live-state-syncfor recovery.
Reference wiring (live examples)
- A route mutation —
routes/portify.tspublishes{ type: 'features-changed' }right aftersavePortifyreturns, through theworkspaceEventsdep onPortifyRouteDepsthatserver.tsinjects. - A background job — the coverage job store publishes
coverage-changedon every write viabridgeCoverageJobEvents(coverageJobStore, workspaceEvents)inserver.ts, so job completion reaches the client without the runner knowing about the WS. For the client side readapps/web/src/features/flights/state/feature-activity.tsandapps/web/src/features/flights/components/use-stage-band-data.ts.
Both surfaces, or it's only half-wired
A user-visible change can enter through REST, MCP, jobs, direct source edits or standalone runs. Wiring one route does not cover the other writers. Prefer the shared owner over repeated event calls. The rule the user holds you to:
Whether triggered by an MCP tool or by the GUI, the change must show up live — the user must never refresh to see the latest state.
So for every mutation, trace every writer and consumer. The classic gap: a REST
route emits features-changed but the MCP
tool that performs the same write (the Desktop path) does not — so a mutation made
from Desktop leaves the badge stale until a manual refresh.
Audit — reviewing an existing route for completeness
When reviewing a mutation that is NOT yours, check both surfaces:
rg -n 'publishWorkspaceEvent|workspaceEvents\.publish|bridge.*Events' apps/web-server/src
rg -n 'useInvalidationKey|invalidate\(' apps/web/src
Check whether a store bridge or shared writer already covers a mutation before adding a publisher. Then follow the event all the way to each reader, including derived data and connected agents. Correct publication alone is not completion.
Relationship to neighbours
- [[cl_live-state-sync]] — the client side: once the event arrives, don't gate a must-happen UI transition on a single push. This skill is the server side: make sure the push exists in the first place.
- [[cl_async-task-ux]] — background jobs (coverage, portify) complete async;
their runner is where
finishOk/finishErrlive — both must emit events. - [[cl_verify-changes]] — changes to
apps/web-server/**need Tier 3 (canary-apply) to confirm end-to-end. Unit tests verify the event is called; live confirms it propagates to the browser without a refresh.
Learned corrections (/todo-learn)
2026-06-25 — Don't value-gate live-update wiring; "rare" is not an exemption
- Rule: If a mutation has any live UI consumer, wire its
WorkspaceEvent— even when the only stale scenario is rare (e.g. two clients editing the same thing at once, like the Verify-config dialog). Do not recommend skipping a gap on cost/value grounds ("narrow edge case", "dialog refetches on reopen", "by design"). - Why: The "user must never refresh to see real state" bar is absolute. How unlikely the concurrent-edit case is doesn't make a stale UI acceptable — rarity ≠ exempt. The user holds every visible mutation to live-update, full stop.
- How to apply: When auditing/adding a mutation, the only valid reason to omit change delivery is "no UI or agent consumer exists at all." If a surface shows the data live (even an on-demand dialog another client could mutate underneath), wire the event + make the consumer refetch — non-destructively (don't clobber the editing user's in-progress local state; refetch the list, preserve selection/form). Present the fix, not a skip.
04 同仓库更多 Skills
off-by-one
暂无简介
multi-failure-cascade
暂无简介
broken-delete-contract
暂无简介
canary-lab
Use when the user wants Canary Lab to take a product repo end to end — "test this app", "onboard this repo", "run a flight", "evaluate what I just built" — through the flight pipeline (start_flight / get_flight / respond_flight_checkpoint over MCP). One conducted pipeline continues a configured suite or takes bare repo(s) to a green, covered, healed run and publishes a downloadable Report; Parallel setup continues as Canary-owned background work. Use a focused skill only when the user asks for that single capability without asking for a Flight or /canary-lab.
canary-lab-verify
Use when verifying a Canary Lab feature against a RUNNING target — a deployed environment ("verify checkout on staging", "run the saved verify config", "check the deployed app") or a locally booted app ("verify a running app") — through the verify MCP tools (list/get/create/update_verification_config, boot_services, execute_verification, get_verification_result). No heal loop. For run + heal use canary-lab-run; for end-to-end onboarding use canary-lab (flight).
canary-lab-run
Use when running or healing an EXISTING Canary Lab feature locally — "run <feature>", "fix the failing run", "rerun 7cvh", "drive the heal loop" — through the repair MCP tools (start_run, wait_for_heal_task, signal_run, get_heal_context, pause_run, cancel_heal, abort_run). Fix failing runs by editing app/service code, not tests. For end-to-end onboarding of a new repo use canary-lab (flight); for deployed-environment checks use canary-lab-verify.