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 #486
A finished run now settles within seconds of its final result instead of holding its crew slot until the 45-minute cap. Cause. runClaude (src/crew/claude.ts) already closed the session's stdin after a result nobody followed up.
stopped closed without shipping deploy 5253536
1 earlier comment · 1 event
The settle logic in claude.ts is sound and well tested. Two misses. FIRST FIX: the live repaint never happens. The KINDS list in the live script (src/web/live.ts) does not include run.finishing, so browsers ignore the event announceFinishing emits and the board keeps saying working until another run event arrives, which is the confusion this pull removes. Add run.finishing to KINDS and add a test that fails without it. SECOND, both doors: the board says finishing but the terminal run list (src/tui/screens/runlist.ts) still shows only running. Show finishing there when finishingAt is set, check the studio run page the same way, and test it.
A finished run now settles within seconds of its final result instead of holding its crew slot until the 45-minute cap.
Cause. runClaude (src/crew/claude.ts) already closed the session's stdin after a result nobody followed up. After that it waited with no limit for the process to exit and for stdout/stderr to end. Two things could hold it until the cap:
- Something left running: a server or other process the agent started in the background kept the process from exiting, or kept its output pipe open.
- A folded steer: a steer that Claude Code merged into the turn already being answered left the runner waiting for one more result that never came.
What changed:
- Settle (
claude.ts): once the final result is in and no steer is pending, the forge closes stdin and gives the process 5 s (settleMs) to exit. After that it stops the whole process group, stops reading its output, and the run settles on the result it already gave, as done. The log sayssession: still open 5s after its result; stopping it. - Idle guard: after any result, if the session writes nothing for 5 minutes (
idleMs), it is closed and settled as done. The log line sayssession: no output for 300s after its last result. This catches the folded steer. - Steers after the result: the session is closed, so the steer function returns false and the words go on the issue or pull for the next run. That is the existing rule for a run nobody is listening to. There is no "stay open" option; the session stays open only while a person's words are still owed a turn.
- Finishing on the board: migration 40 adds
run.finishing_at.noteRunFinishingsets it when the final result arrives and clears it when a wrap-up turn starts. A transientrun.finishingevent repaints the board's live regions, and the board shows finishing instead of working. The event is left out of activity feeds likerun.started. - Docs: the steering section of
docs/APPS.mddescribes the new ending.
Merge with main: the only conflict was the check line in forge.json. It now runs both main's new test/web-apps.test.ts and this pull's test/session-settle.test.ts.
Tests: the new test/session-settle.test.ts uses fake claudes that:
- give a result, then hold stdout open through a background child: the run settles in under 10 s, as
completed; - exit on their own: the run is not stopped;
- get a steer after the result: the steer returns false;
- take a steer and go silent: the idle guard settles the run as done.
Without the fix, the first one waits for the deadline. test/board.test.ts has a new test for the finishing word. No tests were changed to make them pass.
Check results:
- Before the merge: the full check passed:
tscand 616 tests. - After the merge: 630 of 632 passed on a run slowed by leftover test processes from an earlier run of mine. The two that failed were in
checks.test.tsandfork-flow.test.ts, both timed waits. Rerun on their own with the check's--timeout 60000, both files pass (34/34). - Known environment failure:
test/migrate.test.tsfails in this sandbox because it needs a Forgejo. It fails the same way on unchangedmainand isn't in the check.
Not done: slot accounting in src/crew/dispatch.ts is unchanged. A finishing run still holds its slot, but only for the few seconds it takes to push and open or update the pull.
To try it: run bun test --timeout 60000 test/session-settle.test.ts test/steer.test.ts test/board.test.ts. On a preview, a run's log ends with a session: line when the forge had to close the session, and its board card says finishing from the final result until it lands.
🤖 Generated with Claude Code
A finished run now settles within seconds of its final result instead of holding its crew slot until the 45-minute cap.
Cause.
runClaude(src/crew/claude.ts) already closed the session's stdin after a result nobody followed up. After that it waited with no limit for the process to exit and for stdout/stderr to end. Two things could hold it until the cap:What changed:
claude.ts): once the final result is in and no steer is pending, the forge closes stdin and gives the process 5 s (settleMs) to exit. After that it stops the whole process group, stops reading its output, and the run settles on the result it already gave, as done. The log sayssession: still open 5s after its result; stopping it.idleMs), it is closed and settled as done. The log line sayssession: no output for 300s after its last result. This catches the folded steer.run.finishing_at.noteRunFinishingsets it when the final result arrives and clears it when a wrap-up turn starts. A transientrun.finishingevent repaints the board's live regions, and the board shows finishing instead of working. The event is left out of activity feeds likerun.started.docs/APPS.mddescribes the new ending.Tests: the new
test/session-settle.test.tsis added to theforge.jsoncheck. It uses fake claudes that:completed;Without the fix, the first one waits for the deadline.
test/board.test.tshas a new test for the finishing word. The fullforge.jsoncheck passes:tscand 616 tests across 41 files.test/migrate.test.tsfails in this sandbox because it needs Forgejo; it fails the same way on unchangedmainand isn't in the check. No tests were changed to make them pass.Not done: slot accounting in
src/crew/dispatch.tsis unchanged. A finishing run still holds its slot, but only for the few seconds it takes to push and open or update the pull.To try it: run
bun test test/session-settle.test.ts test/steer.test.ts test/board.test.ts. On a preview, a run's log ends with asession:line when the forge had to close the session, and its board card says finishing from the final result until it lands.🤖 Generated with Claude Code
Closes #474