Skip to content

Summary swap makes a gated Turn reuse an old answer #3687

Closed

Description

@sentry-junior

Summary

A prepared-summary swap keeps the messages after its mark verbatim, so the replacement can hold answer tool results (reply, noReply) from earlier Turns. The compaction handler still sets the Turn start to 0. For a gated Turn (Task or Thread agent Turn, Automation run), the earlier answer then counts as this Turn's answer. A resumed slice returns without calling the model, and the Turn ends with the earlier Turn's answer.

Code

packages/junior/src/chat/agent/index.ts at bafa715db:

  • applyActiveContextCompaction calls runResume.setTurnStartMessageIndex(0) after any replacement ("The whole replacement belongs to this Turn"). That holds for a blocking summary, which keeps only user messages. It does not hold for compactWithPreparedSummary (services/context-compaction-swap.ts), which keeps every message after the mark.
  • The checkpoint then stores turnStartSeq: -1, so the resumed record has turnStartMessageIndex: 0.
  • On resume, if (behavior.gated && readTurnAnswer(turnMessages())) return undefined; finds the earlier answer and skips the model.
  • Without a resume, answer: readTurnAnswer(turnMessages()) at Turn end and the missing-answer reminder (turnStartIndex()) read the same range.

Reproduction

Integration test through child-agent wiring:

  1. Named child. Turn 1 answers with reply.
  2. Commit long history and a ready compaction_prepared at that seq.
  3. Turn 2 answers with noReply.
  4. Lower botConfig.contextWindowTokens so Turn 3 swaps at Turn start.
  5. Turn 3 calls systemTime, then yields (soft yield or Turn timeout).

Result: the paused record has turnStartSeq: -1, the resumed slice makes no model call, and the invocation completes with result "". Expected: the resumed slice calls the model and Turn 3 gets its own answer.

History

Related

via @dcramer.

--

View Session [Sentry]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions