Skip to content

Commit d3fb8c8

Browse files
anandgupta42claude
andcommitted
fix: [#834] address coderabbit — set _subscribed=true only after successful Bus.subscribe
Reviewer flagged that setting `_subscribed = true` BEFORE calling `Bus.subscribe` means a single throw permanently disables retry — the deleted-session counter eviction silently stops working for that process. The previous justification ("silent retry would noisily re-throw every call") was conservative-by-default but the wrong default: `Bus.subscribe` is robust enough that throws are exceptional, and the cost of "every todowrite logs a quiet error" is lower than "the daemon-mode memory fix is silently disabled". Flipped the order so `_subscribed` is set inside the try block after a successful subscribe. On failure, `_subscribed` stays false and the next todowrite call retries. Comment updated to match. 12/12 tests pass; marker check clean; no behavior change in the happy path (one Bus.subscribe call, idempotent on subsequent invocations). Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
1 parent 33aa344 commit d3fb8c8

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

‎packages/opencode/src/tool/todo.ts‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,23 @@ export const TODOWRITE_REFUSE_THRESHOLD = 50
3737
// and `recordTodoWriteCall` has no awaits before the guard flips, so two
3838
// concurrent first-calls cannot both enter the subscribe block.
3939
//
40-
// Failure handling: if `Bus.subscribe` throws (Bus not yet initialized in
41-
// some test contexts), we still flip `_subscribed = true` to avoid retrying
42-
// every call. The counter remains correct for the in-memory case — only the
43-
// daemon-mode auto-cleanup is lost, and the explicit `clearTodoWriteCounter`
44-
// escape hatch remains available. This is a deliberate trade-off: silent
45-
// retry every call would noisily re-throw on every todowrite invocation.
40+
// Failure handling: `_subscribed` flips to true ONLY after a successful
41+
// `Bus.subscribe`. If subscribe throws (e.g. Bus not yet initialized in
42+
// a test context), `_subscribed` stays false so the next todowrite call
43+
// retries. Bus.subscribe is synchronous + the handler set is idempotent
44+
// per identity, so racy first-calls won't double-subscribe.
4645
let _subscribed = false
4746
function ensureSessionDeletedSubscription(): void {
4847
if (_subscribed) return
49-
_subscribed = true
5048
try {
5149
Bus.subscribe(Session.Event.Deleted, (evt) => {
5250
todoWriteCallsBySession.delete(evt.properties.info.id)
5351
})
52+
_subscribed = true
5453
} catch {
55-
// See comment above — subscription is best-effort, no retry by design.
54+
// Bus may not be initialized yet (some test contexts). Leave
55+
// _subscribed=false so the next todowrite call retries the subscribe.
56+
// The counter still works correctly for the in-memory case meanwhile.
5657
}
5758
}
5859

0 commit comments

Comments
 (0)