Skip to content

fix(repair): retry state-repo pushes on concurrent-writer rejection - #711

Merged
steipete merged 1 commit into
mainfrom
fix/state-publish-push-retry
Jul 20, 2026
Merged

steipete merged 1 commit into
mainfrom
fix/state-publish-push-retry

Conversation

@steipete

Copy link
Copy Markdown
Contributor

Problem

The spam scanner workflow failed twice on 2026-07-19 while publishing its audit to the state repo:

Both logs show the same shape: the state push loses a race to a concurrent workflow (error: failed to push some refs to 'https://github.com/openclaw/clawsweeper-state'), and then the publish aborts with

Git publish failure: phase=push processes=15 duration_ms=6484 error=git command <redacted-args> exited 1

Root cause

publishMainCommit already has bounded, jittered retry loops for lost push races. The failure is in the recovery path itself: after the rejected push, pushCommit fetches the new remote head and plans sweep-status/ledger merges, which runs git merge-base <local> <remote> through runGit without allowFailure.

Production state checkouts are shallow, and fetchPublishRemote deliberately preserves that with --depth=1. A depth-1 fetch of the racing writer's tip records it as a new shallow boundary, so it shares no visible ancestry with local HEAD. merge-base exits 1 with no output, runGit throws, and the exception escapes every retry loop. The metrics line from the failed runs (merge-base:1, displayed as the anonymous git command) confirms exactly this sequence.

Fix

In pushCommit's post-rejection recovery, probe the merge base with spawnGit instead of runGit. When there is no common base (the shallow-race signature), log it and return false instead of throwing. The caller's existing bounded retry loop (maxAttempts, jittered backoff, Git publish failure: diagnostic preserved) then falls through to rebuildPublishCommit, which re-applies the publish directly on the fetched remote head - that path never needs shared ancestry (its merge base is the source commit's parent, always local). Genuine auth/network push failures behave as before, and the reconcile-records no-common-base publish still fails closed.

Also adds log and merge-base to the redaction display safelist so future failures name the failing git action instead of git command.

All callers of the shared helper benefit: every workflow publishing through repair:publish-main (spam-scanner, sweep, repair-publish-results, comment-router, cluster intake/worker, self-heal, finalize-open-prs, commit-review, proof-nudges, issue-implementation intake, conflict self-heal) plus in-process users of publishMainCommit.

Validation

  • New regression test publishMainCommit survives a shallow-checkout push race without a common Git base reproduces production exactly: shallow (depth-1) checkout, concurrent two-commit remote push, theirs strategy. Without the fix it fails with the production error (Git publish failure: phase=push ... error=git command <redacted-args> exited 1); with the fix it publishes both the local and the concurrent changes.
  • pnpm run build:all plus the full test/repair/git-publish.test.ts suite.
  • pnpm run check locally (one pre-existing host-specific failure: the immutable-ledger server-merge test fails identically on unmodified main on macOS because includeIf.gitdir does not match the symlinked tmpdir realpath; unrelated to this diff).

Internal-only reliability fix; no changelog entry.

A shallow state checkout fetches a racing writer's push with --depth=1, so
the new remote head shares no local ancestry. pushCommit's recovery then
ran git merge-base through runGit, which threw and escaped every publish
retry loop (spam scanner runs 29701094002 and 29702697623). Probe the
merge base non-fatally and defer disjoint-history races to the caller's
bounded rebuild-on-remote-head retry path. Also safelist log and
merge-base in redacted command display so future failures name the action.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5c28770bcb

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/repair/git-publish.ts
console.log(
`No common Git base with ${remote}/${branch} after a lost push race; deferring to a remote-head rebuild`,
);
return false;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve concurrent files before rebuilding broad paths

When a shallow checkout loses a push race and the remote writer changed a different child of a published directory, this return sends execution to rebuildPublishCommit, which removes each entire publish path and checks it out from the stale source commit (src/repair/git-publish.ts:1743-1749). This can delete accepted concurrent state: for example, .github/workflows/repair-publish-results.yml:197 publishes all of results, and the spam scanner publishes all of results/spam-audit, so an unrelated result added by the racing writer is absent from the rebuilt commit and is removed on the next push. The no-common-base recovery needs to preserve remote children outside the local diff rather than replacing directory snapshots wholesale.

Useful? React with 👍 / 👎.

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P1 Urgent regression or broken agent/channel workflow affecting real users now. merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. labels Jul 19, 2026
@clawsweeper

clawsweeper Bot commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 19, 2026, 7:27 PM ET / 23:27 UTC.

Summary
The PR treats shallow-history merge-base failures after a rejected state-repo push as retryable rebuilds and adds a regression test for that race.

Reproducibility: yes. in source: the supplied shallow-checkout race test gives a concrete reproduction shape, but the submitted evidence does not show an after-fix run that exercises a concurrent sibling beneath the same published directory.

Review metrics: 1 noteworthy metric.

  • Publish-path surface: 2 files changed; +68/-3. One shared state-publish helper affects multiple workflow publishers, so a narrow fallback change has broad concurrent-write consequences.

Merge readiness
Overall: 🦪 silver shellfish
Proof: 🦪 silver shellfish
Patch quality: 🦪 silver shellfish
Result: blocked until real behavior proof from a real setup is added.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • [P1] Preserve remote siblings during no-common-base recovery and add a regression test for a concurrent file within the same published directory.
  • Post redacted output or logs from a real shallow state-repository publish race after the correction; updating the PR body should trigger a fresh review, or a maintainer can comment @clawsweeper re-review.

Proof guidance:

  • [P1] Needs real behavior proof before merge: The PR body reports unit and CI validation, including a realistic local Git regression test, but does not provide after-fix evidence from a real state-repository workflow; add redacted live output or logs after fixing the data-preservation case. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Risk before merge

  • [P2] Merging this fallback as written can silently remove concurrently accepted state files when a workflow publishes a directory and the racing writer changed a different child within that directory.

Maintainer options:

  1. Preserve remote siblings before rebuilding (recommended)
    Change the no-common-base recovery so it reapplies only local changes while retaining concurrent remote children, then cover that same-directory race with a regression test.
  2. Pause the fallback change
    Do not merge the shallow-race fallback until the rebuild path has a demonstrated non-destructive merge policy for broad directory publishes.

Next step before merge

  • [P1] The contributor needs to correct the destructive rebuild behavior and supply real after-fix publish evidence; this is not safe to pass or auto-close in its current form.

Security
Cleared: The diff changes local Git recovery behavior and tests without adding dependencies, permissions, secrets access, or new external code execution.

Review findings

  • [P1] Preserve concurrent siblings before rebuilding broad paths — src/repair/git-publish.ts:1270
Review details

Best possible solution:

Preserve fetched remote children outside the local publish diff during no-common-base recovery, add a same-directory concurrent-writer regression test, and provide redacted evidence from a real shallow state-repository publish run before merge.

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

Yes in source: the supplied shallow-checkout race test gives a concrete reproduction shape, but the submitted evidence does not show an after-fix run that exercises a concurrent sibling beneath the same published directory.

Is this the best way to solve the issue?

No: returning to a broad directory rebuild avoids the merge-base exception but does not preserve remote files outside the local diff, so the fallback needs a non-destructive reapplication strategy.

Full review comments:

  • [P1] Preserve concurrent siblings before rebuilding broad paths — src/repair/git-publish.ts:1270
    Returning false here enters rebuildPublishCommit, which reconstructs each published path from the stale local source. When a workflow publishes a directory and the racing writer added a different child in that directory, the next push can delete that accepted remote file. Reapply only the local diff onto the fetched remote head and add a same-directory race regression test.
    Confidence: 0.94

Overall correctness: patch is incorrect
Overall confidence: 0.94

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against d7e01ce59f9d.

Label changes

Label changes:

  • add P1: The patch can silently discard concurrently accepted workflow state during a common publishing race.
  • add merge-risk: 🚨 other: The merge risk is data preservation in the state repository and does not map cleanly to the narrower PR-only risk labels.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦪 silver shellfish.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The PR body reports unit and CI validation, including a realistic local Git regression test, but does not provide after-fix evidence from a real state-repository workflow; add redacted live output or logs after fixing the data-preservation case. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Label justifications:

  • P1: The patch can silently discard concurrently accepted workflow state during a common publishing race.
  • merge-risk: 🚨 other: The merge risk is data preservation in the state repository and does not map cleanly to the narrower PR-only risk labels.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦪 silver shellfish.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The PR body reports unit and CI validation, including a realistic local Git regression test, but does not provide after-fix evidence from a real state-repository workflow; add redacted live output or logs after fixing the data-preservation case. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed

What I checked:

  • Concurrent-state-loss review evidence: The existing review identifies that returning false here routes to rebuildPublishCommit, whose broad-path rebuild removes and restores whole publish paths; concurrent children added remotely under a published directory can therefore be omitted from the next push. (src/repair/git-publish.ts:1270, 5c28770bcb79)
  • Rebuild-path evidence: The reviewer traced the destructive directory replacement to rebuildPublishCommit at src/repair/git-publish.ts:1743-1749, with broad results publishing used by repair workflows. (src/repair/git-publish.ts:1743, 5c28770bcb79)
  • Regression coverage gap: The added shallow-race test proves that both writers' changes survive when they use different top-level publish paths, but it does not cover a concurrent sibling file beneath the same broad directory publish path. (test/repair/git-publish.test.ts:439, 5c28770bcb79)

Likely related people:

  • steipete: The PR author provided the production incident analysis and proposed change in the shared repair-publish path; current-main provenance could not be independently expanded in this read-only environment. (role: recent repair-publish contributor; confidence: low; commits: 5c28770bcb79; files: src/repair/git-publish.ts, test/repair/git-publish.test.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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.

How this review workflow works
  • 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.

@steipete
steipete merged commit 611b3f1 into main Jul 20, 2026
15 checks passed
@steipete
steipete deleted the fix/state-publish-push-retry branch July 20, 2026 01:33
azaj01 pushed a commit to azaj01/clawsweeper that referenced this pull request Sep 21, 2026
…penclaw#711)

A shallow state checkout fetches a racing writer's push with --depth=1, so
the new remote head shares no local ancestry. pushCommit's recovery then
ran git merge-base through runGit, which threw and escaped every publish
retry loop (spam scanner runs 29701094002 and 29702697623). Probe the
merge base non-fatally and defer disjoint-history races to the caller's
bounded rebuild-on-remote-head retry path. Also safelist log and
merge-base in redacted command display so future failures name the action.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. P1 Urgent regression or broken agent/channel workflow affecting real users now. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant