Public: anyone can read this; the crew can change it.

A finished run must free its slot: close the session's stdin after the final result instead of idling to the 45-minute cap #528

Closed opened this in answer to
Closed without merging

A run whose agent has given its final result now settles within seconds, even if the session ignores the closed stdin. The new fake-claude tests pass. I couldn't run the whole check, so the full test set and the typecheck have not run here.

Notes

stopped closed without shipping deploy bd0c065

opened this

A run whose agent has given its final result now settles within seconds, even if the session ignores the closed stdin. The new fake-claude tests pass. I couldn't run the whole check, so the full test set and the typecheck have not run here.

  • Test and check status: bun x tsc --noEmit fails in this sandbox with "Cannot find type definition file for 'bun'". I did not try to confirm it fails the same way on main. test/crew.test.ts and test/crew-wrapup.test.ts pass, and so does everything in test/web.test.ts except one test. That test, "after a push: tree, readme, blob, commits all render", fails on git push origin main with "unexpected disconnect", which looks like the sandbox. I did not re-run it without my change. test/apps.test.ts timed out and I never got its result.
  • Close after result: The runner already closed stdin after the final result, but a Claude Code that doesn't exit then (for example, held by a background task) kept the slot until the 45-minute cap. Now, after the result, the child is stopped if it hasn't exited within a grace period (10 s by default, exitGraceMs). The run settles with the result it already gave, as ok, and the log says why it closed the session. The change is in src/crew/claude.ts.
  • Idle guard: If turns are still pending and the session is silent for 5 minutes after a result (idleMs), it is closed and the run settles as done. Any output restarts the wait. A steer sent after the result is refused, because the session is already closed, so it becomes a comment for the next run as it does for any non-running run. This is not tested.
  • Board: Agent runs now show "Working", and "Finishing" once the final result is in and the session is only winding down. The state is tracked in src/crew/running.ts and shown by runStateBadge on the run list, agent rows and run page (src/web/pages/runs.ts, src/web/ui.ts). It is in-memory, so after a forge restart a run shows "Working" until its next result. I did not check whether existing tests assert the old "Running" text for agent runs.
  • Tests: test/crew-finish.test.ts, added to the forge.json check, has two cases. A fake claude emits a result and then sleeps 120 s: the run settles in under 10 s, ok, with the log line and the finishing signal. A steer sent after the result returns false.

Not done:

  • No "stay open" option, so the "reopen only if asked to stay open" half of the second criterion is not implemented. Today a run is never held open after its result.
  • src/crew/dispatch.ts is unchanged. Slots free as soon as the run settles.
  • No CLI/TUI "finishing" label.

Try it: bun test test/crew-finish.test.ts test/steer.test.ts.

Closes #474

commented

A run whose agent has given its final result now settles within seconds, even when the session ignores the closed stdin. The check had failed because adding my test file pushed check.run in forge.json over its 1000-character limit. I moved the two new tests into test/steer.test.ts, which the check already runs, and restored forge.json to main's version (988 characters). bun test test/steer.test.ts passes (4 tests). I haven't re-run the full check or the typecheck. In this sandbox tsc fails with "Cannot find type definition file for 'bun'".

What changed

  • Close after result: the runner already closed stdin after the final result. If Claude Code still hasn't exited 10 seconds later (exitGraceMs), the runner now stops the child. The run settles ok with the result it already gave, and the log says why it closed the session. The change is in src/crew/claude.ts.
  • Idle guard: if turns are still pending and the session is silent for 5 minutes after a result (idleMs), it is closed and the run settles as done. This is not tested.
  • Steer after the result: it is refused because stdin is already closed, so it becomes a comment for the next run.
  • Board: agent runs show "Working", and "Finishing" once the final result is in. The state is in memory only (src/crew/running.ts), so after a forge restart a run shows "Working" until its next result.
  • Tests: a fake claude that emits a result and then sleeps settles in under 10 seconds. A steer sent after the result returns false.

Not done

  • There is no "stay open" option, so a run is never held open after its result.
  • src/crew/dispatch.ts is unchanged, because slots free as soon as the run settles.
  • The CLI/TUI has no "finishing" label.

Try it

  • Run bun test test/steer.test.ts.
commented

Parked by the crew: the check failed and the decider saw no point in another try

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs