Skip to content

Hold new sends while bb restarts into an update (updateWhenIdle) - #7003

Merged
ymichael merged 1 commit into
mainfrom
update-when-idle-hold-sends
Nov 4, 2026
Merged

ymichael merged 1 commit into
mainfrom
update-when-idle-hold-sends

Conversation

@ymichael

@ymichael ymichael commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

With updateWhenIdle on, bb restarts once no thread is running, but nothing stopped a new send from starting a turn in the gap between that decision and the process exiting. The launcher's restart decision (app-update.ts) counts running threads once and answers restart. The launcher then waits 1.5 s and shuts bb down, and the desktop path waits 1.5 s and installs. A message sent in that window starts a turn, and the restart cuts it straight away. The same applies to Update now. This is one of the follow-ups to #6203 and #6955 in #6127.

What changed

Behind updateWhenIdle (on for early adopters):

  • Send hold. apps/server/src/services/system/app-update-send-hold.ts arms a hold flag in app_settings (appUpdateSendHold). The launcher service arms it in decideRestart before it counts running threads. The desktop service arms it once the download finishes, also before counting. The flag is in the database, so a crash or restart can't leave it set in a later process.

  • Dispatch checkpoint. dispatch-attempt.ts queues every dispatch attempt as a new app-update wait while the flag is set. That covers sends, Send now, retries, new threads' first messages and child notices. The turn doesn't start.

  • Release. The flag clears in these cases:

    • The launcher decides defer or cancel.
    • The launcher rejects the restart request, or returns to idle afterwards.
    • The desktop defers, refuses, or fails to download or install.
    • The server boots, which covers every real restart, including an update that fails after the server stopped, where the old version comes back.

    Clearing the flag sends a new app-update-released queue wake. Like host-connected, it re-attempts each held row in order, and the normal checkpoint routes it.

  • Ordering. At boot the release runs before the startup sweep and before daemons reconnect. A held row on a thread the restart cut waits as thread-busy or host-offline. On reconnect, Resume threads a restart cut off (resumeThreadsAfterRestart experiment) #6955 queues the resume at the front, and the held rows go out after the resumed turn, in order.

  • Wording.

    • Queue row: "Sending after bb restarts to update" with the Download icon.
    • Send now is disabled on held rows; the server refuses it with "bb is restarting to update".
    • bb thread queue list: "sending after bb restarts to update".
  • Domain: app-update added to queuedMessageWaitingOnSchema.

  • Docs: docs/configuration.md (updateWhenIdle) and bb guide machines.

  • No daemon wire change, so HOST_DAEMON_PROTOCOL_VERSION stays the same. No plugin SDK surface file changed.

What users see differently: with the experiment on, a message sent in the second or two between "Restarting" and bb going down no longer starts a turn that gets cut. It shows in the queue as "Sending after bb restarts to update", and goes out once bb is back, after the thread's resume. If the update doesn't happen, it goes out at once.

How you verified

Tests (apps/server):

  • test/threads/restart-resume.test.ts → "holding sends while bb restarts to update" (real server harness):

    • A held send stays queued with no turn; release sends it.
    • Experiment off: the send isn't held.
    • A hold followed by a server boot and daemon restart: an idle thread's held message sends on reconnect. A cut thread runs resume, "First follow-up", "Second follow-up", in that order.

    The first and third fail with the checkpoint disabled (checked).

  • test/system/app-update.test.ts: the launcher service holds before it counts threads. It keeps the hold through restart, and releases it when the launcher returns to idle, on cancel, on defer, and when the restart request is rejected.

  • test/system/desktop-app-update.test.ts: hold on install; hold then release on a refuse failure or a defer.

  • pnpm exec turbo run lint typecheck for server, app, cli, db, domain, templates and integration-tests passes. Targeted tests for app-update, desktop-app-update, restart-resume, public-system-app-update and the app's queued-message-wait pass.

Live: a real source-mode install (pnpm start from a clone of a local bare origin), with marker commits pushed to the origin and real Codex agent threads. A script polled /system/app-update and posted /threads/:id/send as soon as the activity read restarting.

  1. Update when idle, nothing running: the send returned {"delivery":"queued","waitingOn":{"kind":"app-update"}} and the log showed "Holding new sends until bb restarts to update". bb came back on marker 1 about 10 s later, and the thread answered the held message.
  2. Update now (--yes) with a thread running a 100 s shell loop and resumeThreadsAfterRestart on: sends to the running thread and an idle thread were both held. After the restart:
    • The running thread read "Thread interrupted because bb restarted / bb will resume the thread shortly". It resumed and answered A-FINISHED.
    • Only then did it run the held message. Its queue showed it as "waiting for the current turn to finish" during the resume.
    • The idle thread's held message was requested at 20:34:08, as soon as bb was back.
  3. Failed update: I dirtied the checkout right after the restart decision, so the fast-forward failed ("Update to source checkout a51ccad183 failed: The working tree has uncommitted changes"). bb came back on the old commit and sent the held message.

Refs #6127

🤖 Generated with Claude Code

AGENT GENERATED

@ymichael
ymichael force-pushed the update-when-idle-hold-sends branch from 1620753 to b42b181 Compare November 4, 2026 18:54
With the updateWhenIdle experiment on, the server arms a send hold when it
decides to restart into an update: at the launcher's ready decision, or once
the desktop download finishes. Until bb stops, every dispatch attempt,
including Send now and retries, queues its message as an `app-update` wait
instead of starting a turn the restart would cut. The flag lives in
app_settings, so the next boot clears it and re-attempts the held rows before
the daemons reconnect; a reconnect that cuts a running thread queues its
resume first and the held rows follow it in order. A deferred, cancelled or
failed update releases them at once.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ymichael
ymichael force-pushed the update-when-idle-hold-sends branch from b42b181 to 63316ff Compare November 4, 2026 19:01
@ymichael
ymichael merged commit 36bcfa5 into main Nov 4, 2026
51 checks passed
@ymichael
ymichael deleted the update-when-idle-hold-sends branch November 4, 2026 19:10
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