Skip to content

fix(apply): accept receipt-backed own writes in deferred re-apply freshness - #1734

Merged
steipete merged 8 commits into
mainfrom
fix/receipt-based-freshness
Oct 1, 2026
Merged

steipete merged 8 commits into
mainfrom
fix/receipt-based-freshness

Conversation

@steipete

@steipete steipete commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

Summary

A close proposal that its exact-review producer keeps open (durable comment synced, close gate kept_open) ended in a ~23-minute source_drift_requeue loop whenever its direct publication was deferred. Examples: openclaw/openclaw#143911 (runs 36671559049 -> 36672608523 -> 36673368897) and openclaw/openclaw#139260 (run 36673226845). The batch publisher re-applied the same review and treated the producer's own writes as source drift. Apply freshness now accepts an updated_at moved only by ClawSweeper-recorded writes. Real external changes still block and requeue.

Root cause

The producer's last write is releasing its review lease, a DELETE of the lease comment after the durable comment PATCH. The deletion moves the PR updated_at and leaves no live comment to witness. The batch re-apply of the same pre-apply artifact therefore saw updated_at changed and recorded skipped_changed_since_review with sourceDriftVerified, which requeues a full review.

The deferral itself (invalid_direct_publication_plan: conflicting direct publication retry) is a separate queue defect and is not changed here. The ordinary-item revision allocator does not floor on directly published revisions, so a re-admitted item can reuse one, and the canonical tuple receipt correctly rejects the different bytes. That revision-reuse defect is tracked as a separate follow-up lane.

Change

  • Freshness. createApplySourceFreshness generalizes fix(apply): stop own acknowledgement edits from requeueing source drift #1715's acknowledgement witness into one receipt check. A post-snapshot update is automation-only when either:

    • a live ClawSweeper item-marker comment, or a ClawSweeper-actor timeline event, has exactly the latest updated_at; or
    • the review generation's own lease comment is gone, while the durable review comment carries this generation's clawsweeper-review-version marker (item, reviewed_at, source revision, lease owner, lease comment id), was synced after the snapshot, and the update follows the generation's last recorded write by at most five minutes.

    Both paths also require a matching complete source/timeline/head/review-activity receipt, and no non-automation comment, review comment or timeline event after the snapshot.

  • Policy. The AGENTS.md "Safety Rules" drift line now says that drift blocks apply unless the only change is the existing ClawSweeper review comment, or a ClawSweeper-recorded write for the item (docs/scheduler.md) while the complete source/timeline/head/activity receipt matches and no non-automation activity follows the review snapshot. docs/scheduler.md documents both receipt paths.

  • Proof harness. scripts/e2e/apply-source-drift-final-effect.mjs adds the #143911 producer-then-batch scenarios. Capture restores the durable comment's snapshot body from its read-only GraphQL edit history, and the seeded review lease stays live so the apply adopts it as production does.

Behavior proof

scripts/e2e/apply-source-drift-final-effect.mjs drives real gh against a stateful synthetic GitHub API seeded from read-only captures. Builds: baseline cac974b3e1 (origin/main), candidate 349741921f.

Receipts, seed hashes and limits are in docs/proof/receipt-based-freshness/README.md.

Validation

  • node --test test/apply-source-freshness.test.ts: 9/9 pass. The new positive cases fail on origin/main.
  • pnpm run check on the merged code head 606ffe5e65: exit 0 (7,133 tests, 0 fail).
  • Later commits changed only AGENTS.md, the e2e harness and proof docs. For those, the focused gate passed: freshness tests 9/9, lint:scripts, check:docs, check:changelog, format:check. Main did not move, so the full check was not re-run.

OpenClaw Bay: not affected. No queue, status, telemetry or dashboard data contract or public field changes.

Risks/rollback

  • The released-lease receipt cannot see a deletion's exact time. It is bounded to five minutes after the generation's last recorded ClawSweeper write, guarded by the complete activity receipt and the no-non-automation-activity check.
  • An exact revert of a body edit inside that window stays invisible. The content is then identical to what was reviewed.
  • The extra context read happens only on drift with a complete activity identity.
  • Rollback: revert the two fix(apply) commits and the AGENTS.md line. Freshness then returns to fix(apply): stop own acknowledgement edits from requeueing source drift #1715 behavior.

Follow-up: the queue revision-reuse defect behind conflicting direct publication retry is tracked as a separate lane.

Review

Codex /review (autoreview, branch mode against origin/main, P0–P1 threshold): clean on head 53deda6319, "patch is correct" (0.86). It confirmed that the new freshness exceptions require a matching complete review receipt and no visible non-automation activity after the snapshot.

Follow-up tracked separately: the "conflicting direct publication retry" deferral comes from exact-review revision reuse after direct publication. A re-admitted item can be allocated a revision it already published directly. That is a queue allocator defect with its own PR and proof; this PR intentionally does not loosen the direct-publication immutability check.

…shness

A close proposal that its exact-review producer kept open (durable comment
synced, close gate kept_open) ends with the producer releasing its review
lease, which deletes the lease comment and moves the PR updated_at. When
direct publication was deferred, the batch publisher re-applied the same
review, saw that bump as source drift, recorded skipped_changed_since_review,
and requeued a full source_drift_requeue review about every 23 minutes
(openclaw/openclaw#143911 runs 36671559049 -> 36672608523 -> 36673368897,
openclaw/openclaw#139260 run 36673226845).

Apply freshness now generalizes the acknowledgement witness from #1715 into
one receipt check for ClawSweeper's own writes. An update after the review
snapshot is automation-only when a ClawSweeper-recorded receipt for the item
accounts for the latest updated_at: a live ClawSweeper item-marker comment or
a ClawSweeper-actor timeline event (managed label edit) with exactly that
time, or the review generation's own lease comment is gone while the durable
review comment carries that generation's review-version marker (item,
reviewed_at, source revision, lease owner, lease comment id), was synced after
the snapshot, and the update follows the generation's last recorded write by
at most the five-minute apply-lease hold. Every receipt also requires the
complete source, timeline, head, and review-activity receipt to match and no
non-automation comment, review comment, or timeline event after the snapshot.
Human comments, title/body or label edits, PR reviews, and new heads still
block and requeue.

The real-transport e2e harness gains the #143911 producer-then-batch shape and
external-change controls.
@clawsweeper

clawsweeper Bot commented Oct 1, 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 P1 Urgent regression or broken agent/channel workflow affecting real users now. 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 Oct 1, 2026
@clawsweeper

clawsweeper Bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 1, 2026, 3:05 AM ET / 07:05 UTC.

ClawSweeper review

What this changes

ClawSweeper's apply lane accepts its own receipt-backed updates during deferred publication, with regression coverage, transport traces, and updated safety documentation.

Merge readiness

✅ Ready for maintainer review

This PR remains necessary: current main handles acknowledgement edits but still rejects the producer's released-lease update during deferred re-apply. The patch has no actionable correctness findings, and the recorded production-path proof supports the fix.

Priority: P1
Reviewed head: 53deda631901029d2673d248f15acf7046207932

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, well-supported repair with production-path transport evidence and no actionable findings.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (logs): Native gh exercises the compiled apply owner against a stateful synthetic API: the candidate accepts producer lease-release drift without duplicate substantive writes, while human comments, changed heads, and title edits still block. The recorded candidate has unchanged production code at this head; hosted queue publication and real GitHub mutation are outside the stated proof scope. No stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (logs): Native gh exercises the compiled apply owner against a stateful synthetic API: the candidate accepts producer lease-release drift without duplicate substantive writes, while human comments, changed heads, and title edits still block. The recorded candidate has unchanged production code at this head; hosted queue publication and real GitHub mutation are outside the stated proof scope. No stored-data contract changes.
Evidence reviewed 7 items Pinned change and current-main necessity: The introduced delta is cac974b..53deda6. Main has the acknowledgement-only witness; the branch adds item-marker/timeline witnesses and the generation-bound released-lease allowance. The earlier merged fix #1715 does not implement this deferred re-apply case.
Freshness and authority boundaries: The released-lease path requires the durable comment's item, review timestamp, source revision, lease owner, and lease comment ID to match the report. Both new witnesses require complete source/timeline/head/review-activity equality and reject visible non-automation activity. Existing newer-review, lease, close eligibility, and final-effect freshness guards remain intact.
Real production-path proof: The proof drives compiled non-dry-run apply-decisions and update-review-status through native gh 2.101.0 on Node v24.21.0/macOS against a stateful synthetic GitHub API. The baseline requeues after producer lease deletion; the candidate records existing comment metadata and keeps the item open without another durable PATCH, label write, or close. Human-comment, title-edit, and changed-head controls still reject before substantive effects. The API and queue-wrapper coverage limits are expressly documented.
Findings None None.
Security None None.

How this fits together

The apply lane consumes completed review records and checks live GitHub activity before publishing comments, reconciling labels, or closing items. Its freshness checks must distinguish ClawSweeper's coordination writes from changes that invalidate a review.

flowchart TD
  A[Completed review record] --> C[Apply freshness checks]
  B[Live GitHub activity] --> C
  C --> D[Match source and activity receipt]
  D --> E[Verify automation write]
  E --> F[Publish through existing action gates]
  D --> G[Reject drift and requeue]
  E --> G
Loading

Before merge

None.

Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Production and test growth production +94/-14; tests +244/-31; proof harness +239/-96 Production growth is justified by the generation-bound receipt checks; regression and transport coverage exercise their acceptance and rejection paths.
Recorded transport comparisons 8 producer/batch cases; 24 acknowledgement regression runs The recorded matrix covers recovery from own-write drift and rejection of external changes through the real apply owner.

Technical review

