Skip to content

Compact Responses within the sliding window in one summary - #1485

Merged
AnthonyRonning merged 2 commits into
masterfrom
codex-compact1459-maple
Nov 7, 2026
Merged

AnthonyRonning merged 2 commits into
masterfrom
codex-compact1459-maple

Conversation

@AnthonyRonning

@AnthonyRonning AnthonyRonning commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Closes #1459.

Server compaction reached past the sliding window and worked through archived history in serial batches, so turning it on for an established conversation could make the next request a multi-million-token job. That is what failed in the Nov 4 pilot. This puts compaction back on the Pi model: summarize the older part of what the model can already see, once, and keep a recent tail.

What changed

  • Same boundary as the sliding window. Each request's active context uses the legacy rules: newest 1,000 rows, first user message, and a tail that opens on a user message. A test compares the selection against the real legacy selector. The row cut moves to a boundary between complete exchanges, so it can drop slightly more than legacy at that edge but never shows more. Source outside the boundary stays stored and retrievable but is never replayed or summarized.
  • One summary operation. History batches, transcript fragments and provisional folding are gone. If a selection cannot fit, it narrows from the old end and keeps the first user message.
  • The boundary is durable. CheckpointPayload.active_start records where the active window starts, because a freed budget would otherwise walk a recomputed window back into the archive. It must be a covered key, so deleting it invalidates the checkpoint rather than leaving it dangling. Older payloads decode unchanged.
  • Helper failure no longer fails the answer. The windowed prompt fits whenever the required input does, so a failed, stalled or rejected helper falls back to it.
  • Timing attribution. responses.compaction.helper_timing separates stream open, first chunk, first visible text and last chunk from total preparation, including for a helper dropped by cancellation.
  • docs/development-contracts.md now states the context-scope contract.

Continuum's size limit

Real-provider testing found that Continuum's proxy refuses content past 4,000,000 bytes as an HTTP 500, whatever the model's window says, because its shard key cannot grow further. Every Maple request carries the cache_salt that triggers this.

  • Helpers measure their serialized request and narrow without a provider call.
  • The exact refusal now reads as an input-size rejection, so a refused main prompt can take forced compaction.
  • This part reaches flag-off traffic: the refusal no longer counts as a route failure in inference/health.rs. Previously three in 60 seconds opened the route's circuit for 30 seconds for everyone.

The legacy path has the same limit and is otherwise unchanged. With the flag off, a GLM Flash conversation that fills its window still fails; that needs its own fix.

Validation

On 69ef8e0e, on current master: pre-commit gates, the os-rust lane with 1,133 tests passing and 57 opt-in ignored (run on the same code just before commit), and the disposable DB suite with 54 tests passing and none skipped. That includes all 21 compaction persistence tests.

The runtime evidence below predates the rebase, which merged cleanly, and the row-cut fix in 69ef8e0e. That fix has unit coverage only, because a runtime check needs a conversation over 1,000 rows. It used the encrypted SDK client against a Local stack, with synthetic conversations seeded through the legacy path to reproduce a first enablement.

Real model, default reasoning Helper input Helper time Prompt Answered at
Kimi K3 222k tokens 40s 261k → 27k 47s
GLM 5.3 222k tokens 68s 261k → 27k 72s
GLM Flash, over its window 618k tokens 76s 1.03M → 53k 83s

Each was one helper call. All three then recalled facts held only in the summary, said they did not know a fact from an archived turn, answered from the retained tail, and reused the checkpoint with no helper call.

Against a controllable upstream:

  • A 3.1M-token conversation sent the helper only legacy-visible rows, with archived sentinels absent apart from the first user message legacy also keeps. All 186 canonical items stayed retrievable.
  • Upstream 500, length-cut summaries and repeated size rejection all completed on the windowed prompt with no checkpoint.
  • A real 5-minute stall still answered, at 302s.
  • Cancelling during a stall ended cleanly with no checkpoint.
  • context_management: [] returned a typed message_exceeds_context_limit with no helper.
  • Provider rejection of the main prompt recovered through forced compaction, including the full proxy-refusal chain.
  • A tool loop compacted mid-Response and kept its tool pairs.
  • No synthetic content appeared in the debug logs.

