← Back to Pull requests

feat(harness): add local preview capability preflight #5254

Closed
unknown closed this pull request without merging on Oct 10, 2026 01:27 UTC
View on GitHub
unknown unknown commented on Sep 13, 2026 09:17 UTC
Author

Summary

Showing a page locally depends on independent things that each fail differently: the client may have no GUI surface at all, the embedded browser refuses file:// by policy, and the conversation's own view may not be the one on screen. Attempting the preview and reading the first error conflates them.

A refused loopback connection is the worst case. "Nothing listening yet", "server still starting", and "separate network namespace" are indistinguishable at the socket — yet the refusal reads like proof of the last one, which is exactly the inference the session recorded in #5213 made.

preview_preflight answers each capability with verified, unsupported, or unknown, and names the observation behind it:

| Capability | What is observed | Can be |
| --- | --- | --- |
| gui_surface | whether a Desktop browser view host is registered | verified / unsupported / unknown |
| url_schemes | what the real address policy (parseNavigable) accepts — file:// is rejected | unsupported (settled) |
| browser_view | whether this conversation's view accepts an observe action now | verified / unknown, or unsupported only when there is no host |
| loopback_endpoint | HEAD / against a caller-named loopback origin, only if one is passed | verified / unknown — never unsupported |

unsupported is reserved for settled boundaries statable without probing; everything else is unknown and says outright what it does not prove. A connection outcome therefore never becomes unsupported.

No result claims a page is ready. An answer from the origin — a 404 included — proves a listener, not that the page exists or loads. surface (can this client display a page at all) and endpoint (does something listen at the named origin, or not_checked) are reported separately, and page load remains #5235's question. When the caller does not already have both verified, the report names ArtifactPreview and defers to that tool's own description for what its URL guarantees.

The probe sends HEAD / to the origin, never the caller's path, so a capability check cannot trip a dev-server route with side effects. It settles on the first of a response, an upgrade, an error, the caller's abort, or an absolute deadline — the deadline lives in the promise, not on the socket, because a 101 Switching Protocols makes Node close the request without emitting response or error. Only 127.0.0.1 and [::1] are accepted: this is deliberately stricter than isLoopbackHost, because localhost can resolve to either family and a refusal would not say which address was tried.

Where it is published

Inside desktop_artifact_preview, beside ArtifactPreview. Not the Browser offer: every Browser tool is admitted against an Origin read from the view's current URL, so a capability check there would need a page already loaded and would fail with the very Browser admission requires an HTTP origin error it exists to explain. And sharing an offer with ArtifactPreview means the route it hands off to is always granted with it. The offer's tool set is assembled only in buildArtifactPreviewOfferTools, and a test pins both tools there and checks that the handoff names only a tool the same offer grants.

Relationship to the managed preview endpoint (#5238 / #5316)

ManagedArtifactPreview.prepare HEAD-checks the route it just created, which is real reachability evidence for that endpoint. It needs an existing HTML Artifact, reports failure by throwing rather than classifying, and says nothing about a GUI surface, the view's visible-lease state, URL-scheme policy, or a caller-supplied endpoint. It also succeeds in a runtime with no GUI at all — the preflight is what distinguishes that case before anything is attempted.

Scope

Preflight only. Staging-root filesystem visibility was dropped in review: HTML Open never touches that directory, so it measured a non-preview path. Page load is #5235. This does not weaken the file:// policy.

Fixes #5234.

Verification

npm --workspace @maka/desktop run build:main
node --test --test-force-exit dist/main/__tests__/preview-preflight.test.js \
  dist/main/__tests__/runtime-host-artifacts-ipc-main.test.js \
  dist/main/__tests__/managed-artifact-preview.test.js \
  dist/main/__tests__/browser-tools.test.js \
  dist/main/__tests__/runtime-host-native-capabilities.test.js
npm run check:asf-headers && npm run check:locale-hygiene

  • 27/27 preflight tests; 98/98 across the affected suites above.

  • Each fix was ablated in the built output to confirm its test goes red: a readiness claim on a 404 listener (2 red), GET instead of HEAD / (1), "nothing answered" wording (2), no upgrade arm (1), no abort listener (1).

  • Real-socket coverage: HEAD / is the only request sent even when a path is passed; a 101 answers well inside the deadline; cancellation settles against a silent server; the deadline fires with an injected 120 ms limit; an https:// origin against a plain listener exercises the TLS branch and reports "no usable HTTP response"; a refused port returns a value, not a throw. Removing the preflight from the offer builder turns the offer test red.

  • biome lint, check:asf-headers, check:locale-hygiene pass. tsc -p tsconfig.main.json reports no errors in the changed files.

  • Not run by me: no Electron flow, so a real GUI surface and embedded browser are unexercised, and I did not rerun the full test:dist. My checkout cannot build @maka/ui (upstream added virtua in #5366 after my last install), which leaves 65 tsc errors in unrelated files — the same 65 with this change stashed. CI installs clean.
  • AI use

    Select exactly one:

  • No generative tool made a substantive contribution

  • Generative tooling made a substantive contribution
  • Tool(s) and scope: Claude Opus 5 / 5.5 via Claude Code — drafted the implementation, tests and this description under my direction, reproduced the reviewed 101 Switching Protocols defect before fixing it, and ran the ablations above. I reviewed every change and the verification output. Every commit carries a Generated-by trailer.

    Checklist

  • Tests cover the change and fail without it

  • Lint, format, typecheck and the affected suites pass locally
  • Does this PR entail a change in behavior?

  • Yes — described under Summary above

  • No
  • 🤖 Generated with Claude Code

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: liugddx Review duration: 38410m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #5254"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 20.5% · Safe to merge
    20.5%
    Repository