Best possible solution:

Retain generation-bound automation receipts while preserving external-change rejection and the existing final action gates.

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

Yes: current-main source and the recorded baseline production-path replay establish that producer lease deletion causes deferred re-apply to report source drift. This reviewer did not execute the harness.

Is this the best way to solve the issue?

Yes: the patch extends the existing freshness owner using complete review receipts and generation identity, without weakening publication immutability or duplicating queue ownership.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P1: The reported production loop repeatedly requeues completed reviews and prevents deferred publication from settling.
  • add merge-risk: 🚨 automation: The patch changes freshness admission before automated GitHub effects; matching receipts and recorded external-change controls cover this sensitive boundary.
  • add proof: sufficient: Contributor real behavior proof is sufficient. Native gh exercises the compiled apply owner against a stateful synthetic API: the candidate accepts producer lease-release drift without duplicate substantive writes, while human comments, changed heads, and title edits still block. The recorded candidate has unchanged production code at this head; hosted queue publication and real GitHub mutation are outside the stated proof scope. No stored-data contract changes.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (logs): Native gh exercises the compiled apply owner against a stateful synthetic API: the candidate accepts producer lease-release drift without duplicate substantive writes, while human comments, changed heads, and title edits still block. The recorded candidate has unchanged production code at this head; hosted queue publication and real GitHub mutation are outside the stated proof scope. No stored-data contract changes.

Label justifications:

  • P1: The reported production loop repeatedly requeues completed reviews and prevents deferred publication from settling.
  • merge-risk: 🚨 automation: The patch changes freshness admission before automated GitHub effects; matching receipts and recorded external-change controls cover this sensitive boundary.
  • 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 (logs): Native gh exercises the compiled apply owner against a stateful synthetic API: the candidate accepts producer lease-release drift without duplicate substantive writes, while human comments, changed heads, and title edits still block. The recorded candidate has unchanged production code at this head; hosted queue publication and real GitHub mutation are outside the stated proof scope. No stored-data contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. Native gh exercises the compiled apply owner against a stateful synthetic API: the candidate accepts producer lease-release drift without duplicate substantive writes, while human comments, changed heads, and title edits still block. The recorded candidate has unchanged production code at this head; hosted queue publication and real GitHub mutation are outside the stated proof scope. No stored-data contract changes.

Evidence

What I checked:

  • Pinned change and current-main necessity: The introduced delta is cac974b..53deda6. Main has the acknowledgement-only witness; the branch adds item-marker/timeline witnesses and the generation-bound released-lease allowance. The earlier merged fix fix(apply): stop own acknowledgement edits from requeueing source drift #1715 does not implement this deferred re-apply case. (src/clawsweeper-apply-source-freshness.ts:278, 53deda631901)
  • Freshness and authority boundaries: The released-lease path requires the durable comment's item, review timestamp, source revision, lease owner, and lease comment ID to match the report. Both new witnesses require complete source/timeline/head/review-activity equality and reject visible non-automation activity. Existing newer-review, lease, close eligibility, and final-effect freshness guards remain intact. (src/clawsweeper-apply-source-freshness.ts:310, 53deda631901)
  • Real production-path proof: The proof drives compiled non-dry-run apply-decisions and update-review-status through native gh 2.101.0 on Node v24.21.0/macOS against a stateful synthetic GitHub API. The baseline requeues after producer lease deletion; the candidate records existing comment metadata and keeps the item open without another durable PATCH, label write, or close. Human-comment, title-edit, and changed-head controls still reject before substantive effects. The API and queue-wrapper coverage limits are expressly documented. (docs/proof/receipt-based-freshness/README.md:24, 53deda631901)
  • Recorded final effects and regression controls: The receipt contains 8 producer/batch comparisons and 24 acknowledgement regression runs. All recorded external-change controls have zero close requests; the close-capable acknowledgement case makes exactly one close per build. Parsed headline traces contain 122 baseline requests and 135 candidate requests, with matching producer effects and only apply-lease creation/deletion during batch. No trace errors were recorded. (docs/proof/receipt-based-freshness/receipt.json:1, 53deda631901)
  • Proof remains applicable to reviewed production code: The recorded candidate is 3497419. Comparing that candidate to the reviewed head produces no src or scripts changes; the later commit adds regression proof documentation. No stored format, schema, configuration default, or dependency source changes are introduced. (docs/proof/receipt-based-freshness/README.md:5, 53deda631901)
  • Policy, validation, and Bay scope: The full root AGENTS.md was read; no nested AGENTS.md or maintainer-note files were found. The branch supplies the required changelog fragment and explains why Bay needs no change. git diff --check passed and the checkout remained clean. Runtime tests were not executed during this read-only review; reported full and focused validation remain supplemental evidence. (AGENTS.md:78, 53deda631901)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • goutamadwant: 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.

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. P1 Urgent regression or broken agent/channel workflow affecting real users now. 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