Skip to content

fix(compaction): emit a failure event and back off after a failed summary - #1584

Merged
edenreich merged 2 commits into
mainfrom
fix/compaction-estimate-and-backoff
Oct 20, 2026
Merged

edenreich merged 2 commits into
mainfrom
fix/compaction-estimate-and-backoff

Conversation

@edenreich

@edenreich edenreich commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Closes #1581. The estimate gap and the force: true question continue in #1586.

A compaction whose summary request fails logs the error, returns the messages unchanged and emits nothing, so the stream shows compaction_started with no end and the next turn crosses the same threshold and tries again. Each attempt is a full summarisation request. On the run in the issue six compaction_started fired in six minutes before one compaction_completed.

It now emits compaction_failed with the error and skips the next bufferSize auto checks. A forced compaction (/compact, session rollover) still runs.

Changes

  • internal/conversation/conversation_optimizer.go: compaction_failed event, skipAutoChecks counter, inBackoff.
  • Test: a failing client yields started + failed events, no retry for bufferSize turns, a retry after, and force bypasses the backoff.

Not in this PR

The issue also reports the trigger estimate running far above the provider's prompt_tokens. The cause is not established, so the estimate is unchanged here.

no docs ticket: internal-only fix

Verification

task precommit:run clean, go test ./... green.

…a failed summary

The trigger estimate counted every assistant message's reasoning, which is never resent to the provider, so a reasoning model ran the estimate to 2.4x the gateway-reported prompt_tokens and tripped auto-compaction at a fraction of the window.
A compaction whose summary request failed emitted nothing and was retried on the next turn. It now emits compaction_failed with the error and skips the next bufferSize auto checks. A forced compaction still runs.
@edenreich edenreich changed the title fix(compaction): drop reasoning from the estimate and back off after a failed summary fix(compaction): emit a failure event and back off after a failed summary Oct 20, 2026
@edenreich
edenreich merged commit 3431881 into main Oct 20, 2026
1 check passed
@edenreich
edenreich deleted the fix/compaction-estimate-and-backoff branch October 20, 2026 18:27
@edenreich edenreich moved this from Todo to Done in 2026 Oct 20, 2026
@inference-gateway-releaser

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 0.233.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

@inference-gateway-releaser inference-gateway-releaser Bot added the released Shipped in a release label Oct 20, 2026
edenreich added a commit that referenced this pull request Oct 20, 2026
…zer (#1595)

Resolves #1592

## Summary

`maybeRolloverSession` runs at the top of every headless turn and
`PerformRollover` compacted with `force=true`. That is the `force: true`
on every auto compaction in #1586, and it had three effects on the run
there: the backoff from #1584 only guards `!force`, so a failed summary
was retried every turn (five `compaction_started` in six minutes), each
failed attempt still started a new session and copied the full history
into it, and the gate estimated over hidden system reminders the
compaction then dropped, which is how `current_tokens: 497420` was
logged under a 500k threshold.

## Changes

- `MaybeRollover` calls the new `performRollover` with `force=false` for
the token trigger, so the optimizer applies its own threshold and
failure backoff. The idle trigger and the manual `PerformRollover`
(`/compact` outside the TUI) keep forcing.
- A gated rollover whose optimizer produced no checkpoint message
returns `errNoCheckpoint` and leaves the session and the group index
untouched. Message count cannot tell, since the skill restorer re-emits
loaded skills after the checkpoint. `MaybeRollover` logs it at debug.
- `visibleMessages` is shared by the gate and the compaction, so both
estimate the same message set.
- Tests: the fired case asserts `force=false`,
`TestMaybeRollover_NoCheckpointKeepsSession` pins the failed-summary
path over three turns, `TestMaybeRollover_IdleTriggerForces` pins the
idle path, and `TestShouldRollover` gains a hidden-entries case.

In headless both the rollover and `optimizeConversation` in the agent
loop consult the optimizer once per turn, so a backoff of `buffer_size`
now counts two checks per turn. Unifying the two gates is a separate
change.

no docs ticket: internal bug fix.

---------

Co-authored-by: inference-gateway-maintainer[bot] <246577062+inference-gateway-maintainer[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released Shipped in a release

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[BUG] Auto-compaction over-estimates context and re-fires every turn after a failed summary

1 participant