Skip to content

Commit 0dc8a96

Browse files
committed
fix: recover issue implementation job races
1 parent b0b53c1 commit 0dc8a96

5 files changed

Lines changed: 198 additions & 160 deletions

File tree

‎.github/workflows/repair-cluster-worker.yml‎

Lines changed: 2 additions & 160 deletions
Original file line numberDiff line numberDiff line change
@@ -100,86 +100,7 @@ jobs:
100100
id: check_job
101101
env:
102102
JOB_PATH: ${{ inputs.job }}
103-
run: |
104-
restore_automerge_job() {
105-
case "$JOB_PATH" in
106-
jobs/*/inbox/automerge-*.md) ;;
107-
*) return 1 ;;
108-
esac
109-
filename="${JOB_PATH##*/}"
110-
stem="${filename%.md}"
111-
rest="${stem#automerge-}"
112-
number="${rest##*-}"
113-
repo_slug="${rest%-${number}}"
114-
owner="${JOB_PATH#jobs/}"
115-
owner="${owner%%/*}"
116-
repo_name="${repo_slug#${owner}-}"
117-
if [ -z "$number" ] || [ "$number" = "$rest" ] || [ -z "$repo_name" ] || [ "$repo_name" = "$repo_slug" ]; then
118-
return 1
119-
fi
120-
repo="$owner/$repo_name"
121-
ref="#$number"
122-
branch="clawsweeper/automerge-$repo_slug-$number"
123-
mkdir -p "$(dirname "$JOB_PATH")"
124-
cat > "$JOB_PATH" <<EOF
125-
---
126-
repo: $repo
127-
cluster_id: automerge-$repo_slug-$number
128-
mode: autonomous
129-
allowed_actions:
130-
- comment
131-
- label
132-
- fix
133-
- raise_pr
134-
blocked_actions:
135-
- close
136-
- merge
137-
require_human_for:
138-
- close
139-
- merge
140-
canonical:
141-
- $ref
142-
candidates:
143-
- $ref
144-
cluster_refs:
145-
- $ref
146-
allow_instant_close: false
147-
allow_fix_pr: true
148-
allow_merge: false
149-
allow_unmerged_fix_close: false
150-
allow_post_merge_close: false
151-
require_fix_before_close: true
152-
security_policy: central_security_only
153-
security_sensitive: false
154-
target_branch: $branch
155-
source: pr_automerge
156-
---
157-
158-
# ClawSweeper adopted PR repair candidate
159-
160-
Maintainer opted $ref into ClawSweeper automerge.
161-
162-
Source PR: https://github.com/$repo/pull/$number
163-
Title: PR $ref
164-
165-
ClawSweeper should use this job only for the bounded ClawSweeper review/fix loop:
166-
167-
- If ClawSweeper emits an explicit repair marker, requests changes, or finds failing checks/rebase work, and the PR branch is safe to update, emit a fix artifact with \`repair_strategy: "repair_contributor_branch"\` and \`source_prs: ["https://github.com/$repo/pull/$number"]\`.
168-
- If the PR branch cannot be safely updated, emit a narrow credited replacement only when the artifact can preserve the original contributor credit; otherwise return \`needs_human\`.
169-
- Do not merge, close, or bypass review gates from the worker. The comment router owns final merge only after a passing ClawSweeper verdict for the exact current head.
170-
- Keep repair scope limited to actionable ClawSweeper findings, failing relevant checks, and required review feedback on this PR.
171-
EOF
172-
}
173-
174-
if [ -f "$JOB_PATH" ]; then
175-
echo "job_exists=1" >> "$GITHUB_OUTPUT"
176-
elif restore_automerge_job; then
177-
echo "job_exists=1" >> "$GITHUB_OUTPUT"
178-
echo "::notice title=Restored automerge repair job::Job file '$JOB_PATH' was missing from the state checkout; reconstructed it from the workflow input."
179-
else
180-
echo "job_exists=0" >> "$GITHUB_OUTPUT"
181-
echo "::notice title=Stale repair dispatch::Job file '$JOB_PATH' no longer exists on the current state checkout; skipping this worker."
182-
fi
103+
run: scripts/restore-repair-job.sh "$JOB_PATH" "this worker"
183104

184105
- name: Capture execution gates
185106
id: capture_gates
@@ -331,86 +252,7 @@ jobs:
331252
id: check_job
332253
env:
333254
JOB_PATH: ${{ inputs.job }}
334-
run: |
335-
restore_automerge_job() {
336-
case "$JOB_PATH" in
337-
jobs/*/inbox/automerge-*.md) ;;
338-
*) return 1 ;;
339-
esac
340-
filename="${JOB_PATH##*/}"
341-
stem="${filename%.md}"
342-
rest="${stem#automerge-}"
343-
number="${rest##*-}"
344-
repo_slug="${rest%-${number}}"
345-
owner="${JOB_PATH#jobs/}"
346-
owner="${owner%%/*}"
347-
repo_name="${repo_slug#${owner}-}"
348-
if [ -z "$number" ] || [ "$number" = "$rest" ] || [ -z "$repo_name" ] || [ "$repo_name" = "$repo_slug" ]; then
349-
return 1
350-
fi
351-
repo="$owner/$repo_name"
352-
ref="#$number"
353-
branch="clawsweeper/automerge-$repo_slug-$number"
354-
mkdir -p "$(dirname "$JOB_PATH")"
355-
cat > "$JOB_PATH" <<EOF
356-
---
357-
repo: $repo
358-
cluster_id: automerge-$repo_slug-$number
359-
mode: autonomous
360-
allowed_actions:
361-
- comment
362-
- label
363-
- fix
364-
- raise_pr
365-
blocked_actions:
366-
- close
367-
- merge
368-
require_human_for:
369-
- close
370-
- merge
371-
canonical:
372-
- $ref
373-
candidates:
374-
- $ref
375-
cluster_refs:
376-
- $ref
377-
allow_instant_close: false
378-
allow_fix_pr: true
379-
allow_merge: false
380-
allow_unmerged_fix_close: false
381-
allow_post_merge_close: false
382-
require_fix_before_close: true
383-
security_policy: central_security_only
384-
security_sensitive: false
385-
target_branch: $branch
386-
source: pr_automerge
387-
---
388-
389-
# ClawSweeper adopted PR repair candidate
390-
391-
Maintainer opted $ref into ClawSweeper automerge.
392-
393-
Source PR: https://github.com/$repo/pull/$number
394-
Title: PR $ref
395-
396-
ClawSweeper should use this job only for the bounded ClawSweeper review/fix loop:
397-
398-
- If ClawSweeper emits an explicit repair marker, requests changes, or finds failing checks/rebase work, and the PR branch is safe to update, emit a fix artifact with \`repair_strategy: "repair_contributor_branch"\` and \`source_prs: ["https://github.com/$repo/pull/$number"]\`.
399-
- If the PR branch cannot be safely updated, emit a narrow credited replacement only when the artifact can preserve the original contributor credit; otherwise return \`needs_human\`.
400-
- Do not merge, close, or bypass review gates from the worker. The comment router owns final merge only after a passing ClawSweeper verdict for the exact current head.
401-
- Keep repair scope limited to actionable ClawSweeper findings, failing relevant checks, and required review feedback on this PR.
402-
EOF
403-
}
404-
405-
if [ -f "$JOB_PATH" ]; then
406-
echo "job_exists=1" >> "$GITHUB_OUTPUT"
407-
elif restore_automerge_job; then
408-
echo "job_exists=1" >> "$GITHUB_OUTPUT"
409-
echo "::notice title=Restored automerge repair job::Job file '$JOB_PATH' was missing from the state checkout; reconstructed it from the workflow input."
410-
else
411-
echo "job_exists=0" >> "$GITHUB_OUTPUT"
412-
echo "::notice title=Stale repair dispatch::Job file '$JOB_PATH' no longer exists on the current state checkout; skipping execute."
413-
fi
255+
run: scripts/restore-repair-job.sh "$JOB_PATH" "execute"
414256

415257
- uses: ./.github/actions/setup-pnpm
416258
if: ${{ steps.check_job.outputs.job_exists == '1' }}

‎CHANGELOG.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ checkpoint, and status-only commits are intentionally omitted.
3434

3535
- Accepted spaced `auto merge` command aliases everywhere `automerge` and
3636
`auto-merge` are accepted, including the top-level `/auto merge` shorthand.
37+
- Recovered issue implementation workers from state propagation races by
38+
reconstructing minimal `source: issue_implementation` jobs from the dispatched
39+
job path instead of skipping the worker as stale.
3740
- Made `/clawsweeper stop` revoke repair-loop labels and block older
3841
automerge/autofix comments from continuing, so a trusted pass marker cannot
3942
clear a human-review pause and merge after a maintainer stop.

‎docs/repair/operations.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,9 @@ dispatch the repair worker for one open issue and ask it to create or update a
282282
single ClawSweeper implementation PR. The generated job uses
283283
`source: issue_implementation`, `repair_strategy: new_fix_pr`, blocks merge and
284284
close actions, and reuses `clawsweeper/issue-<repo>-<number>` on reruns.
285+
Workers can reconstruct this minimal job from the requested `jobs/.../issue-*.md`
286+
path when a dispatch races ahead of state propagation, so the request does not
287+
silently skip as stale.
285288
When `CLAWSWEEPER_AUTO_IMPLEMENT_REPRO_BUGS=1`, review publish can also dispatch
286289
the same lane automatically for strict bug reports only: `item_category: bug`,
287290
`reproduction_status: reproduced`, `reproduction_confidence: high`, high

‎docs/work-lane.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ have an open PR reference or existing ClawSweeper implementation PR, writes the
4545
normal `source: issue_implementation` job, commits the ledger, then dispatches
4646
`repair-cluster-worker.yml` in autonomous mode.
4747

48+
Comment-triggered issue implementation uses the same durable job format. If a
49+
worker starts before the new state commit is visible in its checkout, the worker
50+
reconstructs the minimal `source: issue_implementation` job from the job path
51+
and continues instead of treating the dispatch as stale.
52+
4853
PRs created from this path are labeled `clawsweeper` and
4954
`clawsweeper:autogenerated`. The lane is PR-only: it does not merge or close the
5055
source issue.

‎scripts/restore-repair-job.sh‎

Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
JOB_PATH="${1:-${JOB_PATH:-}}"
5+
SKIP_TARGET="${2:-this worker}"
6+
7+
if [ -z "$JOB_PATH" ]; then
8+
echo "JOB_PATH is required" >&2
9+
exit 1
10+
fi
11+
12+
write_output() {
13+
local key="$1"
14+
local value="$2"
15+
if [ -n "${GITHUB_OUTPUT:-}" ]; then
16+
echo "$key=$value" >> "$GITHUB_OUTPUT"
17+
else
18+
echo "$key=$value"
19+
fi
20+
}
21+
22+
restore_automerge_job() {
23+
case "$JOB_PATH" in
24+
jobs/*/inbox/automerge-*.md) ;;
25+
*) return 1 ;;
26+
esac
27+
local filename stem rest number repo_slug owner repo_name repo ref branch
28+
filename="${JOB_PATH##*/}"
29+
stem="${filename%.md}"
30+
rest="${stem#automerge-}"
31+
number="${rest##*-}"
32+
repo_slug="${rest%-${number}}"
33+
owner="${JOB_PATH#jobs/}"
34+
owner="${owner%%/*}"
35+
repo_name="${repo_slug#${owner}-}"
36+
if [ -z "$number" ] || [ "$number" = "$rest" ] || [ -z "$repo_name" ] || [ "$repo_name" = "$repo_slug" ]; then
37+
return 1
38+
fi
39+
repo="$owner/$repo_name"
40+
ref="#$number"
41+
branch="clawsweeper/automerge-$repo_slug-$number"
42+
mkdir -p "$(dirname "$JOB_PATH")"
43+
cat > "$JOB_PATH" <<EOF
44+
---
45+
repo: $repo
46+
cluster_id: automerge-$repo_slug-$number
47+
mode: autonomous
48+
allowed_actions:
49+
- comment
50+
- label
51+
- fix
52+
- raise_pr
53+
blocked_actions:
54+
- close
55+
- merge
56+
require_human_for:
57+
- close
58+
- merge
59+
canonical:
60+
- $ref
61+
candidates:
62+
- $ref
63+
cluster_refs:
64+
- $ref
65+
allow_instant_close: false
66+
allow_fix_pr: true
67+
allow_merge: false
68+
allow_unmerged_fix_close: false
69+
allow_post_merge_close: false
70+
require_fix_before_close: true
71+
security_policy: central_security_only
72+
security_sensitive: false
73+
target_branch: $branch
74+
source: pr_automerge
75+
---
76+
77+
# ClawSweeper adopted PR repair candidate
78+
79+
Maintainer opted $ref into ClawSweeper automerge.
80+
81+
Source PR: https://github.com/$repo/pull/$number
82+
Title: PR $ref
83+
84+
ClawSweeper should use this job only for the bounded ClawSweeper review/fix loop:
85+
86+
- If ClawSweeper emits an explicit repair marker, requests changes, or finds failing checks/rebase work, and the PR branch is safe to update, emit a fix artifact with \`repair_strategy: "repair_contributor_branch"\` and \`source_prs: ["https://github.com/$repo/pull/$number"]\`.
87+
- If the PR branch cannot be safely updated, emit a narrow credited replacement only when the artifact can preserve the original contributor credit; otherwise return \`needs_human\`.
88+
- Do not merge, close, or bypass review gates from the worker. The comment router owns final merge only after a passing ClawSweeper verdict for the exact current head.
89+
- Keep repair scope limited to actionable ClawSweeper findings, failing relevant checks, and required review feedback on this PR.
90+
EOF
91+
}
92+
93+
restore_issue_implementation_job() {
94+
case "$JOB_PATH" in
95+
jobs/*/inbox/issue-*.md) ;;
96+
*) return 1 ;;
97+
esac
98+
local filename stem rest number repo_slug owner repo_name repo ref branch
99+
filename="${JOB_PATH##*/}"
100+
stem="${filename%.md}"
101+
rest="${stem#issue-}"
102+
number="${rest##*-}"
103+
repo_slug="${rest%-${number}}"
104+
owner="${JOB_PATH#jobs/}"
105+
owner="${owner%%/*}"
106+
repo_name="${repo_slug#${owner}-}"
107+
if [ -z "$number" ] || [ "$number" = "$rest" ] || [ -z "$repo_name" ] || [ "$repo_name" = "$repo_slug" ]; then
108+
return 1
109+
fi
110+
repo="$owner/$repo_name"
111+
ref="#$number"
112+
branch="clawsweeper/issue-$repo_slug-$number"
113+
mkdir -p "$(dirname "$JOB_PATH")"
114+
cat > "$JOB_PATH" <<EOF
115+
---
116+
repo: $repo
117+
cluster_id: issue-$repo_slug-$number
118+
mode: autonomous
119+
allowed_actions:
120+
- comment
121+
- label
122+
- fix
123+
- raise_pr
124+
blocked_actions:
125+
- close
126+
- merge
127+
require_human_for:
128+
- close
129+
- merge
130+
canonical:
131+
- $ref
132+
candidates:
133+
- $ref
134+
cluster_refs:
135+
- $ref
136+
allow_instant_close: false
137+
allow_fix_pr: true
138+
allow_merge: false
139+
allow_unmerged_fix_close: false
140+
allow_post_merge_close: false
141+
require_fix_before_close: false
142+
security_policy: central_security_only
143+
security_sensitive: false
144+
target_branch: $branch
145+
source: issue_implementation
146+
required_pr_labels:
147+
- clawsweeper:autogenerated
148+
---
149+
150+
# ClawSweeper issue implementation candidate
151+
152+
ClawSweeper Repair should create or update one implementation PR from \`$branch\`.
153+
154+
Source issue: https://github.com/$repo/issues/$number
155+
Title: Issue $ref
156+
157+
## Operator Prompt
158+
159+
Use the source issue as the product request or bug report. Verify the request is still valid on latest \`$repo@main\`, inspect nearby code, and make the narrowest implementation that directly satisfies the issue. If the issue is too broad, underspecified, security-sensitive, already fixed, or not safely implementable by automation, do not change code; report the exact blocker.
160+
161+
When code changes are appropriate, emit a fix artifact with \`repair_strategy: "new_fix_pr"\`, \`source_prs: []\`, this issue in \`linked_refs\`, and validation commands for the touched surface.
162+
163+
## Guardrails
164+
165+
- Do not merge.
166+
- Do not close the issue from this lane.
167+
- Keep one PR for this issue; reuse \`$branch\` if it already exists.
168+
- Keep the diff narrow and avoid unrelated refactors.
169+
- Preserve issue context and link https://github.com/$repo/issues/$number in the PR body.
170+
- Add a changelog entry when the target repo expects one.
171+
EOF
172+
}
173+
174+
if [ -f "$JOB_PATH" ]; then
175+
write_output job_exists 1
176+
elif restore_automerge_job; then
177+
write_output job_exists 1
178+
echo "::notice title=Restored automerge repair job::Job file '$JOB_PATH' was missing from the state checkout; reconstructed it from the workflow input."
179+
elif restore_issue_implementation_job; then
180+
write_output job_exists 1
181+
echo "::notice title=Restored issue implementation job::Job file '$JOB_PATH' was missing from the state checkout; reconstructed it from the workflow input."
182+
else
183+
write_output job_exists 0
184+
echo "::notice title=Stale repair dispatch::Job file '$JOB_PATH' no longer exists on the current state checkout; skipping $SKIP_TARGET."
185+
fi

0 commit comments

Comments
 (0)