Skip to content

refactor: build exact-review lease heartbeats with one typed command - #1796

Merged
obviyus merged 2 commits into
mainfrom
exact-review-heartbeat-client
Oct 9, 2026
Merged

obviyus merged 2 commits into
mainfrom
exact-review-heartbeat-client

Conversation

@obviyus

@obviyus obviyus commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

What

A typed exact-review queue request command, and its first lane: every lease heartbeat in event-review-apply.

  • New src/repair/exact-review-queue-request.ts (built to dist/repair/exact-review-queue-request.js). heartbeat --phase <review|status|finalizing> [--review-acknowledgement-comment-id <id>] [--generation-start] reads the lease tuple from EXACT_REVIEW_ITEM_KEY, EXACT_REVIEW_LEASE_ID, EXACT_REVIEW_LEASE_REVISION, EXACT_REVIEW_CLAIM_GENERATION, EXACT_REVIEW_SOURCE_HEAD_SHA, GITHUB_RUN_ID and GITHUB_RUN_ATTEMPT. It validates the tuple with the queue's own rules (positive integers, numeric run id, 40-hex head SHA). It prints the JSON body. The phase options are a discriminated union: an acknowledgement comment id only with status, generation_start only with review, because the queue accepts them only there. Invalid input prints no body and exits 1.
  • control_plane_curl stays the transport. Response handling in the steps is unchanged.
  • Lane migrated (this PR only): event-review-apply. It had 9 inline node -e heartbeat builders (3 validated, 6 not), plus the review step's mark_finalizing Node derivation and verify_startup_authority jq derivation. All 11 now call the command. prepare_heartbeat builds the review, startup and finalizing bodies before generation, so an invalid tuple still stops the step before any request.
  • Each remaining lane (claim, complete, lifecycle receipts, enqueue, terminal finalization) gets its own follow-up PR after this one lands.

Copy counts (lease heartbeat body builders in .github/workflows/sweep.yml):

before after
inline node -e builders 9 0
derived bodies (node -e spread, jq '. + {generation_start: true}') 2 0
typed command 0 1

Why

agent://SlopWorkflows/report finding 2: the queue protocol lives in ~30 YAML heredocs, and typed decisions are rebuilt from env strings with ad-hoc checks. The heartbeat body is the most copied of them. Validation had drifted: 3 copies checked the tuple, and 6 sent Number("") → 0 and let the queue reject it.

Proof

  1. Old vs new bodies for fixed inputs. Each old builder is extracted from origin/main:sweep.yml and executed as it was; the new body comes from the built command:
IDENTICAL  Fence re-review command status
IDENTICAL  Fence automatic review in progress
IDENTICAL  Release automatic review status fence
IDENTICAL  Fence automatic review completion
IDENTICAL  Release automatic review completion fence
IDENTICAL  Mark unsuccessful re-review
IDENTICAL  Fence terminal automatic review failure
IDENTICAL  Release terminal automatic review status fence
IDENTICAL  Review exact event item: mark_finalizing
SEMANTIC   Review exact event item: review loop
  old: {"item_key":"openclaw/openclaw#1675",…,"source_head_sha":"aaaa…"}
  new: {"item_key":"openclaw/openclaw#1675",…,"source_head_sha":"aaaa…","phase":"review"}
SEMANTIC   Review exact event item: verify_startup_authority
  old: {…,"source_head_sha":"aaaa…","generation_start":true}
  new: {…,"source_head_sha":"aaaa…","phase":"review","generation_start":true}
8/8 fence bodies byte-identical

The two semantic differences add "phase":"review". The queue already treats a missing phase as review (dashboard/exact-review-queue.ts: body.phase === undefined ? "review" : …), and it requires generation_start to come with phase review.

  1. Lane e2e: scripts/e2e/exact-review-start-authority.mjs runs the real "Review exact event item" shell and control-plane-curl.sh against an isolated HTTP peer. It needs Linux process groups (the test skips on macOS), so it ran in node:24-bookworm --init. Before (main's lane) and after: all 12 scenarios have the same results (stale, stale-oversized, revoked-during-oversized-setup, inactive, unknown-conflict, service-failure, transport-failure, retry-current, invalid-tuple with 0 requests, current, current-oversized, revoked-after-start). guarded=true, every process group reaped, current charges generation_start exactly once.
{"scenario":"invalid-tuple","code":1,"launched":false,"requests":0,"generationStartRequests":0,...}
{"scenario":"current","code":0,"launched":true,"requests":3,"generationStartRequests":1,"superseded":false,"mayPublish":true,"processesReaped":true}
{"scenario":"retry-current","code":0,"launched":true,"requests":4,"generationStartRequests":2,...}
  1. test/sweep-workflow.test.ts executes the extracted fence and startup scripts. The startup test now runs the real prepare_heartbeat against the built command. test/repair/exact-review-queue-request.test.ts runs the CLI entry point for bodies and every rejection.

  2. pnpm run check: 6964 pass. The first run had two failures: a test that pinned the old phase: "finalizing" text (fixed in 9de2b99) and the known interrupted native unshallow git-acquisition flake, which passes alone (13/13). After the fix, test/review-reliability-workflow.test.ts passes. codex review --base origin/main: "No actionable defects found."

  3. Saved real reports re-rendered with render-comments.mjs (prompt-rest, prompt-lean, prompt-dump, async-proof/{base,branch}, retire-proof/166090): 6/6 byte-identical.

Codex dispositions

  • codex review --base origin/main: no findings.

Merge Danger

  • Door: two-way. No stored data and no queue protocol change; revert restores the inline builders.
  • Blast radius: event-review-apply lease heartbeats (status fences, the review heartbeat loop, the startup ownership check, finalization). All migrated steps run only after setup-pnpm with build:all succeeded, so dist/repair/exact-review-queue-request.js is present. If the command failed, the fences would fail closed (no GitHub mutation) and the review would not start. The e2e above shows the lane behaves the same in all 12 scenarios.
  • Independent of refactor: sign workflow control-plane requests in one helper #1794 (no overlapping hunks; it merges cleanly in either order).

@obviyus
obviyus requested a review from a team as a code owner October 9, 2026 08:07
@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 P3 Low-risk cleanup, docs, polish, ergonomics, or speculative feature. 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 9, 2026
@clawsweeper

clawsweeper Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

The review workflow builds lease heartbeats—requests that confirm a worker still owns a review—with one typed command instead of copied shell builders.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A useful consolidation with production workflow and real transport evidence, preserved contracts, and no actionable correctness finding.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): Supplied terminal output exercises the changed heartbeat command through the actual workflow shell and real curl client in a Node 24 Linux container: current ownership proceeds, invalid tuples send no requests, and stale or revoked leases stop work and suppress publication. Body-equivalence checks cover status fences; controlled HTTP responses and review-process fixtures limit the proof to workflow behavior rather than deployed queue or GitHub execution. No stored-data contract changes require migration.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Refactor · Worth it: Yes
Reason: Eleven copied or derived heartbeat builders become one typed owner with consistent validation. The maintenance benefit exceeds the small new command’s cost, and designed behavior is preserved.

Merge readiness

✅ Ready for maintainer review

Keep open: this is a useful, bounded consolidation that current main does not contain. No actionable patch defect was found.

Priority: P3
Reviewed head: 9de2b998f038dadf2f47ff16fe6b3d63085f8152

Before merge

None.

Findings

None.

Agent review details

How this fits together

GitHub Actions workers send lease heartbeats to ClawSweeper’s review queue before generation, during review, and around status publication. The queue checks ownership and returns whether the worker may continue.

flowchart TD
  A[Workflow lease fields] --> B[Typed heartbeat command]
  C[Review or status phase] --> B
  B --> D{Valid request inputs?}
  D -->|No| E[Stop before sending]
  D -->|Yes| F[Existing curl retry client]
  F --> G[Review queue ownership check]
  G --> H[Continue or stop worker]
Loading

Technical review

Best possible solution:

Keep heartbeat serialization in one typed command while leaving queue authorization and transport retries with their existing owners.

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

Not applicable: this PR consolidates existing heartbeat construction rather than fixing a reported user-facing failure.

Is this the best way to solve the issue?

Yes: the command replaces copied builders without adding a competing transport or changing the queue’s ownership contract.

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

  • Repository policy: Read the complete root AGENTS.md. No nested AGENTS.md or maintainer-notes directory was found; applied narrow-change, proof, build-availability, changelog, and read-only guidance. (AGENTS.md:1, 9de2b998f038)
  • Introduced implementation: The introduced diff replaces nine inline builders and two derived bodies. The command preserves lease fields and phase-specific options; request routes, transport, retries, and response handling remain unchanged. (src/repair/exact-review-queue-request.ts:38, 9de2b998f038)
  • Queue contract and compatibility: The existing queue treats omitted phase as review, requires generation_start to use review, validates acknowledgement IDs, and checks the full lease tuple. Explicit review phase preserves existing semantics. No stored schema, serialized state format, settings, or migration changes are introduced. (dashboard/exact-review-queue.ts:3015, 9de2b998f038)
  • Build availability: The workflow runs setup-pnpm with build:all before migrated steps. build:all includes build:repair, whose compiler includes src/repair/**/*.ts. Cleanup fences depend on successful earlier review or status authorization, so the new executable is available when they run. (.github/workflows/sweep.yml:770, 9de2b998f038)
  • Current-main necessity and merge safety: Fetched main has no typed heartbeat command, and none of the introduced paths changed between the merge base and fetched main. The raw test-merge record has exactly the pinned main and head parents; its diff retains the seven introduced files without removing unrelated main changes. (src/repair/exact-review-queue-request.ts, 75fbe0ae0beb)
  • Real workflow proof: The fully supplied PR body, captured source revision dfb681e95689eb328570f2c5110c8f1c0d1e02b47a1928c5b203f8a5be408f62, reports execution of the production workflow shell and real curl helper in node:24-bookworm against an isolated HTTP peer. After-fix output shows invalid tuples send zero requests, current ownership launches with one generation-start request, and revocation scenarios prevent publication and reap process groups. Inspection of the harness confirms those production boundaries; queue responses and expensive review work are controlled fixtures, not deployed Actions or Worker execution. (scripts/e2e/exact-review-start-authority.mjs:19, 9de2b998f038)

Likely related people:

  • Peter Steinberger: Raw commit 36efe27 adds .github/workflows/sweep.yml:890 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 36efe27df880; files: .github/workflows/sweep.yml)

Review metrics

Metric Value Why it matters
Heartbeat duplication 9 inline builders and 2 derivations replaced by 1 command Lease-body maintenance now has one owner within the migrated workflow.
Production versus test changes Production +137/-148; tests +128/-20 The typed command reduces production code overall while adapting workflow and CLI contract coverage.

Labels

Label changes:

  • add P3: This preserves existing review behavior while reducing workflow duplication and validation drift.
  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit 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:

  • P3: This preserves existing review behavior while reducing workflow duplication and validation drift.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • 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 need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

Reviewed October 9, 2026, 4:10 AM ET / 08:10 UTC.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P3 Low-risk cleanup, docs, polish, ergonomics, or speculative feature. 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