Files
buzz/desktop
Matt Toohey 440899c11b feat: reap prewoken agents the draft never used
The composer's mention prewake starts a stopped local agent one second
into a qualifying draft. Nothing reclaimed it: if the draft was
abandoned, the eager harness and its worker subprocesses stayed up --
and showed as online to the whole community -- until app quit, a manual
Stop, or a config-change restart. Every existing harness self-reap timer
is disabled or inapplicable on the eager spawn path.

The prewake should be a pure latency optimization with no lifetime side
effects: (prewake + send) must end where (send alone) does, a durable
running agent, and (prewake + abandoned draft) must end where (abandoned
draft alone) does, a stopped one. Bound the second case in the harness,
because only the harness can see turns, heartbeats, and queued work
race-free -- any desktop-side "is it idle?" decision has an unavoidable
time-of-check/time-of-use race against an in-flight turn it cannot
observe, including turns serving a third party who messaged the
prewoken agent.

buzz-acp gains `--exit-if-unused` / `BUZZ_ACP_EXIT_IF_UNUSED`: exit
gracefully if no event has ever been dispatched within N seconds of
boot; the first dispatch disarms it permanently. Deliberately not the
existing rolling `--exit-after-inactivity` TTL, which would make a
prewoken-then-used agent exit 15 minutes after its last turn while a
send-started one lives forever -- the same user action producing
different lifetimes depending on typing speed. A one-shot boot bound
restores exact pre-prewake behavior instead: first real use promotes the
agent to a normal durable start, with no promotion RPC.

The disarm seam is `dispatch_pending`, which already stamps
`last_activity`; both facts now live in one `DispatchActivity` so a
future dispatch path cannot stamp the clock and forget the latch. The
tick arm reuses the busy gates `idle_pool_sleep_due` codifies -- no turn
or heartbeat in flight, no undispatched queued work, no wake/respawn
running -- since accepted-but-throttled work means the harness is about
to be used and exiting would strand it *before* the dispatch that would
have disarmed the bound. Graceful exit is code 0, which
`sync_managed_agent_processes` already records as a clean stop, so no
desktop-side exit handling is needed.

Desktop states the policy at spawn. `lazy: bool` becomes a three-variant
`SpawnPolicy` (Durable / Lazy / Speculative) that owns all three
lifetime env values: the combinations were never independent -- a lazy
speculative pair would defeat the prewake it exists for -- and a second
adjacent bool at `spawn_agent_child(.., false, false, ..)` would have
been unreadable. `BUZZ_ACP_EXIT_IF_UNUSED` is written on every spawn,
inert for deliberate starts, and joins RESERVED_ENV_KEYS so user env
cannot strip the bound. `start_managed_agent` takes `speculative`;
only the local arm consumes it, since a draft mention must never deploy
remote compute. 900s matches IDLE_POOL_SLEEP_SECS -- expiry costs only a
cold start, because the preflight re-arms on a resumed draft and the
send path has always started a non-running mentioned agent.

`managedAgentStartFlightKey` still excludes the flag, now documented: a
send arriving while a prewake is in flight should share it, since the
send's own dispatch is what promotes the harness.

Two files were at the size ceiling and are split along their existing
patterns rather than grown: `start_managed_agent_process` moves to
`runtime/start.rs` beside its sibling submodules, and the two
start-with-preflight entry points to `commands/agents_start.rs` beside
`agents_pending.rs` / `agents_deploy.rs` / `agents_profile.rs`.

Tests: the bound fires when never dispatched, is disabled at 0, holds
before the bound, is disarmed permanently by one dispatch (checked far
past the bound), and is deferred by each busy gate; each SpawnPolicy
maps to its three env values; the new reserved key is stripped from user
env; the prewake's start input carries `speculative: true`; a durable
start shares its flight key. buzz-acp 830 unit tests, Tauri 2776, 5688
desktop JS, and 74 mentions E2E specs pass.

Signed-off-by: Matt Toohey <contact@matttoohey.com>
2026-08-28 16:08:16 +10:00
..
…

Buzz

Desktop chat shell with:

  • Tauri + React + TypeScript + Vite
  • Tailwind CSS
  • shadcn/ui-ready shared components
  • Biome (lint/format/check)
  • Feature-driven frontend structure

Scripts

  • pnpm dev - run the web frontend
  • pnpm tauri dev - run the desktop app
  • pnpm build - typecheck and build frontend
  • pnpm typecheck - TypeScript checks
  • pnpm lint - Biome lint
  • pnpm format - Biome format (write)
  • pnpm check - Biome check

Structure

  • src/shared - reusable app-wide code (ui, lib, styles)
  • src/features - feature modules (vertical slices)
  • src/app - top-level app composition