Skip to content

fix: keep a live agent's address files when the hello fails - #72

Merged
antonrh merged 1 commit into
mainfrom
agent-address-race
Nov 20, 2026
Merged

antonrh merged 1 commit into
mainfrom
agent-address-race

Conversation

@antonrh

@antonrh antonrh commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

The bug

Agent.ensure(true) ran when the hello to the address in <store>/agent.addr failed: no answer, a timeout while the agent was still starting, or "the agent refused". It deleted agent.addr and console.addr and spawned a new agent. When those files belonged to a live agent (just started by another process, or busy), the new agent exited with "an agent already runs" (the store lock), and the live agent kept the lock with no address files: no app could reach it until it idle-exited (30 min). Seen as an agent.log with repeated "an agent already runs" lines and only otlp.addr left in the store.

The fix

  • ensure deletes nothing. The agent itself removes stale address files at startup, under the store's lock; the Python SDK already leaves them alone.
  • ensure(true) first asks whether the address answers (Agent.answers, a bare connect to unix:/tcp:). If it does, the agent is there and no second one starts.
  • start() waits up to START_WAIT_MS until the address answers, not until the file is non-empty. A unix socket's address is the same path on every restart, so a changed file can't be the signal. If another process's agent wins the race, its address answers and the start counts as done.
  • The address parsing moved from Sender.handshake to Agent.connect, which both use.
  • RESTART_MS/failedAt work as before.

Tests

AgentTest:

  • a fake agent that listens but doesn't answer the hello yet: the sender's failed hello leaves agent.addr and console.addr in place, and no second agent starts. This test fails on main.
  • a stale unix: address that nothing listens at: a fake TRACEPANEL_AGENT_BIN writes a new address a moment later, and ensure(true) returns true with that address.
  • answers is a bare connect.

./gradlew check is green.

Agent.ensure(true) deleted agent.addr and console.addr before starting a new
agent. When they belonged to an agent another process had just started, or a
busy one, the new agent exited ("an agent already runs") and the live one
was left without addresses until it idle-exited. Now nothing is deleted (the
agent removes stale ones under the store's lock), ensure first asks whether
the address answers (a bare connect), and a start waits until it does.
@antonrh
antonrh merged commit 9fe75f5 into main Nov 20, 2026
6 checks passed
@antonrh
antonrh deleted the agent-address-race branch November 20, 2026 09:15
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.

1 participant