Skip to content

feat(mobile): carry browser screencast frames over the bridge as base64 (OTA phase C, C6.1) - #21758

Merged
Jinwoo-H merged 11 commits into
mainfrom
ota-c6-1-screencast-encoder
Sep 20, 2026
Merged

Jinwoo-H merged 11 commits into
mainfrom
ota-c6-1-screencast-encoder

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Phase C, C6.1: the shell's half of the screencast binary lane (design-ota-c6.md §1, §7; rulings rulings-ota-c6.md 1, 2 and 5). Eleven commits on ee61e3bd41, inert: no route declares the grant, no registered route reaches the browser pane, and a page that does not ask for binary frames sees the same JSON stream as before.

The bridge contract already carried the lane (event.binary with b64, format, frameSeq and metadata; subscribe.wantsBinary; the page-side decoder decodeBridgeScreencastFrame, whose docstring handed the encoder to C6). The shell side never honoured wantsBinary, so a page asking for binary frames got nothing, and a screencast frame over the 640 KiB message cap ended the stream with overflow for good.

commit what
4833dcdc06 BridgeHostSubscriptions honours wantsBinary: the native listener is handed an encoder that turns a BrowserScreencastFrame into the envelope's event.binary, round-tripped through the real decoder byte for byte; a fresh three-bytes-at-a-time base64 encoder (bridge/bridge-screencast-encoder.ts), written for a cost argument that survives not knowing Hermes rather than the per-byte one being quadratic, which on V8 it is not (the docstring carries the four measured variants and the correction)
73c46f4563 ruling 1: an event.binary over the frame cap or the unacked window is dropped and the stream lives, a JSON event over the same cap still ends with overflow, both pinned side by side; a per-subscription and per-host dropped-frame count reaches the shell's dev facts line (mobile-web-shell-dev-facts.ts, absent at zero)
ca304ac887 ruling 5: the grant screencastBinary (bridge/bridge-screencast-grant.ts) in the shell's implemented set; one camelCase token because the manifest's GRANT_NAME_PATTERN admits one token or a native.<a>.<b> verb and refuses browser.screencast, characterised in manifest-contract.test.ts (not red-first: the pattern already admitted the name)
94d831a235 the dropped-frame total read through the bridge hook, typed through the wiring instead of a cast (the tests-typecheck ratchet was red on the previous commit)
dd019cba1b the counter kept with the ledger it belongs to; no behaviour
f843f2b48e the host serves the binary lane only to a route granted it: bridgeBinaryLaneVerdict reads the session's resolved grants, the same list init.grants.native is built from, so the host offers the lane in init exactly when it will serve it (pinned as its own case); ungranted, the subscription proceeds as today (JSON events, no error frame, pinned positively). Found by the lane and ruled in: per-route grants exist to stop exactly this class. The existing bridge-hook test red on it, because its dropped-frame case had been receiving binary frames ungranted all along
8174f8bf0b bridge-host.ts was at 298 of 300 counted lines; the page's three stream frames (open with its four refusals and the lane verdict, cancel, ack) move into bridge-host-stream-frames.ts, a pure move apart from a two-line local alias (servesBinaryFrames) inlined at its one call site: no test changed or added, 745 tests green on the same assertions; host 298 → 270 and new module 59 at the split, 271 and 60 at the head
290c35f872 round 2: a frame was encoded and stringified before the unacked window was tested, so a stalled page made the shell pay a full encode for every frame it then dropped; the frame's size is now computed exactly from its serialized header plus the image's base64 length (base64 is ASCII, so JSON escapes none of it), the window rule reads once before the encode and again on the frame that was, and the encoder is built from that header so the shape measured and the shape sent cannot drift (red-first with a counting encoder: window full, ten frames, ten encodes → zero with the drop count still ten; an over-cap frame one → zero; two carryable frames still encode twice). The screen test's shared setup moves to file level and resets the mutable dependencies, pinned by a last case asserting the defaults (deleting the reset fails only that case: the leak was inert because the mutating block ran last). bridge-host-subscriptions.ts 228 → 179 lines
65c36e70f8 CodeRabbit (Major): onBinaryFramesDropped: setDroppedBinaryFrames updated React state on every dropped frame in a production build too, where the dev-facts line renders nothing, so an over-cap page re-rendered the shell screen once per dropped frame (measured: five drops, five extra renders; with the fold, zero). The dev-facts module now owns the number behind its line and the rule that it is state only where something renders it; the screen holds neither flag nor counter. isDevelopmentBuild became a call rather than a module constant so a production case can exist at all (a build flag never changes at runtime). Found while writing that case: the screen test's usePageHostSnapshot double returned a fresh object per render, the identity the host effect is keyed on, so every case in that file had been measuring a host rebuilt on every render; the double now returns one object
d9311e0c8c round 1 and pullfrog: the dev-facts dropped-frame total reset with the host that counts it (the screen kept a retired host's number until the new host's first drop, so the count fell; red-first: [1] where [1, 0] was expected; the reset also fires on the first build, so both hook cases pin a leading zero rather than a flag suppressing it); the BUILD_ID_PREFIX_LENGTH docstring that stayed behind above failureMessage when the constant moved, and the doubled docstring on one it in page-route-policy.test.ts, deleted
846be963aa the diagnostic binary-lane-refused (one arm in the union, one line in the reporter, deduped per host) when a page asks for the lane ungranted; the verdict answers serve / not-asked / ungranted so the decision and the report read one rule; silent when never asked and silent when granted are both pinned

No reader of a grant is a closed enum (page BridgeGrantsSchema.native and the shell's route schema are both open string arrays, the latter's docstring saying an unknown grant leaves that one route native), so an older shell parses a manifest naming screencastBinary and renders the session route natively, and an older page holds the string and does nothing with it. BRIDGE_PROTOCOL_VERSION is untouched.

Measured (Node, the vitest runtime; Hermes unmeasured, C6.6 measures the device)

frame encode + stringify at 10 fps
77,293 B (the design's phone frame) 0.57 ms 5.7 ms/s
491,298 B (largest under the cap at CDP's nine-field metadata with a real timestamp, overhead 294 B; 491,373 B at the test's four fields, since the encoder emits 4 characters per 3 bytes the largest fitting image is a multiple of 3; the design's 491,309 and 281 B were measured with toy metadata) 3.78 ms 37.8 ms/s

The dropped-frame counter read back in test: totals [1, 2] across two streams, dropped: 1 each, bytes: 666,862 (image 666,668 plus the 194-byte envelope, computed independently).

Not in this PR

Verified

  • Lane gates on 846be963aa: mobile tsc, ratchet (728 files), whole-tree oxlint, oxfmt, root oxlint and oxfmt on the changed files, full mobile suite (732 files, 8276 passed, no Errors line), config/scripts with mobile deps required (223 files, 2053 passed), root shared suite, both changed-code gates, node tsc, machine-path grep clean; origin/main is an ancestor, so the merge tree is the head.
  • Round 1 (on 846be963aa): approve, every ruling reproduced under mutation (binary branch cancelling: 6 red with the JSON control green; verdict always serve: 4 red; grant out of the implemented set: 12 red); its lows are d9311e0c8c.
  • Round 2 (on 65c36e70f8): approve; ten mutations red as claimed with the JSON overflow control green throughout; the real usePageHostSnapshot holds one useState object, so the old test double was rebuilding the host per render; its two lows are 290c35f872.
  • CodeRabbit on 846be963aa: the reset on host rebuild (already d9311e0c8c) and the production render path (65c36e70f8).
  • Lead reproduction: verify-gates.sh on dd019cba1b, 846be963aa, d9311e0c8c, 65c36e70f8 and 290c35f872 against ee61e3bd41 (mobile 732/8269, 732/8276, 732/8277, 732/8279 and 732/8283, config 2053, all exit 0, machine paths 0; merge-tree clean against 8dee68a8d1); forcing the over-cap binary branch to cancel reds the five drop and counter cases and leaves the JSON overflow control green; making the lane verdict always serve reds exactly the two ungranted cases (no listener handed, diagnostic reported) and nothing else of 748; on 290c35f872, removing the pre-encode window check reds exactly the two counting-encoder cases; the split commit's diff touches only the two modules and no test.

Part of the mobile OTA plan (Phase C). Reference PR #13386, never merged.

…phase C, C6.1)

`bridge-screencast-binary.ts` landed in C0 as the page's half of the binary
lane and named C6 as the owner of the encoder that satisfies it. This is that
encoder, plus the host honouring `wantsBinary`: a subscribe that asked for
binary gets an `onBinaryFrame` on the native stream, and each frame crosses as
the envelope's `event.binary` on the same `seq` ledger as the stream's JSON
events, because the page acks by that count.

The base64 encoder is grouped rather than per byte or per `fromCharCode`
window. Its docstring carries the measurement, including the part that
contradicts the design note this came from: on V8 the per-byte form is the
fastest of the three, not the quadratic one, and the chunked form it was meant
to beat is the slowest. The grouped one is here because its cost does not
depend on how an engine ropes `+=`, and Hermes is what the shell runs.

No new opcode, no `v` bump, no negotiation added: `wantsBinary` is already in
the contract and is the negotiation. Over-cap behaviour is unchanged in this
commit — a binary event over the frame cap still ends the stream, which is what
C6.2 changes.

Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
… stream (OTA phase C, C6.1)

Measured at the pane's own request parameters, a screencast frame exceeds the
640 KiB envelope on a phone layout whenever the page will not compress: JPEG's
worst case is 0.545 bytes per pixel at quality 72, so mobile view mode at
780x1424 is 811,289 bytes, 124% of the cap. Ending the stream there blacks out
a browser tab for the life of the pane over one frame.

So the two kinds of event part at the cap. A JSON event that will not fit still
ends the stream with `overflow`, because its reader cannot see the hole it
would leave; a screencast frame is dropped and the stream lives, because the
next frame is one throttle interval away and the pane is still showing the last
one. Both are asserted side by side so neither turns into the other.

A drop leaves no other trace: the diagnostic beside it prints once per host, so
a stream shedding a frame a second and one that shed a single frame read the
same. The host therefore counts them per stream for the diagnostic and keeps a
session total, and the shell's dev facts carry that total — the surface that
already shows build state, with the line moved into its own module so what it
says is pinned rather than inferred from a template. The 12-character build
prefix it has always shown is unchanged.

Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
…, C6.1)

Ruling 5's negotiation, and the check it asked for first: no reader of a grant
is a closed enum, so there is no blocker and nothing an older page has to
tolerate. `BridgeGrantsSchema.native` and the shell's manifest reader are both
open string arrays, and the shell reader's own docstring already states the
degradation — a grant name a build does not know leaves that one route native
rather than refusing the bundle.

What does constrain the name is the host contract's `GRANT_NAME_PATTERN`: a
grant is one camelCase token or a `native.<domain>.<action>` verb with at least
two dot segments. So `browser.screencast` and `native.screencast` are both
refused, and the lane is `screencastBinary`. `screencast` alone would be wrong:
the page can already subscribe to `browser.screencast` and receive its JSON
events, and only the binary frames need the encoder.

Added to the shell's implemented set, which is the same list `init.grants.native
` offers, so a route declaring it is served by a shell that has the encoder and
left native by one that does not. No route declares it here; C7's session route
does.

The contract-side case is a characterisation pin, not a red-first one: the
pattern already admitted this name, and the test records that the two tempting
spellings are the ones it refuses.

Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
…OTA phase C, C6.1)

The hook gained a required `onBinaryFramesDropped` two commits ago and this
test kept calling it without one, so the tests-typecheck ratchet went red on
that commit — caught here rather than in CI because an exit code was read off a
pipeline's last stage instead of the script.

Fixed by wiring the callback into the probe rather than by a cast, and with the
case that makes the wiring evidence instead of types: a dropped frame raises
the total the screen receives, and the stream stays subscribed while it does.

Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
…elongs to (OTA phase C, C6.1)

Declared between a getter and a method, which is not where this class keeps
state: the subscription map is at the top and the counter is the same kind of
thing. Move only.

Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
… it (OTA phase C, C6.1)

Reported as a gap after C6.1's third commit and ruled on: the host honoured
`wantsBinary` from any page, so a route that never declared `screencastBinary`
could still make the shell encode base64 on its behalf. That is the hole
per-route grants exist to close — the same class as a route granted only
`navigate` and `storage` reaching the clipboard.

The rule now reads the session's resolved list, which is what its route
declared narrowed to what this shell implements, and is the same set
`init.grants.native` is built from. So the host offers the lane in `init`
exactly when it will serve it.

Ungranted is not a refusal. The subscription proceeds and its JSON events cross
as before, which is the silence every other grant gives at the call site; a
page that reads its own grants never reaches that state. Both branches are
pinned beside each other, and `grantsForRoute` is pinned dropping a grant this
shell does not implement — granted-but-unimplemented and never-granted arrive
at the host as the same absence, so its rule reads one case.

The grant name moves into the module that holds the rule reading it, so the two
cannot drift. `bridge-host.ts` is at 298 of its 300-line cap after this.

Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
…(OTA phase C, C6.1)

`bridge-host.ts` reached 298 of its 300-line cap, so the next main merge that
touched it would have crossed under CI pressure on someone else's PR. Split
deliberately instead, at the boundary the growth came from.

`bridge-host.ts` is the host's lifecycle and its dispatch. Opening a stream is
the only frame kind whose handling is more than one line of delegation — four
refusals and, since C6.1, the binary-lane decision — so it moves whole, and
`cancel` and `ack` move with it so all three stream frames are decided in one
place. The host's `cancel` arm still chooses between a stream and a request
where it always did: a page's `cancel` names one or the other, and splitting
that choice would leave half an arm in each module.

Counted without blank lines or comments, as the rule counts them:
bridge-host.ts 298 -> 270, and the new module is 59.

A pure move. No test changed and none was added, which is what makes the
existing suites the proof: 45 files and 745 tests green on the same assertions
as before.

Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
…ot granted (OTA phase C, C6.1)

An ungranted `wantsBinary` is not a refusal on the wire, so nothing crosses
back: the subscription proceeds and its JSON events cross as they always have.
That left a page which did ask getting JSON for the life of the document with
no side able to say why. `notify-refused` has covered the equivalent notify
case since C0; this is the same shape for the one frame kind that lacked it.

The rule now answers a verdict rather than a boolean, because `not-asked` and
`ungranted` are the same answer for different reasons and only one is worth
reporting. So the decision and the report read one rule, and a page that never
asked stays silent — pinned, along with a granted route staying silent, so the
line cannot start firing on either.

The wire is unchanged and pinned unchanged: the case beside this one still
asserts one JSON event delivered and zero error frames.

Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
@coderabbitai

coderabbitai Bot commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 5db1c808-de88-4be3-ab6f-30577f803162

📥 Commits

Reviewing files that changed from the base of the PR and between 65c36e7 and 290c35f.

📒 Files selected for processing (4)
  • mobile/src/mobile-web-shell/MobileWebShellScreen.test.tsx
  • mobile/src/mobile-web-shell/bridge-host-screencast.test.ts
  • mobile/src/mobile-web-shell/bridge-host-subscriptions.ts
  • mobile/src/mobile-web-shell/bridge/bridge-screencast-encoder.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 6 remain after this review.


📝 Walkthrough

Walkthrough

The mobile web shell now supports a granted binary screencast lane. It encodes and delivers binary frames, preserves shared event sequencing, and drops oversized or unacknowledged binary frames without ending the stream. The bridge emits refusal and drop diagnostics, forwards cumulative drop counts to the screen, and displays them in development facts. Tests cover encoding, grants, routing, backpressure, diagnostics, and rendering.

Priority: ➖ Normal

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 48.39% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 31 functions across 21 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The description provides extensive technical context and testing details, but it does not follow the required template. It omits the required ELI5, What Changed, Why, Linked Issue with a Fixes referen… Rewrite the description using the repository template. Add every required section, include a valid linked issue in the Linked Issue section, provide visual proof or write exactly N/A with a reason, complete the testing and checklist items, …
✅ Passed checks (3 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly identifies the main change: carrying browser screencast frames over the bridge as base64. It is concise and specific.
Full details: Description check

Explanation

The description provides extensive technical context and testing details, but it does not follow the required template. It omits the required ELI5, What Changed, Why, Linked Issue with a Fixes reference, Visual Proof or explicit N/A, AI Disclosure, Review, Agent skill upstream boundary, Notes, and Checklist sections.

Resolution

Rewrite the description using the repository template. Add every required section, include a valid linked issue in the Linked Issue section, provide visual proof or write exactly N/A with a reason, complete the testing and checklist items, and address AI Disclosure and Agent skill upstream boundary.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 97658b10-cfd0-4d26-a0a9-922e5c8e8ad4

📥 Commits

Reviewing files that changed from the base of the PR and between ee61e3b and 846be96.

📒 Files selected for processing (20)
  • mobile/src/mobile-web-shell/MobileWebShellScreen.tsx
  • mobile/src/mobile-web-shell/bridge-diagnostic-log.ts
  • mobile/src/mobile-web-shell/bridge-host-contract.ts
  • mobile/src/mobile-web-shell/bridge-host-init.test.ts
  • mobile/src/mobile-web-shell/bridge-host-screencast.test.ts
  • mobile/src/mobile-web-shell/bridge-host-stream-frames.ts
  • mobile/src/mobile-web-shell/bridge-host-subscriptions.ts
  • mobile/src/mobile-web-shell/bridge-host-test-fakes.ts
  • mobile/src/mobile-web-shell/bridge-host-test-harness.ts
  • mobile/src/mobile-web-shell/bridge-host.ts
  • mobile/src/mobile-web-shell/bridge/bridge-screencast-encoder.test.ts
  • mobile/src/mobile-web-shell/bridge/bridge-screencast-encoder.ts
  • mobile/src/mobile-web-shell/bridge/bridge-screencast-grant.ts
  • mobile/src/mobile-web-shell/mobile-web-shell-dev-facts.test.ts
  • mobile/src/mobile-web-shell/mobile-web-shell-dev-facts.ts
  • mobile/src/mobile-web-shell/page-route-policy.test.ts
  • mobile/src/mobile-web-shell/page-route-policy.ts
  • mobile/src/mobile-web-shell/use-mobile-web-shell-bridge.test.ts
  • mobile/src/mobile-web-shell/use-mobile-web-shell-bridge.ts
  • src/shared/mobile-web-bundle/manifest-contract.test.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.

Comment on lines +218 to +220
// A dropped screencast frame leaves no other trace on a device: the stream stays up by design
// and the diagnostic beside it prints once per host.
onBinaryFramesDropped: setDroppedBinaryFrames

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🚀 Performance & Scalability | 🟠 Major | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

rg -n "screencastBinary|onBinaryFramesDropped|isDevelopmentBuild|routeGrants|granted" mobile/src/mobile-web-shell src/shared/mobile-web-bundle | head -240
sed -n '135,230p' mobile/src/mobile-web-shell/MobileWebShellScreen.tsx
sed -n '145,200p' mobile/src/mobile-web-shell/use-mobile-web-shell-bridge.ts
sed -n '1,100p' mobile/src/mobile-web-shell/bridge-host-stream-frames.ts

Repository: stablyai/orca

Length of output: 33734


🏁 Script executed:

#!/bin/bash
set -e
printf '%s\n' '--- candidate route and manifest files ---'
rg -l -n "MobileWebShellScreen|screencastBinary|grantsForRoute|DevFacts|createBridgeHost|droppedBinaryFrames" mobile src/shared --glob '!**/*.test.*' | head -120
printf '%s\n' '--- route/session grant resolution ---'
sed -n '1,240p' mobile/src/mobile-web-shell/mobile-web-shell-session.ts
sed -n '1,220p' mobile/src/mobile-web-shell/page-route-policy.ts
printf '%s\n' '--- screen remainder and DevFacts ---'
sed -n '1,330p' mobile/src/mobile-web-shell/MobileWebShellScreen.tsx
printf '%s\n' '--- host drop path and subscriptions ---'
sed -n '1,230p' mobile/src/mobile-web-shell/bridge-host.ts
sed -n '1,280p' mobile/src/mobile-web-shell/bridge-host-subscriptions.ts
printf '%s\n' '--- non-test route declarations mentioning shell/manifest ---'
rg -n "routes\s*:|pathname\s*:|screencastBinary|mobile-web-shell|web-shell" mobile src/shared --glob '!**/*.test.*' --glob '*.{ts,tsx,js,jsx,json}' | head -260

Repository: stablyai/orca

Length of output: 50369


🏁 Script executed:

set -e
printf '%s\n' '--- route/session grant resolution ---'
sed -n '1,230p' mobile/src/mobile-web-shell/mobile-web-shell-session.ts
sed -n '1,180p' mobile/src/mobile-web-shell/page-route-policy.ts
printf '%s\n' '--- screen and host callback ---'
sed -n '1,290p' mobile/src/mobile-web-shell/MobileWebShellScreen.tsx
sed -n '1,220p' mobile/src/mobile-web-shell/bridge-host.ts
sed -n '1,300p' mobile/src/mobile-web-shell/bridge-host-subscriptions.ts
printf '%s\n' '--- production declarations ---'
rg -n "routes[[:space:]]*:|pathname[[:space:]]*:|screencastBinary|MobileWebShellScreen|DevFacts" mobile src/shared --glob '!**/*.test.*' --glob '*.{ts,tsx,js,jsx,json}' | head -300

Repository: stablyai/orca

Length of output: 50369


🏁 Script executed:

set -e
printf '%s\n' '--- exact binary grant bindings outside tests ---'
rg -n "screencastBinary|BRIDGE_SCREENCAST_BINARY_GRANT|MOBILE_WEB_SHELL_GRANTS" . --glob '!**/*.test.*' --glob '!**/node_modules/**' --glob '!**/dist/**' --glob '!**/build/**'
printf '%s\n' '--- manifest route/grant producers and readers outside tests ---'
rg -n "MobileWebBundleManifest(Read|Facts)|read-manifest|manifest\.routes|routes:.*grants|grants:.*pathname|MobileWebBundleRoute" mobile src modules --glob '!**/*.test.*' --glob '!**/node_modules/**' --glob '!**/dist/**' --glob '!**/build/**' | head -260
printf '%s\n' '--- manifest contract and transport binding ---'
sed -n '80,135p' src/shared/mobile-web-bundle/manifest-contract.ts
sed -n '1,180p' mobile/src/transport/mobile-web-bundle-reply-schemas.ts
rg -n -A18 -B12 "kind: 'read-manifest'|readManifest|read-manifest" mobile/src --glob '!**/*.test.*'

Repository: stablyai/orca

Length of output: 28824


Do not update React state for invisible production facts.

When a manifest route grants screencastBinary and an unacknowledged binary subscription drops frames, BridgeHostSubscriptions calls onBinaryFramesDropped for each dropped frame. The callback reaches setDroppedBinaryFrames, so changing totals can trigger repeated production renders even though DevFacts returns null.

Gate the state update with isDevelopmentBuild, or keep the production total outside React state.

Proposed fix
-    onBinaryFramesDropped: setDroppedBinaryFrames
+    onBinaryFramesDropped: isDevelopmentBuild ? setDroppedBinaryFrames : () => undefined
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// A dropped screencast frame leaves no other trace on a device: the stream stays up by design
// and the diagnostic beside it prints once per host.
onBinaryFramesDropped: setDroppedBinaryFrames
// A dropped screencast frame leaves no other trace on a device: the stream stays up by design
// and the diagnostic beside it prints once per host.
onBinaryFramesDropped: isDevelopmentBuild ? setDroppedBinaryFrames : () => undefined

…it (OTA phase C, C6.1)

Round 1 on #21758, three findings.

The real one: the count is per host and the screen's copy was not. A rebuilt
host starts its own total at zero, so the screen kept the retired host's number
until the new one dropped a frame and then read *lower* — a falling count looks
like frames coming back, which is worse than starting over. The hook now
announces a fresh count as it builds a host. That also reports zero on the
first build, where the screen is already at zero and React bails out of the
render; the two hook cases pin that leading zero rather than leave it to be
rediscovered.

Two docstrings that described nothing: `BUILD_ID_PREFIX_LENGTH`'s stayed behind
when the constant moved to the dev-facts module and had drifted above
`failureMessage`, and `page-route-policy.test.ts` kept the docstring of the
test it replaced above the one that replaced it. Both deleted; the first's text
lives on the new module.

Red-first for the reset, checked against its final expectations rather than its
first: with the one line reverted both hook cases fail on the missing zero, and
both pass with it.

Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ℹ️ No critical issues — one stale doc reference plus a couple of small notes.

Reviewed changes

  • Shell encodes screencast frames to base64 — BridgeHostSubscriptions now honours wantsBinary, handing the client an onBinaryFrame listener and wrapping each frame into event.binary via a new three-bytes-at-a-time encoder.
  • Over-cap binary frames are dropped, not fatal — a frame over the message cap or the unacked window bumps a dropped count and leaves the stream open; JSON events still end with overflow.
  • screencastBinary grant gates the lane — bridgeBinaryLaneVerdict serves binary only to a session whose resolved route grants include it, reports binary-lane-refused locally otherwise, and the name joins the shell's implemented set.
  • Dropped-frame total reaches the dev-facts line — a per-host total flows through onBinaryFramesDropped to formatMobileWebShellDevFacts, absent at zero.
  • Stream-frame handling moved — open / cancel / ack extracted from bridge-host.ts into bridge-host-stream-frames.ts as a pure move.

I traced the cross-module pieces that carry risk: the page's ack thresholds (64 frames / 1 MiB) sit well inside the shell's window (256 / 4 MiB), so the new drop rule is a stalled-page backstop rather than a normal-path behavior; byte accounting matches on both sides (utf8ByteLength(json)); a dropped frame spends no seq, and the grant gate is fed by grantsForRoute (declared ∩ implemented), so granted-but-unimplemented and never-granted are the same absence at the host. The encoder is pinned against Node's Buffer, which is a genuine oracle.

ℹ️ Stale reference to the removed handleSubscribe

bridge-host-requests.ts:65 still says the native. subscribe fence lives in handleSubscribe, but that function was deleted by this PR; the fence now lives in createBridgeHostStreamFrames's open.

Technical details
# Stale comment after the stream-frame extraction

## Affected sites
- `mobile/src/mobile-web-shell/bridge-host-requests.ts:64-66` — the docstring on `forward` names `handleSubscribe`, which no longer exists.

## Required outcome
- Point the comment at the module/function that now owns the subscribe fence (`bridge-host-stream-frames.ts`, `createBridgeHostStreamFrames.open`), or describe it without naming the removed symbol.

ℹ️ Nitpicks

  • bridge-host-subscriptions.ts — deliverBinaryFrame base64-encodes and JSON.stringifys the whole frame before sendEvent decides it does not fit, so an over-cap or window-full frame pays the full encode cost to be discarded. Since the cap is enforced on the encoded event, the unacked frame-count branch could short-circuit before the encode; entirely optional given the measured cost and the C6.6 device pass.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

… render path (OTA phase C, C6.1)

CodeRabbit's Major on #21758. The total went into React state on every dropped
frame in every build, and outside a development build the line that reads it
renders null — so an over-cap page re-rendered the whole shell screen up to ten
times a second for a fact nobody can see. Measured, not argued: five drops,
five extra renders.

Fixed at the seam rather than with a ternary at the call site. The dev-facts
module owns the line, so it now owns the number behind it and the rule that the
number is only state where something renders it. The screen holds no flag and
no counter; it asks for both and passes the reporter on. The reporter is stable,
so the bridge host is never rebuilt for it.

`isDevelopmentBuild` becomes a call rather than a module constant. A build flag
never changes at runtime so this costs nothing, and as a constant the branch was
unreachable to anything that did not set the global before the module loaded —
which is why the production case could not be written at the screen at all.

Also fixed, found while writing that case: the screen test's
`usePageHostSnapshot` double returned a fresh object on every render, so the
host effect's identity changed each time and the bridge host was torn down and
rebuilt on every render of the screen, settling every pending request with it.
The real hook holds the snapshot in `useState` and is stable. One object for the
file now. This was masking the fold under test — the count reset to zero on
every render — and every other case in that file was measuring a rebuild storm.

Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ No new issues found.

Reviewed changes

  • Dropped-frame total now resets with the host that owns it — useMobileWebShellBridge calls binaryFramesDroppedRef.current(0) in the same layout effect that builds the host, so a rebuilt host starts its count over instead of the screen showing the retired host's number and then going down on the next drop.
  • The reset is pinned at both ends — the existing hook case now expects [0, 1, 2] to record the leading zero, and a new case rebuilds the host and expects [0, 1, 0].
  • Two dead docstrings deleted — the orphaned BUILD_ID_PREFIX_LENGTH block that had drifted above failureMessage (the constant and its text live in mobile-web-shell-dev-facts.ts now), and the duplicated JSDoc in page-route-policy.test.ts raised in the previous review.

I traced the reset through the hook: the ref-refresh useLayoutEffect is declared above the host-building one, so binaryFramesDroppedRef.current reads the current render's handler when the reset fires, and setDroppedBinaryFrames is stable so the reset cannot re-enter the effect. The new reset case fails without the one line, so it is real coverage. The change is correct and mergeable as-is.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

…C, C6.1)

Round 2 on #21758, two lows.

The encode is a base64 pass over the whole image and the window decides whether
the frame can be posted at all, so deciding after encoding made a page that had
stopped acking pay for every frame the shell then threw away — the reviewer's
case is ten 300 KB frames against a closed window, 3 MB encoded and nothing
sent. The size is knowable without encoding: base64 is ASCII, so JSON escapes
none of it and the frame is its header serialized plus exactly the image's
encoded length. `encodeBridgeScreencastFrame` is now built from that header
rather than beside it, so the shape measured and the shape sent cannot drift,
and the window arithmetic is one rule read before the encode and again on the
frame that was.

Exact, not conservative, so the drop diagnostic still reports the whole frame
and the committed byte pin is untouched.

Red-first with the real encoder wrapped in a counter: window full, ten frames,
ten encodes before and zero after, with the drop count still ten. An over-cap
frame likewise goes from one encode to none. A third case holds the other
direction — two carryable frames still encode twice — so the fix cannot pass by
encoding nothing.

Second low: the dev-facts block sat outside the only `beforeEach` and left
`routeGrants` and `client` mutated, inert only because it runs last. The shared
setup moves to file level where the mutable dependencies actually live, resets
both, and a case at the end of the file pins it — deleting the reset fails
there and nowhere else, since nothing else runs after a case that mutates them.

Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ No new issues found.

Reviewed changes

The delta since the prior pullfrog review is commit 65c36e70f8 (CodeRabbit's Major), which keeps the dropped-frame total out of a production build's render path.

  • Dropped-frame total stopped re-rendering production builds — useMobileWebShellDroppedFrames in mobile-web-shell-dev-facts.ts now owns the counter state and its reporter no-ops outside a development build, so an over-cap page no longer re-renders the whole shell screen once per dropped frame.
  • isDevelopmentBuild became a call, not a constant — reading the flag where it is used makes the production branch reachable from a test that toggles the global, which is what let the fix be pinned.
  • Screen test's snapshot double made stable — the usePageHostSnapshot mock returned a fresh object per render, changing the identity the host effect is keyed on; it had been rebuilding the bridge host on every render of that file. One hoisted object now.
  • New coverage — a counted viewRenders case pins the production no-extra-render property, and a running-total/reset case pins the dev-facts line.

I traced the gate through the callback path (BridgeHostSubscriptions.onBinaryFrameDropped → host → onBinaryFramesDropped → the hook): the drop still fires and the stream stays up in both builds; only the state write is folded away in production. The reporter is a useCallback([]), so the bridge host is not rebuilt for it, and the host-scoped reset from d9311e0 is unchanged. The production test can fail with the gate removed (five drops would produce five renders), so it is real coverage rather than theatre. Mergeable as-is.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ No new issues found.

Reviewed changes

The delta since the prior pullfrog review is commit 290c35f872 ("price a screencast frame before encoding it").

  • A screencast frame is priced before it is encoded — deliverBinaryFrame computes the frame's exact byte size from the serialized header plus the image's base64 length and reads the window rule before the base64 pass, so a stalled page no longer pays a full encode for every frame the shell then drops.
  • One carry rule — the cap/window test moves into canCarry, read once before the encode and again in sendEvent on the encoded frame, so the shape measured and the shape sent cannot drift.
  • The encoder exposes the price — bridgeScreencastFrameHeader (the event with an empty b64) and bridgeScreencastBase64Length (Math.ceil(n/3)*4), with encodeBridgeScreencastFrame built from the former.
  • Screen test setup hoisted to file level — the shared mutable dependencies is reset per test, including routeGrants and client, pinned by a final guard case so a case that grants the screencast lane cannot leak into the next.

I checked the exactness premise — base64 is ASCII, so JSON escapes none of it and the pre-encode price equals the encoded frame — and the existing over-cap diagnostic case pins the reported frame size to 666,668 + 194 bytes, which the new price still reproduces. I also removed the pre-encode check locally and confirmed the two new window/over-cap cases go red (encodes: 10 and encodes: 1 where zero is expected), so the new coverage is real. The three changed test files pass.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@Jinwoo-H
Jinwoo-H merged commit f5d2d6e into main Sep 20, 2026
32 checks passed
@Jinwoo-H
Jinwoo-H deleted the ota-c6-1-screencast-encoder branch September 20, 2026 08:19
Jinwoo-H added a commit that referenced this pull request Sep 20, 2026
… carries (OTA phase C, C6) (#21769)

C6.1 (#21758) pinned the frame `decodeBridgeScreencastFrame` hands back with an exact
`toEqual`; C6.2 (#21754) made that decoder carry the wire's `b64` on the frame so the page's
data URI can reuse it. Each PR was green against the main it branched from, and their
squashes together red two of C6.1's cases on main. The pins stay exact and gain the field,
with the encoded string spelled out rather than wildcarded.

Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
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.

1 participant