Skip to content

User message appended during compaction is buried before the summary while the continuation anchor points at older work #3604

Open

Description

@7Sageer

Background

#3537 adds a continuation anchor after the compaction summary ("Context compaction is complete — continue the work that was in progress when it began."). Codex review on that PR flagged a race that was verified against the project's own test (keeps messages appended while compacting an unchanged prefix in packages/agent-core-v2/test/agent/fullCompaction/fullCompaction.test.ts).

Problem

When the user appends a message while compaction is generating its summary, historySafeToCompact accepts it (unchanged prefix + real user input) and the rebuilt context becomes:

user: old kept messages...
user: "new user while compacting"   <- appended during compaction, lands here
user: [compaction summary]          <- summarizer never saw the new message
user: [continuation anchor]         <- "continue the work that was in progress when it began"

The last message directs the model to resume the work that was in progress when compaction began, but the user's newest intent arrived after that point. The fresh request is neither covered by the summary nor anchored — it sits buried before the summary while the final slot points at older work. Before #3537 the newest slot was the summary itself (content, not a resume directive), so the anchor sharpens a pre-existing positioning gap into an explicit misdirection for this corner.

The window is narrow (the user must send input during summary generation) and the new message is preserved verbatim, so impact is bounded — hence deferred from #3537.

Directions

  • Prompt layer: make the anchor target the latest preserved user message instead of the work in progress at begin, e.g. "the latest preserved user message above is the current request; continue any work it left in progress rather than starting over." Positional targeting is race-robust because the kept set preserves chronological order, so its last message is always the newest genuine input.
  • Harness layer: place user messages appended after compaction begin past the handoff (after summary + anchor) in the rebuilt shape. Semantically cleanest but changes kept-set accounting (keptUserMessageCount, fold parity).

Related: #2680, #3487, #3537 (codex review comment: #3537 (comment))

Activity

  1. HelloWorldU commented on Sep 9, 2026

    @HelloWorldU

    Would it make sense to place messages received during compaction after the handoff, while leaving messages queued for later as they are? That seems to preserve the intended flow without adding responsibilities to the handoff prompt. If this direction sounds reasonable, I’d be happy to work on it.

  2. HelloWorldU commented on Sep 16, 2026

    @HelloWorldU

    Gentle ping — does the proposed direction make sense? If so, I’d be happy to open a PR.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions