Repository navigation
fix(coding-agent): trigger agent REPL cleanup on compaction - #552
sethkarten wants to merge 9 commits into
Conversation
a52c720 to
7029d83
Compare
9bf701d to
520b310
Compare
520b310 to
933e0b2
Compare
snimu
left a comment
There was a problem hiding this comment.
I really like a cleanup phase, but I'm wondering if we should rather make compaction a two-step process, of first cleaning up the kernel and then writing the summary, or the other way around; rather than compacting and then having the new agent clean up the kernel.
That would avoid a situation where the summary references kernel state that the new agent cleans up. Which is mostly fine and should work, but I'm worried that it takes a bit of model capacity to keep the contradiction in mind, and I'd rather have that model capacity spent somewhere else.
My goal is to keep the post-compaction model as fresh and clean as possible and let it focus only on its actual work.
bc567db to
0ada255
Compare
0ada255 to
9a90e30
Compare
9a90e30 to
fab1381
Compare
fab1381 to
a585963
Compare
a585963 to
65d926d
Compare
65d926d to
947ec6c
Compare
fcf7a20 to
cafea73
Compare
cafea73 to
70c3a3d
Compare
70c3a3d to
d50cf68
Compare
d50cf68 to
eca638f
Compare
eca638f to
c868cd7
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit ab2b7d9. Configure here.
|
superseded by v0.5.0 |

Summary
delimport gc; gc.collect()after cleanup instead of automatically clearing useful kernel stateThis complements #551, which evicts compacted session-history payloads from the Node.js process. The subagent runtime cleanup and lifecycle policy remain isolated in #547 and #548.
Tests
test/suite/agent-session-compaction.test.ts— 28 passednpm run checkStacked on #551.
Note
Trigger kernel REPL cleanup via a maintenance role after compaction commits
AgentSessionnow runs a host-side kernel maintenance role (kernel-maintenance.ts) that executes cleanup cells against the already-running IPython kernel to reclaim stale REPL objects.prepareCompactionnow accepts optionalcustomInstructionsand returns amaintenanceContextMessagesarray so the maintenance role has appropriate conversation context._boundedKernelMaintenanceContexthelper trims that context to fit within a token budget (capped at half the model context window, between 1024 and 32000 tokens), inserting a synthetic notice when truncation occurs._notifyKernelStateAfterCompactionpath that injected a hiddenipython_statemessage after compaction is removed and replaced by this active cleanup role.Changes since #552 opened
AgentSession._runSerializedRefineCheckpointto process committed pending compaction snapshots synchronously at serialized boundaries instead of scheduling interactive timers, with guards to discard snapshots whensettings.compactis disabled orcommitState.valueis false [ef45ddf]AgentSession._runSerializedAutoRefineReview,AgentSession._runSerializedRefine, and the underlying plan method to accept and propagate trajectory messages from compaction snapshots through the review and refinement pipeline [ef45ddf]AgentSession._drainPendingRefinementForDisposalto route disposal-time draining of committed compact snapshots through the serialized review and refine path [ef45ddf]SerializedInternalsand added tests verifying serialized boundary consumption of deferred compact snapshots, disposal-time draining behavior, and skipping of uncommitted snapshots [ef45ddf]AgentSession._runAutoCompactionmethod [21742f9]AgentSession._drainPendingRefinementForDisposalmethod condition to requirepending.commitState.value === truebefore triggering compact auto-refine review [b872434]Macroscope summarized ab2b7d9.
Note
Medium Risk
Touches compaction, parent IPython kernel mutation, and auto-refine scheduling with many concurrency and commit-gating paths; mistakes could delete live REPL state or apply harness edits on failed compactions, though gates and tests target those cases.
Overview
Replaces post-compaction hidden
ipython_statenotices with an active kernel maintenance role (kernel-maintenance.ts) that plans against the full pre-compaction transcript in parallel with summary generation, but blocks parentipythontool execution until the compaction entry is durably committed. Failed, cancelled, or extension-owned compactions cannot mutate the kernel; namespace deletes are disabled when the live-name probe fails or context is incomplete.Compact-triggered auto-refine now snapshots the same pre-compaction trajectory, can plan in parallel, and applies only after a successful commit via an
applyGate; deferred snapshots survive busy/cooldown/serialized boundaries and disposal. Successful refinements append a durable session completion message listing harness edits; unpersisted status messages are generalized beyond compaction outcomes.prepareCompactiongains optionalcustomInstructionsandmaintenanceContextMessagesfor the maintenance role. Auto-compaction publishes a_compactionOperationquiescence gate so refinement apply does not race session rewrites.Reviewed by Cursor Bugbot for commit b872434. Bugbot is set up for automated code reviews on this repo. Configure here.