Skip to content

fix(publish): prevent state races from timing out result delivery - #720

Merged
brokemac79 merged 1 commit into
mainfrom
codex/csw-049-bounded-publish-reconcile
Jul 20, 2026
Merged

brokemac79 merged 1 commit into
mainfrom
codex/csw-049-bounded-publish-reconcile

Conversation

@brokemac79

Copy link
Copy Markdown
Contributor

Related: #712
Related: #714
Related: #716

What Problem This Solves

Fixes an issue where completed issue and PR reviews remain queued when concurrent exact-result publishers race to update the shared state branch.

The incident began immediately after #712 merged at 2026-07-20 06:04:34Z. That change made a shallow publisher hydrate Git history when merge-base could not see common ancestry. Under the normal 32-writer publication load, losing writers repeatedly entered --deepen / --unshallow; many timed out after 60 seconds and held their publication lease through the failed attempt. The queue was still at 215 publication items with all 32 slots active at 2026-07-20 13:21Z.

This is not a label-only or dashboard-only issue: the failure occurs in the exact-result publication step before the durable result can finish its comment/label/application lifecycle.

Why This Change Was Made

Exact event publication commits one known record tuple. This change gives that path a dedicated pushSingleRecordTupleCommit entry point which:

  • captures the source commit and derives the one allowed tuple key from the staged publication paths;
  • opts only that bounded path into fix(repair): rebuild reconciliation on remote head for unrelated histories #716's remote-head rebuild when shallow history hides the merge base;
  • avoids history hydration in the hot two-writer race; and
  • keeps the existing tuple arbitration, including preservation of a newer concurrent remote tuple.

All generic pushCommit callers retain the existing #714/#716 hydration behavior. This does not change queue capacity, add retries, reset state, alter gates, dispatch Actions, or weaken reconciliation safety.

User Impact

Issue and PR result publishers that lose a state-branch push race can reconcile immediately on the fetched remote head instead of spending up to 60 seconds hydrating history and failing. This should release publication leases promptly and let the backlog drain while preserving both independent record tuples and the newer winner for same-tuple races.

GitHub API rate limiting remains a separate possible failure mode; this patch intentionally addresses the dominant Git fetch timeout signature rather than masking it with capacity or retry changes.

Evidence

Production causal proof

Real behavior proof

Environment: Crabbox local-container, Docker image mcr.microsoft.com/playwright:v1.60.0-noble.

Focused lease: cbx_00f30e0daaa8 (pearl-shrimp). The Docker run built tsconfig.repair.json, ran the exact two-writer regression plus the existing shallow/unrelated-history guards, checked the production call-site contract, and ran scoped oxlint, oxfmt, and git diff --check.

tests 4
pass 4
fail 0
Found 0 warnings and 0 errors.
All matched files use the correct format.
exitCode: 0

The new integration case creates a depth-1 publisher and a second writer against a real bare Git remote. The second writer wins the first push; a shim fails the test if git fetch --deepen is attempted. The publisher then rebuilds on the fetched remote head, pushes successfully, remains shallow, and the remote contains both the publisher's tuple and the concurrent writer's tuple.

Broad lease: cbx_53da04c5a2c5 (golden-krill). The Docker run rebuilt all three TypeScript targets and ran the complete repair suite:

tests 987
pass 980
fail 0
skipped 7
duration_ms 48006.822504
Found 0 warnings and 0 errors.
All matched files use the correct format.
exitCode: 0

The broad Crabbox setup materialized untouched files from Git's LF index because raw Windows-to-Linux sync otherwise presents repository-wide CRLF fixture noise. The initial raw-sync failure was entirely in workflow text/contained pnpm harness expectations; after Linux checkout normalization and a Corepack pnpm shim, the unchanged full suite passed without exclusions.

Not proven pre-merge: production backlog drain. The deterministic test proves the exact failed two-writer lifecycle and removes the 60-second hydration command from that bounded path; live drain must be observed after deployment.

Review gates

  • Dirty patch: codex-review --mode local --full-access — clean, no accepted/actionable findings.
  • Committed branch vs actual base: codex-review --mode branch --base origin/main --full-access — clean, no accepted/actionable findings.
  • The branch review also exercised the same-tuple shallow race and confirmed the newer remote tuple remains the winner.
  • git diff --check passed on the host and on the scoped Linux patch.

Risks And Rollout

The behavior change is opt-in and limited to exact single-record result publication. A guard rejects zero or multiple tuple identities before enabling the bounded rebuild. Generic checkpoint, ledger, and other reconciliation callers are unchanged.

The main rollout signal is the publication queue: the active-lease timeout signature should disappear first, then leased duration and ready depth should fall. A remaining GitHub rate-limit signature would be separate evidence rather than a reason to broaden this patch.

No automerge is requested. A maintainer should make the explicit merge decision after normal CI and review-stage evidence.

Attribution

This repair builds on Peter Steinberger's state recovery and remote-head reconciliation work in #712, #714, and #716. It preserves those correctness changes while narrowing the exact event publisher's contention path.

@brokemac79

Copy link
Copy Markdown
Contributor Author

@clawsweeper review

@clawsweeper

clawsweeper Bot commented Jul 20, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@brokemac79
brokemac79 merged commit 4d06149 into main Jul 20, 2026
9 checks passed
@brokemac79
brokemac79 deleted the codex/csw-049-bounded-publish-reconcile branch July 20, 2026 13:40
azaj01 pushed a commit to azaj01/clawsweeper that referenced this pull request Sep 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant