Skip to content

Repair conflicted bot PRs on the frequent poll - #1108

Merged
max-sixty merged 5 commits into
mainfrom
codex/repair-conflicted-bot-prs
Aug 31, 2026
Merged

max-sixty merged 5 commits into
mainfrom
codex/repair-conflicted-bot-prs

Conversation

@max-sixty

@max-sixty max-sixty commented Aug 31, 2026 •

Copy link
Copy Markdown
Owner

Extend the 15-minute notifications workflow's precheck to count possible conflicts on PRs from the configured bot. The agent boots only when notifications or an eligible PR need work; the shared resolver then performs the authoritative local merge test.

When a conflict needs manual help, Tend posts one human-readable comment with a marker scoped to that head. Frequent ticks skip the same head, a new head is eligible immediately, and nightly still retries. Before changing a branch, the resolver re-reads the PR's head and base and pushes with an exact lease.

Verification
  • wt test — 849 Python tests and 32 worker tests passed; worker typecheck passed
  • pre-commit run --all-files — passed

This was written by Codex on behalf of max-sixty

@tend-agent tend-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The gate's shape is right: one query, an authoritative local test behind it, and a head-scoped marker so a deferred conflict doesn't re-boot every quarter hour. Three notes on the marker path (inline), plus a couple that don't attach to a line.

The marker is only written on the deliberate-defer path. A session that times out, hits the token ceiling, or gets replaced in the queue before it reaches "resolution is too complex" leaves no marker — so the next tick boots on the same PR, and so does every tick after it. Under nightly that cost one session a day; on the frequent poll it's ~96. I don't see a cheap fix (writing the marker up front would post "needs manual resolution" on PRs the bot is about to fix cleanly), so this may just be worth knowing about rather than closing.

--force-with-lease may not be buying anything. Step 3 re-reads the live head and verifies the retained head is an ancestor of HEAD, which makes the push a fast-forward; a plain git push is already refused on any surprise. The lease is the only thing in the skill that enables a force at all, and the ancestry check is what actually guarantees the outcome.

The deferral reconciliation is prose where a script would fit. "If the head changed, delete only the stale comment. Otherwise keep the oldest current-head comment and remove every other deferral comment" is four branches of edge-case handling, executed by an LLM, mutating comments on PRs, with nothing testing it — running-in-ci's Scripts over prose recipes points at that shape. It also mostly disappears if the marker moves off comments (see the inline on the precheck).

Unrelated: #1106 edits workflows.py, docs/tend.example.yaml, and the install-tend copy around the same setup-guard if:. Different concern, but the two will conflict.

Verified locally
  • uv run pytest generator/tests/test_shared_steps.py generator/tests/test_cross_file_contracts.py generator/tests/test_integration.py — 52 passed
  • GH_DEBUG=api gh pr list --json comments on this repo — the emitted GraphQL is comments(first: 100) {nodes {id ...
  • The two test assertions suggested inline pass against the current notifications-check.sh

…ed-bot-prs

# Conflicts:
#	docs/tend.example.yaml
#	plugins/install-tend/skills/install-tend/references/tend.example.yaml
@max-sixty

Copy link
Copy Markdown
Owner Author

Addressed the inline findings in 69715c1. I also simplified reconciliation: create only when no same-head deferral exists, then delete only the newly created comment if the head changed or an older same-head comment won a race.

I kept the exact force lease. A normal fast-forward push can still recreate a concurrently deleted branch or restore a concurrent reset to an ancestor; leasing against the retained head SHA prevents both. A session that dies before writing a deferral may retry next tick, but there is no comparably cheap safe pre-work marker, and that failure only wastes compute.

This was written by Codex on behalf of max-sixty

@tend-agent tend-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The move to search with comments(last: 100) reads the newest comments, but the jq that consumes it was left on the old response shape, and the gate silently fails closed as a result.

gh pr list --json comments returned comments as an array; the GraphQL field returns comments { nodes { ... } }. any($pr.comments[]?; .author.login == $bot ...) iterates the object's values, so the first thing it hands the predicate is the nodes array, and jq aborts with Cannot index array with string "author". jq -er exits non-zero, the && chain falls to the else, and conflict_count is pinned at 0 — so tend-notifications never boots for a conflict and emits ::warning::bot PR conflict scan failed every 15 minutes instead. One inline fixes it.

The reason CI is green is the second inline: the fake gh wraps the fixtures in {data: {search: {nodes: .}}} but leaves each PR's comments as a bare array, so the suite exercises a shape the API never produces. With the fixtures reshaped and the script left as-is, both conflict tests fail with conflict_count 0 — which is exactly what production would do.

Verified locally

Ran generator/src/tend/templates/notifications-check.sh at 699a858 under a fake gh returning the real envelope (comments: {nodes: [...]}), with one marked CONFLICTING PR and one unmarked UNKNOWN one:

jq: error (at <stdin>:1): Cannot index array with string "author"
::warning::bot PR conflict scan failed; retrying next cycle
conflict_count=0

With only $pr.comments[]? → $pr.comments.nodes[]?, the same fixture gives conflict_count=1 — the marked head suppressed, the unmarked one counted.

Test-side, in a worktree at 699a858:

  • fixture reshaped, script unchanged → test_notifications_check_boots_for_unknown_or_conflicting_bot_prs and test_notifications_check_suppresses_only_the_marked_bot_head both fail (assert '0' == '2', assert '0' == '3')
  • both inlines applied → uv run pytest generator/tests/test_shared_steps.py generator/tests/test_cross_file_contracts.py generator/tests/test_integration.py — 52 passed

Comment thread generator/tests/test_shared_steps.py Resolved
@max-sixty
max-sixty merged commit f61a955 into main Aug 31, 2026
16 checks passed
@max-sixty
max-sixty deleted the codex/repair-conflicted-bot-prs branch August 31, 2026 01:36
max-sixty pushed a commit to max-sixty/leaf that referenced this pull request Aug 31, 2026
Automated nightly regeneration of tend's workflow files.

**tend version:** 0.1.22 → 0.1.24

## Notable changes

- **Conflicted bot PRs are now repaired on the frequent poll**
(max-sixty/tend#1108). `tend-notifications` gains a `conflict_count`
boot gate: it runs a GraphQL scan for open bot PRs whose `mergeable` is
not `MERGEABLE`, skips ones already carrying a `tend-conflict-deferred`
marker for the current head, and boots the agent when either
notifications or conflicts are outstanding. This is the bulk of the
workflow-body diff.
- **A multi-line adopter prompt now survives generation**
(max-sixty/tend#1103). Block scalars gain explicit indentation
indicators — `prompt: |` becomes `prompt: |2`, likewise `sandbox_setup:`
— so a prompt or setup script whose first line is itself indented no
longer changes meaning. This repo's `sandbox_setup:` (the Playwright
headless-shell install) is regenerated under the new form.
- **Review gating tightened** (max-sixty/tend#1087, max-sixty/tend#1107,
max-sixty/tend#1080). `APPROVE` is gated on the author stating merge
readiness rather than on the draft flag alone; the posting preflight is
bound to the outward action; and the code-review pass becomes its own
step, gated at submit.
- **`uv` is provisioned for agent sessions** (max-sixty/tend#1109), and
pre-check setup guards are preserved through regeneration
(max-sixty/tend#1106).
- Experimental Gist-backed Claude memory (max-sixty/tend#1110) — off
unless configured.

Full upstream range:
max-sixty/tend@0.1.22...0.1.24

## Also in this PR

`tend init` now writes `.github/actionlint.yaml` — a `concurrency.queue`
ignore scoped by glob to `**/.github/workflows/tend-*.yaml`. This repo
carried the same accommodation as a blanket `-ignore` arg on the
actionlint pre-commit hook, which suppressed that schema error
everywhere, including in workflows this repo owns. The generated file
replaces it, so the false positive stays ignored on the generated
workflows and a real one in `ci.yaml` or `publish-site.yaml` now fails.

Verified by running `pre-commit run actionlint --all-files` in the
regeneration worktree with the blanket arg removed and the generated
config in place: passed.

---------

Co-authored-by: leaf-agent <[email protected]>
max-sixty pushed a commit to max-sixty/worktrunk that referenced this pull request Aug 31, 2026
Nightly regeneration of tend's workflow files, picking up two upstream
releases.

**tend version:** 0.1.22 → 0.1.24

### Notable changes

- **The frequent poll now repairs conflicted bot PRs**, not just unread
notifications — the `tend-notifications` boot gate gained a GraphQL
query that test-merges open bot PRs and looks for deferral markers in
recent comments, so a conflicted PR wakes the queue instead of waiting
for the nightly sweep
([max-sixty/tend#1108](max-sixty/tend#1108)).
- **Review gating tightened**: `APPROVE` is now conditioned on the
author stating merge readiness rather than the draft flag alone, the
posting preflight is bound to the outward action, and the code-review
pass became its own step gated at submit
([max-sixty/tend#1087](max-sixty/tend#1087),
[max-sixty/tend#1107](max-sixty/tend#1107),
[max-sixty/tend#1080](max-sixty/tend#1080)).
- **Generator fixes that change this repo's YAML**: an adopter's
`prompt:` may now span more than one line (the `|2` block-indent markers
in the diff), pre-check setup guards are preserved, and the
`concurrency.queue` actionlint ignore is written out
([max-sixty/tend#1103](max-sixty/tend#1103),
[max-sixty/tend#1106](max-sixty/tend#1106),
[max-sixty/tend#1095](max-sixty/tend#1095)).
- **`uv` is provisioned for agent sessions**, and Gist-backed Claude
memory ships as experimental
([max-sixty/tend#1109](max-sixty/tend#1109),
[max-sixty/tend#1110](max-sixty/tend#1110)).
- Pinned harness versions moved with the releases: Claude 2.1.251, Codex
0.151.0, uv 0.12.7.

### A second commit, outside the usual regen

`tend init` now also writes `.github/actionlint.yaml` (the
`concurrency.queue` ignore from max-sixty/tend#1095). The nightly recipe
stages only `.github/workflows` and `.config`, so it landed untracked
and would be re-created on every future run — the second commit tracks
it. This repo runs no actionlint job or pre-commit hook, so the file is
inert here; it only suppresses a false positive for anyone linting these
workflows locally.

Full compare: max-sixty/tend@0.1.22...0.1.24

---------

Co-authored-by: worktrunk-bot <[email protected]>
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.

2 participants