Skip to content

Daemon: tell a resting bot when a background command no wait collected ends - #625

Merged
lydakis merged 7 commits into
mainfrom
claude/project-thread-acrsif
Nov 1, 2026
Merged

lydakis merged 7 commits into
mainfrom
claude/project-thread-acrsif

Conversation

@lydakis

@lydakis lydakis commented Nov 1, 2026 •

Copy link
Copy Markdown
Owner

Why

This is the third idea from DeepSeek Harness's super-agent design, which George approved on 11-01. Today, when a bot runs shell with background=true and then rests, the command's end goes nowhere. The result waits in the store until something calls wait on the handle. A lead that started a 20-minute build and ended its turn never finds out the build failed. Claude Code tells its model when a background shell ends. Codex leaves it to the model to poll. With #621 letting background commands run for up to a day, the gap gets wider.

What changes (the concrete edits)

Store, schema 76 → 77; protocol 45 → 46 (src/store/db.rs, client/src/lib.rs). This takes schema 77, which project memory had reserved, and protocol 46 for the new bot setting.

  • processes gains told INTEGER. It holds the turn that told the bot, or 0 when there is nothing to tell. The migration sets told = 0 on every command that had already ended, so an upgrade tells nobody about old work.
  • processes gains bot TEXT, which process_start writes from the command's turn. The migration fills it for commands still running, the only ones whose end can still be told.
  • New partial index processes_untold ON processes(bot,id) WHERE told IS NULL AND delivered IS NULL AND status<>'running'.
  • New Database::tell_finished(bot):
    • It does nothing if the bot is missing or has a turn running. The tool text says "no turn of yours runs".
    • A bot with quiet_background has its ended commands marked told = 0 and is never told.
    • Otherwise it collects the bot's ended commands that nothing waits on and that are not yet told.
    • It reads only the partial index (UNTOLD: processes INDEXED BY processes_untold WHERE bot=?1 … ORDER BY id LIMIT ?2). It never walks a bot's history or other bots' commands. It reads only the fields that say how each command ended, never the output, and at most as many as the note has room for. A unit test checks the plan (no turns, no sort) and counts VM steps, which are the same with 10 or 10,000 untold commands.
    • It submits one turn: delivery: steer, origin: "background", request id background-<first id>. The words are JSON only, for example {"finished":{"proc:7":{"exit_code":0,"success":true,"wall_time_ms":5012}}}. The fields are those of ended_as: exit_code, success, timed_out, signal, wall_time_ms, and error/detail. No output is included; wait on the handle reads it.
    • One note holds at most an eighth of the bot's context_bytes, and always at least one entry. A long detail is cut at 96 bytes. Commands that don't fit stay untold, and the note's own finish() tells the next batch.
    • It marks each command in the note with told = <turn>.
    • The note and its told marks commit together under a savepoint, at startup too.
    • The note is not held to the pending-submission bounds: the commands that ended bound it, and --max-processes caps those.
  • tell_finished runs after finish() commits, for a command that ended while a turn was running. It runs after process_finish, for a command that ends while no turn of the bot's is running. It also runs at open, for commands that a restart or the pull cord ended.
  • New Database::saw_end(id) sets told = 0 on a terminal whose end the bot already saw in a write_stdin or start result.
  • Retention skips a turn that still has a note to run about its commands (its told turn queued, ready or running), and a turn whose ended commands no note has told yet. That way the wait the note invites finds the results.
  • New bot setting quiet_background (CLI --quiet-background), off by default. A client that collects results itself sets it. src/AGENTS.md requires a daemon default to be changeable per bot.
  • pub const BACKGROUND_ORIGIN = "background", exported from src/store.rs.

Server

  • src/server/turn.rs:
    • collect() calls tell_finished inside the existing process_finish store op. When the told turn is ready, it calls handles.turn_ready().
    • A new seen() helper finds the terminal whose output carries exit_code. saw_end runs inside the same tool_finish op that records the result, so the two commit together. This covers the start, a poll, write_stdin, and the parked poll's resume. A terminal whose start failed is marked seen too.
  • src/server/handles.rs: a ready: Notify with turn_ready() and readied().
  • src/server/mod.rs: one more select! arm, () = service.handles.readied() => service.ready_hint = true, so the run loop dispatches the told turn.

Tool text (src/tools.rs, shell description). After "collect its result later with wait." it adds:

If no wait collects it, its end comes as a message once no turn of yours runs: {"finished":{"proc:N":{how it ended}}}; wait on the handle reads the output.

It is about 150 bytes, kept short because every request of every bot with shell carries it.

Sonny

  • sonny/src/transcript.rs shows the turn as "From a background command".
  • sonny/src/lookout/mod.rs author() treats origin background like a trigger's fire, so only how the turn ends is news to a lead.
  • sonny/FEATURES.md: a new "Background command ends" row.

Docs: docs/RUST_PROTOTYPE.md (Deferred tool results, and the settings table), docs/CLI.md, docs/NEXT.md item 39 ("done in part"), and docs/DAEMON_MEASUREMENTS.md. Getting the result in the call's place mid-turn stays an open item.

Why it is built this way

  • When to tell: when no turn is running, never mid-turn. A running turn hears about the end when the turn finishes, and a bot with no turn running hears at once. A mid-turn steer would lift the running foreground shell into the background. It would also wake a parked wait that is about to collect the result anyway. Claude Code accepts that interruption, but we don't need it, because a turn that wants the result sooner already has wait.
  • No output in the note. Large output is stored once and read through the handle, so the note costs a few dozen tokens however much the command printed.
  • JSON, not prose. The daemon writes no harness text for bots. The note is data in the shape the tool description promises, and clients decide how to show it.
  • Told once, durably. told is set in the same transaction that queues the turn. A command collected by wait, or a terminal whose end the bot saw, is never told.
  • Steer, not queue or attach. With no turn running and nothing ahead, a steer starts at once, just as a queued turn would. If the person's message got there first, the note joins that turn at its next boundary instead of waiting a whole turn behind it. An attach never starts a turn, so a resting bot would hear nothing.

Coordination with #621

#621 raises the background timeout_ms cap to a day and edits the same shell description in src/tools.rs. The two changes fit together: a day-long build's end now reaches its bot. This branch has merged main and carries #621's text with this sentence added.

Daemon fast and light

  • No new task, thread or timer.
  • tell_finished runs inside store jobs that already exist (finish, process_finish). It is one indexed read of a partial index that is empty in the common case, and it stops at its batch.
  • saw_end adds no store op. It is one more UPDATE inside the existing tool_finish op, and only when a terminal's end is seen.
  • The Perf workflow's matched screen of 5c9e615 is in docs/DAEMON_MEASUREMENTS.md. Nothing moved past noise, and the gate counted no more store work per turn.
  • The run loop gains one Notify arm. Nothing new is kept per bot in memory.

Tests

  • cargo test --workspace and cargo clippy --workspace --all-targets -D warnings are clean.
  • New store tests in tests/store_contract.rs:
    • a_background_command_no_wait_collected_is_told_once_its_bot_rests covers a command told once at the turn's end, one told at once while the bot rests (a failure is told the same way), and waited or seen commands never told.
    • a_bot_whose_client_collects_results_itself_is_never_told, submissions_filling_the_pending_bounds_hold_back_no_note, retention_keeps_what_a_note_still_to_run_tells_of, notes_of_many_ended_commands_each_fit_the_bots_context, retention_keeps_ended_commands_a_later_note_is_still_to_tell.
    • schema_76_tells_no_bot_of_commands_that_ended_before covers the upgrade: a command that ended before is never told, and one the restart lost is told as process_lost.
  • tests/store_payloads.rs: the reopen test now runs the told turn before pruning.
  • Runtime (AGENT_TEST_RUNTIME=1):
    • New test_a_background_command_no_wait_collected_is_told_once_the_bot_rests. It checks the steer from background, the JSON with exit code 3 and no stdout, that wait still reads done\n, and that there is exactly one extra turn.
    • The retention test now finishes the told turn before deleting.
    • tests/test_wait.py: the restart test lets Dave hear about the fresh command's end before his next submit.
    • tests/test_compaction.py: the paced-copy test pinned how many copies came after the retry, a number that depends on the tools' own bytes. It now pins only the paced copy and its retry.
    • The whole Python suite ran in the cloud container. The only failures came from the container itself: psutil is missing for two bench imports, and bwrap is missing for one trigger start test, two test_served tests and three test_acp tests.

🤖 Generated with Claude Code

…d ends

