Repository navigation
fix(persistence,daemon,sandbox): support localhost dual-stack loopback in isolated Sandbox roots and clarify unreachable PostgreSQL errors - #760
Merged
yifanxuaaa merged 4 commits intoNov 23, 2026
Conversation
… shared loopback and clarify unreachable PostgreSQL daemon open errors
On Linux, both `native` and `docker` machines use `Loopback::Shared` in
`reach.rs` and run their Sandbox daemons inside `namespaces` roots
pivoted to an unpacked image without `/etc/hosts` or `/etc/resolv.conf`
(`image_tar/filter.rs` drops init files). `store.reach` and `reach_check`
ran in the host or worker container where `localhost` resolved, so
`store doctor` reported ok while `sandbox create` failed inside the
daemon with `Store open: physical Store I/O: pack persistence: Refused {
status: "Closed" }` and suggested `layerfs machine doctor`.
- `layerfs-platform/src/reach.rs`: under `Loopback::Shared` on Linux,
rewrite `localhost` to `127.0.0.1` (refusing `sslmode=verify-full` as
`Unsupported`, matching other rewrites). Keep `127.0.0.1`, `[::1]`,
`?host=`/`?hostaddr=`, Unix sockets, non-loopback hosts, and macOS
`native` unchanged.
- `layerfs-daemon`: map PostgreSQL `PersistenceError::Refused { status:
"Closed" }` at Store open to `ApplicationError::PostgresUnreachable {
host }` (`cannot reach PostgreSQL Store at <host>`, without userinfo).
- `layerfs-sandbox/src/launch/local.rs`: translate PostgreSQL Store-open
unreachable failures in `abandon` to `Unavailable` (`Sandbox <id> did
not start: its daemon cannot reach PostgreSQL Store <store>'s server
at <host>`), noting on `namespaces` when `<host>` is a hostname that
the Sandbox root has no `/etc/hosts` or `/etc/resolv.conf`, instead of
exposing `pack persistence: Refused` and suggesting `machine doctor`.
- Docs: update `workers-and-reach.md`, `platforms.md`, and `sandbox.md`.
Tests: added `engine/crates/layerfs-daemon/tests/postgres_unreachable.rs`
and `control/crates/layerfs-sandbox/tests/postgres_reach_localhost.rs`;
updated `layerfs-platform` `machine_reach` and `conformance` for Linux
`Shared` `localhost` rewriting. Both new tests failed on `ed9118963` and
pass on this fix. No test deleted; no assertion weakened.
Production LOC: 205844 -> 205950 (delta +106); core 40988, engine 95845
-> 95889 (layerfs-daemon 9024 -> 9068), control 58745 -> 58807
(layerfs-platform 3692 -> 3708, layerfs-sandbox 17117 -> 17163), api
10266. Scope and method: tools/production_loc.py --root --json on git
archive extracts of ed91189 and HEAD tree
b9aea00. Reference absent (retired
R9c; last counted 65,417 at tree 498dd19).
Revert the Loopback::Shared localhost-to-127.0.0.1 rewrite in layerfs-platform/src/reach.rs (and its reachability/conformance test changes) so localhost URLs remain intact across native host checks, store doctor, and Sandbox routes, restoring IPv6 ::1-only localhost PostgreSQL connectivity. In engine/crates/layerfs-persistence (Connector::new), pair a single localhost TCP host (when no hostaddr is explicitly configured) with both 127.0.0.1 and ::1 via Config::hostaddr while retaining localhost for TLS hostname verification (sslmode=verify-full), so Sandbox roots without /etc/hosts or DNS dial both IPv4 and IPv6 loopback directly. Narrow the /etc/hosts hint in control/crates/layerfs-sandbox/src/launch/local.rs to exclude localhost, and update docs/architecture/engine/store/postgresql.md. Deleted tests: - control/crates/layerfs-sandbox/tests/postgres_reach_localhost.rs (tested the reverted route::reached localhost -> 127.0.0.1 rewrite) Production LOC (tools/production_loc.py --root): - From 5276f5c: core +0 (40988->40988), engine +12 (95889->95901), control -13 (58807->58794), api +0 (10266->10266), total -1 (205950->205949) - From ed91189: core +0 (40988->40988), engine +56 (95845->95901), control +49 (58745->58794), api +0 (10266->10266), total +105 (205844->205949)
postgresql_localhost (layerfs-persistence, real PostgreSQL, env-gated): a localhost URL reaches a server listening only on ::1 or only on 127.0.0.1, also where localhost does not resolve; IP literals and a given hostaddr are dialled as given; other host names and Unix sockets get no loopback; sslmode=verify-full is refused as before; TLS checks the name localhost. localhost_reach (layerfs-platform): Linux native and docker dial every Store URL as the caller and store doctor dial it. No tests deleted. Production LOC: 205,949 -> 205,949 (delta 0) core 40,988 -> 40,988 (0) engine 95,901 -> 95,901 (0) control 58,794 -> 58,794 (0) api 10,266 -> 10,266 (0) reference absent (retired R9c; last counted 65,417 at tree 498dd19) Method: tools/production_loc.py --detail on parent 9cf5b0b and the staged tree Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Tier: P1 (engine/crates/layerfs-persistence, engine/crates/layerfs-daemon) ; risks: risk:store ; gate: yes ; de-escalated: none
Summary
On Linux,
store doctorand host/worker reach checks resolvelocalhostthrough the host or worker/etc/hosts, whereas Sandbox daemons run inside isolatednamespacesroots stripped of/etc/hostsand/etc/resolv.conf. Previously, connecting to alocalhostPostgreSQL Store succeeded instore doctorand then failed insidesandbox createwith the internal errorpack persistence: Refused { status: "Closed" }.layerfs-persistence(Connector::new): When aPostgresSelectionURL names a singlelocalhostTCP host (case-insensitive) without an explicithostaddr, pairlocalhostwith both127.0.0.1and::1viaConfig::hostaddrwhile keepinglocalhostas the TLS hostname verification target. This allows isolated Sandbox roots without/etc/hostsor DNS to reach both IPv4 and IPv6 loopback PostgreSQL servers, while leaving IP literals, explicithostaddr, multi-host URLs, Unix sockets, and other hostnames unchanged.layerfs-daemon(ApplicationError::PostgresUnreachable): MapPersistenceError::Refused { status: "Closed" }when opening aDaemonStore::Postgrestocannot reach PostgreSQL Store at <host>(extracting only the hostname, never credentials or internalpack persistencedetails).layerfs-sandbox(launch/local.rsabandon): Translate daemon PostgreSQL-unreachable startup failures intoUnavailable(Sandbox <id> did not start: its daemon cannot reach PostgreSQL Store <store>'s server at <host>), appending(the Sandbox root has no /etc/hosts or /etc/resolv.conf, so a hostname may not resolve there; use an IP address)onnamespaceswhen<host>is a non-localhosthostname.Docs & Tests
docs/architecture/engine/store/postgresql.md,docs/architecture/api/sdk/sandbox.mdengine/crates/layerfs-persistence/tests/postgresql_localhost.rs: verifieslocalhost/LocalHostreachability on both::1-only and127.0.0.1-only servers (including masked/etc/hostsand/etc/resolv.conf), preservation of IP literals / explicithostaddr/ non-localhosthosts / Unix sockets,sslmode=verify-fullrefusal parity, and TLS hostname verification forlocalhost.control/crates/layerfs-platform/tests/localhost_reach.rs: verifies Linuxnativeanddockerpass Store URLs through unchanged sostore doctorand Sandbox dials match.engine/crates/layerfs-daemon/tests/postgres_unreachable.rs: verifies daemon stderr reportscannot reach PostgreSQL Store at 127.0.0.1without leaking passwords orpack persistence.ed9118963).Checks (base
ed9118963, headffd7e77d8)cargo +1.85.1 fmt --all -- --check: passed (ffd7e77d8)python3 -B tools/check_product_boundary.py --skip-sdk: passed (1594 production files,ffd7e77d8)python3 -B -m unittest discover -s tools -p "test_*.py": 181 tests OK (ffd7e77d8)cargo +1.85.1 clippy --locked --workspace --exclude layerfs-node --all-targets -- -D warnings: passed at9cf5b0b11(headffd7e77d8adds two test files only, both built cleanly viacargo +1.85.1 test --locked ... --no-run)postgresql_localhostundernsenter+ masked/etc/hostson::1and127.0.0.1,localhost_reach,postgres_unreachable,ipv6_doctor.sh): all passedlf-ci.shfast,slow,mount+lf-ci-pg.shonffd7e77d8):fast: 2920 run, 2908 passed, 12 failed, 26 skipped (rc=100); all 12 failures (layerfs-api::machine_power::start_and_stop_a_machine, 10×layerfs-api::sandbox_get_no_lease,layerfs-sandbox::workspace_isolation::sandbox_modules_never_import_workspace) reproduce identically on baseed9118963.slow: 177 passed, 0 failed, 11 skipped (rc=0).mount: 46/46 binaries passed (113 passed, 0 failed, 3 ignored).pg:layerfs-persistence(29/29),layerfs-store-service(10/10),layerfs-project(1/1),layerfs-api(2/2),layerfs-cli(2/2) passed (NOT_RUN=0,rc=0). (lf-ci-pg.shhad a stalelayerfs-control --test doctor_store_postgresqlline;doctor_store_postgresql.rswas removed upstream in29af0171d.)Production LOC: 205844 -> 205949 (delta +105) vs base
ed9118963(core +0,engine +56,control +49,api +0;tools/production_loc.py --detail; recompute against target tip at merge time).