Repository navigation
Description
Summary
infer agent only evaluates SessionRolloverManager.ShouldRollover once, at session start (cmd/agent.go:195 → maybeRolloverSession at cmd/agent.go:247). The multi-turn loop at cmd/agent.go:370 never re-checks, so a long agent run can cross both the token-fill (compact.auto_at) and idle (compact.rollover_on_idle_minutes) thresholds without ever producing a new session file with a summary.
Chat mode does the right thing — it re-evaluates rollover on every user message at internal/handlers/chat_message_processor.go:239-248. Agent mode should mirror that.
Why this matters
There are two compaction tiers and only one currently survives the agent loop:
ConversationOptimizer.OptimizeMessages(internal/agent/agent.go:321-323) trims what the LLM sees on everyRun. ✅ Works in agent mode — keeps the LLM under context.SessionRolloverManager.PerformRolloverproduces a summary and starts a new session file. ❌ Only fires at agent startup; never inside the loop.
Consequence: the LLM stays under context (tier 1), but the persisted conversation file grows monotonically across a 50-turn run, the idle threshold is never enforced mid-run, and the user never gets the fresh-session-with-summary behavior they get in chat mode for the same workload.
Proposed behavior
- Add a rollover check inside the agent loop in
cmd/agent.go:370— natural placement is right beforeexecuteTurn()(parallel to the system-reminder injection added in [FEATURE] Add 'infer conversations show <id>' subcommand #547's branch). - Use the same
SessionRolloverManagerinstance and the samegroupKeyresolved at startup so the new session id is linked to the same group. - On rollover: replace
s.sessionID, clears.conversation, reload vias.initializeSession(newID)— same flowmaybeRolloverSessionalready implements. - Decide whether to also reset
s.completedTurnsafter a rollover (probably yes, since the rolled-over session is conceptually a fresh start with the summary as turn-0 context). - Idempotent and cheap:
ShouldRolloveris a token estimate + a timestamp check, safe to call every turn.
Acceptance Criteria
-
SessionRolloverManager.ShouldRolloveris re-evaluated inside the agent turn loop incmd/agent.go. - When it fires mid-loop,
PerformRolloverruns, the session id is swapped, the conversation is reloaded, and the loop continues against the new session. - Token-trigger rollover fires within ~1 turn of crossing
compact.auto_atpercent of the model's context window. - Idle-trigger rollover never fires inside an agent loop (the agent is actively running, so the idle check is structurally a no-op there) — confirm and document the asymmetry, or guard explicitly to skip the idle path.
-
s.completedTurnsbehavior across rollover is documented (reset vs. preserved) and matches chat-mode semantics. - Test covers: rollover fires mid-loop on token threshold; loop continues against new session id; group key is preserved.
Activity
feat(agent): re-check session rollover inside the turn loop (#549)
feat(agent): re-check session rollover inside the turn loop (#549) (#550
fix: chat rollover async ux (#551)
chore(release): 0.114.0 [skip ci]
inference-gateway-releaser commentedon May 29, 2026
🎉 This issue has been resolved in version 0.114.0 🎉
The release is available on GitHub release
Your semantic-release bot 📦🚀