Not covered, and open decisions

  • Not run: hosted Dev or production, the Research UI, tool loops on a real model, or Kimi K3.1 Pro, which landed after these runs. Token counts in the real runs are approximate because seeded rows took theirs from the mock upstream.
  • Partial summaries on GLM Flash: that run summarized 618k of a 1.03M window to stay under the proxy limit. The rest of the older window left model context, though it stays stored.
  • No cross-request backoff: a truly stalled helper costs each request the 5-minute budget. The real runs took 40–76s, so this probably should wait for rollout data.
  • Pilot checkpoints from Nov 4 still load, so their summaries of older history stay in use. Clearing them would be a production action.

No flag, rollout or deployment change. Rolling back is unchanged: turning the flag off returns to the legacy path.

🤖 Generated with Claude Code

Server compaction reached past the sliding window and worked through
archived history in serial batches, so enabling it on an established
conversation could turn the next request into a multi-million-token job.
The pilot failed on exactly that.

Each request now uses the sliding window's own boundary. Source outside it
stays stored but is never replayed or summarized. One helper request
summarizes the older active context, narrowing from the old end when it
cannot fit, and a checkpoint records where the active window starts so a
freed budget cannot walk back into the archive. The windowed prompt fits, so
a failed or stalled helper falls back to it and the Response still answers.

Continuum's proxy refuses content past 4,000,000 bytes as an HTTP 500,
whatever the model's window. Helpers measure their request instead of sending
one it would refuse. That exact refusal now reads as an input-size rejection:
it can start reactive compaction and no longer counts against route health.

Closes #1459

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment on lines +252 to +255
archive(
0..current.saturating_sub(ACTIVE_WINDOW_ROWS),
&mut result.archived,
);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Keep tool exchanges intact at the 1,000-row cutoff

This archives individual rows before atomic grouping. If a stored tool call falls immediately before the cutoff and its matching tool result immediately after it, the result stays visible while its call is discarded. When the remaining window fits the token budget, the early return at lines 296–297 preserves that split. The context builder considers the pair matched using the full metadata, and final projection does not repair it, so the provider receives an orphan role: tool message and can reject an otherwise valid conversation.

I reproduced this on 18f765d2 with an isolated unit test: 1,002 historical rows, the call at index 1 and result at index 2, followed by the current user input. With a 100,000-token budget, ActiveContext::select archives the call but project emits the result. The assertion that every emitted result retains its call fails.

Please advance the row cutoff past the complete crossing exchange and add a regression test for a pair straddling this boundary. The existing tool-boundary test covers the token-budget cut, but not the 1,000-row cut.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed the fix in 69ef8e0e: this looks good and resolves the finding. The row cutoff now falls between whole window units, preserving tool call/result pairs, reasoning/answer pairs, and pending exchanges around the current input. The three added regression tests cover these cases.

I reran the focused compaction suite through the pinned CI shell with cargo test --locked --all-features compaction and RUSTFLAGS="-D warnings": 160 passed, 0 failed, 21 ignored. The ignored tests require a disposable migrated PostgreSQL database and were not run in this rereview. No new findings in the focused rereview.

The 1,000-row cut ran on raw rows before grouping, so it could land inside
a tool exchange or between a reasoning row and its answer. A split exchange
sent a tool result without its call, and a split reasoning group produced a
checkpoint that failed validation after the helper had been paid for.

Cut between window units instead. A unit that crosses the limit leaves whole,
so the window can drop slightly more than the sliding window would but never
shows more. A pending exchange around the current input stays whole.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

Responses compaction: restore Pi-style active-window behavior; remove archive backfill and serial batching

1 participant