Skip to content

fix: let the agent read every queued message in full when the queue overflows - #208259

Merged
obviyus merged 3 commits into
mainfrom
fix/queue-overflow-full-text
Nov 29, 2026
Merged

obviyus merged 3 commits into
mainfrom
fix/queue-overflow-full-text

Conversation

@obviyus

@obviyus obviyus commented Nov 29, 2026 •

Copy link
Copy Markdown
Collaborator

What Problem This Solves

With the default queue settings (drop: "summarize", cap: 20), messages that overflow the cap reached the model only as 160-character previews under [Queue overflow] Dropped N messages due to cap.. Past about 2x cap, the oldest overflowed messages were cancelled outright (summary elisions trimmed to the cap). The user sent those messages; the agent never read them whole.

Why This Change Was Made

Invariant: the cap decides how many separate turns a backlog gets. It never decides which text the model reads.

  • drop: "summarize" keeps the overflow claim: overflowed sources still run together as one turn, grouped by delivery context. That turn now renders exactly like a collect batch: [Queued messages while agent was busy], then each source as Queued #N (from <sender>) with its full approved text. Its transcript row comes from the collect recorder (full text, mentions, media).
  • A single overflowed source runs as itself, like a single collect item.
  • Removed: the 160-character cut and summary line cap in applyQueueDropPolicy, previewQueueSummaryPrompt, onSummaryElide, summaryElisions, activeSummarySources, trimSummaryElisionsToCap, createOverflowSummaryRetrySource, the overflow-only transcript recorder and its idempotency key, and consumeQueueSummaryDelivery (replaced by the existing mailbox-cleanup detach, now exported). summaryEntries: {source, line}[] became summarySources: FollowupRun[].
  • The local TUI queue had the same cut through the shared helper: it now carries overflowed messages whole and renders them in its collect prompt.
  • Docs: docs/concepts/queue.md, docs/gateway/config-agents/messages-and-talk.md, docs/concepts/session-controller.md, and the messages.queue.cap/drop help text.

Kept as is: drop: "old" | "new" (public config; removing it needs a migration), steering collaborativeSteeringFallback: "reject", ambient room event previews (documented group contract), droppedCount.

User Impact

When many messages arrive while the agent is busy (default cap 20), the agent now reads every one of them in full instead of a 160-character preview, and none are cancelled past twice the cap. Overflowed messages still arrive as one combined turn, so the number of turns stays the same.

Decisions (recorded defaults)

  • Accepted edge case: a flood while the agent is busy now enters one turn at full size. Compaction is the bound; no byte cap was added.
  • The brief's test asked for "all 4 whole in the next turn". With cap 2 the design gives one combined turn for the 2 overflowed messages and one turn each for the 2 within the cap. The test asserts every message reaches a transcript user row whole, with the 2 overflowed ones in one row.
  • The overflow-specific transcript idempotency key (route hash) is gone with its recorder; combined overflow turns use the collect key, the same as collect batches today.
  • Telegram E2E used messages.queue.mode: "followup" with cap: 2: the default steer mode injects into the active embedded run, so the queue never overflows on that runtime.

Evidence

  • Unit, red on base / green on head: queue.collect.test.ts › "keeps every overflowed message whole in the combined turn transcript" (base: expected '[Queue overflow] Dropped 2 messages d…' to contain '1:aaaa…').
  • Tests asserting the removed behavior (summary lines, elision eviction, overflow idempotency key) were deleted or rewritten to the new contract.
  • Unit tests, local: every touched test file plus src/auto-reply/reply/queue*.test.ts, src/auto-reply/reply/queue/*.test.ts, src/sessions/session-controller.mailbox*.test.ts (all green after the final edit). tsgo:core, tsgo:core:test, oxlint, oxfmt clean. The importer set is 276 test files, so CI runs the rest.
  • Real Telegram E2E (Test Server, telegram-e2e-userbot, --source-gateway, mock model with MOCK_RESPONSE_CHUNK_DELAY_MS=12000, messages.queue: {mode: "followup", cap: 2}, DM): sent Start the slow turn now., then 4 messages of 377 characters each (LONGMSGn-START … LONGMSGn-END) 3 s apart while the first turn was busy. Telegram inbound batching merged messages 1 and 2 into one inbound on both sides.
    • Base d9cc195ce70f: second model request user row = [Queue overflow] Dropped 1 message due to cap. / Summary: / - LONGMSG1-START word1x0 … w… (160 characters). LONGMSG1-END and every part of message 2 appear in 0 model requests. Messages 3 and 4 arrived whole.
    • Head: the same overflowed source reaches the second model request whole: LONGMSG1-START … LONGMSG1-END followed by LONGMSG2-START … LONGMSG2-END. All 4 start/end markers appear in the model requests. 4 replies seen in Telegram on both sides.
    • Extra head run with Telegram batching off (messages.inbound.byChannel.telegram: 0): each message got its own turn, all 4 whole. The queue did not overflow in that run (timing), so it is not overflow proof.

- drop: summarize regroups overflowed sources into one turn rendered like collect, with full text.
- Removes the 160-character cut, the summary line cap, summary elisions and the overflow-only recorder.
- Local TUI queue carries overflowed messages whole.
@clawsweeper

clawsweeper Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime size: XL labels Nov 29, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. impact:message-loss Channel message delivery can be lost, duplicated, or misrouted. impact:session-state Session, memory, transcript, context, or agent state can drift or corrupt. labels Nov 29, 2026
@obviyus obviyus changed the title fix(queue): keep every overflowed message whole fix: let the agent read every queued message in full when the queue overflows Nov 29, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 29, 2026
- Overflowed exec completions keep full output; summarize no longer cancels sources.
@obviyus

obviyus commented Nov 29, 2026

Copy link
Copy Markdown
Collaborator Author

Rejected review findings:

  • [P1] Bound overflow batches before constructing the model request (drain.ts:172-175): rejected. The design for this PR names this exact case as an accepted edge case: a flood while the agent is busy enters one turn at full size, and compaction is the bound. A batch size limit is a new guard and a second scheduling rule that this change was told not to add. The same unbounded grouping already exists for collect batches, which use the same selector and renderer. The old behavior "solved" this by cutting each message to 160 characters and cancelling sources past 2x cap, which is the defect this PR removes. A context-size split for combined turns, if wanted, belongs to the batch selector for both collect and overflow, in its own PR.

…ll-text

# Conflicts:
#	src/auto-reply/reply/queue/delivery-context.ts
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 29, 2026
@clawsweeper

clawsweeper Bot commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

Codex review: passed.

What this changes

This PR replaces truncated overflow summaries with full-message combined turns in the Gateway and local TUI queues.

Example: With cap 2, four 302-character messages arrive while an agent is busy.

  • Before: The two overflowed messages reach the model as truncated previews.
  • After: The two overflowed messages share one full-text turn, followed by the two remaining messages.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The implementation is coherent and supported by reported shipped-path evidence, but the unclassified required-test failure limits merge confidence.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The body reports Telegram Test Server messages passing through the source Gateway into captured model requests, with all LONGMSG1–4 start/end markers preserved after overflow at cap 2. Inference was mocked; local TUI behavior has source and test evidence only. This supports the changed content-transfer boundary without establishing real-model behavior.
Patch quality 🦐 gold shrimp (3/6) No actionable review findings were identified.

Product

Kind: Preference · Worth it: Yes · Fix scope: Complete
User problem: Busy-session overflow truncates user messages and eventually cancels older overflowed sources before the agent reads them whole.
Reason: Historical behavior intentionally kept bounded previews; this maintainer-authored PR approves replacing that policy with full-content retention and records the flood tradeoff.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-approved change preserves queued message content, and source review found no actionable regression; a failing required Node test gate still needs attribution.

Reviewed head: b9fdccb82090aa2ff4ef9924c9638889df51842e

Before merge

None.

Findings

None.

Agent review details

How this fits together

Inbound messages enter the session mailbox, which selects compatible sources for execution; the queue adapter produces model prompts, transcript rows, and source-settlement outcomes.

flowchart TD
  A[Inbound messages] --> B[Session mailbox]
  B --> C[Overflow source group]
  B --> D[Pending individual sources]
  C --> E[Shared collect renderer]
  D --> F[Agent execution]
  E --> F
  F --> G[Transcript and source settlement]
Loading

Technical review

Best possible solution:

Use the existing collect machinery to preserve complete approved overflow content while retaining mailbox-owned selection and source custody.

Do we have a high-confidence way to reproduce the issue?

Current-main source establishes the truncation and overflow eviction paths, supported by the author's reported baseline failure and Telegram request captures; this read-only review executed no target code.

Is this the best way to solve the issue?

Reusing collect rendering and recording is a coherent, smaller implementation of the approved retention policy, with obsolete overflow machinery removed.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 139550f2cc8d.

Provenance checked

  • Overflow truncation and bounded summaries changes intended behavior with a stated reason (c7ae510: The shared helper already carried 160-character summaries; earlier queue documentation promised short bullets, and subsequent comments identify prompt-growth protection as the reason for bounding them.)
  • Session mailbox ownership and source settlement keeps the original intent (36e277d: Consolidate turns, queues, and Stop under one session controller while retaining individual input custody.)
  • Overflow sender and room-event context keeps the original intent (f58fd16: Restore each summarized source's sender and room-event framing without borrowing live-item metadata, as documented in fix: overflow summaries lose the summarized message's sender and room-event context #187833.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

PR surface

Source -353, Tests -233, Docs 0, Generated 0. Total -586 across 34 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 11 68 421 -353
Tests 19 196 429 -233
Docs 3 9 9 0
Config 0 0 0 0
Generated 1 2 2 0
Other 0 0 0 0
Total 34 275 861 -586

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🐚 platinum hermit and patch quality is 🦐 gold shrimp.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🐚 platinum hermit and patch quality is 🦐 gold shrimp.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed November 29, 2026, 6:50 AM ET / 11:50 UTC.

@obviyus
obviyus merged commit 361a94c into main Nov 29, 2026
198 of 200 checks passed
@obviyus
obviyus deleted the fix/queue-overflow-full-text branch November 29, 2026 12:03
@obviyus

obviyus commented Nov 29, 2026

Copy link
Copy Markdown
Collaborator Author

Landed in 361a94c. Bug: with the default drop: summarize, messages that overflowed the queue cap reached the model only as 160-character previews, and some were cancelled past 2x cap. Fix: overflowed messages run as one combined turn that keeps every message whole, rendered like a collect batch. Proof: a unit test that fails on the base, and a Telegram Test Server E2E where the base cut the overflowed message at 160 characters and the head delivered it whole.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 30, 2026
…verflows (openclaw#208259)

## What Problem This Solves

With the default queue settings (`drop: "summarize"`, `cap: 20`), messages that overflow the cap reached the model only as 160-character previews under `[Queue overflow] Dropped N messages due to cap.`. Past about 2x cap, the oldest overflowed messages were cancelled outright (summary elisions trimmed to the cap). The user sent those messages; the agent never read them whole.

## Why This Change Was Made

Invariant: the cap decides how many separate turns a backlog gets. It never decides which text the model reads.

- `drop: "summarize"` keeps the overflow claim: overflowed sources still run together as one turn, grouped by delivery context. That turn now renders exactly like a `collect` batch: `[Queued messages while agent was busy]`, then each source as `Queued #N (from <sender>)` with its full approved text. Its transcript row comes from the collect recorder (full text, mentions, media).
- A single overflowed source runs as itself, like a single `collect` item.
- Removed: the 160-character cut and summary line cap in `applyQueueDropPolicy`, `previewQueueSummaryPrompt`, `onSummaryElide`, `summaryElisions`, `activeSummarySources`, `trimSummaryElisionsToCap`, `createOverflowSummaryRetrySource`, the overflow-only transcript recorder and its idempotency key, and `consumeQueueSummaryDelivery` (replaced by the existing mailbox-cleanup detach, now exported). `summaryEntries: {source, line}[]` became `summarySources: FollowupRun[]`.
- The local TUI queue had the same cut through the shared helper: it now carries overflowed messages whole and renders them in its collect prompt.
- Docs: `docs/concepts/queue.md`, `docs/gateway/config-agents/messages-and-talk.md`, `docs/concepts/session-controller.md`, and the `messages.queue.cap`/`drop` help text.

Kept as is: `drop: "old" | "new"` (public config; removing it needs a migration), steering `collaborativeSteeringFallback: "reject"`, ambient room event previews (documented group contract), `droppedCount`.

## User Impact

When many messages arrive while the agent is busy (default cap 20), the agent now reads every one of them in full instead of a 160-character preview, and none are cancelled past twice the cap. Overflowed messages still arrive as one combined turn, so the number of turns stays the same.

### Decisions (recorded defaults)

- Accepted edge case: a flood while the agent is busy now enters one turn at full size. Compaction is the bound; no byte cap was added.
- The brief's test asked for "all 4 whole in the next turn". With cap 2 the design gives one combined turn for the 2 overflowed messages and one turn each for the 2 within the cap. The test asserts every message reaches a transcript user row whole, with the 2 overflowed ones in one row.
- The overflow-specific transcript idempotency key (route hash) is gone with its recorder; combined overflow turns use the collect key, the same as `collect` batches today.
- Telegram E2E used `messages.queue.mode: "followup"` with `cap: 2`: the default `steer` mode injects into the active embedded run, so the queue never overflows on that runtime.

## Evidence

- Unit, red on base / green on head: `queue.collect.test.ts` › "keeps every overflowed message whole in the combined turn transcript" (base: `expected '[Queue overflow] Dropped 2 messages d…' to contain '1:aaaa…'`).
- Tests asserting the removed behavior (summary lines, elision eviction, overflow idempotency key) were deleted or rewritten to the new contract.
- Unit tests, local: every touched test file plus `src/auto-reply/reply/queue*.test.ts`, `src/auto-reply/reply/queue/*.test.ts`, `src/sessions/session-controller.mailbox*.test.ts` (all green after the final edit). `tsgo:core`, `tsgo:core:test`, oxlint, oxfmt clean. The importer set is 276 test files, so CI runs the rest.
- Real Telegram E2E (Test Server, `telegram-e2e-userbot`, `--source-gateway`, mock model with `MOCK_RESPONSE_CHUNK_DELAY_MS=12000`, `messages.queue: {mode: "followup", cap: 2}`, DM): sent `Start the slow turn now.`, then 4 messages of 377 characters each (`LONGMSGn-START … LONGMSGn-END`) 3 s apart while the first turn was busy. Telegram inbound batching merged messages 1 and 2 into one inbound on both sides.
  - Base `98bb8cc00cc9`: second model request user row = `[Queue overflow] Dropped 1 message due to cap.` / `Summary:` / `- LONGMSG1-START word1x0 … w…` (160 characters). `LONGMSG1-END` and every part of message 2 appear in 0 model requests. Messages 3 and 4 arrived whole.
  - Head: the same overflowed source reaches the second model request whole: `LONGMSG1-START … LONGMSG1-END` followed by `LONGMSG2-START … LONGMSG2-END`. All 4 start/end markers appear in the model requests. 4 replies seen in Telegram on both sides.
  - Extra head run with Telegram batching off (`messages.inbound.byChannel.telegram: 0`): each message got its own turn, all 4 whole. The queue did not overflow in that run (timing), so it is not overflow proof.

Co-authored-by: Ayaan Zaidi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation gateway Gateway runtime impact:message-loss Channel message delivery can be lost, duplicated, or misrouted. impact:session-state Session, memory, transcript, context, or agent state can drift or corrupt. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: XL status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant