Skip to content

perf(queue): hold organic churn longer on actively re-reviewed items - #1708

Merged
steipete merged 9 commits into
mainfrom
perf/active-item-review-debounce
Oct 5, 2026
Merged

steipete merged 9 commits into
mainfrom
perf/active-item-review-debounce

Conversation

@steipete

@steipete steipete commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Items that already completed two exact reviews in the last hour now coalesce their next organic push/edit for 10 minutes (capped at 15 minutes from the first pending enqueue) instead of 90 s–3 min. A churning PR gets one review of its latest revision instead of one full, often revoked, review per push. Commands, publication, scheduled intake, repair follow-ups and recovery keep their timing.

Root cause

Production (2026-09-28): in 1.5 h, 305 full exact reviews covered only 200 unique items, and 65 items were reviewed 2+ times. Part of that is legitimate churn: PRs pushed repeatedly (e.g. openclaw/openclaw#159945, openclaw/openclaw#159516 and openclaw/openclaw#159895 each had 3 heads in 1.5 h).

The queue debounce is 90 s, extended to at most 3 min. After that, every new source revision dispatches a full ~7 min review, and a later push revokes the in-flight one (superseded_total is 50,054 of 323,303 enqueued). Every started review also debits the scheduled review budget (at Codex generation start since #1738), so churn starves backlog coverage.

Change

  • exactReviewQueueDebouncedAttempt gains an activeItem mode: max(ordinary, min(now + ACTIVE_DEBOUNCE, firstPendingEnqueue + ACTIVE_DEBOUNCE_MAX)). It never shortens the ordinary debounce.
  • An item is active when it completed EXACT_REVIEW_ACTIVE_ITEM_REVIEW_THRESHOLD (2) successful review generations within EXACT_REVIEW_ACTIVE_ITEM_WINDOW_MS (1 h).
  • Only review-triggering GitHub item actions (opened, reopened, edited, synchronize, ready_for_review, converted_to_draft, unlocked, unlabeled) without command context or publication are eligible. They are checked only on the two ingress paths: a new item, and a merge into a pending or just-revoked item.
  • Unchanged: commands, manual reviews, publication and scheduled lanes (still immediate); recovery, dead-letter/parked/direct-lifecycle requeue and branch_repaired (ordinary timing); the immediate first PR opened/ready_for_review.
  • A superseding push still revokes the in-flight lease immediately. Only the successor's nextAttemptAt moves.
  • Completion history is stored in a new additive table, exact_review_queue_review_completions:
    • keyed (item_key, run_id, run_attempt);
    • written best-effort after /complete, direct-publication receipt conversion and /reconcile;
    • pruned to the window.
  • Stores without the table or without history behave exactly as before. Rollback ignores the table.
  • Next-wake reads the delayed nextAttemptAt: one wake at the due time, no polling. The 15-min maximum hold stays below the 30-min soft queue-pressure age.
  • dashboard/wrangler.toml sets EXACT_REVIEW_ACTIVE_ITEM_REVIEW_THRESHOLD=2, EXACT_REVIEW_ACTIVE_ITEM_WINDOW_MS=3600000, EXACT_REVIEW_ACTIVE_ITEM_DEBOUNCE_MS=600000 and EXACT_REVIEW_ACTIVE_ITEM_DEBOUNCE_MAX_MS=900000. docs/limits.md documents the rule and overrides, and changelog.d/1708-active-item-review-debounce.md adds the changelog entry.

Behavior proof

  • Claim: after two completed reviews in the last hour, three organic pushes over 8 minutes produce one dispatch of the latest revision after the active-item debounce; on main each produces a dispatch after ~90 s and the earlier reviews are revoked. Commands stay immediate, first-time items keep 90 s, held items do not poll, and a store written by main upgrades in place.
  • Surface: the real ExactReviewQueue Durable Object in workerd (Miniflare, SQLite DO). Real enqueue, alarm dispatch, claim, complete and stats; loopback GitHub fixture with a synthetic RSA credential; production env values.
  • Command: node scripts/proof-active-item-debounce.mjs c46e375c825223a7b3fbcf592794dc949065f0f8 <tools> <fresh-output-dir>
  • Environment: local; Node 24.21.0, workerd 1.20260701.1, Miniflare 4.20260701.0. Base c46e375c82 is current main, including fix(queue): charge the review budget at Codex generation start #1738. Head e78f8bf0ec is the integrated branch with a clean tree. The pushed head a3cdbb6d5b changes only the proof README.
  • Artifact: result.json (sha256 aace6983d4776d23cb10ae21e4e44e89e7a6f7b7453ed6de2de05f57dbffe6c2) records every enqueue, wake, dispatch and completion. The table matches the earlier run against 8d659e7cb9 (artifact sha256 b0ec8866…a9f8b).
Measure main this PR
Dispatches after the 2 completed reviews 3 (21.5 / 25.5 / 29.5 min) 1 (35.0 min, latest head)
Reviews revoked by a newer push 2 0
Waits for pushes at 20 / 24 / 28 min 90 / 90 / 90 s 600 / 600 / 420 s (15-min cap)
Queue wakes, 20–35 min 3 2
Explicit command dispatch delay 1 s 1 s
First-time PR dispatch delay 90 s 90 s
Store written by main, next edit n/a 90 s, then dispatched and recorded

Limits: synthetic GitHub, credential, clock and queue data. The review is modeled as a 7-minute claim-to-complete lease; no workflow, inference, production state or GitHub mutation. Unit tests cover the recovery bypass, window expiry and the stale-heartbeat 409.

Maintainer decision

Peter, 2026-10-04: the active-item debounce is approved for production. After two successful reviews within an hour, the next organic event waits 10 minutes, capped at 15 minutes from the first pending enqueue, while explicit commands stay immediate.

Integration with current main

  • Current main was merged twice, the second time after fix(queue): charge the review budget at Codex generation start #1738 landed.
  • Only CHANGELOG.md conflicted. Its entry now lives in a changelog.d fragment, following the repository's fragment policy.
  • The queue code merged cleanly. The debounce only moves nextAttemptAt for eligible organic events. It does not touch:
    • budget charging (generation start, scheduled prepayment);
    • the source_drift_requeue loop breaker, since that action is not in the organic set;
    • revision allocation;
    • the runaway counter.
  • The workerd proof above was rerun on the integrated head against current main, including the persisted-store upgrade case.

Validation

  • Four new tests in test/dashboard-worker-queue-policy.test.ts: active delay and 15-min cap with alarm timing; command/recovery/stale-window bypass; immediate revocation with a delayed successor; additive migration. Three fail on main and all pass here.
  • The first CI run on the integrated head failed two loop-breaker tests from feat(queue): park source-drift review loops and alert on runaway reviews #1732 in test/exact-review-source-drift-loop.test.ts. They complete several reviews of one item, send an organic edited event, and expect an immediate dispatch. The active-item hold correctly delayed that dispatch by 10 minutes.
    • The shared admission harness (test/dashboard-worker-harness.ts) already zeroes the ordinary dispatch debounce. It now also sets EXACT_REVIEW_ACTIVE_ITEM_WINDOW_MS: "0", so the hold is off unless a test opts in.
    • The active-item tests use their own harness and set the window explicitly. Production behavior is unchanged.
  • On head e71e8d5555, pnpm run build:all, check:static and lint pass. Every test/exact-review-*, test/dashboard-* and workflow suite passes: 1,322 tests, 0 failures, 5 skipped.
  • The earlier full pnpm run check gate covered static checks, limits, docs, dashboard strict, queue boundary, format, build, lint and changed-coverage; all passed. CI reruns it on this head. The full suite has 7009 passing and 1 pre-existing environmental failure (test/apply-drift-refresh.test.ts needs bash ≥ 4 mapfile; it fails identically on main on macOS bash 3.2 and passes with bash 5). Coverage is 87.67 / 78.34 / 90.99.

OpenClaw Bay

Not affected. No public field, backoff reason, projection or control is added; held items keep the existing dispatch_debounce backoff reason and existing pending counts. The history table is internal to the queue DO.

Risks / rollback

  • Risk: a legitimately active PR waits up to 10–15 min longer for its next automatic review. Explicit @clawsweeper re-review still bypasses the wait. Automerge follow-ups with a command status marker stay immediate.
  • Tuning: EXACT_REVIEW_ACTIVE_ITEM_WINDOW_MS=0 disables the rule. The other three vars tune the threshold and delays.
  • Rollback: a plain revert. The additive table is ignored by old code, and no queue item schema changed.

Review

Codex /review (autoreview, branch mode against origin/main at c46e375c82, P0–P1 threshold): clean on head e71e8d5555 (with the harness fix) and before that on a3cdbb6d5b, with no accepted or actionable findings. It was clean earlier against 8d659e7cb9.

An item that already completed EXACT_REVIEW_ACTIVE_ITEM_REVIEW_THRESHOLD (2)
successful review generations within EXACT_REVIEW_ACTIVE_ITEM_WINDOW_MS (1 h)
now waits EXACT_REVIEW_ACTIVE_ITEM_DEBOUNCE_MS (10 min) from its latest
organic source revision before dispatch, capped at
EXACT_REVIEW_ACTIVE_ITEM_DEBOUNCE_MAX_MS (15 min) from the first pending
enqueue. Repeated pushes coalesce into one pending entry and are reviewed once
with the latest revision instead of starting (and revoking) a full review per
push.

Only review-triggering GitHub item actions count as organic. Commands,
publication, scheduled intake, repair follow-ups, recovery work, first
reviews, items below the threshold and immediate PR openings keep their
existing timing. A superseding event still revokes an in-flight lease
immediately; only the next dispatch waits. The active delay never shortens
the ordinary debounce.

Completion history lives in an additive exact_review_queue_review_completions
table keyed by item and workflow run, written best-effort after /complete,
direct-publication conversion and workflow_run reconciliation, and pruned to
the window. A store without history behaves exactly as before. Next-wake
reads the delayed nextAttemptAt, so held items do not poll.
@clawsweeper

clawsweeper Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@clawsweeper clawsweeper Bot added P2 Normal priority bug or improvement with limited blast radius. merge-risk: 🚨 automation 🚨 Merging this PR could break CI, automerge, proof capture, label sync, or automation. proof: sufficient Contributor real behavior proof is sufficient. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 28, 2026
@clawsweeper

clawsweeper Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 4, 2026, 8:44 PM ET / October 5, 2026, 00:44 UTC (Revision 8).

ClawSweeper review

What this changes

The review queue delays repeated automatic updates longer on frequently reviewed items, using recent completion history while preserving explicit-command and recovery timing.

Merge readiness

✅ Ready for maintainer review

This remains useful work distinct from the merged queue fixes. The pinned patch has no actionable correctness finding, and the recorded production-delay approval covers its current behavior.

Priority: P2
Reviewed head: e71e8d55550c1755a095c8ffea197ca67826a948

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused implementation with strong recorded queue-runtime and upgrade evidence, and no actionable findings.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): Recorded workerd execution exercises the real queue and HTTP transport through enqueue, dispatch, claim, completion, and SQLite storage: organic churn dispatches fall from three to one while commands and fresh items retain their timing. The persisted baseline-store upgrade succeeds; production code is unchanged since that proof. Coverage excludes workflow execution, inference, and live GitHub mutations.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): Recorded workerd execution exercises the real queue and HTTP transport through enqueue, dispatch, claim, completion, and SQLite storage: organic churn dispatches fall from three to one while commands and fresh items retain their timing. The persisted baseline-store upgrade succeeds; production code is unchanged since that proof. Coverage excludes workflow execution, inference, and live GitHub mutations.
Evidence reviewed 8 items Pinned introduction and merge result: Inspected the introduced delta from pinned main to the exact PR head. The verified test merge records main followed by the exact head as its raw parents and contains the same eight changed files.
Still necessary on pinned main: Pinned main implements only the ordinary 90-second debounce with a three-minute cap; it lacks the completion-history-based extension. The merged work at #1732 and #1738 addresses separate loop-breaking and budget-charging behavior.
Timing and completion-path inspection: The two enqueue paths consult recent completions only for eligible organic actions. Immediate decisions bypass the delay, existing lease revocation remains intact, recovery callers retain the ordinary helper defaults, and completion recording covers complete, direct-publication conversion, and reconciliation.
Findings None None.
Security None None.

How this fits together

ClawSweeper's review queue receives GitHub events and review commands, coalesces updates, and dispatches review workflows. This change adjusts dispatch timing using successful review completions stored in the queue's SQLite database.

flowchart TD
  A[GitHub updates and commands] --> B[Review queue]
  C[Recent review completions] --> D[Active item check]
  B --> D
  D --> E[Ordinary or extended delay]
  E --> F[Scheduled queue wake]
  F --> G[Review workflow dispatch]
  G --> C
Loading

Before merge

None.

Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Production and validation LOC production +234/-3; tests +333/-0; proof harness +460/-0 Production growth implements completion history and bounded timing; most added code supports validation.
Recorded churn dispatches 3 baseline → 1 candidate The real workerd queue scenario demonstrates fewer redundant reviews while retaining the latest revision.

Technical review

Best possible solution:

Keep one bounded pending review for active organic churn, with immediate operator commands and unchanged recovery behavior.

Do we have a high-confidence way to reproduce the issue?

Not applicable as an existing-behavior bug: this adds an approved queue policy; the recorded workerd comparison demonstrates the targeted churn scenario.

Is this the best way to solve the issue?

Yes. Extending the existing debounce at organic ingress keeps one scheduling mechanism and preserves command, publication, and recovery behavior.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against c46e375c8252.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This is a bounded queue-efficiency improvement with preserved command and recovery paths.
  • merge-risk: 🚨 automation: Automatic reviews of active items intentionally wait up to fifteen minutes; the recorded approval explicitly accepts this timing tradeoff.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): Recorded workerd execution exercises the real queue and HTTP transport through enqueue, dispatch, claim, completion, and SQLite storage: organic churn dispatches fall from three to one while commands and fresh items retain their timing. The persisted baseline-store upgrade succeeds; production code is unchanged since that proof. Coverage excludes workflow execution, inference, and live GitHub mutations.
  • proof: sufficient: Contributor real behavior proof is sufficient. Recorded workerd execution exercises the real queue and HTTP transport through enqueue, dispatch, claim, completion, and SQLite storage: organic churn dispatches fall from three to one while commands and fresh items retain their timing. The persisted baseline-store upgrade succeeds; production code is unchanged since that proof. Coverage excludes workflow execution, inference, and live GitHub mutations.

Evidence

What I checked:

  • Pinned introduction and merge result: Inspected the introduced delta from pinned main to the exact PR head. The verified test merge records main followed by the exact head as its raw parents and contains the same eight changed files. (dashboard/exact-review-queue.ts:2489, e71e8d55550c)
  • Still necessary on pinned main: Pinned main implements only the ordinary 90-second debounce with a three-minute cap; it lacks the completion-history-based extension. The merged work at feat(queue): park source-drift review loops and alert on runaway reviews #1732 and fix(queue): charge the review budget at Codex generation start #1738 addresses separate loop-breaking and budget-charging behavior. (dashboard/exact-review-queue.ts:16414, c46e375c8252)
  • Timing and completion-path inspection: The two enqueue paths consult recent completions only for eligible organic actions. Immediate decisions bypass the delay, existing lease revocation remains intact, recovery callers retain the ordinary helper defaults, and completion recording covers complete, direct-publication conversion, and reconciliation. (dashboard/exact-review-queue.ts:13640, e71e8d55550c)
  • Real queue behavior and upgrade proof: The captured PR body and proof README report real workerd SQLite Durable Objects using loopback HTTP: three baseline churn dispatches become one latest-head dispatch, commands remain immediate, first-time items retain 90 seconds, and a baseline-written store resumes successfully. The inspected harness exercises production enqueue, alarm, dispatch, claim, completion, and storage. Receipt SHA-256 is reported as aace6983d4776d23cb10ae21e4e44e89e7a6f7b7453ed6de2de05f57dbffe6c2; the raw receipt was not supplied locally. Synthetic clock, GitHub responses, credentials, and modeled review duration limit the claim to the queue boundary. (docs/proof/active-item-debounce/README.md:8, e71e8d55550c)
  • Proof continuity and prior review: Production queue files and the proof script are unchanged from the documented proven integrated head. Since the prior reviewed head, only three lines disabling the active hold in the shared test harness changed. The previous completed review retained no findings; the new dedicated timing tests still explicitly exercise the active hold. (test/dashboard-worker-harness.ts:942, e71e8d55550c)
  • Accepted delay tradeoff and Bay boundary: The captured PR body records Peter's October 4 approval of the ten-minute organic hold capped at fifteen minutes, with explicit commands immediate. That acceptance matches the current configuration. The body also explains that Bay needs no change because public fields, controls, and the existing dispatch_debounce reason remain unchanged. (dashboard/wrangler.toml:86, e71e8d55550c)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • vincentkoc: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (7 earlier review cycles)
  • reviewed 2026-09-28T03:48:30.060Z sha 35cec97 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-28T06:17:24.515Z sha c73e9e7 :: blocked before merge. :: none
  • reviewed 2026-09-28T07:14:41.386Z sha aee02e4 :: blocked before merge. :: none
  • reviewed 2026-09-30T00:27:15.758Z sha 4511800 :: blocked before merge. :: none
  • reviewed 2026-10-03T10:27:18.505Z sha 4511800 :: blocked before merge. :: none
  • reviewed 2026-10-04T21:23:39.542Z sha 4511800 :: blocked before merge. :: none
  • reviewed 2026-10-04T23:39:29.401Z sha a3cdbb6 :: needs maintainer review before merge. :: none

@steipete
steipete merged commit dd58d9e into main Oct 5, 2026
17 checks passed
@steipete
steipete deleted the perf/active-item-review-debounce branch October 5, 2026 00:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 automation 🚨 Merging this PR could break CI, automerge, proof capture, label sync, or automation. P2 Normal priority bug or improvement with limited blast radius. proof: sufficient Contributor real behavior proof is sufficient. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant