auto-continue v2: an interrupted turn frees the session, and a timer that fires mid-turn waits

The code review of v1.56.0 found that the v2 plugin never cleared `busy` on
session.execution.interrupted (the projector makes the session idle there, as the plugin's own
header says), and that onTimer() returned while busy without re-arming. So after a turn the user
interrupted, the resume of a manual /compact was dropped for good, and so was one whose
compaction ended before its turn did. `busy` is now cleared on interrupted, and a timer that fires
while a turn runs re-arms instead of dropping; a turn that starts still clears what is pending, so
the re-arm never relaunches over it. Two tests, red on the old code, green now with the 14.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Hasan BasbunarandClaude Opus 5.5 committed 2026-11-22 19:03:09 +01:00
1 parent e780dd9f56
commit 843fd4f2ad
2 files changed
+16 -1

No files matched your search

+5 -1
View File
@@ -106,8 +106,11 @@ function arm(ctx, sessionID, s) {
}
async function onTimer(ctx, sessionID, s) {
if (s.busy) return; // a turn started meanwhile; its own events decide
if (!s.errPending && !s.compactPending) return;
// a turn still runs: wait for it rather than drop what is pending (a manual /compact can end
// before its turn does); a turn that STARTS clears the pending flags itself, so this re-arm
// never relaunches over it (review of v1.56.0, finding 8)
if (s.busy) { arm(ctx, sessionID, s); return; }
if (s.consecutive >= MAX_CONSECUTIVE) {
await log(`STOP (${sessionID.slice(0, 12)}): ${MAX_CONSECUTIVE} relaunches without progress`);
s.errPending = false;
@@ -168,6 +171,7 @@ export default {
// superseded and inactivity are control flow, not technical errors
await log(`interrupted (${d.reason ?? "?"}) not relaunched (${sessionID.slice(0, 12)})`);
const s = getState(sessionID);
s.busy = false; // the projector makes the session idle here too (projector.ts)
s.errPending = false;
s.compactPending = false;
continue;
+11
View File
@@ -137,6 +137,17 @@ class TheV2AutoContinuePlugin(unittest.TestCase):
self.assertEqual(len(sent), 1)
self.assertIn("just compacted", sent[0]["text"])
# review of v1.56.0, finding 8: an interrupted turn left `busy` set, and a timer that fired while
# busy returned without re-arming, so the resume of a manual /compact was dropped for good
def test_a_manual_compaction_after_an_interrupted_turn_is_relaunched(self):
sent = self.run_steps([E(STARTED), interrupted("user"), compaction_ended("manual"), W])
self.assertEqual(len(sent), 1, "the interrupted turn left the session idle, not busy")
self.assertIn("just compacted", sent[0]["text"])
def test_a_manual_compaction_that_ends_before_its_turn_does_is_relaunched_after_it(self):
sent = self.run_steps([E(STARTED), compaction_ended("manual"), {"wait": 150}, E(SUCCEEDED), W])
self.assertEqual(len(sent), 1, "the timer that fired while busy waits for the turn instead of dropping")
# a turn that started meanwhile decides on its own
def test_an_execution_started_after_the_error_cancels_the_relaunch(self):
self.assertEqual(self.run_steps([failed("connection refused"), E(STARTED), W]), [])