Companion-app skill: WebSocket resilience for blue/green deploys - #92
Open
beaugunderson wants to merge 2 commits into
Open
Companion-app skill: WebSocket resilience for blue/green deploys#92beaugunderson wants to merge 2 commits into
beaugunderson wants to merge 2 commits into
Conversation
|
@beaugunderson - should the scope of this be beyond companion apps? |
Member
Author
|
@kristenoneill probably, i just updated the one place we talked about it in CPA, i'll widen it |
Member
Author
|
made that change 👍 |
Plugin WebSockets drop mid-session at deploy cutover and reconnect onto a fresh process. The skill documented push but not how to survive the gap. Adds guidance distilled from canvas-hyperscribe: treat the socket as a re-sync hint (broadcasts are ephemeral, the process holds no durable state), re-fetch the snapshot on every reconnect, back off with jitter to avoid a thundering herd, reconnect on browser online, and make mutating POSTs idempotent for retry safety.
The blue/green deploy-resilience guidance only lived in the companion-app skill, but WebSockets are a general SDK feature (custom chart summary sections, NoteRestrictionsUpdatedEffect, companion apps). Add a plugin- agnostic 'WebSockets must survive blue/green deploys' subsection to the canvas-sdk skill (the durable, hand-authored home; the context file is auto-regenerated from docs and would be overwritten), and add a conditional WebSocket-resilience review gate to the wrap-up command so the guidance fires during real plugin work instead of only sitting in a reference doc.
|
Rebased |
canvas-sisyphus
Bot
force-pushed
the
bg-ws-deploy-resilience
branch
from
August 24, 2026 23:34
4cfc14f to
5509aaa
Compare
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.
The Canvas Plugin Assistant
companion-app-patternsskill documented realtime push via WebSocket (rule 12 / §7) but its reconnect guidance was a thin fixed-4s-backoff snippet with no story for what happens during a daytime blue/green deploy — when the server drains the old container, drops every client's socket at once, and reconnects them onto a freshly booted process. WebSockets are a general SDK feature, though, not a companion-app-only one, so this PR also lifts the resilience guidance out of that single skill and puts it everywhere a plugin author will hit it.The core principle: the socket is a re-sync hint, not a source of truth. Broadcasts are fire-and-forget and ephemeral (no replay, no per-client queue, no ack), and the plugin process keeps no durable state across a restart, so anything sent during the deploy gap is lost. The client recovers by re-fetching the authoritative snapshot from its
SimpleAPIendpoint.companion-app-patternsskill — rewrote the guidance to carry the resilience lessons from canvas-hyperscribe, scoped to what a plugin author can actually do inside the sandbox.companion_app_patterns_context.txt§7 replaces the old "### Reconnect" subsection with "### Surviving deploys & reconnection": the three facts that drive the design (broadcasts are ephemeral, the process holds no durable state, disconnects are synchronized), re-fetch the snapshot on every (re)connect by wiring the load to the socketopenevent, exponential backoff + jitter + cap instead of a fixed delay, reconnect immediately on the browseronlineevent, and an optional heartbeat to detect the half-open socket a cutover can leave behind. A new "### Mutations must be idempotent across a deploy" subsection covers the dropped-response case: a cutover can drop the response to an in-flight mutating POST, the client can't tell "never applied" from "applied, response lost" so it retries, and the server must re-check state and no-op rather than double-apply.SKILL.mdadds quick-reference rule 13, renumbers the following rules, and fixes the Reference Implementations cross-references.canvas-sdkskill — this is the durable, plugin-agnostic home, since the same WebSocket concern applies to custom chart summary sections and real-time note-restriction updates (NoteRestrictionsUpdatedEffect), not just companion apps. Added a "### WebSockets must survive blue/green deploys" subsection with the four core principles (push is a hint / pull is the truth, re-fetch on every reconnect, backoff + jitter + cap plus theonlineevent, idempotent mutations) and a pointer to the full worked client code in companion-app-patterns. The guidance lives inSKILL.mdrather thancoding_agent_context.txtbecause the latter is auto-regenerated from docs.canvasmedical.com and would overwrite anything added there.wrap-upcommand — added a conditional "WebSocket Deploy Resilience" review gate (modeled on the existing cache-busting gate, its sibling "survive a deploy" check) so the guidance actually fires during real plugin work instead of only sitting in a reference doc. It greps for WebSocket usage and, if found, verifies all four requirements, then the trailing sections were renumbered and both summary tables gained a row.No code or runtime behavior changes — this is plugin-authoring guidance only.