Skip to content

fix(server): idle compaction skips a session the next message would not resume - #456

Merged
trancong12102 merged 1 commit into
mainfrom
onicode/idle-compaction-scheduled
Nov 19, 2026
Merged

trancong12102 merged 1 commit into
mainfrom
onicode/idle-compaction-scheduled

Conversation

@trancong12102

Copy link
Copy Markdown
Contributor

Follow-up to the context-boundary notes from #439. One clear bug is fixed here. The rest are product calls, listed below with a recommendation.

What was wrong and the fix

Since #439, a thread can hold a fresh native session for a scheduled task's runs, beside the main conversation. After such a run, the idle-compaction timer measured the active session (the schedule's), found it large with a warm cache, and dispatched /compact. Dispatch then sent that /compact to the main conversation, the session the next message resumes. The measurement and the compaction were about different sessions.

Now the orchestrator drops a beforeCacheExpires compaction when the active session is not the one the next message resumes. The thread then waits for the user's next message instead of compacting a session nobody measured. "Compact and send" (onReturn) and a typed /compact are unchanged. They already go to the conversation the message resumes.

Tests

  • ProviderSwitch.integration.test.ts: in the existing scheduled-fresh-session case, an idle compaction after the scheduled run reaches no provider. It fails on main, where the compaction lands on the main conversation.

Council review

Round 1: Codex (gpt-6.2-astra, high) and Claude Opus, on a first version that sent idle compaction to the active session.

  • Codex: "Compact and send" would then compact the schedule's session while the message resumed the uncompacted main conversation. Opus: the compaction would land on a schedule session that is rarely resumed. Opus suggested skipping idle compaction after a scheduled fresh run instead. Changed to skip.
  • Codex: a provider switch committing between the timer's measurement and its dispatch can compact the new selection with the old measurement. This race predates fix(server): history sent to providers follows the conversation it came from #439. Left, see below.

Round 2: both reviewers, on a version that skipped in idleCompactionWindow.

  • Both: the timer's projection reads load neither completed user-message items nor the session's first run, so the check never fired in production. Fixed by moving the check to dispatch, where the orchestrator holds the full thread and already computes the conversation session. Both confirmed that "Compact and send" and /compact route consistently, and that no compaction is wrongly skipped in the cases asked about. That holds for the dispatch version too: when no main session qualifies, the conversation session is the active one, so compaction still runs.
  • This final shape came after round 2 and has had no third review.

Context-boundary notes from #439

Product calls, not changed here. Both reviewers agreed with each recommendation.

  • Main-conversation handoffs include schedule output. A provider switch, recovery or portable fork from a main run carries schedule rows, so a long scheduled result can push out the user's own history. Recommend leaving schedule rows out of a main handoff, or ranking them below main rows.
  • Usage-limit continuation can resume a scheduled run in the main chat. It matches on provider instance only. Recommend resuming on the limited run's own session, and skipping auto-resume when that session cannot be resumed.
  • A wake steered back to the provider that holds its session opens a third native session instead of resuming the schedule's. Low priority.
  • After a scheduled run, the main conversation's cache can expire uncompacted. The timer is keyed by thread, so the scheduled run replaced the main run's timer, and this change now skips it. Recommend a per-session timer only if this shows up in usage.
  • Not bugs:
    • The handoff note's covered run range can name a main run that sits between a schedule run and its wake, though that run's content is excluded. Cosmetic.
    • A rolled-back run's later usage report beats a retained compaction. Conservative.
    • A Claude partial compaction without post_tokens, and Codex's retained user messages, undercount the post-compaction estimate. The work reserve cushions it but does not bound it.

Left

  • The switch race: a stale timer can compact a newly selected instance. The fix is for the timer's command to carry the provider thread it measured, and for dispatch to drop it when that is no longer active.
  • The clients' "Compact and send" offer may still be based on the schedule session's usage, rather than the conversation the message resumes.

Opus 5.5 in Claude Code, through Onicode.

🤖 Generated with Claude Code

…ot resume

After a scheduled task's fresh run, the timer measured the schedule's session
while the /compact went to the main conversation. The orchestrator now drops a
before-cache-expires compaction when the active session is not the one the
next message resumes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@trancong12102
trancong12102 merged commit 9e8eb8c into main Nov 19, 2026
17 checks passed
@trancong12102
trancong12102 deleted the onicode/idle-compaction-scheduled branch November 19, 2026 21:35
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.

1 participant