#9647·pi

Emit session_compact_end event to extensions after clearing compaction state

Author: lkraiderCreated Sep 15, 2026Updated Sep 17, 2026

session_compact is currently emitted to extensions before this._clearManualCompactionState() runs in agent-session.ts.

Because this._compactionAbortController is still active when session_compact fires, any extension trying to inspect ctx.isIdle() or dispatch a follow-up message (sendUserMessage) throws: "Cannot submit a prompt while compaction is in progress. Wait for compaction to finish and retry."

Could we emit a session_compact_end event on _extensionRunner right after clearing the controller in AgentSession.prototype.compact (around line 1565)?

this._clearManualCompactionState();
await this._extensionRunner?.emit({
  type: "session_compact_end",
  compactionEntry: savedCompactionEntry,
  reason: "manual",
  willRetry: false,
});

This would let extensions coordinate post-compaction workflows directly, with zero timers, zero deferral hacks, and 100% native engine alignment.