Skip to content

fleet proxy serve inherits the sandbox egress HTTPS_PROXY in userspace mode; queue/shell legs fail until it is restarted with tailscaled's CONNECT proxy #12426

Closed

Description

@dezren39

Observed

On the Muse sandbox seat (agent felix), with tailscaled running in userspace mode, fleet agent doctor --agent felix reported the queue and shell legs down:

  • queue: repo-queue: broker: tunnel to 100.99.113.103:4801: proxy closed during CONNECT
  • shell: laptop-agent: HTTP 502: broker: tunnel to 100.99.113.103:4799: proxy closed during CONNECT

while bridge and github were ok. Direct checks proved the laptop itself was fine: via tailscaled's local CONNECT proxy (curl -x http://127.0.0.1:3130 http://100.99.113.103:4799/ and :4801/) both laptop services answer HTTP 401 (auth expected), and tailscale ping to 100.99.113.103 answers via DERP.

Root cause

The running fleet proxy serve (the session proxy the queue/shell legs tunnel through) had been started with the sandbox egress proxy in its environment (HTTPS_PROXY=http://hatch-egress-proxy:3128) instead of tailscaled's local CONNECT proxy (http://127.0.0.1:3130). The egress proxy cannot route tailnet IPs, so every CONNECT to the laptop closed. Its own log warned: fleet proxy serve: HTTPS_PROXY must be set (runtime proxy env) (tunnels will fail until it is set) — the value was set, but to the wrong proxy.

The proxy had been (re)started by the doctor/init-ensure path, which spawns it inheriting the ambient environment. The bootstrap tailnet phase writes the correct value to ~/.local/state/tailscale/fleet-proxy.env (export HTTPS_PROXY=http://127.0.0.1:3130) and prints "start fleet proxy with HTTPS_PROXY from .../fleet-proxy.env", but nothing actually starts the proxy with that env.

Fix applied on the seat (verified)

Killed the proxy and restarted it with the egress vars stripped and HTTPS_PROXY=http://127.0.0.1:3130 (+ LAPTOP_AGENT_POOL=50). The HTTPS_PROXY warning disappeared from its log and a re-run of fleet agent doctor --agent felix passed all four legs (bridge, queue, github, shell all ok; "fleet shell reaches the laptop").

Suggested fix

In userspace mode, whoever (re)starts fleet proxy serve — init-ensure.sh, the doctor's auto-start, and the bootstrap tailnet phase — should source fleet-proxy.env (or otherwise set HTTPS_PROXY=http://127.0.0.1:3130 with the egress proxy vars stripped) instead of inheriting the ambient sandbox egress proxy. Kernel mode is unaffected (direct dialling).

Context

  • Seat: Muse sandbox, agent felix, fleet 0.1.0-dev.14982+gd26fa16 (from-main build d26fa16).
  • Found by the felix-seat-keeper cron run, Sat 2026-11-21 ~23:25 CST.

Activity

  1. added
    kind/bugSomething isn't working (prefixed form of the classic bug label)
    app/fleetpkgs/fleet multicall binary + platform crates
    on Nov 22, 2026
  2. developing-today commented on Nov 22, 2026

    @developing-today
    Contributor
  3. dezren39 commented on Nov 23, 2026

    @dezren39
    MemberAuthor

    Agent note — Lane LJ claiming #12426 (self-served from GitHub; fleet agent next rungs empty/down this pass).

    Fresh premise check (2026-11-23 ~01:47 CST):

  4. dezren39 commented on Nov 23, 2026

    @dezren39
    MemberAuthor

    Lane LD claiming the Python-side remainder of this issue.

    Premise re-verified fresh on current main:

    Slice: mirror the #12645 rule in the Python client and broker — resolve the recorded tailnet proxy ($FLEET_PROXY_ENV, then the named agent's ~/.local/state/tailscale/agents/<slug>/fleet-proxy.env, then ~/.local/state/tailscale/fleet-proxy.env) ahead of the ambient env for the tailnet CONNECT leg only; the Cloudflare leg keeps the ambient proxy, as in the Rust shape. Unit tests included.

  5. dezren39 commented on Nov 23, 2026

    @dezren39
    MemberAuthor

    Progress: PR open for the Python-side slice — #13071 (recorded tailnet proxy resolution mirrored into laptop-agent.py + laptop-agent-broker.py, 9 unit tests green). Merging on the verified head, then a done record with the remaining scope.

  6. dezren39 commented on Nov 23, 2026

    @dezren39
    MemberAuthor

    Agent note · claimed — Lane LN (archer)

    Taking the init-ensure spawner slice of #12426: tools/init-ensure.sh in dezren39/hatch spawns fleet proxy serve with only LAPTOP_AGENT_POOL=50 set, inheriting the ambient sandbox egress HTTPS_PROXY — the exact defect this issue files.

    Fresh premise check (2026-11-23, read-only):

    • dezren39/hatch origin/main tools/init-ensure.sh: the spawn line is setsid nohup env LAPTOP_AGENT_POOL=50 "$FLEET_BIN_OK" proxy serve — no reference to fleet-proxy.env anywhere in the file; the later fleet init call (spawn mode runs the proxy role in-process) likewise inherits the ambient env.
    • The other two surfaces the issue names, checked on current main: the fleet doctor (fleet-agent enroll::doctor) does not spawn the proxy at all; scripts/muse/bootstrap.sh writes fleet-proxy.env + prints the hint but starts nothing. The sandbox heal script (laptop-channel-heal.sh) already starts the broker with an explicit proxy env and kills wrong-env brokers — the pattern this fix mirrors.
    • No live claim on this issue (only a Kaneo link comment).

    Scope: source ~/.local/state/tailscale/fleet-proxy.env for the proxy spawn and the fleet init call in init-ensure.sh when the file exists (userspace mode); absent file (kernel mode) keeps today's inherit behavior. Fix lands in dezren39/hatch; this issue stays the record.

  7. dezren39 commented on Nov 23, 2026

    @dezren39
    MemberAuthor

    Done record for the in-repo remainder of this issue: PR #13071 merged (382dc9bd4283).

    What landed:

    • pkgs/fleet/laptop-agent.py: new tailnet_https_proxy() resolver mirroring fleet-config's fleet: tailnet tunnels use the seat's recorded tailnet proxy (#12555) #12645 rule exactly — candidate order $FLEET_PROXY_ENV, then the named agent's ~/.local/state/tailscale/agents/<slug>/fleet-proxy.env, then ~/.local/state/tailscale/fleet-proxy.env; same bootstrap slug rule and env-file parse rule. tunnel_socket (the tailnet leg) prefers the recorded proxy over the ambient HTTPS_PROXY. The Cloudflare leg keeps the ambient proxy, as in the Rust shape.
    • pkgs/fleet/laptop-agent-broker.py: broker_tunnel_socket resolves through the client's resolver when the deployed copy provides one; an older deployed client leaves the ambient env in charge.
    • pkgs/fleet/tests/test_tailnet_proxy_env.py: 9 tests, all green — slug/candidate/parse cases mirror fleet-config's Rust cases value-for-value, resolution order (shared < agent < explicit) is covered, and an end-to-end tunnel_socket check against a fake CONNECT proxy proves the recorded proxy wins over an ambient egress proxy.

    State of the issue's named fix paths after this PR:

  8. dezren39 commented on Nov 23, 2026

    @dezren39
    MemberAuthor

    Agent note — Lane LJ: #12426 done. PR #13080 merged (647dd8013cda); this issue auto-closed as completed on the merge.

    What the premise check found on current main: the felix-seat failure mode was already half-fixed. PR #12645 (for #12555) made tailnet tunnel construction prefer the seat's recorded tailnet proxy (fleet-proxy.env) over the ambient HTTPS_PROXY — but fleet proxy serve resolved that egress once at startup and cached it in the Broker for the process's whole life. A broker (re)started while tailscaled was down, or before bootstrap wrote the env file, kept the ambient value (or none) forever — the manual restart in this issue's "Fix applied on the seat" was the only cure.

    The landed remainder (one file, pkgs/fleet/crates/fleet-proxy/src/serve.rs): both tailnet tunnel opens now resolve the egress fresh per open via a new Broker::tailnet_egress() over the existing egress_from_env; the pure preference function resolve_tailnet_egress (fresh wins → startup parse as fallback → resolution error) carries three unit tests naming that oracle. Opens are pooled and recovery-gated, so the cost is one small file read per new tunnel, not per request.

    Verification: cargo test -p fleet-proxy 113/113 + 14/14 at the original head and again after a rebase onto current main; cargo fmt clean; the new functions re-read on main at the merge SHA. The Cloudflare leg's egress is deliberately unchanged (the ambient platform proxy is its correct source), and the spawn sites named in the suggested fix (bootstrap hint, spawn_serve env inheritance) need no change once the value is read at open time — a broker's inherited environment no longer steers its tailnet tunnels at any point in its life. The same evidence closes the parent defect #12555.

  9. dezren39 commented on Nov 23, 2026

    @dezren39
    MemberAuthor

    Agent note · done — Lane LN (archer)

    Landed: dezren39/hatch PR #22, merged 4c9294875bc0 (head 39cc08c SHA-guarded; fix re-read on hatch main: helper at tools/init-ensure.sh:68, spawn sites at :100/:104).

    What changed, in tools/init-ensure.sh only:

    • New tailnet_proxy_env helper: when ~/.local/state/tailscale/fleet-proxy.env exists, source it and drop the other ambient proxy vars (http_proxy, https_proxy, HTTP_PROXY, all_proxy, ALL_PROXY) so only the tailnet HTTPS_PROXY survives into the spawn.
    • Both broker spawns (fleet proxy serve and the Python fallback) and the spawn-mode fleet init call (which runs the proxy role in-process) now run in a subshell applying the helper first.
    • Env file absent (kernel mode; bootstrap removes it there): spawns inherit the ambient env exactly as before. Subshell scoping keeps the rest of the prelude — the secrets broker's BWS calls in particular — on the egress route.

    Disposition of the three surfaces this issue names:

    1. init-ensure.sh — was the defective spawner; fixed above.
    2. The doctor's auto-start — verified on current code main: enroll::doctor in fleet-agent never spawns the proxy (no proxy serve spawn exists in that crate); nothing to change.
    3. The bootstrap tailnet phase — verified on current code main: scripts/muse/bootstrap.sh writes the env file and prints the hint but starts nothing; nothing to change.

    Verification: bash -n clean; mechanism test with the helper extracted verbatim from the edited script under an egress-shaped ambient env — env file present: the child sees only HTTPS_PROXY=http://127.0.0.1:3130 (plus NO_PROXY bypass lists) and the parent env is untouched; env file absent: the child inherits the ambient env unchanged. The test caught one real gap mid-work (this seat's ambient env also carries ALL_PROXY/all_proxy), which is why those two are in the unset list.

    Named remainder (not part of this issue's fix): on relay-shaped seats like this sandbox — where no fleet-proxy.env exists and the correct broker env is the heal script's relay value — an init-ensure spawn that wins the race against the heal script still inherits the ambient env; the heal script owns that shape and corrects wrong-env brokers on its cadence. The currently-down queue leg on this seat is the separate platform session-proxy fault, not this defect.

    Closing #12426 as completed on this record.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    app/fleetpkgs/fleet multicall binary + platform crateskind/bugSomething isn't working (prefixed form of the classic bug label)status:done

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions