Repository navigation
fix(shell): the rate-limit wait stops when the agent cancels the call - #4168
Conversation
Pacing landed in amd#4023 but sleeps straight through cancellation. Every tool runs inside `_call_tool_bounded`'s window, which sets a cancellation flag when the call overruns and stops waiting for the worker — so a wait of up to a minute that ignores the flag keeps a worker alive past its own timeout, running the command nobody is waiting for any more (amd#2600), and delays a user's Stop by the rest of the wait. The wait now runs in 0.25s slices and returns as soon as the flag is set. `docs/spec/shell-tools-mixin.mdx` still taught the pre-amd#4023 contract — a rate-limited 4th command, a caller-side sleep-and-retry loop, and a result shape with no `waited_seconds` — so it now matches what the code does. Co-Authored-By: Claude Opus 5 <[email protected]>
|
Verdict: Approve with suggestions The rate-limit wait now happens in short slices and bails out as soon as the agent gives up on the call, instead of sleeping straight through — that's the right fix, the cancellation check lands before the first sleep so an already-abandoned call never sleeps at all, and the new test pins both the total wait and the slice size. Nothing here blocks merge. Two things worth a follow-up:
Also worth a cheap test: the new one only covers the case where the call is already cancelled before any waiting happens, so nothing proves the "stops partway through a long wait" behaviour the fix is actually for. Real-world evidenceNo evidence bundle was produced for this PR ( 🔍 Technical details🟡 Cancellation is reported as a rate-limit refusal (
|
A shell command held back by the rate limit now waits in short slices and gives up the moment the agent cancels the call. Before this, it slept straight through: a user who pressed Stop waited out the rest of the wait, and a call that overran its own timeout left a worker running a command nobody was waiting for any more — the stray-process problem #2600 exists to prevent.
The pacing behaviour itself (#4023) is unchanged; only its interruptibility is. The mixin's spec had also kept describing the pre-#4023 contract — a refused 4th command, a caller-side sleep-and-retry loop, and a result shape without
waited_seconds— so anyone reading it got the opposite of what the code does.Test plan
pytest tests/unit/test_shell_rate_pacing.py tests/unit/test_shell_guardrails.py tests/unit/test_skill_binary_grants.py— 409 passed, 1 skipped.test_a_stop_during_the_wait_ends_it_instead_of_sleeping_onfails onmain(the wait sleeps on) and passes here.🤖 Generated with Claude Code