Skip to content

refactor(apply): read the apply close decision from the typed review record - #1848

Merged
obviyus merged 2 commits into
mainfrom
review-record-s3-apply-close
Oct 9, 2026
Merged

obviyus merged 2 commits into
mainfrom
review-record-s3-apply-close

Conversation

@obviyus

@obviyus obviyus commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

What

Row 2 slice S3 (typed ReviewRecord): the apply close path reads the reviewed decision from the report's review_record line.

  • New src/clawsweeper-apply-close-decision.ts:
    • validateReportClose(dependencies, item, markdown, closeReason, options) validates the close that apply will do. The reviewed fields come from the record (readReviewRecordOrLegacy). The host gives what the record cannot hold: the apply's close reason (with decision: close, confidence: high, as before), the close comment that apply posts (the report's Close Comment section), and a maintainer proof: override label on the current labels. A record that does not read returns skipped_changed_since_review with review_record: …; fresh review required. No close.
    • unreadableReviewRecordReason(markdown): the apply loop checks it once for each item, next to the reconciliation skip, and before any promotion can start. A promotion calls updateReviewRecordDecision, which removes a record that does not read. Without this early check, a promoted item with a corrupt record would close through the legacy fallback.
  • src/review-record.ts: readReviewRecordOrLegacy(markdown, legacyDecision). A report without the line gets its decision from reportDecision() until the backfill shows 0 missing. A line that does not read gets no fallback. reportDecision is not deleted.
  • The reportDecision() call sites in apply:
    1. clawsweeper-apply-close-execution.ts: the current-report validation before the close → validateReportClose
    2. same file: paired linked issue validation → validateReportClose
    3. same file: paired linked issue validation after the closeout comment → validateReportClose
    4. clawsweeper-apply-close-guards.ts: currentCloseGatesPassed (same-author pair start) → validateReportClose
    5. same file: counterpart validation → validateReportClose
    6. clawsweeper-apply-decision-workflow.ts: pre-sync duplicate validation → validateReportClose
    7. same file: pairedIssueDurableReviewCommentUpdatedAt used reportDecision(md, "implemented_on_main").closeReason, which only gives back its argument. It is now the constant.
  • Tests: test/apply-close-decision.test.ts (record wins over the report text, legacy fallback, corrupt line, proof override), e2e apply tests for a record-driven block and a corrupt record (apply-stale-version-bug-policy, apply-pr-promotion). The author-budget fixture record now holds the same proof and rating as its report text (before, the fixture record was the generic issue decision; with the record as the source the close was correctly blocked).

Why

Design review-record-design.md §6 step 3: the close path stops rebuilding a Decision from markdown. A corrupt record fails closed (fresh review) instead of being filled by the report parsers (audit Finding 4).

Proof

apply-decisions CLI, main 314018ccc build vs branch build, the repo's recording gh stub (promotionGhMock), withMockCodexProof. Driver reused from the S1 proof (/tmp/r2proof/s3/apply-proof.ts). gh calls are sorted with paths and uuids masked; markdown compared with apply timestamps masked.

# Scenario apply-report gh calls main / branch comments markdown
1 saved review #167817 (review record from a real review), comment sync identical: review_comment_synced 66 / 66 (identical) identical identical
2 saved review #167817 (no review record), comment sync identical: review_comment_synced 66 / 66 (identical) identical identical
3 saved review #167298 (backfilled review record), comment sync identical: review_comment_synced 66 / 66 (identical) identical identical
4 saved review #167298 (no review record), comment sync identical: review_comment_synced 66 / 66 (identical) identical identical
5 saved review #167054 (backfilled review record), comment sync identical: review_comment_synced 81 / 81 (identical) identical identical
6 saved review #167054 (no review record), comment sync identical: review_comment_synced 81 / 81 (identical) identical identical
7 stale F-rated PR promotion and close (review record) identical: review_comment_synced, closed (low-signal unmergeable PR) 205 / 205 (identical) identical identical
8 stale F-rated PR promotion and close (no review record) identical: review_comment_synced, closed (low-signal unmergeable PR) 205 / 205 (identical) identical identical
9 stale F-rated PR promotion and close (corrupt review record) main: review_comment_synced, closed (low-signal unmergeable PR)
branch: skipped_changed_since_review (review_record: the value is not JSON; fresh r…)
205 / 0 differ differ
10 stored proposed low-signal close (review record) identical: skipped_changed_since_review (closeout evidence freshness receipt could not…) 98 / 98 (identical) identical identical
11 stored proposed low-signal close (no review record) identical: skipped_changed_since_review (closeout evidence freshness receipt could not…) 98 / 98 (identical) identical identical
12 stored proposed low-signal close (corrupt review record) main: skipped_changed_since_review (closeout evidence freshness receipt could not…)
branch: skipped_changed_since_review (review_record: the value is not JSON; fresh r…)
98 / 0 differ differ
13 stored proposed low-signal close, dry run (review record) identical: closed (dry-run: would close as low-signal unmergeable PR) 51 / 51 (identical) identical identical
14 stored proposed low-signal close, dry run (no review record) identical: closed (dry-run: would close as low-signal unmergeable PR) 51 / 51 (identical) identical identical
15 stored proposed low-signal close, dry run (corrupt review record) main: closed (dry-run: would close as low-signal unmergeable PR)
branch: skipped_changed_since_review (review_record: the value is not JSON; fresh r…)
51 / 0 identical identical
16 proposed duplicate close, coverage proof covered (review record) identical: review_comment_synced, skipped_changed_since_review (closeout evidence freshness receipt could not…) 121 / 121 (identical) identical identical
17 proposed duplicate close, coverage proof covered (no review record) identical: review_comment_synced, skipped_changed_since_review (closeout evidence freshness receipt could not…) 121 / 121 (identical) identical identical
18 proposed duplicate close, coverage proof covered (corrupt review record) main: review_comment_synced, skipped_changed_since_review (closeout evidence freshness receipt could not…)
branch: skipped_changed_since_review (review_record: the value is not JSON; fresh r…)
121 / 0 differ differ

Notes:

  • Rows 1–6 are saved real reviews (#167817 from a real local review with its real record; #167298 and #167054 saved production reports, with the line made by the S2 backfill converter legacyReviewDecision, and without). They are keep-open, so comment sync runs, as in the S1 proof.
  • Row 7–9 exercise the close-execution site through a promotion and a real close. Rows 13–15 exercise a stored proposed close up to the dry-run close. Rows 10–12 and 16–18 reach the close step on both builds (current-report validation passed) and then stop at the stub's freshness receipt, identically.
  • Corrupt line (rows 9, 12, 15, 18): main closes (or would close); branch records skipped_changed_since_review / review_record: the value is not JSON; fresh review required, makes 0 gh calls, keeps the report in items/ with the line unchanged and action_taken: skipped_changed_since_review, and writes no comment. (Row 15 is a dry run, so neither build writes the report.) That action is in the review_refresh bucket, so the item gets a fresh review.

Checks run: pnpm run build:all, focused tests (all test/apply-*.test.ts plus close-reasons, oversized-pr-close, review-close-policy, clawsweeper, action-ledger, work-plan-artifacts, review-record, review-record-backfill: 510 pass, 0 fail), pnpm run lint, pnpm run format:check.

Codex dispositions

codex review --base origin/main, two runs (after each commit): no findings. The first run noted format errors in a full check; fixed with oxfmt.

Merge Danger

Low. Reports with a readable record or no record behave the same (proof rows above, and the existing apply suite). The only behavior change is for a report whose review_record line does not read: apply now skips it for a fresh review instead of comment sync, promotion or close. S1 stores only records that read back, so such reports should be rare. Rollback is a plain revert; nothing stored changes.

@clawsweeper

clawsweeper Bot commented Oct 9, 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. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 9, 2026
@clawsweeper

clawsweeper Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

ClawSweeper reads close-validation fields from the stored structured review decision, retains support for older reports, and skips reports with unreadable records.

Example: Apply processes a stale PR report containing review_record: {broken.

  • Before: Apply can promote and close the PR using the report text.
  • After: Apply records skipped_changed_since_review with review_record: the value is not JSON; fresh review required.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) A useful, focused implementation with no actionable code findings, supported by CLI comparisons whose external boundaries are mocked.
Proof confidence 🦐 gold shrimp (3/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Refactor · Worth it: Yes
User problem: Automated close checks can reconstruct review details from report text instead of using the structured decision that was saved.
Reason: The cutover completes the existing record-storage design and prevents unreadable records from falling through promotion into legacy closing. It preserves the established close policies and live safeguards.

Merge readiness

✅ Ready for maintainer review

This PR remains necessary: current main stores typed review records but still reconstructs close decisions from report text. No merged replacement or actionable introduced defect was found.

Priority: P2
Reviewed head: c42f954170c974751bb0fcd8d19b35e22b7e36b3

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: The supplied CLI comparisons use mocked GitHub and Codex; a controlled real-transport apply run showing valid-record and legacy behavior plus corrupt-record rejection is not supplied.
Agent review details

How this fits together

ClawSweeper saves reviews as reports that its apply workflow reads before publishing comments or closing GitHub items. This change selects the reviewed decision data while retaining the existing live eligibility and freshness checks.

flowchart TD
  A[Saved review report] --> B{Structured record present?}
  B -->|No| C[Read legacy report text]
  B -->|Yes| D[Strictly read structured decision]
  D -->|Unreadable| E[Skip and request fresh review]
  D -->|Readable| F[Existing close validation]
  C --> F
  F --> G[Live eligibility and freshness checks]
  G --> H[Close or keep open]
Loading

Technical review

Best possible solution:

Keep one strict record reader as the close-validation source, with the temporary legacy fallback and existing live closeout safeguards.

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

Not applicable: this is a reader cutover rather than a reported production bug. Source inspection and the supplied CLI comparisons establish the corrupt-record fallback path on the base.

Is this the best way to solve the issue?

Yes: the adapter reuses the strict stored-record reader and existing close validator, replacing the old validation path without adding a competing policy owner.

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

  • Current-main necessity: Current main still passes reportDecision(getMarkdown(), closeReason) into close validation. The merged storage and backfill stages do not perform this reader cutover; the canonical search found no merged replacement. (src/clawsweeper-apply-close-execution.ts:403, 314018ccc4e3)
  • Introduced reader cutover: The pinned introduced diff replaces the six close-validation call sites with one adapter. It retains the existing validator and supplies the apply-owned close reason, confidence, published comment and proof override. (src/clawsweeper-apply-close-decision.ts:42, c42f954170c9)
  • Corrupt-record rejection: The apply loop checks record readability before promotion can remove an invalid record and expose the legacy fallback. Added CLI tests verify the skipped disposition and preservation of the corrupt report. (src/clawsweeper-apply-decision-workflow.ts:933, c42f954170c9)
  • Proof scope and source identity: The fully supplied PR body, captured as sourceRevision 7728b2b2c5e418945a7d340e0442392f35d3b7cda2c991e2624525163fdfcb65 and checked against the live body, reports apply-decisions CLI comparisons using promotionGhMock and withMockCodexProof. Corrupt records produce zero mocked GitHub calls; valid and legacy cases retain matching outcomes. These comparisons do not exercise real GitHub transport. (c42f954170c9)
  • Stored-report compatibility: No stored format, version, writer or migration changes. The new reader accepts existing version-1 records, preserves backfill origin and uses the existing report reader only when the record is absent. The supplied comparisons include saved production reports both with and without records. OpenClaw Bay's projections and public data contracts are unchanged. (src/review-record.ts:135, c42f954170c9)
  • Preserved closeout safeguards: fix: require verified provenance for main-implemented PR closes #1212 established independently reviewed paired issues, live formal fixing relationships and final eligibility checks before closeout. This patch changes decision reading while retaining those checks and their final mutation boundary. (src/clawsweeper-apply-close-execution.ts:681, 023046ec0354)

Likely related people:

  • Ayaan Zaidi: Raw commit 410f120 adds src/review-record.ts:92 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 410f120f8b9a; files: src/review-record.ts)

Review metrics

Metric Value Why it matters
Production and test changes Production +135/-36 lines; tests +190/-2 lines Production growth provides one close-validation adapter and an early corruption check while replacing the existing call sites.

Labels

Label changes:

  • add P2: This is a bounded reliability improvement to automated close validation, with no established urgent production incident.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: This is a bounded reliability improvement to automated close validation, with no established urgent production incident.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

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 need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

Reviewed October 9, 2026, 6:13 PM ET / 22:13 UTC.

@obviyus
obviyus merged commit 277f5a0 into main Oct 9, 2026
27 checks passed
@obviyus
obviyus deleted the review-record-s3-apply-close branch October 9, 2026 22:16
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. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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