Skip to content

fix(agent-bus): deliver subagent messages while they're current - #338

Merged
nixuuu merged 1 commit into
devfrom
fix/agent-bus-stale-messages
Nov 7, 2026
Merged

nixuuu merged 1 commit into
devfrom
fix/agent-bus-stale-messages

Conversation

@nixuuu

@nixuuu nixuuu commented Nov 7, 2026 •

Copy link
Copy Markdown
Member

Child send_message calls defaulted to a separate parent turn. While the parent was waiting or testing, those turns accumulated behind its work and repeated information it had already read from the child or its completion report.

  • Default child-to-ancestor messages now steer a running turn. Explicit queue delivery and the existing steer fallback remain available; an active wait_threads receives messages in its result and returns early.
  • Reads consume only messages whose text they return. Snapshot, consumption and tool result commit together under the recipient lock; unstarted turns and unentered steers are withdrawn durably, while admitted history stays intact. Cancellation releases an active wait, and restart/replay preserves its deadline and consumed result.
  • An explicit message matching the final text from the same child turn is deduplicated against its completion report. Active waits also claim completion reports before a steer is created. Queued notes include the UTC send time and whether the recipient was busy.
  • Tool descriptions and subagent instructions explain automatic final reporting, mid-task updates and ask_user. Polish bus, architecture and data-model docs describe the semantics and additive migration 0095. No proto or UI changes.

Validation: bun install, bun run gen:check, bun run typecheck, bun run lint, bun run format:check and the web build pass locally. All 16 new scripted-worker regressions pass, covering wait delivery, default ancestor steer, idle/explicit queue timing, fallback, final-report deduplication, covered reads, cancellation and restart/replay. Existing bus, notification and provider/tree tests also pass. Opt-in live coverage was extended but not run.

Full CI is green: static checks, all four test shards with temp-directory checks, web/Linux builds and the aggregate check. The local full check:tmp --timeout 30000 run had 1742 passes, 161 skips and one unrelated linked-composer failure (Studio B disconnected); that file passed its isolated rerun, with a clean temp-directory check. The local full run also confirmed no leftover test temp directories.

Copy audit (docs/copy.md §8): model-facing text is English, short and factual. Delivery notes identify the sender and give an explicit UTC time; busy context describes why a message waited. Tool guidance states what happens next and when to use send_message or ask_user. No promotional language, personality copy or visual-only cues. UI layout, responsive-name checks and browser review are not applicable because no UI text or components changed.

This corrects long-standing default delivery behavior; no recent introducing PR was identified.

@nixuuu
nixuuu marked this pull request as ready for review November 7, 2026 13:23
@nixuuu
nixuuu merged commit 6e2f243 into dev Nov 7, 2026
11 checks passed
@nixuuu
nixuuu deleted the fix/agent-bus-stale-messages branch November 7, 2026 13:24
nixuuu added a commit that referenced this pull request Nov 8, 2026
nixuuu added a commit that referenced this pull request Nov 8, 2026
Report inputs could appear after newer answers, leave empty cancelled
work, and repeat for the same child result. Desktop and phone could
retain different projections after consumption or reconnect. This keeps
report delivery unique per recipient and child turn and preserves the
loaded timeline window across recovery.

### Causes and evidence

1. In the supplied recording, repeated purple reports with 4-hop and
2-hop badges sit beside empty cancelled work while newer 03:33 and 03:35
turns appear below during scrolling. Web appended turns without
transcript elements after all event-backed rows. Those turns now keep
their canonical ordinal position; transcript/background events retain
event sequence order.
2. A spawn and subsequent admitted steers can share a target turn.
Completion previously notified once per call: the gateway/worker
reproduction produced three reports for one result. Delivery now claims
the result once per recipient under its existing thread lock. Different
hop counts are consistent with distinct calls; the original call IDs are
unavailable, so the recording alone cannot establish the precise relay
path.
3. Consuming pending bus inputs cancelled them without withdrawing their
timeline rows or broadcasting the changed projections. Consumption now
withdraws them and publishes turn/steer updates. Migration 0096 repairs
historical consumed inputs while preserving started/dispatched work and
genuine cancellations. Explicit-message consumption was introduced by
#338; per-call completion notifications and the empty-turn layout
predate it.
4. Real-browser paging exposed another jump: report-bearing threads
conservatively fall back to a full snapshot on reconnect, replacing an
expanded window with its last 24 turns. Additive UI field `from_turn_id`
preserves the inclusive oldest loaded turn on both clients, with
authoritative reset for invalid history. Late old turn updates stay
outside a loaded tail. Fork ancestry keeps chain order.

`nightly.100` includes #350 and was published at 00:21:46 Warsaw on
November 8, before the reported 03:33 observation. Installation on the
reporting Mac is unconfirmed. These paths reproduce on a base containing
#350 and explain persistence either way. No linked-computer topology is
needed.

### Validation

- Gateway↔scripted-worker/Postgres regressions cover admitted steers,
fallback/consumption, wait_threads progress, idle report delivery,
distinct results with identical text, repeated sweeps, late old
projections, disk-cache restore, expanded history, and gateway restart.
A paired mobile client uses Connect over pinned Network access with the
same device credential after restart; its projection matches the
BFF-coalesced desktop path. Before the fix, duplicate delivery was 3
instead of 1 and consumed inputs never updated live.
- Migration upgrade regression preserves genuine, started and dispatched
cancellations. History integration covers full-snapshot resume and
invalid window/version resets.
- Gates passed: `bun install`, `bun run gen:check`, `bun run typecheck`
(including mobile), `bun run lint`, `bun run format:check`, and the web
build. The complete `bun run check:tmp` ran in four sequential native
shards (`--shard=1/4` through `4/4`, `--timeout 30000`): **1780 pass,
161 skip, 0 fail across all 320 files**, with a clean test temp
directory after each shard. Two monolithic attempts were interrupted by
SIGTERM, so sharding completed the full gate. The existing steering
regression now expects one shared-result report instead of two.
- Real browser: light/dark at 1280×800 and 390×844, long labels,
older-page loading/reconnect, genuine cancellation placement,
consumed-report removal, jump to latest, and composer reply also
observed by the paired mobile client. Test servers and tabs were closed.
Packaged macOS/iPhone apps and the optional Android emulator were not
run. The isolated fixture lacks linked-computer runtime, producing an
unrelated `/api/computers` 409.
- Copy audit (§8): no UI strings added or changed; consumed inputs no
longer render misleading empty cancelled work. Existing cancellation
copy remains for real cancellations.

CI: static checks, all four CI test shards, and Web/Linux builds passed
on this head. Windows packaging reached the prepared runtime and
electron-builder, then failed with HTTP 504; its failed job was retried
once. No external review yet; inline self-review found no outstanding
issues.

Fixes: #338
Related: #350
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