Repository navigation
Description
id(world-presentation): ScreenPatch::apply never validates the replacement cells — a patch carrying control characters, an orphaned wide-glyph continuation, or an impossible column count produces an invalid screen instead of falling back to a full frame
Summary
ScreenSurface is a validated type everywhere it is built from untrusted data:
parse_surface(pkgs/id/src/world_presentation.rs:260) rejects control characters, glyphs that occupy 0 or 3+ columns, wide glyphs split by style spans, and continuations that do not match their leading glyph.ScreenSurface::from_cells(world_presentation.rs:54) refuses any cell set whoserender_ansi()isNone— the constructor enforces the portable-screen invariant.
ScreenPatch::apply (world_presentation.rs:188-218) is the exception. It checks only the patch header (version/dimensions match prev) and run geometry (runs in order, non-overlapping, inside the grid), then splices the runs' replacement cells into a clone of prev.cells and returns Some(ScreenSurface { .. }) built by struct literal — the replacement cells are never validated. A patch is a wire-shaped value: ScreenPatch, CellRun, and ScreenCell all derive Deserialize (with deny_unknown_fields, but no cell-content checks), so a deserialized patch can carry cells no guest view could ever produce:
- a cell whose symbol is a raw ESC string (
"\u{1b}[2J", columns 1) — the exact guest control sequenceparse_surfaceexists to keep out of presenters; - a run that replaces only the leading cell of a two-column glyph with a one-column cell, orphaning the continuation cell at the next index;
- a cell with
columns: 3(no glyph occupies 3 columns) orcolumns: 2in the last column of a row (no room for its continuation).
In every case apply returns Some(screen) and the produced screen is invalid: its own render_ansi() returns None. That breaks apply's documented contract (world_presentation.rs:183-187): None is the signal that "the patch does not belong to prev — the caller falls back to a full frame". A malformed-cells patch returns Some, so the caller applies it, gets an unrenderable screen, and never falls back. diff only ever emits valid cells (it clones them from validated screens), which is why the existing tests — all built on diff round-trips — never see this.
Evidence (verified this run, main c4fb5996)
Probe on the laptop, ~/git/fleet/probe-2026-10-30-laneA-screenpatch/: the real world_presentation.rs compiled as a module (md5 8477cb3bf70ca698ce0b0720b0d32864, identical to main), patches built by deserializing JSON into the real ScreenPatch:
control diff-patch: apply==next:true render_ok:true
case1 esc-cell: apply=Some render_ansi_is_some:false
case2 orphan-continuation: apply=Some render_ansi_is_some:false cell1_columns:0
case3 columns-3: apply=Some render_ansi_is_some:false
case4 wide-at-last-column: apply=Some render_ansi_is_some:false
Case 2 detail: prev is the valid screen for rows ["界ab"]; the patch replaces only index 0 with ("x", columns 1), leaving index 1 as the wide glyph's continuation (columns: 0, empty symbol) with no leading wide glyph.
Why it matters
The module's whole purpose is that guests never supply terminal escapes or malformed glyphs to presenters (module doc, world_presentation.rs:1-7). ScreenPatch is the F12.11 delta type (#805) that clients will apply to reconstruct screens from patch data; the moment a patch arrives over a transport instead of being produced locally by diff, its cells are untrusted input, and apply is the reconstruction point — the one place that can refuse and trigger the documented full-frame fallback. Today it rebuilds an invalid screen and reports success, degrading the client to a blank/error view (the ANSI presenter returns None) with no recovery signal, and leaving non-ANSI presenters to consume cells that violate the invariants they were promised.
Acceptance criteria
-
ScreenPatch::applyreturnsNonewhen the produced screen would be invalid — at minimum for: a replacement cell containing a control character or a symbol that is not exactly one grapheme; acolumnsvalue other than 0/1/2, or a width that disagrees with the symbol's actual width; a wide glyph whose continuation is missing/mismatched, a continuation with no leading wide glyph, or a wide glyph starting in a row's last column (the same rulesrender_ansi/parse_surfaceenforce). - A patch that is valid except for its cells must behave exactly like a mismatched patch today:
None, so the caller falls back to a full frame. - Regression tests beside the existing patch tests: ESC-symbol cell refused, orphaned continuation refused,
columns: 3refused, wide glyph at the last column refused; the existingdiffround-trip and parity tests still pass unchanged. - Triage pins the enforcement shape (validate the spliced result once, e.g. the
from_cells/render_ansicheck, vs per-cell validation during the splice) — either is acceptable if the cases above returnNone.
Related: #805 (F12.11 delta frames — this is a correctness gap in its first slice, not the remaining binary/resume work). Distinct from #2802/#2824 (world/collab WebSocket frame-shape trust on the session path; this is the presentation patch type).
Activity
dezren39 commentedon Oct 31, 2026
state: filed
agent: new-issue-creator-code-a
Found via: filed this run (2026-10-30 lane A) — code read of pkgs/id/src/world_presentation.rs at main c4fb599 plus a laptop probe of the real module (md5-matched): ScreenPatch::apply splices deserialized replacement cells into a ScreenSurface with no cell validation, returning Some for screens whose render_ansi() is None (ESC symbol cell, orphaned wide-glyph continuation, columns=3, wide glyph at last column), defeating the documented full-frame fallback. Control diff-patch applied and rendered correctly. Evidence and acceptance criteria are in the issue body; probe at ~/git/fleet/probe-2026-10-30-laneA-screenpatch/ on the laptop. Not self-solved: enforcement shape (whole-result vs per-cell validation) is triage's pin. Related #805 (first-slice correctness, not its remaining work).
8 remaining items
dezren39 commentedon Nov 2, 2026
state: picked_up
agent: repo-worker-code (OpenChamber scheduled lane)
Found via: claimed queue task 5464 in repo-health-code-pilot on 2026-11-02 (attempt 1). Revalidated issue #2910 OPEN; no matching active ScreenPatch PR found, and hard-stop labels are absent.
Next: refresh main, inspect ScreenSurface validation helpers, add whole-result validation and regression tests for all four malformed patches.
dezren39 commentedon Nov 2, 2026
state: handed_off
agent: repo-worker-code (OpenChamber scheduled lane)
Task: repo-health-code-pilot #5464 completed as pr_opened. PR #4260 is OPEN and MERGEABLE; CI checks are queued.
Evidence:
cargo test --manifest-path pkgs/id/crates/id-core/Cargo.toml --lib world_presentation::testspassed (20/20), including all four explicit malformed-patch regressions and existing patch parity tests.Follow-up: CI and review on PR #4260. Sandbox backlog/sweep bookkeeping deferred to fleet reconciliation.
dezren39 commentedon Nov 3, 2026
agent-note:v1
state: done (already fixed at current main)
Agent: queue worker repo-worker-code (lane bf419306-c4ef-470f-a553-beabf93239de, OpenChamber scheduled lane)
Task: 8007 — triage #2910 (loop-back coverage pass 2026-11-03)
Verdict: no longer reproducible — the contracted behaviour is implemented at current
mainand the four malformed-patch cases are pinned by regression tests. Closing with evidence; no new work routed.What I checked fresh (2026-11-03):
ScreenPatch::applyno longer builds aScreenSurfaceby struct literal. It splices the runs and returnsScreenSurface::from_cells(usize::from(prev.width), usize::from(prev.height), cells).ok()— so a reconstruction that violates the screen invariants now returnsNone, which is exactly the documented full-frame fallback signal this issue asks for. Introduced with the revisioned ScreenPatch work (d488f321c, PR feat(id): revisioned JSON ScreenPatch view frames — #805 Phase 1 #3932 — id: F12.11 delta and binary frames (screen patches, resume tokens) #805 Phase 1).pkgs/id/crates/id-core/src/world_presentation.rs):patch_refuses_a_result_that_is_not_a_valid_screen(:866),patch_refuses_a_control_character_replacement(:889),patch_refuses_a_narrow_replacement_that_leaves_an_orphaned_continuation(:905),patch_refuses_a_cell_with_an_invalid_column_count(:937),patch_refuses_a_wide_glyph_in_the_last_column_of_a_row(:956). These landed with PR test(id): cover invalid ScreenPatch replacements #4260 (merged 2026-11-02T15:34Z, merge8df6dc296f2a), which was the queue's own follow-up (task 5464) and is why the issue's implementation thread ends without a close comment here.main:cargo test --manifest-path pkgs/id/crates/id-core/Cargo.toml --lib world_presentation::tests— 28 passed, 0 failed (wholeworld_presentationmodule, including the patch parity and delta-size tests).Path note for future readers: the module moved from
pkgs/id/src/world_presentation.rs(path in the issue body) topkgs/id/crates/id-core/src/world_presentation.rswith the crate split; the code and types are the same.Labels:
task/triageremoved (no live task). Closing as completed.developing-today commentedon Nov 3, 2026
agent-note:v1
state: triaged (coverage pass)
Coverage pass 2026-11-03: reviewed in the fleet-wide per-issue pass (drift / overlap / already-handled / stale / blockers / ordering). Verdict: still live; queued in repo-health-code-pilot as triage at priority 30 (priority/low). If this is already handled at current main, the triage closes it with evidence; if it needs splitting, the triage files the split.
Found via: coverage pass 2026-11-03