Skip to content

Per-turn agent input payload duplicates group history and restates sender/delivery facts up to 5x #99218

Description

@obviyus

Per-turn agent input payload carries duplicated history, repeated sender identity, and a 3-5x restated delivery contract

Current behavior

A payload audit of what the agent model receives on a single inbound turn (traced through src/agents/system-prompt.ts, src/auto-reply/reply/inbound-meta.ts, src/auto-reply/reply/prompt-prelude.ts, and the Telegram body fold, verified against test/fixtures/agents/prompt-snapshots/) found the ordering and cache discipline are correct, but the payload carries roughly 700-800 tokens of per-turn overhead on a busy group turn, most of it redundant:

  1. Group history is delivered twice, in two formats, in the same user message (Telegram). The untrusted prefix carries the chat-window block (Conversation context (untrusted, chronological...) — compact #id <ts> sender: body lines from the message cache, src/auto-reply/reply/inbound-meta.ts:262-282), and the body separately carries the [Chat messages since your last reply - for context] fold built from the group-history window (extensions/telegram/src/bot-message-context.session.ts:452-474). Core dedupes only its own JSON history block against the chat window (chatWindowCoversHistory, inbound-meta.ts:592, :728); it cannot see or suppress the Telegram body fold. The two windows overlap but differ in selection, so the model sees mostly-the-same messages twice with different ids and formats.
  2. Per-history-line envelope overhead. Each folded body line re-runs formatInboundEnvelope (bot-message-context.session.ts:176-191), repeating channel name, group label, chat id, and full weekday+timestamp+timezone — ~100-130 chars of constant boilerplate per line, up to 50 lines, all already stated once in Conversation info.
  3. Sender identity stated up to 5 times per turn: Conversation info.sender/sender_id, a whole Sender JSON block whose label recombines its own other fields (inbound-meta.ts:642-659), the envelope body line, the chat-window lines, and on Telegram quote-reply turns a seam that renders #59 Pash: [Telegram Ops id:...] Pash: text (inbound-meta.ts:407-441).
  4. Delivery/silence contract stated 3-5 times on message-tool-only turns: system ## Messaging etiquette, group chat context, the per-turn Delivery: hint as the first block of every user message (inbound-meta.ts:554-559); room events add visible_reply_contract: plus a closing directive while the Room context: block contains another copy of the hint (prompt-prelude.ts:143-164). The statements agree, but repetition dilutes salience and burns tokens.
  5. Header noise: the extra system prompt renders under ## Group Chat Context even for direct chats (src/agents/system-prompt.ts:1316-1321), and the meta block nests its own ## Inbound Context heading at the same level (inbound-meta.ts:535).

Expected behavior

One canonical group-history block per turn in one compact format; constant facts (channel, group label, chat id) stated once per block, not per line; one sender identity statement; one authoritative per-turn delivery-contract statement per layer; chat-type-appropriate headers.

Impact

Every group turn on every channel pays the token cost, and the duplicated near-identical history is the largest single source of model confusion on ambient/group turns — directly relevant to the over-reply behavior tracked in #99142.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Normal backlog priority with limited blast radius.bugSomething isn't workingclawsweeper:needs-product-decisionClawSweeper marked this issue as needing a product or behavior decision.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.maintainerMaintainer-authored PR

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions