Skip to content

Commit 33aa344

Browse files
anandgupta42claude
andcommitted
fix: [#834] address fourth-pass re-review — clarify lazy-subscribe semantics + accurate warn copy
Reviewer caught three documentation/copy issues that survived earlier passes: 1. Comment claimed "subscribing at module load is the established pattern" but the code subscribes lazily on first call. Rewrote the comment block to describe what the code actually does, plus the deliberate no-retry trade-off on subscribe failure (silent retry would re-throw every call). 2. Warn message said "the list will be discarded if you exceed 50 calls." Misleading — the refuse branch preserves the existing list (returns it in metadata). Changed to "further updates will be refused" and added "(Your current list is preserved.)" so the agent doesn't conclude its work is at risk. 3. `clearTodoWriteCounter` had no documented access-control rationale. Added one-line note that no auth check is needed (single local user, no remote callers, same privilege boundary as any in-process import). No behavior change — pure documentation + user-facing string. 12/12 tests pass; marker check clean. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
1 parent 1600efa commit 33aa344

1 file changed

Lines changed: 18 additions & 6 deletions

File tree

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

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,17 @@ export const TODOWRITE_WARN_THRESHOLD = 25
3232
export const TODOWRITE_REFUSE_THRESHOLD = 50
3333

3434
// Clear counters on session deletion so daemon-mode processes don't
35-
// accumulate entries indefinitely. Subscribing at module load is the
36-
// established pattern in `share/share-next.ts` and `session/projectors.ts`.
35+
// accumulate entries indefinitely. Subscribing lazily on first call avoids
36+
// requiring an init step in callers — safe because Node is single-threaded
37+
// and `recordTodoWriteCall` has no awaits before the guard flips, so two
38+
// concurrent first-calls cannot both enter the subscribe block.
39+
//
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.
3746
let _subscribed = false
3847
function ensureSessionDeletedSubscription(): void {
3948
if (_subscribed) return
@@ -43,8 +52,7 @@ function ensureSessionDeletedSubscription(): void {
4352
todoWriteCallsBySession.delete(evt.properties.info.id)
4453
})
4554
} catch {
46-
// Bus may not be initialized in some test contexts; the counter still
47-
// works correctly for the in-memory case. Subscription is best-effort.
55+
// See comment above — subscription is best-effort, no retry by design.
4856
}
4957
}
5058

@@ -80,6 +88,10 @@ export function recordTodoWriteCall(sessionID: string): {
8088
* counter cleared without ending the session. The operator can call this
8189
* from a debug context. Sessions reset automatically on `session.deleted`,
8290
* so most users never need this.
91+
*
92+
* No auth check: the CLI runs as a single local user with no remote callers;
93+
* the worst case is a user resetting their own session's counter. Same
94+
* privilege boundary as any other in-process import.
8395
*/
8496
export function clearTodoWriteCounter(sessionID: string): void {
8597
todoWriteCallsBySession.delete(sessionID)
@@ -175,8 +187,8 @@ export const TodoWriteTool = Tool.define("todowrite", {
175187
`${JSON.stringify(params.todos, null, 2)}\n\n` +
176188
`WARNING: todowrite has been called ${decision.count} times this session. ` +
177189
`Typical usage is 5-15 calls. Consider whether you're updating the list ` +
178-
`more often than needed — the list will be discarded if you exceed ` +
179-
`${TODOWRITE_REFUSE_THRESHOLD} calls.`,
190+
`more often than needed — further updates will be refused if you exceed ` +
191+
`${TODOWRITE_REFUSE_THRESHOLD} calls. (Your current list is preserved.)`,
180192
metadata: {
181193
todos: params.todos,
182194
warning_emitted: true,

0 commit comments

Comments
 (0)