Skip to content

fix(cli): restart the agent after restart-proxy so its netns re-links to wg-client - #93

Open
shejnowicz wants to merge 1 commit into
masterfrom
fix/69-restart-proxy-orphans-agent
Open

fix(cli): restart the agent after restart-proxy so its netns re-links to wg-client#93
shejnowicz wants to merge 1 commit into
masterfrom
fix/69-restart-proxy-orphans-agent

Conversation

@shejnowicz

Copy link
Copy Markdown
Collaborator

Fixes #69.

Summary

`sandcat restart-proxy` restarted `mitmproxy` and `wg-client` but left the `agent` container running. The agent uses `network_mode: service:wg-client`, which Docker resolves to a specific network-namespace file descriptor at agent-container start time. Restarting `wg-client` tears down that namespace and creates a fresh one, but the agent's existing fd still points at the torn-down namespace — so DNS and all outbound connectivity break inside the agent even though both proxy services are healthy.

Fix: after `wg-client` restart completes and reports healthy, also restart `agent`. Docker re-resolves the `network_mode` reference against the fresh `wg-client` on start, so the agent picks up a working netns.

The netns re-link is guarded by the agent's pre-restart running status, so `restart-proxy` on a proxy-only stack (agent stopped manually or never started) doesn't spontaneously start it.

Test plan

  • bats: `test/restart-proxy/restart-proxy.bats` — 3/3 pass. New cases: proxy+agent both running (agent restart happens), proxy-only running (agent restart skipped).
  • Full CLI init/restart-proxy/composefile suites still green.
  • Hands-on end-to-end verification of the exact reproduction from the issue:
    • Master (bug): `sandcat restart-proxy` → `curl https://github.com\` from agent fails with `Could not resolve host`.
    • With fix: same command returns `200` after `sandcat restart-proxy`.
    • Edge case with fix: stop the agent, run `sandcat restart-proxy`, agent stays stopped (Exited 137) — no accidental restart.

🤖 Generated with Claude Code

… to wg-client

sandcat restart-proxy restarted mitmproxy and wg-client but left the
agent container running. The agent uses
`network_mode: service:wg-client`, which Docker resolves to a specific
network-namespace file descriptor at agent-container start time.
Restarting wg-client tears down that namespace and creates a fresh
one, but the agent's existing fd still points at the torn-down
namespace — so DNS and all outbound connectivity break inside the
agent even though wg-client and mitmproxy are healthy.

Re-link by restarting the agent after wg-client comes back healthy, so
Docker resolves the netns reference against the fresh wg-client on
container start. Guarded by the agent's pre-restart running status,
so the netns re-link is a no-op when only the proxy stack is up (e.g.
detached IDE session, agent stopped manually).

Fixes #69.

Verified end-to-end: with the fix, `curl https://github.com` from
inside the agent still returns 200 after `sandcat restart-proxy`,
matching the pre-restart behaviour. Without the fix the same command
fails with "Could not resolve host: github.com" (reproduced against
the tip of master before the change).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@adamw

adamw commented Aug 25, 2026

Copy link
Copy Markdown
Member

Since we restart both the proxy and the agent, that's like a total restart? So maybe we should drop this option, or just rename it to restart? As the core component (the agent container) is restarted?

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.

sandcat restart-proxy orphans the running agent, breaking all networking

2 participants