Skip to content

feat(browser): route previews via oc-preview://, harden PreviewFetch, and ban raw file:// unconditionally - #303

Merged
Hona merged 30 commits into
devfrom
previews/pr2-app-routing
Nov 20, 2026
Merged

Hona merged 30 commits into
devfrom
previews/pr2-app-routing

Conversation

@Hona

@Hona Hona commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

Summary

Lands PREVIEWS PR 2 on top of dev (95cb36a8, including #281, #300, #304, #292, #294, #274, #309, #310, #307, #306, #301, #296): routes all workspace HTML previews (local and remote /api/fs/read/*) and artifacts (/api/experimental/artifacts/<id>/view/* & artifact://) into isolated oc-preview:// tabs, bans raw file:// unconditionally across engine and app, adds the "show source" / browser.preview.unsupported fallback for older engines lacking Ready.preview, adds preview chrome markers + "Show the file's code", and closes all notes/review-rd281.md PR 2 conditions across Rounds 1–3 (1e3f4992, 67771007, d125ebfd).


Round-3 (d125ebfd) Findings & Polish Closed (ccb6a64e, 8 files)

  1. Bounded credit-wait timeout + EngineMsg::Ready.preview_credit handshake:
    • Added PREVIEW_CREDIT_WAIT_TIMEOUT = 20 s (matching PREVIEW_PER_READ_TIMEOUT) to PreviewChunkBudget::acquire (crates/browser-pane/src/preview.rs): an unconsumed fetch() or stalled consumer can no longer pin PreviewFetchPool workers beyond 20 s — on expiry acquire marks the entry canceled, aborts the upstream HTTP fetch, and releases ActiveGuard immediately.
    • Added #[serde(default)] preview_credit: bool to EngineMsg::Ready (apps/browser-engine/src/{wire,engine}.rs, crates/browser-pane/src/{protocol,transport}.rs): rune-browser-rx calls preview_chunk_budget.set_credit_enabled(*preview_credit) (reset to false on disconnect), so pre-PR #281-era dev engines (Ready.preview == true, preview_credit == false) bypass credit blocking and stream > 1 MiB previews cleanly without deadlock (while the engine's own 2 MiB queue cap and pool caps still bound in-flight bytes).
  2. Ranged-200 completion cancels and removes proxy immediately:
    • Both PendingProxy::deliver_chunk (apps/browser-engine/src/preview/mod.rs) and ProxyResourceHandler::read (apps/browser-engine/src/preview/handler.rs) send PreviewCredit { cancel: true } (never returning credit for dead tail) and call remove_proxy(req_id) as soon as remaining_to_deliver == Some(0) && skip_remaining == 0, stopping the host HTTP stream immediately instead of pumping up to 128 MiB of unused tail.
  3. Both Round-3 non-blocking polish items landed (crates/opencode-kit/src/client/preview.rs):
    • Restored ErrorKind::Interrupted (EINTR) retry in Server::preview_stream.
    • Restricted Content-Length header parsing to non-empty ASCII digits (t.bytes().all(|b| b.is_ascii_digit())).

Round-1 & Round-2 Conditions Retained

  • Lossless unbounded engine control events + preview-only byte-credit flow control: Global events channel stays on dev's unbounded mpsc::channel + plain .send(...); read_messages dispatches PreviewResponse{Head,Chunk,End} directly to Arc<PreviewRegistry>; last_pump prevents pump starvation; EngineMsg::PreviewCredit runs end-to-end (1 MiB credit / 2 MiB cap) directly on rune-browser-rx.
  • Tool-scoped built-in open_file & Links:Open + third-party plugin ban: Workspace:OpenFile / OpenFileSource and Links:Open enforce current_tool_scope, refusing cross-session targets and hidden/secret HTML entries synchronously with 0 tabs opened and marking allowed tool previews agent_driven = true. Plugins::is_builtin_plugin (Tier::Bundled && running()) blocks third-party grant minting and TabScope::check_tab denies third-party mutations/DevTools on preview tabs.
  • Fair PreviewFetchPool & AbortablePreviewResolver: 8 workers, 3/tab, 4/server, 16 queued/tab, 64 global; .timeout_resolve(Some(5s)), literal-IP fast path, detached preview-dns capped at 16 global / 4/host, < 1 ms Condvar wake on PreviewAbort::abort() releasing the pool worker immediately.
  • Unconditional raw file:// ban, #292/#294/#274/#307 preservation, context menu isolation, older-engine fallback (engine_caps_known(), 0 OpenTabs on open_refused_tab), and history/savedTabs/closedTab/sitePermissions isolation: all intact.

Live Verification (Real CEF 156.0.26 + Real opencode-desktop.exe)

  • Round-3 three live probes (proof/previews/pr2-r3-proof.ts -> pr2-r3-proof.json: ALL_PASS):
    1. Unconsumed 2 MiB fetches free slots at 20 s credit timeout; Tab 2 unaffected: Tab 1 started 3 × 2 MiB unconsumed fetches; Tab 2 loaded fast_ok.json immediately (216 ms); all 3 unconsumed server HTTP streams aborted cleanly at 20,262 ms, and Tab 1 recovered immediately with a subsequent fetch (tab1RecoveredAfterTimeout: true).
    2. Pre-PR dev engine binary (48534ca6, no preview_credit): Real opencode-desktop.exe + real pre-PR dev opencode-browser-engine.exe streamed a 4,194,304-byte (4 MiB) remote preview cleanly (status: 200, elapsedMs: 609, zero deadlock).
    3. Ranged 200 OK on 16 MiB stops at range end (raw TCP wire bytes counted at scratch server): Requesting Range: bytes=10-109 against a 16,777,216-byte 200 OK server yielded exact 206 with all 100 bytes matching (exactBytesMatched: true) while the scratch TCP server aborted early after writing only 131,072 bytes (0.78% of 16 MiB) on the wire (serverAbortedEarly: true).
  • Prior live proof suites (ALL_PASS): pr2-r2-proof.json, pr2-file-ban-proof.json, pr2-blockers-proof.json, and pr2-app-proof.json.
  • Checks green (0 warnings): pwsh scripts/guardrails.ps1 (5/5), pwsh scripts/web.ps1 -Check (wasm32), apps/browser-engine --bins, opencode-desktop, cargo check --workspace, cargo check -p browser-pane --no-default-features, and cargo check -p browser-policy for aarch64-apple-darwin & x86_64-unknown-linux-gnu; 0 #[test]/#[cfg(test)], 0 .github/ edits.

Hona added 7 commits November 21, 2026 00:00
…hed servers and block check_cdp contextId/userGesture
…te-dual-route-cdp

# Conflicts:
#	apps/desktop/src/surfaces/browser/mod.rs
#	crates/browser-pane/src/protocol.rs
…ow sticky suppression, and harden CdpCall/check_cdp
…te-dual-route-cdp

# Conflicts:
#	apps/browser-engine/src/engine.rs
@github-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

PR test build retired — merged into dev. Install or auto-update OpenCode (Rune) from https://anoma.ly/release/opencode/desktop-rune/dev/macos-arm64-dmg.

Hona added 11 commits November 21, 2026 04:28
…ird-party plugin ban, bounded PreviewFetch pool + abort + backpressure + exact skip, Connecting/zero-OpenTab older-engine fix)
…te-dual-route-cdp

# Conflicts:
#	apps/desktop/src/surfaces/browser/mod.rs
#	crates/browser-pane/src/client.rs
#	crates/browser-pane/src/protocol.rs
…eparse policy and unconditional file:// ban
…ter, per-read timeout, and short-EOF skip guard
…egacy MCP until Unsupported/Unavailable, and fix #292 merge regressions
…ck-pressure and unconditional file:// ban
Hona added a commit that referenced this pull request Nov 20, 2026
- Fold security-confirmed merged PRs #292 (6d7a6ed, WS-1 mandatory
  RemoteServer proxy), #294 (ae3e910, BROWSER-UI file-link/click-to-run
  fix with known symlink/junction root limitation), and #274 (5da6474,
  WS-9 engine MV3 extension host, inert without --extension flags)
- Update browser Reviewed column: #301 in rework (#287 eager-attach
  time_updated regression still live on dev), #296/#298/#302/#303/#305/#306
  in rework, #307 open for pre-merge security review
- Audit upstream anomalyco/opencode fe8def6854..4122af0206 (+2 commits:
  1 skipped #65255 core/codemode, 1 added UP-135 #65215 -> WS-8)
…te-dual-route-cdp

# Conflicts:
#	apps/browser-engine/src/engine.rs
#	crates/browser-policy/src/lib.rs
Hona added a commit that referenced this pull request Nov 20, 2026
…310)

- Update UP-095-UI evidence to reflect that the 4 #294 findings remained
  present from 0.0.0-dev-440 through published 0.0.0-dev-449 (b62e698)
- Refresh open browser PR security-review states (#296 4th read, #301 3rd
  read, #303 2nd read, #307 updated after 1st read, #308 1st read)
Hona added 8 commits November 21, 2026 05:41
… events + PreviewCredit flow control, tool-scoped open_file/Links:Open agent gating, fair PreviewFetchPool + abortable DNS timeout)
…t wait + Ready.preview_credit handshake, ranged-200 completion cancel/remove, EINTR + ascii-digit Content-Length)
…ven across previews and unconditional file:// ban
…te-dual-route-cdp

# Conflicts:
#	apps/desktop/src/plugin_host/native/browser/scope.rs
#	crates/browser-pane/src/client.rs
@Hona
Hona merged commit 6fb05ce into dev Nov 20, 2026
7 checks passed
@Hona
Hona deleted the previews/pr2-app-routing branch November 20, 2026 21:53
Hona added a commit that referenced this pull request Nov 20, 2026
Hona added a commit that referenced this pull request Nov 20, 2026
Hona added a commit that referenced this pull request Nov 20, 2026
…P-143 (#318)

- Fold confirmed merged PRs #307 (a1e7d0d, click-to-load reply videos),
  #306 (b5167f7, atomic agent_driven), #301 (6522f11, routed-session
  attach + recency closing #287 regression), #296 (95cb36a, legacy
  rune_mcp suppression + Half::is_builtin + check_cdp), #303 (6fb05ce,
  oc-preview:// app routing + raw file:// ban completing UP-095-PREVIEWS),
  and #316 (6e98fc2, Rune 7a707454 / #1307 strict local video opening)
- Add missing browser follow-up rows UP-095-3P-CONTRACT (#296 narrow
  third-party plugin browser contract gap) and UP-095-PROMPT-GATE
  (new-session-start-only prompt gate split from #302)
- Record #302 split (tunnel vs gate), #314 masking stream paused pending
  owner decision on agent-tab contexts, and updated browser Reviewed entries
- Audit upstream anomalyco/opencode 4122af0206..b9a60d9d07 (+11 commits:
  3 skipped, 8 added UP-136..UP-143)
Hona added a commit that referenced this pull request Nov 20, 2026
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