Skip to content

feat(review): prepare queue lease identity cutover - #1939

Merged
obviyus merged 3 commits into
mainfrom
fix/quiet-review-leases
Oct 12, 2026
Merged

obviyus merged 3 commits into
mainfrom
fix/quiet-review-leases

Conversation

@obviyus

@obviyus obviyus commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Result

Add dual lease-identity readers and publication fences before the public review-lease cutover. This is stage 1. Current review writers and contributor-visible status do not change. Stage 2 will remove the per-review public lease comment after these readers are deployed.

Problem

An automatic review creates a public “review started” lease comment and later removes it. The POST notifies subscribers. Both writes move item activity and need a released-lease freshness receipt. The reported example is openclaw/openclaw#132955 (comment).

The comment ID also orders same-source review generations. It is not only a mutex ID. Reusing an acknowledgement ID, setting the ID to zero, or putting a queue revision in lease_comment_id would lose that ordering check.

Approved design and rollout

  • Use the existing exact-review queue claim as the review lock. Queue ownership is distinct from publication ownership.
  • Record an explicit queue identity: item key, lease revision, claim generation, producer run ID and run attempt. Reports use review_queue_* fields. Durable review-version markers use v=2, lease_kind=queue and queue_* attributes. Queue reports keep a nonempty review_lease_owner and omit review_lease_comment_id; old exact-event readers therefore reject them as incomplete, not as tuple-less backlog.
  • Keep version 1 readers, comment ownership checks and released-comment receipts for stored and in-flight legacy reports. Queue reports never use the released-comment time window.
  • Compare queue generations only within one item key. Never compare queue revisions with GitHub comment IDs. Invalid or conflicting identities fail closed. A read-only proof can examine a valid legacy-to-queue transition. A writer can replace it only after the signed publication fence confirms the exact producer tuple.
  • Verify live head/source before queue mutations, including retry boundaries. Keep complete activity receipts and human-activity guards. Temporary authority failures retain their retryable error type.
  • The internal publication-authority response adds queueIdentity. Batch publication returns the review producer tuple, not the batch publisher tuple. Existing response fields and stored rows do not change.
  • Readiness and recovery-label backfill accept complete queue identities. A version-only manual or oversized review remains readable without granting readiness.
  • Read-only apply needs no publication credentials. Background mutation runs skip queue reports without a publication claim and continue with unrelated items.

Deploy these readers first. Before stage 2, drain old non-queue writers and ensure all hosted publishers obtain queue authority. Hosted non-queue writers must then fail closed. Keep dual readers during rollback while queue-format reports remain. Do not delete another run's lease to force cutover. No database schema or storage migration is needed. No production deployment or stored-row mutation was done here.

Editing an acknowledgement alone is not a lock: the lowest-ID election needs distinct comment IDs. GitHub documents that comment creation triggers notifications (https://docs.github.com/en/rest/issues/comments#create-an-issue-comment). Its edit documentation does not establish a general notification-free guarantee. This design does not depend on one.

Reader and writer map

Surface Role
clawsweeper-review-comment-leases.ts Public lease POST, winner confirmation, same-run reuse, owned DELETE, expired/superseded reap; reviewStartLeaseOwner parses the owner. Queue heartbeat rejects stale owners before public work.
clawsweeper-command-operations.ts, sweep.yml Reservation CLI, supplied owner/comment ID, expiration PATCH and cleanup. Command acknowledgements already have a queue-only path. This PR does not edit the workflow.
clawsweeper-review-command-workflow.ts, review preparation/lease helpers Start exclusion, supplied-lease election, cache reservation timestamps, report identity and owned cleanup.
Apply decision/lease/review guards Preserve a competing lease, adopt a matching completed-review lease, acquire/verify apply and paired-item locks, check source and stale verdicts around mutations. Queue reports use the publisher fence instead.
Review comment state, record metadata, queue-response CLI, batch preparation Durable tuple parsing, same-source generation ordering, newest-comment selection and current/invalid/legacy report classification.
Report document, review automation/publication and readiness helpers Report metadata and durable markers, bounded fallback identity, pass/readiness eligibility. Legacy report writers remain unchanged.
Comment-router admission Trusted active leases and mutation command owner/comment identity. Queue command writer cutover belongs to stage 2.
Apply source freshness Own-lease timestamps, exact durable-generation receipt, five-minute released-comment receipt, complete source/timeline/head/activity receipt and no-human-activity checks. The release window is legacy-only.
Recovery-label backfill Reads completed review versions after interrupted cleanup; now accepts strict v2 queue versions while retaining v1.
Worker exact-review queue /claim rejects another run and mismatched/expired lease ID or revision, then rechecks after admission. Heartbeat checks item, lease, revision, generation, run, attempt and source head. Completion and publication retain separate fences.
Bay and telemetry Bay reads queue lifecycle projections, not public lease markers. Existing lifecycle/run links stay unchanged. The added authority response is internal. No Bay contract, browser call or mutation control changes.

What contributors see

Item/path Before After stage 1 Planned after stage 2
Automatic PR Eyes reaction, progress edit in the existing acknowledgement, temporary lease comment, final review Same Eyes reaction, existing acknowledgement progress edit and final review; no lease comment
Scheduled automatic issue Eyes reaction, temporary lease comment, final review Same Eyes reaction is the only start signal; final review remains; no new acknowledgement or lease comment
Command review Eyes reaction and existing command acknowledgement progress Same Same existing status surfaces; no new comment

Stage 2 must prove the reaction and PR acknowledgement progress write with the lease comment absent. That visible cutover is not claimed by this reader-only PR.

Real-behavior proof

Frozen head: fc2005a658870e2ce4ef49b617ad30b397f4f70d; the runtime receipt reports dirty: false. The candidate was formatted once before verification; the recorded proof-change patch hash is e448c09687c2dbbcf1850ecd31eb4ca0b9992ebeb1ae545fb5763050cb18f673. Verification does not rewrite source.

Surface: the shipped apply-decisions CLI, including its real GitHub retry path, plus the Durable Object implementation with repository SQLite test storage. The successful fixture starts with a valid version-only legacy manual review and a queue-format close proposal. External GitHub/model processes are controlled services; no product function is replaced in the CLI path.

Command/environment: Crabbox 0.74.0, Docker-backed local-container, node:24-bookworm, 4 CPUs, Node v24.21.0. Run scripts/e2e/queue-review-proof.sh /inputs/latest-stable.tar through crabbox run --provider local-container --local-container-image node:24-bookworm --local-container-cpus 4 --no-hydrate --timing-json, with the pinned v0.3.0 git archive mounted read-only at /inputs/latest-stable.tar and artifact downloads enabled. Current dependencies use pnpm 12.4.1; stable dependencies use pinned pnpm 10.33.2 and its frozen lockfile.

Image: sha256:3d27e5c11e5786e309ec3e03f93ae536eb36e6e5eb3714d5eb3300a36157add0.

Lease/run: cbx_30a5d10cf053 / run_ab2ec1248604105726eb48701ddc36d1.

Claim/scenario Observed result Artifact/trace
Valid queue producer applies its report Existing review is synced; CLI finishes with closed; zero public lease POSTs result.json, apply-requests.jsonl
Competing run reaches the shipped CLI Exit 1; authority 409; zero GitHub mutation requests and effects negative_apply_cases.competing-run, queue-requests.json
Reassigned generation reaches the shipped CLI Exit 1; authority 409; zero GitHub mutation requests and effects negative_apply_cases.stale-generation, queue-requests.json
Authority is revoked during a real mutation retry Valid authority first; first PATCH returns HTTP 503 without an effect; queue generation/run changes; production retry then gets authority 409. Exactly one failed GitHub request, zero effects, no request after revocation, no reported close negative_apply_cases.retry-revocation, retry-trace.json
Source changes before its webhook reaches the queue Live PR-head check blocks the old publisher result.json
Own acknowledgement/proof/publication writes remain fresh Owned acknowledgement receipt passes and successful CLI closes result.json, apply-requests.jsonl
Unfenced read-only/background apply remains usable Both processes exit 0; neither mutates GitHub result.json
Latest stable stored data survives upgrade Real v0.3.0 review, retain and publish CLIs generate the report and generic durable marker. Current reader selects the same comment bytes. Current read-only apply preserves all three stored files and requires a fresh review upgrade-result.json, identical original/final manifests

Compact final-effect observations:

{"head":"fc2005a658870e2ce4ef49b617ad30b397f4f70d","dirty":false,"successful_apply":"closed","lease_posts":0,"competing_run":{"exit":1,"requests":0,"effects":0,"fence":409},"stale_generation":{"exit":1,"requests":0,"effects":0,"fence":409},"retry_revocation":{"exit":1,"requests":1,"first_request_status":503,"effects":0,"last_fence":409}}

The retained, redacted artifacts are under .artifacts/quiet-review-stage1-boundaries/. SHA-256: result 0510d8ece9e0eeda185b7edf618412ef35b74802333bc17283d949b979388724; queue trace 0dd319bc520a24795c229e2305db1f4dddae1cc7d3efec2b7dd760b7f66d30a1; retry trace 2fed222b8c14b2cecb472ba058a2a822a000ba1ec39ced54f0f471a760bdedb9; upgrade result b4f137b4a79c5cecb4a537418db60bb6f4bf3c2b33c12ed5e1107b4617014299. The original and final storage manifests both hash to e67b5cc9bbcb1983a2f5b802a4a655163b99477f2db8c13812d7f3531aa59b28.

Stable-data compatibility boundary

Latest stable is v0.3.0, commit a3469c99f6a8362d57771f750262f6f9c798d649; archive SHA-256 3920599d1230004ac8e89780edfc2a9fb86d63c199a18be7be36104b1b65da82. That release predates both typed review_record data and causal v1 version/state markers. It cannot honestly generate a v1 causal marker.

The actual stable report, durable comment JSON and durable body remain byte-identical after the current reader and read-only apply. Current apply reports review_record: missing record; fresh review required, rather than rewriting or applying unverified old data. This restriction already exists on the unchanged base in src/review-record.ts and src/clawsweeper-apply-close-decision.ts; this PR does not add a historical schema migration. Modern stored v1 causal markers are separately exercised by the successful legacy-manual-to-queue CLI case.

The symlinked macOS temporary-directory case also passed with TMPDIR=/tmp after the scratch path was canonicalized. Only that affected native upgrade validation was rerun for the path repair.

Limits: controlled services are not live GitHub, production authentication, model quality or hosted-workflow proof. Reaction/progress write steps are deliberately not changed or claimed in stage 1. No live target item or Worker was changed. Bay's data contract is unchanged.

Validation and review disposition

  • pnpm run check:fast: passed.
  • Relevant dual-reader, readiness, lease/freshness, authority, recovery and queue lifecycle tests passed. The handwritten helper retry-loop test was removed and replaced by the shipped-CLI retry-revocation proof; the remaining authority file passed 41/41. No deadline was increased.
  • Full node suite during implementation: 5,854 tests, 5,822 passed, 31 skipped, one untouched ETag fixture failed while parsing a raw HTTP response. After trash dist && pnpm run build:all, the lead-requested isolated ETag run passed 27/27. No ETag code was changed. A loaded combined authority run also hit a process-start timeout; the isolated file passed. These local results are not presented as a green full-suite run; required CI was green on the prior implementation head and runs again for this proof-only commit.
  • Codex findings about live source checks, retryable authority errors, readiness, state-free manual/oversized markers, read-only transition and recovery backfill were accepted and fixed with focused coverage.
  • Hosted proof asks were accepted: competing/reassigned owners and retry revocation now run through the shipped CLI before final GitHub effects. Latest-stable stored-data retention now has a real old-to-current run with byte hashes. The security and merge-risk concerns are supported by zero-effect denial traces, not an isolated guard or handwritten retry loop.
  • Hosted exact-head review and green required CI remain the landing gate.

@clawsweeper

clawsweeper Bot commented Oct 12, 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: 🚨 security-boundary 🚨 Merging this PR could weaken sandboxing, authorization, credentials, or sensitive data. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 12, 2026
@clawsweeper

clawsweeper Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR adds queue-based review identity readers and publication fences while retaining existing comment leases and review writers.

Example: Publish a queue-format review for openclaw/openclaw item 74 from run 1074, attempt 1.

  • Before: Readers require a public lease comment ID to recognize the review generation.
  • After: Readers accept the complete queue identity and verify current publication authority before mutations.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) Useful staged work with supplied shipped-CLI authority proof, explicit stable-data compatibility, focused boundary coverage, and no actionable finding.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The supplied exact-head receipt exercises the shipped apply-decisions CLI and real queue authority transport in Crabbox local-container, lease cbx_30a5d10cf053, run run_ab2ec1248604105726eb48701ddc36d1, using node:24-bookworm image sha256:3d27e5c11e5786e309ec3e03f93ae536eb36e6e5eb3714d5eb3300a36157add0. Authorized publication closes the fixture without lease POSTs; competing and reassigned owners dispatch zero mutations; revocation after a failed 503 blocks the production retry with zero effects. The inspected drivers support these observations. External GitHub/model processes are controlled; live GitHub permissions, production authentication, notifications, and hosted deployment are outside this proof.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Feature · Worth it: Yes · Fix scope: Complete
User problem: Automatic review lease comments notify subscribers and add activity churn despite existing queue coordination.
Reason: The supplied maintainer-authored direction authorizes this preparatory stage, and the body clearly reserves visible notification reduction for stage 2.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: the staged queue-identity preparation is useful, preserves legacy publication safeguards, and has no actionable finding.

Priority: P2
Reviewed head: fc2005a658870e2ce4ef49b617ad30b397f4f70d

Before merge

None.

Findings

None.

Agent review details

How this fits together

The exact-review queue coordinates review producers and publishers; report readers carry producer identity into durable comments, and apply guards validate ownership, source freshness, and activity before GitHub effects.

flowchart LR
  A[Review producer] --> B[Exact review queue]
  A --> C[Review report]
  B --> D[Publication authority]
  C --> E[Apply CLI]
  D --> E
  E --> F[GitHub effects]
Loading

Technical review

Best possible solution:

Land the dual-reader preparation, then perform the separately scoped writer cutover after compatible publishers are deployed.

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

Current main source shows the public lease POST path; the supplied current-head CLI receipt demonstrates queue-format publication without those POSTs.

Is this the best way to solve the issue?

Deploying dual readers before changing writers preserves legacy compatibility and extends the existing publication authority without introducing a competing lock owner.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Durable review identity and generation ordering changes intended behavior with a stated reason (fix(review): publish exact merge readiness state #1059: Prevent older generations and identityless publication fallbacks from granting readiness or publication authority.)
  • Manual and queue publication authority keeps the original intent (4a85712: Retain completed manual reviews after publisher failures while requiring current ownership and separate producer lineage.)
  • Released-comment freshness receipts keeps the original intent (2f77794: Avoid own lease deletion causing repeated source-drift reviews while preserving complete receipts and human-activity checks.)
  • Recovery-label reconciliation keeps the original intent (4dc8d1d: Clear obsolete recovery labels only after trusted completed publication and current-head chronology checks.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 4a85712 adds src/manual-publication-authority.ts:26 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 4a857127405c; files: src/manual-publication-authority.ts)

Review metrics

Metric Value Why it matters
Change distribution Production +548/-60; tests +881/-3; proof drivers +1064/-0 Most growth supports dual-format trust-boundary validation and controlled publication/upgrade proof.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This is a useful staged automation improvement that preserves current contributor-visible behavior.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (2 earlier review cycles)
  • reviewed 2026-10-12T01:42:45.498Z sha df85024 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-12T02:15:32.081Z sha fc2005a :: needs maintainer review before merge. :: none

Reviewed October 11, 2026, 10:20 PM ET / October 12, 2026, 02:20 UTC (Revision 3).

@clawsweeper clawsweeper Bot added proof: sufficient Contributor real behavior proof is sufficient. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. merge-risk: 🚨 security-boundary 🚨 Merging this PR could weaken sandboxing, authorization, credentials, or sensitive data. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Oct 12, 2026
@obviyus
obviyus merged commit 142b1e5 into main Oct 12, 2026
36 checks passed
@obviyus
obviyus deleted the fix/quiet-review-leases branch October 12, 2026 02:21
obviyus added a commit that referenced this pull request Oct 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal priority bug or improvement with limited blast radius. proof: sufficient Contributor real behavior proof is sufficient. rating: 🦞 diamond lobster Very strong PR readiness with only minor 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