Skip to content

feat: support local HTTP proxy projects - #513

Open
clvsh wants to merge 6 commits into
mainfrom
t3/research-multilang-app-support
Open

clvsh wants to merge 6 commits into
mainfrom
t3/research-multilang-app-support

Conversation

@clvsh

@clvsh clvsh commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Add proxy: <port> to route a Project’s exact .test hostname over HTTPS to an existing HTTP server on IPv4 loopback. Developers keep their usual server command or IDE.
  • Keep resource and environment reconciliation independent of PHP worker demand. Preserve the last valid route on config errors and reject ports already claimed by another Project or PV runtime.
  • Report the expected local address when the upstream is offline. Add config and reconciliation coverage and run the HTTPS and forwarding-header assertions against real Caddy.

Closes #372

Summary by CodeRabbit

  • New Features
    • Projects can route HTTPS traffic to a local development server without using a PHP worker.
    • PHP-served Projects respond to their primary hostname and one-label subdomains. Proxy Projects respond only to their exact hostname, which takes precedence over wildcard routing.
    • Project listings display configured proxy ports and indicate when a Project is not using PHP.
  • Bug Fixes
    • Invalid or conflicting proxy settings are reported during configuration and project validation. Unavailable proxy servers return a clear error response.
    • Gateway end-to-end testing now runs all ignored tests in the relevant test module.

@coderabbitai

coderabbitai Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Projects can now use a configured loopback HTTP service as their Gateway upstream. The change adds proxy-port configuration and persistence, updates PHP worker demand and Gateway reconciliation, and adds CLI output, documentation, and integration coverage.

Changes: Local HTTP proxy Projects

Layer / File(s) Summary
Proxy configuration and project-facing behavior
crates/config/src/*, crates/config/tests/it/project_config.rs, crates/cli/src/commands/*, DESIGN.md, docs/user/README.md
Project configuration accepts an integer proxy port. An active proxy setting cannot be combined with php or root. CLI project listings expose proxy ports and use "none" as the PHP label for proxy Projects.
Proxy-port persistence and reconciliation
crates/state/src/*, crates/state/tests/state_foundation.rs, crates/daemon/src/project_env.rs, crates/daemon/src/health.rs, crates/daemon/src/jobs.rs, crates/daemon/tests/it/project_env_reconciliation.rs
Project state stores active proxy ports and checks for reserved or conflicting ports. Proxy ports are included in port allocation, and proxy Projects are excluded from PHP runtime demand. Reconciliation tests cover retaining and releasing a port.
Gateway proxy routes and end-to-end coverage
crates/daemon/src/gateway*.rs, crates/daemon/tests/it/gateway_*.rs, crates/daemon/tests/it/real_artifact_gateway_e2e.rs, .github/workflows/real-artifact-e2e.yml
Gateway routes use either PHP or proxy upstreams. PHP routes include the primary hostname and a one-label wildcard; proxy routes use the exact primary hostname and return a custom 502 response when the upstream is unavailable. Gateway reconciliation and real-artifact tests cover proxy routing and forwarding headers.

Estimated code review effort: 4 (Complex) | ~60 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant Gateway as PV Gateway
  participant Upstream as Loopback HTTP server
  Client->>Gateway: HTTPS request for proxy Project hostname
  Gateway->>Upstream: Forward request to configured loopback port
  Upstream-->>Gateway: Return HTTP response
  Gateway-->>Client: Return response over HTTPS
Loading

Possibly related issues

  • prvious/pv#508: Both changes concern preserved Gateway fragments when configuration or hostname ownership conflicts occur; this PR applies the related conflict handling to proxy ports.

Possibly related PRs

  • prvious/pv#507: Both changes affect retained Gateway fragments and site-address handling; this PR adds proxy routes to that configuration path.
Merge Risk: Low · up to f263f

Proxy Projects route over HTTPS to a loopback server and request no PHP worker. Two narrow edge cases remain: a stale proxy-port claim after switching a Project to resource-only, and an unprobed old PHP worker after a rejected Gateway reload. Both are recoverable, so merge risk is low.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "feat: support local HTTP proxy projects" matches the main change. The PR adds a proxy config field that routes a Project's exact hostname over HTTPS to a user-owned HTTP server on loopbac…
Linked Issues check Passed [#372] Coding requirements are covered by the whole-PR change summary. No repository inspection was run for this assessment.

1. Proxy config and validation: parse_project_mapping in `crates/config/…
Out of Scope Changes check Passed The changes map to #372 objectives or to required supporting work:
- Config model, parser, errors, and tests: proxy configuration and validation.
- Gateway config and runtime planning: proxy routes an…
Full details: Title check

Explanation

The title "feat: support local HTTP proxy projects" matches the main change. The PR adds a proxy config field that routes a Project's exact hostname over HTTPS to a user-owned HTTP server on loopback. The changeset touches config parsing, gateway routing, state/port allocation, docs, and E2E tests, all of which support this feature. The title is concise and specific, and it follows a conventional commit style.

Full details: Linked Issues check

Explanation

[#372] Coding requirements are covered by the whole-PR change summary. No repository inspection was run for this assessment.

  1. Proxy config and validation: parse_project_mapping in crates/config/src/parser.rs accepts proxy as a nonzero u16. Invalid values return InvalidProxyPort. ConflictingProxySetting rejects php or root with an active proxy. project_config_validates_proxy_port_and_serving_settings covers these cases.
  2. Resource-only mode: with serve: false, active_proxy_port returns None, so no route is generated. This matches the requirement.
  3. Routing and TLS: gateway_config.rs emits GatewayUpstream::Proxy(port) as a plain reverse proxy to 127.0.0.1:&lt;port&gt; for the exact primary hostname. The Gateway terminates HTTPS with its local CA. The real-artifact E2E test checks gateway-controlled Host and X-Forwarded-* values and a 502 for an offline upstream.
  4. No PHP worker demand: health.rs excludes proxy-port Projects from PHP runtime grouping. project_env.rs uses serves_php() for track demand. The E2E test asserts that no PHP worker ports are assigned.
  5. Process ownership: DESIGN.md and docs/user/README.md state that PV does not start or supervise the target application. No code path in the summary starts it.
  6. Ordinary Project model: path, config, Managed Resource, and environment handling are unchanged. A missing Project directory follows existing behavior, and the hostname reservation is kept.
  7. Acceptance criteria: DESIGN.md and user documentation are updated. Integration tests exist in project_env_reconciliation.rs and real_artifact_gateway_e2e.rs. The CI workflow runs all ignored tests in that module. An exact subdomain such as api.laravel.test works without workspace config.

Change since the previous review: the resource-only proxy_port clear was reverted in f263f0a. The issue does not specify port-claim behavior during resource-only reconciliation, so this revert does not change any issue requirement. The summary of project_env_reconciliation.rs still describes a clear on serve: false. This conflicts with the revert description. The conflict is internal to the port-claim design and does not affect the #372 requirements.

Uncertainty: the evidence is a generated summary. The real-Caddy E2E test is ignored and requires Caddy. Its results were not independently confirmed.

Full details: Out of Scope Changes check

Explanation

The changes map to #372 objectives or to required supporting work:

  • Config model, parser, errors, and tests: proxy configuration and validation.
  • Gateway config and runtime planning: proxy routes and 502 behavior.
  • Health, project_env, and state changes: exclusion of PHP worker demand and port allocation.
  • Migration 19 and state validation: persistence and collision rules for the proxy port.
  • CLI link, list, php use, and init changes: validation and display of proxy-port conflicts.
  • DESIGN.md and docs/user/README.md: required documentation.
  • CI workflow change: runs the new E2E tests.
  • Test fixture updates for the new proxy_port field.

The PHP wildcard TLS demand and the rule that exact hostnames take precedence over wildcard routes relate to #372. They keep the exact proxy hostname from being shadowed by a parent wildcard. They do not implement #371 or #365 as new features. No change is demonstrably unrelated.

Uncertainty: the summary does not show whether the PHP wildcard route behavior is new or pre-existing. The revert of the resource-only port clear is a narrow reconciliation detail tied to proxy-port ownership and does not introduce unrelated work.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • 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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: QUIET
  • Plan: Advanced
  • Run ID: b53f728b-b22c-484a-8994-5054ac332dff
Commits

Reviewing files that changed from the base of the PR and between d86f400 and f263f0a.

Files selected for processing: 1

  • crates/daemon/tests/it/real_artifact_gateway_e2e.rs

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

@codspeed

codspeed Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 7 untouched benchmarks


Comparing t3/research-multilang-app-support (f263f0a) with main (b2e18c7)

Open in CodSpeed

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Important

Proxy-port claims are released before Gateway changes commit, allowing conflicting ownership after a rejected reload.

Approach: appropriate — reuse the existing Project and Gateway model without supervising user-owned servers, but retain active port ownership across the Gateway transaction.

Reviewed changes across configuration, CLI behavior, persistence, routing, and reconciliation recovery.

  • Proxy configuration: integer port validation, dormant resource-only settings, incompatible PHP/root rejection, and CLI integration.
  • Gateway routing: exact-host HTTPS forwarding to loopback, offline diagnostics, and preservation of existing PHP wildcard routing.
  • Reconciliation and state: persisted proxy targets, port allocation exclusions, resource/environment independence, and targeted recovery.
  • Coverage and documentation: parser and reconciliation tests, opt-in real-Caddy checks, workflow selection, and user/design documentation.

Validation: 35 focused tests and formatting passed; a deterministic pv-fake reproduction confirmed the inline finding. A broader run encountered validator-cleanup errors (process Pid(614) was still running and process Pid(631) was still running) and was stopped; real-artifact tests were not run locally.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using gpt-6.1-sol | 𝕏

validate_project_proxy_port_owner(&transaction, &project.id, port)?;
}
transaction.execute(
"UPDATE projects SET proxy_port = ?1 WHERE id = ?2",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[P1] Retain the previous port claim until the Gateway commits. This update releases the old proxy port during Project Apply, even when a rejected Gateway reload leaves its route active. Another Project can then claim that same upstream; I reproduced this conflict and a subsequent invalid edit silently removing the original Project's preserved route.

Technical details
# Active proxy ownership ends before the route switches

## Affected sites
- [database.rs:1633–1635](https://github.com/prvious/pv/blob/d86f400b43919f19df4ef6e076e673ec724bc019/crates/state/src/database.rs#L1633-L1635) replaces the only persisted proxy-port claim.
- [jobs.rs:2489–2516](https://github.com/prvious/pv/blob/d86f400b43919f19df4ef6e076e673ec724bc019/crates/daemon/src/jobs.rs#L2489-L2516) completes Project Apply before applying Gateway changes.
- [database.rs:4452–4461](https://github.com/prvious/pv/blob/d86f400b43919f19df4ef6e076e673ec724bc019/crates/state/src/database.rs#L4452-L4461) and [database.rs:4806–4814](https://github.com/prvious/pv/blob/d86f400b43919f19df4ef6e076e673ec724bc019/crates/state/src/database.rs#L4806-L4814) exclude only persisted claims, not the old active route.
- [gateway.rs:2496–2503](https://github.com/prvious/pv/blob/d86f400b43919f19df4ef6e076e673ec724bc019/crates/daemon/src/gateway.rs#L2496-L2503) silently omits the preserved route when its old port now collides.

## Reproduction
Confirmed with production `Database::finalize_project_reconciliation` and `reconcile_gateway_runtimes`, using `pv-fake` to reject loads:
1. Successfully serve Project A on port 3000.
2. Apply A's change to port 4000, then reject the Gateway load with HTTP 422. A's old port-3000 fragment remains active.
3. Validate and finalize Project B on port 3000. Both operations succeed despite A's active route.
4. Change A's config to `proxy: 0`, permit Gateway loads again, and reconcile. A's preserved fragment is removed because B now owns its old port.

Switching from proxy to PHP or disabling serving also releases the old claim before Gateway application.

## Required outcome
- Keep every still-active proxy port unavailable to other Projects and managed allocation until its Gateway route is confirmed removed or replaced, including rejected and unknown load outcomes.
- Preserve the last-valid route during invalid-config recovery rather than silently dropping it on a newly admitted collision.
- Exercise the rejected-load/reuse/invalid-edit sequence in reconciliation coverage; checking only the persisted target does not protect this boundary.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Confirmed and fixed in bd02f7b. I reproduced it: after a rejected load, the Project's restored Gateway fragment still routed to the old port, while validate_project_proxy_port and the allocator treated that port as free.

PHP worker ports already follow the right rule: they are released only after the Gateway commits (cleanup_stale_worker_runtime). Proxy ports now match it:

  • reconcile_gateway_config records the proxy ports in the applied Gateway config (gateway_proxy_port) after a successful load or a rollback to the previous config.
  • A rejected or unknown load records nothing, so the old port stays claimed.
  • Port validation and the allocator treat both proxy_port and gateway_proxy_port as claims.
  • Another Project can no longer be admitted on a live route's port, so the invalid-config fallback in append_persisted_runtime_project no longer has a collision branch that drops the preserved route.

Covered by proxy_port_stays_claimed_until_the_gateway_stops_routing_to_it, which fails without the fix.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The rejected-load case is fixed, but I reproduced an accepted load to B failing readiness, followed by Project Apply to C, after which both sibling validation and managed allocation accepted B while the same replacement-required Gateway process remained alive, so potentially applied targets still need reservations until that process epoch stops.

Pullfrog  | View workflow run | via Pullfrog | Using gpt-6.1-sol | 𝕏

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Update: bd02f7b is reverted in f263f0a, and we're not handling this case.

It only happens when the Gateway is already failing to apply config and, during that window, the user moves another Project onto the old port:

  • PV runs caddy validate before every load, and the Gateway listens on inherited sockets, so a rejected load after validation is essentially a Caddy bug.
  • The realistic way to get there is an unrelated PHP worker that fails to start. That blocks every Gateway change, and PV already reports the failure.
  • The effect is temporary: the old hostname reaches the other Project's app until the Gateway applies config again.

The claim also made that window worse. The other Project's whole reconciliation failed with an error naming a port its owner had already moved off.

The accepted-but-not-ready case needs the same failing Gateway plus another port change before the process is replaced, so we're leaving it too.

@clvsh
clvsh marked this pull request as ready for review November 19, 2026 17:01
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 19, 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-20T02:39:27.532051Z f263f0a New commits
🔒 Security Review ✅ Completed 2026-11-19T17:10:58.429359Z d86f400 Draft marked ready
ℹ️ 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: d86f400b43

ℹ️ 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".

Comment on lines +1633 to +1635
transaction.execute(
"UPDATE projects SET proxy_port = ?1 WHERE id = ?2",
params![proxy_port, project.id],

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Retain the old proxy port claim until the Gateway switches

When a Project changes from proxy port A to B (or switches to PHP), Project Apply updates this column before the Gateway accepts its new configuration. If the Gateway reload is rejected or unavailable, Caddy retains the route to A, but both validate_project_proxy_port and the allocator now treat A as unclaimed. Another Project can therefore claim A while the original hostname still forwards there; subsequent fallback can also silently drop the old route when append_persisted_runtime_project detects that collision. Retain the active upstream's port reservation until the Gateway successfully switches or removes its route.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Confirmed and fixed in bd02f7b. The old port now stays claimed until the applied Gateway config stops routing to it, including after a rejected or unknown load. Details: #513 (comment)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Update: bd02f7b is reverted in f263f0a, and we are not handling this case. Reasoning: #513 (comment)

@coderabbitai coderabbitai 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.

Actionable comments posted: 2

Note

Quiet mode is enabled, so only the most important comments were posted inline. Other review comments are grouped below.

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (1)

Minor · Clear the stored proxy port when linking a resource-only Project. · database.rs:4384

crates/state/src/database.rs:4384
Minor · Data Integrity & Integration · Quick win

Clear the stored proxy port when linking a resource-only Project.

If Project A holds port 3000, link_project_with_mode(..., ProjectMode::ResourceOnly) changes serves_http but retains proxy_port=3000. into_record then reports proxy_port: None, while collision validation and the allocator still reserve 3000 for A. Project B cannot use that port until A completes another reconciliation or is unlinked.

Clear proxy_port in this update when mode is ResourceOnly. Preserve the last valid port for Served updates.

Other comments: 3

crates/daemon/tests/it/real_artifact_gateway_e2e.rs: 3

151-151: Minor · Stability & Availability · Quick win

Bound the wait for the echo server.

If curl receives a successful response without Caddy contacting the test upstream, curl returns but try_join! keeps waiting for accept(). Curl's timeout no longer applies. Put a deadline on the echo exchange so this routing regression fails the test and reaches cleanup.


158-159: Minor · Functional Correctness · Quick win

Distinguish a removed route from a stale route that returns 502.

The echo listener has already closed. If reconciliation removes the Caddyfile but leaves the live route in place, Caddy returns 502. Curl's default --fail makes that an error, so both assertions pass. Use --no-fail and reject the proxy's 502 response, or keep the echo server running through the disable check.


132-134: Minor · Stability & Availability · Quick win

Return assertion failures through the cleanup path.

If the unavailable-upstream response differs from the expected body, assert_eq! panics before the test shuts down the daemon, stops recorded runtimes, or attaches diagnostics. The later assert! and assert_eq! checks have the same problem. Return descriptive errors from the request block so both failed and successful checks reach cleanup.

Nitpick comments: 1

crates/daemon/tests/it/real_artifact_gateway_e2e.rs: 1

168-169: Trivial · Maintainability & Code Quality · Quick win

Check PHP worker demand while the proxy route is active.

These checks run after serve: false reconciliation. If PV assigns a PHP worker during proxy serving and releases it during disable, the final port inventory can still pass. Check the inventory immediately after the successful proxy request.

Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: QUIET
  • Plan: Advanced
  • Run ID: 7fa1f741-e58f-4e17-ae6d-b474be27819f
Commits

Reviewing files that changed from the base of the PR and between b2e18c7 and d86f400.

Files ignored due to path filters: 25

  • crates/cli/tests/it/snapshots/it__doctor__doctor_fails_when_daemon_socket_is_stale.snap is excluded by !**/*.snap
  • crates/cli/tests/it/snapshots/it__doctor__doctor_fails_when_system_ca_trust_is_missing.snap is excluded by !**/*.snap
  • crates/cli/tests/it/snapshots/it__doctor__doctor_fails_when_system_resolver_is_missing.snap is excluded by !**/*.snap
  • crates/cli/tests/it/snapshots/it__doctor__doctor_fails_with_repair_commands.snap is excluded by !**/*.snap
  • crates/cli/tests/it/snapshots/it__doctor__doctor_on_a_terminal_failing.snap is excluded by !**/*.snap
  • crates/cli/tests/it/snapshots/it__doctor__doctor_on_a_terminal_healthy.snap is excluded by !**/*.snap
  • crates/cli/tests/it/snapshots/it__doctor__doctor_passes_when_required_checks_pass.snap is excluded by !**/*.snap
  • crates/cli/tests/it/snapshots/it__doctor__doctor_reports_cross_account_helper_recovery.snap is excluded by !**/*.snap
  • crates/cli/tests/it/snapshots/it__doctor__doctor_reports_missing_helper_and_continues_other_checks.snap is excluded by !**/*.snap
  • crates/cli/tests/it/snapshots/it__doctor__doctor_warnings_do_not_fail.snap is excluded by !**/*.snap
  • crates/cli/tests/it/snapshots/it__php__php_use_latest_preserves_alias_in_config_and_records_resolved_track.snap is excluded by !**/*.snap
  • crates/cli/tests/it/snapshots/it__php__php_use_updates_project_config_state_and_reports_missing_daemon.snap is excluded by !**/*.snap
  • crates/cli/tests/it/snapshots/it__project_open__link_rejects_invalid_mode_change_without_replacing_served_state.snap is excluded by !**/*.snap
  • crates/config/tests/it/snapshots/it__project_config__project_config_validates_url_placeholder_scopes.snap is excluded by !**/*.snap
  • crates/config/tests/it/snapshots/it__project_config__project_config_writer_updates_php_in_discovered_file.snap is excluded by !**/*.snap
  • crates/daemon/tests/it/snapshots/it__gateway_reconciliation__runtime_plan_defaults_root_to_project_root_without_public_directory.snap is excluded by !**/*.snap
  • crates/daemon/tests/it/snapshots/it__gateway_reconciliation__runtime_plan_defaults_root_to_public_directory_without_config.snap is excluded by !**/*.snap
  • crates/daemon/tests/it/snapshots/it__gateway_reconciliation__runtime_plan_groups_linked_projects_by_php_track.snap is excluded by !**/*.snap
  • crates/daemon/tests/it/snapshots/it__gateway_reconciliation__runtime_plan_resolves_latest_php_track_from_cached_manifest.snap is excluded by !**/*.snap
  • crates/daemon/tests/it/snapshots/it__gateway_reconciliation__runtime_plan_uses_project_root_not_original_or_config_path.snap is excluded by !**/*.snap
  • crates/daemon/tests/it/snapshots/it__project_env_reconciliation__invalid_resource_only_transition_preserves_served_mode.snap is excluded by !**/*.snap
  • crates/daemon/tests/it/snapshots/it__project_env_reconciliation__resource_only_project_uses_custom_env_file_and_no_php_worker.snap is excluded by !**/*.snap
  • crates/state/tests/snapshots/state_foundation__database_runs_migrations_and_exposes_core_schema.snap is excluded by !**/*.snap
  • crates/state/tests/snapshots/state_foundation__linked_projects_preserve_ids_and_refresh_hostnames.snap is excluded by !**/*.snap
  • crates/state/tests/snapshots/state_foundation__migrated_project_resource_state_round_trips_through_public_apis.snap is excluded by !**/*.snap
Files selected for processing: 25

  • .github/workflows/real-artifact-e2e.yml
  • DESIGN.md
  • crates/cli/src/commands/php.rs
  • crates/cli/src/commands/project.rs
  • crates/config/src/error.rs
  • crates/config/src/init.rs
  • crates/config/src/model.rs
  • crates/config/src/parser.rs
  • crates/config/tests/it/project_config.rs
  • crates/daemon/src/gateway.rs
  • crates/daemon/src/gateway_config.rs
  • crates/daemon/src/health.rs
  • crates/daemon/src/jobs.rs
  • crates/daemon/src/project_env.rs
  • crates/daemon/tests/it/gateway_config.rs
  • crates/daemon/tests/it/gateway_reconciliation.rs
  • crates/daemon/tests/it/gateway_runtime_contracts.rs
  • crates/daemon/tests/it/project_env_reconciliation.rs
  • crates/daemon/tests/it/real_artifact_gateway_e2e.rs
  • crates/state/src/database.rs
  • crates/state/src/error.rs
  • crates/state/src/migrations.rs
  • crates/state/src/sql/019_project_proxy_port.sql
  • crates/state/tests/state_foundation.rs
  • docs/user/README.md

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

let held_project_ids = database.held_project_ids()?;
for project in database.projects()? {
if project.mode == ProjectMode::Served
&& project.proxy_port.is_none()

@coderabbitai coderabbitai Bot Nov 19, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Major · Stability & Availability · Heavy lift

Keep probing a PHP worker that still serves a preserved fragment.

After a PHP-to-proxy switch commits, proxy_port is set. The health scan then excludes the project from PHP worker grouping at health.rs:372. If the Gateway reload is rejected, the Gateway can keep serving the preserved PHP fragment, and its worker is no longer in the health probes. If that worker exits later, the health scan does not probe it or restart it. scopes_due also drops backoff state for subjects that are absent from observations. The preserved route can then stay down until a manual reconciliation.

The fix must make the rollback state explicit. Either the health scan must still probe a worker that serves a preserved PHP fragment, or the rollback must hand that worker to a recovery path that restarts it. The inspected code does not establish which of these fits the design, so this comment does not prescribe one.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not changing this in this PR. The gap is real, but it isn't specific to proxy Projects. A PHP 8.4 to 8.5 move, or a switch to resource-only, followed by a rejected Gateway load leaves the old worker serving the preserved route the same way, because the health scan only probes runtimes that Projects currently demand.

It also doesn't wait for a manual reconciliation. The Gateway probe requires the applied config (requires_applied_config: true), so after a rejected load the Gateway reports unhealthy and health recovery retries Gateway reconciliation. A successful retry switches the route and stops the old worker. Probing a worker that only serves a pending switch would be a separate change to the health model.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Analysis chain

Script executed:

#!/bin/bash
set -u
printf '%s\n' '--- repository guidance ---'
fd -HI '^AGENTS\.md$' . --exec sh -c 'echo "--- $1"; cat "$1"' sh {}
printf '%s\n' '--- gateway structure ---'
ast-grep outline crates/daemon/src/gateway.rs --items all --type function,struct,enum --match 'gateway|Gateway|persist|reconcile|reconcil|preserv' 
printf '%s\n' '--- supervisor locations ---'
rg -n -C 4 'has_applied_desired_config|record_restored_config|mark_replacement_required|record_applied_config|desired_config|POST /load' crates/daemon/src
printf '%s\n' '--- gateway tests ---'
rg -n -C 3 'reject|rejected|preserv|retry|health' crates/daemon/tests/it/gateway_reconciliation.rs

Length of output: 35563


Script executed:

#!/bin/bash
set -u
printf '%s\n' '--- repository guidance ---'
fd -HI '^AGENTS\.md$' . --exec sh -c 'echo "--- $1"; cat "$1"' sh {}
printf '%s\n' '--- gateway structure ---'
ast-grep outline crates/daemon/src/gateway.rs --items all --type function,struct,enum --match 'gateway|Gateway|persist|reconcile|reconcil|preserv'
printf '%s\n' '--- supervisor locations ---'
rg -n -C 4 'has_applied_desired_config|record_restored_config|mark_replacement_required|record_applied_config|desired_config|POST /load' crates/daemon/src
printf '%s\n' '--- gateway tests ---'
rg -n -C 3 'reject|rejected|preserv|retry|health' crates/daemon/tests/it/gateway_reconciliation.rs

Length of output: 35562


Script executed:

#!/bin/bash
set -u
for f in crates/daemon/src/supervisor.rs crates/daemon/src/gateway.rs crates/daemon/src/jobs.rs crates/daemon/src/server.rs; do
  echo "--- outline $f"
  ast-grep outline "$f" --items all --type function --match 'config|Config|reconcil|health|Health|recover|Recover'
done
echo '--- supervisor fingerprint transitions ---'
cat -n crates/daemon/src/supervisor.rs | sed -n '399,480p;635,680p'
echo '--- gateway transaction and rollback ---'
cat -n crates/daemon/src/gateway.rs | sed -n '2983,3055p;3060,3335p'
echo '--- health dispatch and caddy resource scope ---'
rg -n -C 5 'scopes_due\(|record_accepted_recovery\(|scan_runtime_health\(|reconcile_gateway_runtimes|ReconciliationScope::Resource|resource_name == "caddy"' crates/daemon/src/server.rs crates/daemon/src/jobs.rs crates/daemon/src/reconciliation.rs
echo '--- base health grouping ---'
git show origin/main:crates/daemon/src/health.rs 2>/dev/null | grep -n -A14 -B3 'projects_by_runtime' | head -35 || true

Length of output: 51959


@clvsh Agreed. The preserved-worker health gap also applies to other Project transitions, so I accept deferring it from this PR.

I was wrong to imply that recovery requires manual reconciliation. After a rejected Gateway load, health recovery can retry Gateway reconciliation automatically. Until a retry succeeds, a worker used only by the preserved route can remain unprobed.

I’m not marking the finding as addressed because the health gap remains.


Learnings added

Learnt from: clvsh
Repo: prvious/pv PR: 513
File: crates/daemon/src/health.rs:372-372
Timestamp: 2026-11-19T20:42:59.010Z
Learning: Within repository "prvious/pv", only for files matching one of ["crates/daemon/src/health.rs"]: In `crates/daemon/src/health.rs`, PHP worker health probes follow current Project runtime demand, not workers used only by preserved Gateway routes. After a rejected Gateway load during a PHP runtime or serving-mode transition, the Gateway can retain the old route while the old worker has no health probe if no other Project demands it. The Gateway's applied-versus-desired config check triggers Gateway health recovery and retries reconciliation, so do not assume the transition requires manual reconciliation. The old worker can remain unprobed until a retry succeeds.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.


Learnings used

Learnt from: CR
Repo: prvious/pv PR: 0
File: DESIGN.md:0-0
Timestamp: 2026-11-11T21:03:39.730Z
Learning: Applicability reference:
AGENTS.md: ## General Rules
- Before making implementation or product decisions, consult DESIGN.md

AGENTS.md: ## General Rules
- If the decision is not covered by DESIGN.md, ask instead of guessing

AGENTS.md: ## 1. Think Before Coding
Before implementing:

- consult DESIGN.md

Source excerpt:
# More Info

## Filesystem Layout

PV keeps the previous active generated Gateway/worker config until the new config validates and `POST /load` accepts it. An API rejection restores the previous generated files while Caddy keeps the previous in-memory config active. Once a running process accepts a config through `POST /load`, PV keeps it: a later readiness failure marks the runtime for replacement instead of reloading the previous config. A freshly started process that never becomes ready is still stopped and its previous files restored, unless it is a worker that still holds a moving Project's routes, which keeps its staged files for the retry.

You are interacting with an AI system.

Comment thread crates/state/src/database.rs Resolved
…ng to it

Project Apply recorded a new proxy port before the Gateway switched routes, so
a rejected or unknown Gateway load left the old route live on a port that other
Projects and the port allocator treated as free.

Record the proxy ports in the applied Gateway config at the Gateway commit point
and treat them as claims alongside each Project's own proxy port. A resource-only
link clears the Project's own claim; the Gateway claim covers a route still live.
Use ensure! so failures still stop the daemon and real Caddy, bound the wait for
the upstream, check that a removed route no longer answers instead of returning
502, and check PHP worker demand while the proxy route is active.
@clvsh

clvsh commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

Follow-up on the CodeRabbit review items outside the inline threads:

  • Resource-only link keeps proxy_port (database.rs): fixed in bd02f7b. link_project_with_mode now clears it for a resource-only link. The Gateway's own claim still holds the port while the old route is live, so clearing it doesn't reopen the rejected-load case.
  • real_artifact_gateway_e2e.rs: all four fixed in a60b1d2.
    • The upstream wait is bounded at 30 seconds. The workflow uses the default nextest profile, which has no timeout.
    • The disabled-route check passes --no-fail, so a stale route's 502 now fails it.
    • Checks use ensure!, so a failure still shuts down the daemon and real Caddy and attaches diagnostics.
    • The PHP worker check runs while the proxy route is active.

@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: a60b1d2813

ℹ️ 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".

Comment thread crates/state/src/database.rs Outdated
Comment on lines +4483 to +4484
"SELECT primary_hostname FROM projects
WHERE ?1 IN (proxy_port, gateway_proxy_port) AND id != ?2",

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve applied proxy port claims after unlinking a Project

When a proxy Project is unlinked and the Gateway rejects or cannot accept the route removal, its old hostname still forwards to the proxy port, but this lookup and the allocator already consider that port free. Unlike the now-covered port-change path, unlink_project_in_transaction deletes the entire Project row (database.rs:1272), including gateway_proxy_port, before the CLI requests reconciliation (commands/project.rs:382–399). Another Project or managed runtime can consequently claim that port while the old route remains active. Preserve applied Gateway port reservations independently of the deleted Project until route removal succeeds.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not fixing this one. It needs the Gateway to fail to remove the unlinked Project's route, and another Project to take that exact port before the Gateway recovers. The effect is temporary misrouting while PV already reports the Gateway failure, and hostname reservations behave the same way after unlink. The gateway_proxy_port column is also gone: bd02f7b is reverted in f263f0a. Reasoning: #513 (comment)

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Important

The existing port-ownership finding remains partially unresolved: a potentially applied target can become available before the marked Gateway process is replaced. No additional findings.

Reviewed changes since d86f400, covering bd02f7b and a60b1d2.

  • Retained confirmed Gateway proxy claims across rejected loads and included them in collision checks and port allocation.
  • Cleared resource-only Project claims without releasing the last applied Gateway reservation.
  • Strengthened proxy test coverage with rejected-load checks, bounded upstream waits, cleanup-safe failures, and stricter route-removal assertions.

Validation: three focused tests and formatting passed. A deterministic production-path probe confirmed the remaining case described in the existing thread; real-artifact tests were not run.

Pullfrog  | Fix it ➔ | View workflow run | Using gpt-6.1-sol | 𝕏

This reverts commit bd02f7b.

The claims only mattered when the Gateway was already failing to apply config
and the user moved another Project onto the old port during that window. The
effect was a temporary misroute while PV already reported the failure, and the
claim made the other Project's reconciliation fail with a misleading error.
@clvsh

clvsh commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

Update on the resource-only link item from the CodeRabbit review: the proxy_port clear was part of bd02f7b, which is reverted in f263f0a. It only matters when pv link switches a proxy Project to serve: false, that Project's reconciliation then fails, and another Project wants the same port. The error clears once the Project reconciles.

The E2E test fixes in a60b1d2 stay.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ℹ️ No additional findings. The previously reported port-ownership failure window is intentionally retained.

Approach: the revert favors Project-applied port claims over Gateway-lifetime reservations, explicitly accepting stale routing during failed transitions.

Reviewed changes since a60b1d2, covering the revert in f263f0a.

  • Removed Gateway port reservations from persistence, reconciliation, collision validation, and allocation.
  • Restored fallback collision handling that omits a preserved proxy route when its old port has another owner.
  • Reverted resource-only link clearing and the retention test, and updated the design contract while preserving the earlier E2E improvements.

Validation: 78 integration tests and formatting passed; daemon test fixtures built successfully. Real-artifact E2E tests were not run.

Pullfrog  | Fix it ➔ | View workflow run | Using gpt-6.1-sol | 𝕏

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.

feat: support local HTTP proxy projects

1 participant