Skip to content

fix: give each configureManualApproval call its own approval client - #59

Open
breken-ai wants to merge 1 commit into
onecli:mainfrom
breken-ai:fix/approval-restart-stale-loop
Open

breken-ai wants to merge 1 commit into
onecli:mainfrom
breken-ai:fix/approval-restart-stale-loop

Conversation

@breken-ai

Copy link
Copy Markdown

What is the current behavior?

OneCLI creates one ApprovalClient in its constructor, and every configureManualApproval call starts that same instance. stop() sets the shared running flag to false and aborts the current poll.

If you stop a handle and then call configureManualApproval again, for example to swap the callback, the new start() sets running back to true synchronously, before the stopped loop has seen the aborted poll. When the stopped loop gets to its catch, if (!this.running) return is false, so it backs off for 5s and keeps polling. After that, both loops take pending approvals, and the stopped handle's callback keeps deciding some of them. In the test below, it denies a request that the new callback would have approved.

The stopped loop also overwrites the shared abortController, so a later stop() aborts only one of the two polls.

What is the new behavior?

Each configureManualApproval call gets its own ApprovalClient, and the handle stops that client. org.configureManualApproval already works this way. A stopped handle stays stopped, whatever other calls do afterwards.

This is independent of #58, which moves the gateway URL resolution into the poll loop. The two PRs touch different files.

Additional context

test/approvals/configure.test.ts registers a callback, stops it, registers a second one, and then answers every poll that is still open with one pending request. It checks that only the second callback receives the request.

Checked locally on Node 22 with pnpm 10.30.1:

Check Result
New test against unpatched main (6579233) failed: the stopped callback got ap-1
New test with this change passed
pnpm test 132 passed (11 files)
pnpm typecheck passed
pnpm build passed

Not tested against a running OneCLI instance.

OneCLI shared one ApprovalClient across calls. stop() only clears the
shared running flag, so calling configureManualApproval again right
after stop() set it back before the stopped loop checked it. That loop
backed off, kept polling, and passed approvals to the stopped handle's
callback. Create a client per call, as org.configureManualApproval
already does.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant