Skip to content

Renderer protocol: rendered echoes the init it answers, and the host drops stale ones - #172

Merged
agorischek merged 5 commits into
mainfrom
rendered-generation
Nov 22, 2026
Merged

agorischek merged 5 commits into
mainfrom
rendered-generation

Conversation

@agorischek

Copy link
Copy Markdown
Collaborator

Follow-up to a Copilot thread on #147. A renderer's rendered acknowledgement of the previous document could arrive after the host sent a new init. The pane then recorded it as painting the new document, so paintState (and the Inspector's snapshot readiness) could report painted too early.

Protocol (renderers/sdk/src/protocol):

  • init may carry generation, a non-negative safe integer the host gives each init it sends.
  • rendered may carry generation, the latest the renderer had received when it reported.
  • The parsers validate both, and an invalid value rejects the message.

SDK client:

  • rendered() echoes the latest init's generation, read from the init the client already keeps for replay.
  • The renderer's init handler never sees the field.
  • Renderers need no change.

Host:

  • RendererFrame numbers each setInit, and sends the number with init, including the one replayed at ready.
  • Its MessageGate drops a rendered for an earlier generation (a new stale admission), before it reaches progress flow control, the reveal or the pane.
  • The pane already moves its init ref with setInit in the same step, so its tagging is now correct.

Compatibility:

  • A host that sends no generation gets none back.
  • A renderer (or older SDK bundle) that echoes none is taken at its word, as before.
  • Older hosts never see the new rendered field, because the client only echoes what the host sent.

Docs: contracts/renderer-frames.md describes both fields, and the generated reference pages are regenerated.

Tests:

  • renderers/sdk/test/protocol.test.mjs: parsing, the client's echo, and the init handler not seeing the field.
  • host/core/test/frame-generation.test.mjs: a real RendererFrame with a fake window drops an earlier generation's acknowledgement and takes an unnumbered one.

…drops stale ones

The host numbers each init it sends (generation), the SDK's client echoes the
latest it received on rendered, and the frame's message gate drops an
acknowledgement of an earlier init. A paint of the previous document that
arrives after a new init no longer counts as painting the new one. Both
fields are optional: hosts that send no generation get none back, and
renderers that echo none are taken at their word, as before.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

A critical race allows an old deferred paint callback to acknowledge a newer init, falsely reporting the new document as painted; acknowledgements must retain their originating init token, with regression coverage.

1 open issue
What changed in this PR

Adds generation tracking to Projections’ renderer protocol so the host can reject stale paint acknowledgements. This follows #147’s pane lifecycle work and aims to prevent premature paint and snapshot readiness.

Changes:

  • Adds optional, validated generations to init and rendered, with SDK echoing and legacy compatibility.
  • Numbers host initializations and filters mismatched acknowledgements before progress, reveal, and pane updates.
  • Adds protocol and frame tests, updates the contract, and regenerates API references.
File Description
packages/​renderers/​sdk/​test/​protocol.test.mjs Tests generation validation, echoing, and handler isolation.
packages/​renderers/​sdk/​src/​protocol/​validation.ts Adds non-negative safe-integer validation.
packages/​renderers/​sdk/​src/​protocol/​renderer-messages.ts Parses optional acknowledgement generations.
packages/​renderers/​sdk/​src/​protocol/​messages.ts Defines and documents both generation fields.
packages/​renderers/​sdk/​src/​protocol/​host-messages.ts Validates initialization generations.
packages/​renderers/​sdk/​src/​client/​host-messages.ts Extracts generations for echoing and hides them from init handlers.
packages/​renderers/​sdk/​src/​client.ts Echoes the latest init generation in acknowledgements.
packages/​host/​core/​test/​frame-generation.test.mjs Tests stale filtering and unnumbered compatibility.
packages/​host/​core/​src/​pane.tsx Clarifies acknowledgement attribution in a comment.
packages/​host/​core/​src/​frame/​replay.ts Includes generations in initialization and replay messages.
packages/​host/​core/​src/​frame/​admission.ts Adds stale acknowledgement admission filtering.
packages/​host/​core/​src/​frame.ts Advances generations and keeps them out of pane events.
docs/​reference/​renderer-sdk.md Regenerates SDK signatures with generation fields.
docs/​reference/​renderer-messages.md Regenerates protocol type references.
docs/​contracts/​renderer-frames.md Documents generation exchange and stale filtering.

Review effort: Balanced

Comment thread packages/renderers/sdk/src/client.ts Resolved
agorischek and others added 4 commits November 21, 2026 16:13
… init it painted

rendered(progress, init) echoes the generation of the init payload it painted,
which the client records as it hands each init to the renderer; the SDK's React
hooks pass it. A paint of the previous document that finishes after a new init
arrives is then dropped by the host. Without the init, the latest is assumed.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…t painted

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@agorischek
agorischek merged commit 47685a0 into main Nov 22, 2026
48 checks passed
@agorischek
agorischek deleted the rendered-generation branch November 22, 2026 00:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants