Skip to content

simulate: cancel a run whose agent stops joining after it worked - #1046

Open
u9g wants to merge 1 commit into
mainfrom
jason/simulate-stop-when-agent-dies
Open

u9g wants to merge 1 commit into
mainfrom
jason/simulate-stop-when-agent-dies

Conversation

@u9g

@u9g u9g commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

When the agent under test dies or wedges partway through lk agent simulate, the run keeps going. Every remaining job waits 30s for an agent, retries in a fresh room, waits again, and fails with No agent joined room … Is the agent running?. The user burns quota and waits minutes for a run that cannot succeed, then reads a report blaming each scenario.

The cause is the broken-agent check. agentBroken returned false as soon as any job had completed, on the premise that "a completed scenario proves the agent works". It only proves the agent worked until that scenario ended. The check now counts only the No agent joined room failures that ended after the last completed job, so a mid-run death or wedge is handled like a startup crash: the run is cancelled and the agent's log is surfaced. Timeouts before the first success (cold start) or between successes are still tolerated. Because the check reads job outcomes rather than the local process, it covers a wedged-but-alive agent and live --agent-name runs too.

Production, last 7 days: this "worked, then every later job failed" pattern was 175 CLI-spawned runs with 1,202 failed jobs, about 47% of all No agent joined room failures. Another 31 live --agent-name runs (145 jobs) had the same pattern; 127 of the 175 CLI runs were never cancelled.

Repro: starter Python agent, CI mode, lk agent simulate text --scenarios scenarios.yaml --samples 3 --concurrency 1 --yes, then SIGKILL the spawned agent once the first job finishes.

  • main: the CLI kept going for 578s and 8 of 9 jobs failed with No agent joined room.
  • this branch: after the 4th join failure the CLI printed The agent is failing to run jobs; cancelling the run., cancelled the 4 jobs not yet run, and exited 1 at 329s.

Tests: TestAgentBroken table tests; the "agent died after working" case fails on main. go test ./cmd/lk/ passes.

A follow-up stacked on this branch adds a faster trip when the local agent process has exited.

agentBroken returned false as soon as any job had completed, on the theory that
a completed scenario proves the agent works. It proves the agent worked until
then: when the CLI-spawned agent dies or wedges mid-run, every remaining job
waits 30s for an agent, retries, and fails with "No agent joined room", and
the run keeps going. That was 1,202 failed jobs across 175 runs in a week.

Count only the join failures that ended after the last completed job, so a
mid-run death cancels the run and surfaces the agent's log like a startup
crash does, while timeouts before or between successes stay tolerated.
@u9g

u9g commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor Author

With this PR, killing the spawned agent after its first job cancels the run after 4 join failures ("The agent is failing to run jobs; cancelling the run."), and the unrun jobs stay pending instead of each failing with "No agent joined room".

agent-dies.mp4

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