A bot that started a command with background=true and ended its turn
never heard how it ended unless it called wait. Now the daemon tells it,
once the bot rests: at the end of the turn that was running when the
command ended, or at once when it ends while the bot rests. It submits
one steer from origin `background` whose words are JSON naming each
handle and how it ended, without the output, which wait still reads:
{"finished":{"proc:7":{"exit_code":0,"success":true,"wall_time_ms":5012}}}

Schema 77: processes.told holds the turn that told it (0 for one the
bot saw end, and for everything that ended before the upgrade). A
command a wait delivered is never told, nor a terminal whose end a
write_stdin returned. Commands a restart or the pull cord ended are
told once the daemon is back. Nothing is said mid-turn, so no running
command is lifted and no parked wait is woken. No protocol bump.

Sonny shows the turn as from a background command, and the lookout
treats it as a trigger's fire: only how it ends is news to a lead.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGHSmyxToLa26Je2pfo
@lydakis lydakis self-assigned this Nov 1, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-01T21:05:08.895209Z aba3ae5 New commits
🔒 Security Review ✅ Completed 2026-11-01T18:57:19.915298Z 1b3322f PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1b3322f1c8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/store/db.rs Resolved
Comment thread src/store/db.rs Resolved
Comment thread src/store/db.rs Resolved
Comment thread src/server/turn.rs Resolved
Comment thread sonny/src/lookout/mod.rs Resolved
Comment thread src/store/db.rs Resolved
Comment thread src/server/turn.rs Resolved
- `quiet_background` (setting and `--quiet-background`, protocol 46):
  a bot whose client collects results itself is never told. A daemon
  default must be one a caller can change per bot.
- The note is not held to the pending-submission bounds: the commands
  that ended bound it, and a refusal left an idle bot untold.
- Finding what to tell reads the partial index from the processes side
  (INDEXED BY processes_untold, CROSS JOIN turns), never a bot's
  history; a unit test checks the plan.
- A terminal whose start failed is its end, and the call said so: it
  is never told later.
- Retention keeps the turns whose commands a note still to run tells
  of, so the wait the note invites finds their results.
- Wording: "at rest" becomes "no turn of yours is running", in the
  shell description and the docs.
- sonny/FEATURES.md row for the note in Sonny.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGHSmyxToLa26Je2pfo
The shell description keeps #621's day-long background cap and adds the
note's sentence after "collect its result later with wait.".

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGHSmyxToLa26Je2pfo

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3a55781a1d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/store/db.rs Resolved
Comment thread src/server/turn.rs Resolved
…t's context

The terminal's end is now marked seen in the same store op that records
its tool result, so a crash between the two can't tell the bot twice.
A note of many ended commands splits into turns of at most an eighth of
the bot's context, and a long detail is cut at 96 bytes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGHSmyxToLa26Je2pfo

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2de01982d8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/store/db.rs Resolved
Comment thread src/store/db.rs Resolved
The sentence telling a bot its background command's end comes as a
message is cut from about 230 bytes to about 150: every request of every
bot with shell carries it. A paced-compaction test pinned how many copies
followed the retry, which depends on the tools' own bytes; it now pins
the paced copy and its retry only. The restart test in test_wait now
lets Dave hear of the fresh command's end before its next submit.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGHSmyxToLa26Je2pfo

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5c9e6153ce

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/store/db.rs Resolved
The note's query now reads only the fields that say how each command
ended, never its output, and at most as many as could fit its room.
The note and the marks of the commands it tells commit together under
a savepoint, also at startup where no store job's transaction holds
them. Retention keeps a turn whose ended commands no note has told yet,
so a batch left for the next note still finds its results. Records the
matched Perf screen.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGHSmyxToLa26Je2pfo

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 89705bfdaf

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/store/db.rs Resolved
…s at its batch

processes gains bot, written from the command's turn, and
processes_untold indexes (bot, id). A note's query reads the bot's
untold commands in order from the index and stops at its LIMIT: no join
to turns, no sort, and no other bot's commands passed over. A test
counts the query's VM steps with 10 and 10,000 untold commands per bot.
Retention's check for untold commands goes through processes_turn.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGHSmyxToLa26Je2pfo
@lydakis
lydakis merged commit d917332 into main Nov 1, 2026
10 checks passed
@lydakis
lydakis deleted the claude/project-thread-acrsif branch November 1, 2026 21:28
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.

2 participants