fix(shared): use HTTP for schemeless loopback previews#29710

open4
main
GitHub fork: codex/fix-preview-loopback-scheme
opened9d agobyJJoaoMarcos44
View on GitHubTwo-way sync enabledPR last imported 1d ago

Problem

Fixes pingdotgg/t3code#29702. Entering 127.0.0.2:<port> without a scheme selects HTTPS, so a plain HTTP preview fails even though the server is working.

Change

Recognize canonical IPv4 loopback hosts when choosing an implicit scheme. Reparse the original input as HTTP so an explicit port such as 443 is preserved. Explicit schemes and public-host defaults keep their behavior.

Scope and approval

This is a small, focused correction of an obvious normalization bug under CONTRIBUTING.md. It changes one shared function and its regression tests, uses the existing host classifier, and adds no setting or workflow. No UI component, port discovery or remote-host rewriting code changes.

Verification

  • Node 26.12.1, VitePlus 1.4.0, Effect 4.0.5, Windows. In an isolated copy of the real files, vp test run src/preview.test.ts --maxWorkers=1 --no-file-parallelism -t "uses HTTP for schemeless IPv4 loopback|preserves public and explicit schemes" changed from 6 expected failures and 5 passing controls to 11 passing selected cases. The other 23 tests were not selected.
  • A real HTTP server bound to 127.0.0.2 returned 200 through the corrected URLs from both normalizePreviewUrl and resolveAddressBarInput. The fixture stopped and the sandbox was removed.
  • vp fmt --check --threads=1 src/preview.ts src/preview.test.ts passed. git diff --check passed.
  • vp run check:changed --concurrency 1 was attempted in an isolated checkout but could not initialize because the minimal installation lacks @effect/platform-node. No full-workspace check, build or integrated browser/mobile UI pass is claimed.

Repository equivalent for the focused tests: vp test run packages/shared/src/preview.test.ts -t "uses HTTP for schemeless IPv4 loopback|preserves public and explicit schemes".

Portable before-fix reproduction.

Focused validation reports and outputs.

Illustrative infographic: a dragon courier shows the loopback preview choosing HTTP to reach the local server

AI-generated illustrative infographic with dragons and a gothic cyber-Renaissance theme. The courier carries a schemeless address through the URL normalizer: the previous HTTPS choice misses the local HTTP server; the corrected HTTP choice reaches it. This is explanatory artwork, not a product screenshot or evidence of an integrated UI test.

Created with GPT-6.1 Sol and GPT-6.1 Terra using Codex.

Takeover verification

Merged current main, preserving both test additions. Blacksmith vp run check:changed github/main passed format, lint, knip, affected typechecks, and 36 tests. Chrome verified the real browser panel resolves schemeless 127.0.0.2:5733/pair to HTTP and loads the local app. Native desktop/mobile unverified.

loopback preview interaction

loopback app loaded over http

Verified by gpt-6.1-sol through the Codex harness.

Checks

22 successful · 6 skipped
All checks passed
3b60e01

Added 2 commits

  • test(shared): reproduce loopback preview scheme inference7cd47df
  • fix(shared): use HTTP for schemeless loopback previewsabd1dfc
Synced from GitHub

Codex Review Summary

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

ReviewStatusCommitReview trigger
📝 Code Review✅ Completed 2026-11-03T00:32:07.216341Z25b7083New commits
ℹ️ 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.

Synced from GitHub

Approvability

Verdict: Needs Human Approval

Macroscope's review found this PR requires human approval — Schemeless IPv4 loopback previews such as 127.0.0.2 now default to HTTP instead of HTTPS, while explicit schemes remain unchanged. This default protocol change requires human confirmation despite its limited loopback scope.

You can add or adjust custom eligibility rules. Learn more.

Synced from GitHub

Review in Change Stack →

No actionable comments were generated in the recent review.

Walkthrough

normalizePreviewUrl now selects HTTP for recognized schemeless IPv4 loopback inputs. Tests cover alternate loopback forms, non-loopback hosts, and explicit schemes.

Changes: Preview URL normalization

Layer / File(s)Summary
Implicit scheme selection and validation
packages/shared/src/preview.ts, packages/shared/src/preview.test.ts
The normalizer records whether the input has an explicit scheme. For recognized schemeless IPv4 loopback hosts that initially default to HTTPS, it returns the input with http://. Tests cover alternate loopback forms, non-loopback hosts, and explicit schemes.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Low

Possibly related PRs

Suggested labels: bugfix

Suggested reviewers: juliusmarminge

Merge Risk: External image Minimal · up to 3b60e

The loopback scheme fix is suitable for merge with no identified material risk.

