Skip to content

fix(watch-pr): cap polling sleeps at the deadline - #666

Open
rudycelekli wants to merge 1 commit into
cursor:mainfrom
rudycelekli:fix/watch-pr-deadline-sleep
Open

rudycelekli wants to merge 1 commit into
cursor:mainfrom
rudycelekli:fix/watch-pr-deadline-sleep

Conversation

@rudycelekli

@rudycelekli rudycelekli commented Oct 16, 2026 •

Copy link
Copy Markdown

Problem

watch-pr --timeout 5 can wait through the entire default 60-second polling sleep before returning TIMEOUT. The same overrun occurs during queued polling and query-error backoff, despite the flag being documented as a deadline.

Change

Cap each polling/backoff sleep at the time remaining until the configured deadline. A zero timeout keeps its existing unlimited behavior. This bounds deliberate sleeps; it does not cancel an already-running GitHub query. Regenerate the Claude Code harness.

Verification

  • Original source: 15 focused controls pass and all 3 deadline regressions fail, each sleeping 60 seconds on an advancing fake clock despite a 5-second deadline.
  • Changed source: all 18 focused tests pass; the full native script package passes 72 tests with Bun 1.4.3. An explicit unlimited-timeout control still sleeps the configured 60 seconds and reaches READY.
  • Strict package typecheck, plugin validator, generated harness check, and git diff --check pass.
  • Tests use a deterministic clock and fixture reader; no real waiting, credentials, or hosted operations are required.

AI assistance: Codex implementation and local verification.


Note

Low Risk
Localized change to sleep timing in the shared polling loop; behavior only differs when a positive timeout is set, with regression tests on a fake clock.

Overview
Fixes watch-pr --timeout so it acts as a real deadline instead of allowing a full polling/backoff sleep (e.g. 60s) after the limit is already reached.

pollUntilTerminal in policy.ts now routes all waits through a helper that, when timeout > 0, sleeps only min(requestedSeconds, timeRemainingUntilDeadline). That applies to normal poll intervals and query-error retry backoff in single, stack, and queued-stack flows. timeout: 0 is unchanged—sleeps use the full configured interval.

New tests in policy.test.ts assert a 5s deadline with a 60s interval yields a single 5s sleep and TIMEOUT, across single/queued/query-retry modes, and that unlimited timeout still sleeps 60s before READY.

Reviewed by Cursor Bugbot for commit 4e0ecdb. Bugbot is set up for automated code reviews on this repo. Configure here.

Signed-off-by: Rudy Celekli <rudycelekli@users.noreply.github.com>
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