Skip to content

fix: background shells end in the chat, with their exit code (BRA-3094) - #216

Draft
Stener1 wants to merge 3 commits into
cosscom:mainfrom
Stener1:bra-3094-background-shells-done
Draft

Stener1 wants to merge 3 commits into
cosscom:mainfrom
Stener1:bra-3094-background-shells-done

Conversation

@Stener1

@Stener1 Stener1 commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A shell Claude leaves running in the background stayed Running in the chat's "Left running in the background" panel after it exited: its timer kept growing and the chip kept saying "2 shells running". For a chat (structured) agent, its shells never ended at all.

Two causes, both in internal/transcript:

 unwrapHost(system/task_notification)          # a chat agent's stream says a shell ended here
   -> queue-operation note
 claudeParser.line(queue-operation)
-  helperDone(note)                            # the crew heard it; the shells never did
+  taskNotified(note)                          # one handler: helpers and shells
+    helperDone(note)
+    jobNote(note)                             # now with the summary's exit code
 claudeSignals(user line)
-  if !bytes.Contains(line, "<task-notification>") return
+  if !bytes.Contains(line, "task-notification") return   # berthd's log writes "<" as <

And a fallback that doesn't wait for any notification (a busy agent is told only when its turn ends):

Reader.Follow (each poll)
  settle()
    for each running shell with an output file in a tasks folder
      if its last non-empty line is "[exited with code N]"
        state = N == 0 ? done : failed, exit = N, until = the file's time
  (the end stays the file's to take back: more output after the line runs it again;
   a notification, when one comes, has the last word, e.g. Stopped)

The panel shows the code and freezes the duration:

 <BackgroundChip>                 "1 shell running" — counts only what runs; "2 finished" for 5 min after
   <JobRow>
-    <State>  Done | Failed | Stopped
+    <State>  Done · exit 0 (grey) | Failed · exit 3 (red) | Stopped
-    took = (until ?? now) - since
+    took = jobTook(job, now)     # frozen once it ended

Job gains exit (omitted until known); an older app ignores it.

Evidence

Live, on a dev box of this checkout with a structured Claude Code (verify-berthd → chat-background-shells-live): Claude starts sleep 20; echo hi and sleep 6; exit 3 in the background.

  • Before (main's berthd, same scenario): 22 s in, both have exited, both still Running, chip "2 shells running". The scenario fails at Failed · exit 3.
    before
  • After (this branch): Failed · exit 3 while the other runs; then Done · exit 0 21 s after the start (the shell sleeps 20 s); output hi readable; durations stay at 20s and 6s over 20 s; the box's own transcript signals say done exit 0 and failed exit 3; the chip says "2 finished".
    failed while the other runs
    done with output
  • Mock (chat-background-shells): gpu/judge-v2's panel shows Running, Done · exit 0, Failed · exit 3, and the ended durations don't move across a clock tick.
    mock panel

Tests (each fails without its half of the fix):

TestABackgroundShellEndsWhenTheStreamSaysSo        host log, task_notification only -> done exit 0 / failed exit 3
TestAShellsNotificationInTheLogsOwnEscapingEndsIt   host log, prompt notification written by Go's JSON -> done
TestAShellEndsWhenItsOutputSaysItExited             [exited with code 0|3] last -> done|failed, file time;
                                                    mid-file -> running; no file -> running; monitor -> running;
                                                    a later "killed" notification -> stopped; same Reader, file grows -> done
TestAShellsExitCodeIsTheNotificationsOwn            `echo 'exit code 3'` completed (exit code 0) -> done exit 0
TestAShellsOutputFileOnlyEndsItWhileItSaysSo        printed the line and went on -> running again; a FIFO there is never opened
background-work.test.ts                             chip counts only running; badge text; frozen duration

Checks: go vet ./... and go test -race ./... pass on the final commit (an earlier run on a loaded box flaked in TestDetach, which fails on main too, and two timing tests that then passed 25/25 and 3/3 alone). App: typecheck:plugins, check:titles, check:type, check:grid, check:csp, check:themes, pnpm test (632 pass), pnpm build, tsc -p e2e; docs build. cargo check not run (no Rust change; this box lacks the GTK libraries).

Codex review and adversarial review: three findings (exit code read from the command text, a FIFO at the output path blocking the reader, a printed marker ending a running shell for good), each fixed with a test above; the re-review found nothing.

verify-berthd gets features/chat-background-shells.md, its map row, and both scenarios.

Merge Danger

Door: two-way

Read-only: it changes how the box reads a conversation and its tasks' output files, and how the app shows them. It writes nothing.

Blast Radius: chat's background panel

The box now reads at most 256 bytes of each still-running shell's output file per conversation read (a regular .output file in a tasks folder only, looked at before it is opened). A shell that prints [exited with code N] itself shows ended until it prints more or its notification comes; Claude Code writes that line on exit.

🤖 Generated with Claude Code

Stener1 and others added 3 commits November 2, 2026 15:25
A chat agent's background shells stayed "Running" in the chat's panel
after they exited, their timers growing and the chip counting them. Its
log says a shell ended only in the stream's task_notification line,
which berthd read for helpers and never for shells; and that log holds
Claude's lines with "<" escaped, so a notification Claude was told as a
prompt didn't match either.

Both shapes now end the shell, through one handler for helpers and
shells. A running shell also ends when its output file's last line says
"[exited with code N]", so it shows within a poll even before a
notification. The panel shows "Done · exit 0" or "Failed · exit N" and
a duration that stops growing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…le never holds up the reader

A command whose text reads "exit code 3" no longer reads as exiting 3;
a pipe where a shell's output file should be is never opened; and a
shell that printed "[exited with code N]" itself and went on runs again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Nov 2, 2026

Copy link
Copy Markdown

@Stener1 is attempting to deploy a commit to the seanbrydonio's projects Team on Vercel.

A member of the Team first needs to authorize it.

@Stener1

Stener1 commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

I can't add the run-ci label from this account (no permission on the repo). Could a maintainer add it? The checks from AGENTS.md pass locally; the PR body lists them.

This branch has not been deployed

No deployments
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