Pre-merge checks: Passed 4
Check nameStatusExplanation
Title checkPassedThe title "fix(shared): use HTTP for schemeless loopback previews" names the main change. The changeset makes schemeless IPv4 loopback inputs (such as 127.0.0.2:) default to HTTP in normalizePre…
Linked Issues checkPassedIssue #29702 requires schemeless IPv4 loopback addresses to use HTTP and explicit schemes to remain authoritative. normalizePreviewUrl first parses the input, then uses isLocalLoopbackHost for par…
Out of Scope Changes checkPassedThe supplied change summary identifies only packages/shared/src/preview.ts and packages/shared/src/preview.test.ts. The source change implements implicit scheme selection. The tests cover the issu…
Description checkPassedThe description follows the repository template and covers the problem, change, scope and approval, and verification. It links the linked issue #29702 and describes the fix: recognizing canonical IPv4…
Full details: Title check

Explanation

The title "fix(shared): use HTTP for schemeless loopback previews" names the main change. The changeset makes schemeless IPv4 loopback inputs (such as 127.0.0.2:<port>) default to HTTP in normalizePreviewUrl, and adds regression tests for that case. The title follows conventional commit format and is specific.

Full details: Linked Issues check

Explanation

Issue #29702 requires schemeless IPv4 loopback addresses to use HTTP and explicit schemes to remain authoritative. normalizePreviewUrl first parses the input, then uses isLocalLoopbackHost for parsed 127.* hostnames and reparses the original input with http://. This preserves ports and paths, including port 443. resolveAddressBarInput uses this normalizer for address inputs. Tests cover 127.0.0.2, other IPv4 loopback forms, port 443, explicit schemes, and non-loopback hosts.

Full details: Out of Scope Changes check

Explanation

The supplied change summary identifies only packages/shared/src/preview.ts and packages/shared/src/preview.test.ts. The source change implements implicit scheme selection. The tests cover the issue and preserved behavior. No UI, settings, workflow, port-discovery, or remote-host rewriting change is identified. The repository diff was unavailable, so this scope result relies on the supplied whole-PR summary and the inspected file contents.

Full details: Description check

Explanation

The description follows the repository template and covers the problem, change, scope and approval, and verification. It links the linked issue #29702 and describes the fix: recognizing canonical IPv4 loopback hosts for implicit-scheme selection and reparsing the original input as HTTP so explicit ports such as 443 are kept. The scope section explains why no prior issue approval is needed for a small, focused fix of an obvious normalization bug, and it cites CONTRIBUTING.md. Verification gives concrete focused test commands, observed results (11 selected cases passing, 23 not selected), a real HTTP server check against 127.0.0.2, format and diff checks, and a clear statement of what was not checked (full-workspace check, build, and native desktop/mobile). The author also adds a later takeover verification with a Blacksmith CI run and Chrome browser check. The template asks for an agent model and harness at the end; the author includes 'Verified by gpt-6.1-sol through the Codex harness', which satisfies this. The illustrative infographic is clearly labeled as non-evidence. Minor issues: the Problem section gives no explicit expected-behavior statement beyond the failure, and the verification section mixes two sets of results, which could confuse a reviewer, but neither omission is critical.

Finishing Touches
Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Some tools did not complete. Review the errors below.

External image ast-grep (0.51.1)

ast-grep could not parse rule config: /ast-grep-rules/ast-grep-essentials/rules/python/security/http-response-from-request.yml

CodeRabbit Verify

  • Run CodeRabbit Verify to test the changes in this pull request.
External image Recent review info
External image Run configuration
External image Commits

Reviewing files that changed from the base of the PR and between 25b7083f011677f3b20fe8dfe282fd6bb8af2bec and 3b60e0160ca6ad10f0b639a17592d8a0286c074e.

External image Files selected for processing: 1
  • packages/shared/src/preview.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.

Added 2 commits

  • Merge branch 'main' into codex/fix-preview-loopback-scheme25b7083
  • chore: merge main into preview loopback fix3b60e01

Note

Written by gpt-6.1-sol on behalf of Maria

Merged current main without rebasing and resolved the test conflict by keeping both the loopback regression cases and main's blank-tab error guidance. No additional behavior changes.

Blacksmith vp run check:changed github/main passed formatting, lint, knip, affected typechecks, and 36 tests. Two independent scoped reviews found no issues. Chrome verification entered schemeless 127.0.0.2:5733/pair in the real browser panel and loaded the local app over HTTP. Explicit schemes and public-host defaults remain covered by the shared tests. Native desktop/mobile were not exercised.

schemeless loopback address resolves to http and loads the local app

local app loaded over http from the loopback address

Synced from GitHub

Note

Written by gpt-6.1-sol on behalf of Maria

Merged current main without rebasing and resolved the test conflict by keeping both the loopback regression cases and main's blank-tab error guidance. No additional behavior changes.

Blacksmith vp run check:changed github/main passed formatting, lint, knip, affected typechecks, and 36 tests. Two independent scoped reviews found no issues. Chrome verification entered schemeless 127.0.0.2:5733/pair in the real browser panel and loaded the local app over HTTP. Explicit schemes and public-host defaults remain covered by the shared tests. Native desktop/mobile were not exercised.

schemeless loopback address resolves to http and loads the local app

local app loaded over http from the loopback address

oh, so u guys already fixed this issue in specific ? . lmk , coz imma close my PR