Skip to content

fix(persistence,daemon,sandbox): support localhost dual-stack loopback in isolated Sandbox roots and clarify unreachable PostgreSQL errors - #760

Merged
yifanxuaaa merged 4 commits into
Ephemeral-AI-Lab:layerfs_v2_0_0from
jiangkoumo:fix/pg-localhost
Nov 23, 2026
Merged

yifanxuaaa merged 4 commits into
Ephemeral-AI-Lab:layerfs_v2_0_0from
jiangkoumo:fix/pg-localhost

Conversation

@jiangkoumo

Copy link
Copy Markdown
Collaborator

Tier: P1 (engine/crates/layerfs-persistence, engine/crates/layerfs-daemon) ; risks: risk:store ; gate: yes ; de-escalated: none

Summary

On Linux, store doctor and host/worker reach checks resolve localhost through the host or worker /etc/hosts, whereas Sandbox daemons run inside isolated namespaces roots stripped of /etc/hosts and /etc/resolv.conf. Previously, connecting to a localhost PostgreSQL Store succeeded in store doctor and then failed inside sandbox create with the internal error pack persistence: Refused { status: "Closed" }.

  • layerfs-persistence (Connector::new): When a PostgresSelection URL names a single localhost TCP host (case-insensitive) without an explicit hostaddr, pair localhost with both 127.0.0.1 and ::1 via Config::hostaddr while keeping localhost as the TLS hostname verification target. This allows isolated Sandbox roots without /etc/hosts or DNS to reach both IPv4 and IPv6 loopback PostgreSQL servers, while leaving IP literals, explicit hostaddr, multi-host URLs, Unix sockets, and other hostnames unchanged.
  • layerfs-daemon (ApplicationError::PostgresUnreachable): Map PersistenceError::Refused { status: "Closed" } when opening a DaemonStore::Postgres to cannot reach PostgreSQL Store at <host> (extracting only the hostname, never credentials or internal pack persistence details).
  • layerfs-sandbox (launch/local.rs abandon): Translate daemon PostgreSQL-unreachable startup failures into Unavailable (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) on namespaces when <host> is a non-localhost hostname.

Docs & Tests

  • Docs: docs/architecture/engine/store/postgresql.md, docs/architecture/api/sdk/sandbox.md
  • Added tests:
    • engine/crates/layerfs-persistence/tests/postgresql_localhost.rs: verifies localhost / LocalHost reachability on both ::1-only and 127.0.0.1-only servers (including masked /etc/hosts and /etc/resolv.conf), preservation of IP literals / explicit hostaddr / non-localhost hosts / Unix sockets, sslmode=verify-full refusal parity, and TLS hostname verification for localhost.
    • control/crates/layerfs-platform/tests/localhost_reach.rs: verifies Linux native and docker pass Store URLs through unchanged so store doctor and Sandbox dials match.
    • engine/crates/layerfs-daemon/tests/postgres_unreachable.rs: verifies daemon stderr reports cannot reach PostgreSQL Store at 127.0.0.1 without leaking passwords or pack persistence.
  • Deleted tests: none (relative to base ed9118963).

Checks (base ed9118963, head ffd7e77d8)

  • 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 at 9cf5b0b11 (head ffd7e77d8 adds two test files only, both built cleanly via cargo +1.85.1 test --locked ... --no-run)
  • Targeted acceptance tests (postgresql_localhost under nsenter + masked /etc/hosts on ::1 and 127.0.0.1, localhost_reach, postgres_unreachable, ipv6_doctor.sh): all passed
  • Full CI (lf-ci.sh fast,slow,mount + lf-ci-pg.sh on ffd7e77d8):
    • 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 base ed9118963.
    • 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.sh had a stale layerfs-control --test doctor_store_postgresql line; doctor_store_postgresql.rs was removed upstream in 29af0171d.)
  • Durable: NOT_RUN — disabled by owner until explicit reauthorization.
  • Not run: macOS / Lima / Apple Container live runs (Linux host only).

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).

jiangkoumo and others added 4 commits November 22, 2026 13:19
… 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>
@yifanxuaaa
yifanxuaaa merged commit 52c1c72 into Ephemeral-AI-Lab:layerfs_v2_0_0 Nov 23, 2026
2 checks passed
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.

2 participants