From 843fd4f2ad1dea4ac06a3be8a76f73ef3f5ec710 Mon Sep 17 00:00:00 2001 From: Hasan Basbunar Date: Sun, 22 Nov 2026 19:03:09 +0100 Subject: [PATCH] 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 --- extras/opencode/auto-continue-v2.js | 6 +++++- tests/test_auto_continue_v2.py | 11 +++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/extras/opencode/auto-continue-v2.js b/extras/opencode/auto-continue-v2.js index 6b40eff5..f22c167e 100644 --- a/extras/opencode/auto-continue-v2.js +++ b/extras/opencode/auto-continue-v2.js @@ -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; diff --git a/tests/test_auto_continue_v2.py b/tests/test_auto_continue_v2.py index 227274ee..8b780b36 100644 --- a/tests/test_auto_continue_v2.py +++ b/tests/test_auto_continue_v2.py @@ -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]), [])