Skip to content

feat(id): compressed binary screen patches — F12.11 phase 4 (#805) - #13372

Open
dezren39 wants to merge 5 commits into
mainfrom
xaltha/805-compression
Open

dezren39 wants to merge 5 commits into
mainfrom
xaltha/805-compression

Conversation

@dezren39

@dezren39 dezren39 commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

Refs #805 — phase 4 does not complete the issue; protocol negotiation / cross-language parity remain.

What this slice does

Optional DEFLATE compression on the negotiated binary ScreenPatch transport, plus the <10%-of-full-frame measurement for sparse redraws:

  • pkgs/id/crates/id-core/src/screen_codec.rs — compressed (v2 binary) frame encode/decode; 7 new tests, including sparse_redraws_measure_under_ten_percent_of_full_frame and compressed_resume_patch_arrives_as_a_version_two_binary_frame.
  • pkgs/id/crates/id-worlds/src/world_session/ — wire the compressed patches through the session view path and resume tokens; new session tests.
  • pkgs/id/web/src/screen-codec.ts (+ tests) and world.ts — TS-side compressed codec parity; 7 new async tests in screen-codec.test.ts.
  • pkgs/id/contract/shell-contract.v1.json — contract bump for the v2 binary frame.

Verification (remote dispatch, GitHub-hosted runners)

Rust — green:

  • developing-today/fleet#45178589558 (cargo test -p id-core -p id-worlds @ 1f8c33512): id-core lib 548 passed / 1 ignored / 0 failed; id-worlds lib 954 passed / 0 failed; all integration suites green.
  • developing-today/fleet#45180694208 (cargo test -p id-core screen_codec @ 625106db1): success.

Web — green:

  • developing-today/fleet#45193026389 (bunx vitest run src/screen-codec.test.ts src/world-program.test.ts @ 625106db1): 2 test files passed, 14 tests passed / 0 failed (screen-codec 13, world-program 1).

Note on #13337: the web suite segfaults at vitest startup in the standard fleet-build container (nix Bun 1.4.2; both forks and threads pools; also fails identically on unmodified main), so this run used the stock node:22-bookworm container with the official Bun 1.4.5 build, where the suite passes. The crash is environmental, not slice code — see #13337 for the tracking issue.

{
  "direct_parent": null,
  "links": [],
  "lineage": {
    "design": null,
    "roadmap_item": null,
    "priority": null
  },
  "pm_meta": 1,
  "provenance": {
    "queue_id": null,
    "scheduled_start": null,
    "picked_up_at": null,
    "work_started_at": null,
    "created_at": "2026-11-23T14:23:14Z",
    "session_id": null,
    "lane": null,
    "host": "htch-runtime",
    "worktree": "/home/hatch/workspace/github-work/code-805",
    "model": null,
    "lane_start_issues": [],
    "workspace_ref": {
      "kind": "worktree",
      "id": "/home/hatch/workspace/github-work/code-805",
      "repo": "developing-today/code",
      "branch": "xaltha/805-compression",
      "sha": "625106db12c735c5209118c838b0d0acd7ea233c"
    },
    "auth_subject": "xaltha",
    "stamped_by": "fleet 0.1.0 (native)"
  }
}

Prove it works
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

Optional DEFLATE compression for the negotiated binary ScreenPatch
transport, plus the under-10%-of-full-frame measurement.

- id-core screen_codec: version-2 envelope {version: 2, compression,
  payload} carrying raw-DEFLATE (RFC 1951) of the version-1 frame;
  encode_view_patch_compressed emits it only when the complete
  compressed frame is smaller, so small frames stay byte-identical
  to version 1. Decoding is bounded by the 1 MiB frame limit in both
  directions; unknown versions/compressions, truncated streams, and
  oversized inflation fail closed. New deps flate2 (rust_backend)
  and serde_bytes, both already in the lockfile, gated under the
  world feature.
- Session: join gains screen_compress (contract revision 16); the
  host sends version-2 frames only to sessions that offered it.
- Browser: decodeViewPatchAsync handles version 2 via
  DecompressionStream('deflate'); the join offers screen_compress.
- Measurement (design Q2 option B): a repeatable test records
  complete logical View payload bytes for a sparse redraw versus a
  full snapshot at 80x24 and 200x60 and asserts the sparse patch
  stays under 10% of the full frame, with patch/full-frame parity.
- Session test: a compressed resume patch arrives as a version-2
  binary frame and applies to exactly the full-frame screen.

Refs #805
b"#" is a byte string (&[u8; 1]) while the else branch yields u8;
the test target failed to compile (E0308). Use the b'#' byte literal.
…le (#805)

The under-10% test failed at 80x24 (279/2487 bytes, 11.2%): a
29-cell status-line restyle is a dense change, and its minimum
encoding already exceeds the bar (the 29-cell run alone is ~244
bytes against a 248-byte bar), so no encoder could meet it. The
nominated typical case is a status count tick plus two scattered
edits, which measures ~8% at 80x24.
Screen bounds are 120x50, so document_screen(200, 60) panics in
from_cells; the 200x60 case could never run. 120x50 is the largest
valid screen and the meaningful second size.
@coderabbitai

coderabbitai Bot commented Nov 23, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 42 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c0860e6a-f76b-423e-84de-3891ccebf77c
Commits

Reviewing files that changed from the base of the PR and between fc6b42f and 625106d.

Files ignored due to path filters: 1

  • pkgs/id/Cargo.lock is excluded by !**/*.lock
Files selected for processing: 14

  • pkgs/id/contract/shell-contract.v1.json
  • pkgs/id/crates/id-core/Cargo.toml
  • pkgs/id/crates/id-core/src/screen_codec.rs
  • pkgs/id/crates/id-core/src/world_presentation.rs
  • pkgs/id/crates/id-worlds/src/shell_contract/tests.rs
  • pkgs/id/crates/id-worlds/src/world_session/mod.rs
  • pkgs/id/crates/id-worlds/src/world_session/session_core.rs
  • pkgs/id/crates/id-worlds/src/world_session/tests.rs
  • pkgs/id/crates/id-worlds/src/world_session/types.rs
  • pkgs/id/crates/id-worlds/src/world_session/view.rs
  • pkgs/id/web/src/screen-codec.test.ts
  • pkgs/id/web/src/screen-codec.ts
  • pkgs/id/web/src/world-program.test.ts
  • pkgs/id/web/src/world.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-23T14:26:16.092500Z 625106d PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 625106db12

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

try {
stream = new Blob([bytes as BlobPart])
.stream()
.pipeThrough(new DecompressionStream("deflate"));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Decode the host's payload using raw DEFLATE

Whenever the host sends a compressed patch, encode_view_patch_compressed produces raw RFC 1951 bytes using Rust's DeflateEncoder, but DecompressionStream("deflate") expects a zlib-wrapped stream. Consequently, host-generated compressed patches fail decoding and cause the browser—which now always advertises screen_compress—to request full views instead of applying them. This mismatch is reproducible with the platform decompressor. Use "deflate-raw" for the negotiated format and test against a Rust-produced compressed fixture; the current TypeScript helper uses CompressionStream("deflate"), so its round-trip tests conceal the incompatibility.

Useful? React with 👍 / 👎.

This branch has not been deployed

No deployments
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