Skip to content

fix(exec): under the orchestrator, a loop exec rewrites the PR body itself (gh api PATCH), so later sequant updates are dropped as "edited by hand" #1302

Closed

Description

@admarble

Found: the #1297 run on 2026-10-04 (PR #1300). In a quality-loop iteration, the exec phase rewrote the PR body itself:

gh api -X PATCH repos/{owner}/{repo}/pulls/1300 -F body=@/tmp/pr1300.md

Exec wrote that it did this "as QA suggested": the previous QA pass reported a missing mutation marker in the PR body. The new body ended with exec's own trailer, not sequant run's. isAutomatedPRBody then treated it as hand-edited, and the orchestrator logged PR #1300 body was edited by hand; not overwritten. Every later update was lost: the QA verdict note, the follow-ups checklist (#1249) and the "QA has not run" line (#1246).

Root cause: #1247's single-producer rule has a hole. The exec skill's PR Creation section, under SEQUANT_ORCHESTRATOR, says "Open no PR by any means: no gh pr create, and no GitHub MCP pull-request tool either." It doesn't forbid editing an existing PR's body or title (gh pr edit, gh api … PATCH …/pulls/N). QA's gap text points at the PR body ("add the markers to the PR body"), and a loop exec takes that as an instruction.

Prior fixes / producers

AC

  • AC-1: Under SEQUANT_ORCHESTRATOR, the exec skill (all copies) forbids changing the PR's body or title by any means: gh pr edit, gh api PATCH on pulls/N, or an MCP tool. It says what to do instead: put the content in the final ## Summary, and the orchestrator carries it into the body. Evidence: a gate test scoped to the PR Creation section, mutation-verified
  • AC-2: When QA runs under the orchestrator, a gap about missing PR-body content names exec's final output as the place to fix it, not the PR body. Evidence: a gate test on the relevant QA section, mutation-verified, within the QA skill's no-growth cap (feat(qa): enforce the follow-up ledger — every deferred item resolves to filed/fixed/dropped; sibling scans search the defect class #1249 AC-5)
  • AC-3: Decide: should the orchestrator's update path reclaim a body whose last editor was a phase agent, not a human? If not, record "dropped: ". Evidence: the decision recorded on this issue

Refs #1297

Activity

  1. added
    bug
    on Oct 4, 2026
  2. admarble commented on Oct 4, 2026

    @admarble
    ContributorAuthor

    Upstream cause (research note)

    The PR body has two roles. Since #939 it is QA's evidence channel: §6i parses SEQUANT_MUTATION markers from $PR_BODY (qa/SKILL.md:2579). Since #1247 it is also an artifact only the orchestrator may write. When QA finds a gap, its gap text names the body as the place to fix it, so a loop exec edits the body.

    The correct path already works. batch-executor.ts:1143-1212 rebuilds the body from the latest exec's ## Summary after every exec, including quality-loop iterations. Exec only needed to put the markers in its Summary. So AC-2 (QA's wording) matters as much as AC-1: QA's text is what prompted the edit.

    For AC-3: isAutomatedPRBody (worktree-manager.ts:2120) decides ownership from the body's content, by looking for the trailer. Any writer who drops the trailer removes sequant's ownership. The check was written to protect PRs that exec opened before #1247. It can't tell a phase agent's edit from a person's edit. Reclaiming bodies last edited by an agent would need ownership recorded in state, for example a hash of the last body sequant wrote. The trailer check can't do that. Weigh this when making the AC-3 decision.

  3. admarble commented on Oct 4, 2026

    @admarble
    ContributorAuthor

    Runner context (before sequant run)

  4. admarble commented on Oct 4, 2026

    @admarble
    ContributorAuthor

    Complexity: Simple (3 ACs, 3 directories: .claude/skills/{exec,qa}, mirrors, src/lib/__tests__)

    AC Quality Check

    • AC-1/AC-2: single line, Evidence: present. Evidence ("a gate test … mutation-verified") names no file or command. Tighten: the test must fail on today's main (neither section has the wording yet), so it is not vacuous.
    • AC-3: Evidence is a recorded decision, so the issue comment is the artifact.
    • ⚠️ No ## Non-Goals section in the issue. Proposed: no change to isAutomatedPRBody or buildAutomatedPRBody; the runner's hand edits stay out of scope.

    Scope Assessment

    Metric Value Status
    Feature count 1 ✅
    AC items 3 ✅
    Directory spread 3 ✅

    Verdict: ✅ SCOPE_OK

    Acceptance Criteria

    AC-1: exec forbids editing the PR body/title under the orchestrator

    Verification: Unit Test (gate test on skill text)
    Scenario: Given exec/SKILL.md → When the "PR Creation and Verification" section (line ~977, scoped from that heading to the next ###) is read → Then it forbids gh pr edit, gh api … PATCH …/pulls/N and an MCP tool for body or title, and says to put the content in the final ## Summary.
    Assumptions: The existing #1247 sentence is the right home. Its last lines already say "put the AC table and every marker in the final ## Summary", so the edit is one added sentence, not a new section.

    AC-2: QA names exec's final output, not the PR body, as the fix location

    Verification: Unit Test (gate test on a delimited QA section)
    Scenario: Given qa/SKILL.md §6i → When a mutation-marker gap is reported under SEQUANT_ORCHESTRATOR → Then the gap text says "add the markers to exec's final ## Summary".
    Assumptions: qa/SKILL.md must not grow (#1249 AC-5). Pay for the new sentence by rewording an existing one.

    AC-3: reclaim agent-edited bodies?

    Verification: Manual (decision recorded)
    Recommendation: dropped: ownership is not derivable from the body. isAutomatedPRBody (worktree-manager.ts:2120) reads the trailer. It cannot tell an agent's edit from a person's. Reclaiming would need a hash of the last sequant-written body in state, and any reclaim would also overwrite a person's later edit, which is the case the check protects. AC-1 and AC-2 remove the cause on the producer side. Reopen only if a phase agent edits a body again after they land.

    Sibling scan (every place a phase is told to write or fix the PR body)

    Owner is the two skills, not a shared reference (_shared/references has no PR-body text; _shared and loop grep clean).

    Site Wording Action
    exec/SKILL.md:982 #1247 no-PR rule AC-1 edit
    exec/SKILL.md:784 "Add the AC verification table to the PR body" Under the orchestrator this contradicts the rule above. Reword to "Summary (PR body when exec opens it)" — in AC-1 scope, same file
    exec/SKILL.md:839 "put this marker in the PR body" Same: point at the final ## Summary under the orchestrator
    exec/SKILL.md:1354,1363,1518 "paste … into the PR body", "Hook verdicts changed:" Same class; give a single orchestrator clause
    qa/SKILL.md:1413,1415 settle block "pasted into the PR body" Same class
    qa/SKILL.md:2579 and §6i Missing/Failed text reads markers from $PR_BODY Reading is fine (orchestrator builds it). AC-2 edit is the wording of the gap

    Open question: the extra exec/qa sites (784, 839, 1354, 1363, 1518, qa 1413) are not in the ACs. Recommend fixing 784 and 839 (they directly teach the edit), and leaving the rest as a follow-up, since QA cannot grow.

    Implementation Plan

    Phase 1: skills (edit .claude/skills/*, then npm run sync:skills for templates/ and plugin/)

    1. exec/SKILL.md:982: add "Do not change the PR's body or title by any means (gh pr edit, gh api PATCH on pulls/N, an MCP tool). To add or fix content, put it in the final ## Summary; the orchestrator carries it into the body, on every exec including loop iterations." Reword lines 784 and 839.
    2. qa/SKILL.md §6i: gap text for Missing/Failed markers names "exec's final ## Summary" under SEQUANT_ORCHESTRATOR; net line count ≤ before. Write awk fields as $(N) (investigation(skills): Claude Code may substitute positional $0 inside qa SKILL.md awk programs when /qa gets an argument #1289 lint).

    Phase 2: gate tests (new src/lib/__tests__/exec-pr-body-edit-skill.test.ts, modelled on qa-followup-ledger-skill.test.ts)

    1. AC-1 test scoped to the exec section: asserts gh pr edit, PATCH, MCP, and ## Summary in that region. Run it over all three mirrors.
    2. AC-2 test scoped to the §6i region: asserts the ## Summary phrase and absence of "add the markers to the PR body".
    3. Mutation-verify both (delete the sentence, only that test fails, restore); put Mutation-verified: AC-N — … markers in exec's final ## Summary, failedTest starting with the test file path, no } in marker text.

    Phase 3: record AC-3 decision as an issue comment.

    Design Review

    1. Where does this belong? In the two skill prompts. The producer side (exec), per "one producer per artifact", plus QA's wording, which prompted the edit.
    2. Simplest correct approach? One forbidding sentence plus a pointer to the path that already works (batch-executor.ts:1143-1212 rebuilds from the latest Summary). Rejected: a consumer guard that reclaims bodies (AC-3), and a hook that blocks gh pr edit (broader, blocks the runner's own legitimate edits).
    3. Pattern and recurrence? fix(run): sequant run has two PR producers — exec opens the PR itself and createPR returns it untouched, dropping the QA note, ready-gate report and summary #1247 (single PR producer) is the only prior fix. This is the second hole in the same rule (create → edit), so ≥2 touches of the class. I checked it: the class here is "phase agents writing the PR artifact"; the fix covers create (existing), edit (AC-1) and the QA text that prompts it (AC-2), so it fixes the class and is not a divergence. A hook-level block was the alternative and is the follow-up if this recurs.
    4. Senior reviewer challenge? "Why prose, not enforcement?" Answer: skills are the control surface for phase agents here; the gate tests pin the wording, and the orchestrator log line (edited by hand) already surfaces a recurrence.
    5. Producers/consumers of the PR body: producers buildAutomatedPRBody (orchestrator), exec's Summary (input), exec direct edit (removed by AC-1), QA wording (AC-2), runner (out of scope). Consumers: isAutomatedPRBody, QA §6i $PR_BODY, ready-gate. Single producer afterward.

    Feature Quality Planning

    All standard checks pass. Notable items:

    Open Questions

    1. Fix the other exec/qa "into the PR body" sites (784, 839 yes; 1354, 1363, 1518, qa 1413 no)? Recommendation: 784 and 839 only. Impact: the rest keep teaching a body paste, but QA cannot grow.
    2. AC-3 as dropped? Recommendation: yes, reason above.

    Recommended Workflow

    Phases: exec → qa
    Quality Loop: disabled
    Reasoning: Small prompt-text fix with two gate tests; no UI, no security surface; testgen skipped (tests are pinned to skill wording, written in exec).

    Label Review

    Current: bug. Recommended: bug, planned. Quality Loop: won't auto-enable.

  5. added
    planned
    on Oct 4, 2026
  6. admarble commented on Oct 4, 2026

    @admarble
    ContributorAuthor

    QA Verdict: AC_MET_BUT_NOT_A_PLUS

    AC coverage: 2/3 met

    Gaps:

    Suggestions:

    • Exec still says to write into the PR body at exec/SKILL.md:1344, 1354, 1518 and 1524, and so does qa/SKILL.md:1413, with no orchestrator clause. Spec deliberately deferred these.
  7. added a commit that references this issue on Oct 4, 2026
  8. admarble commented on Oct 5, 2026

    @admarble
    ContributorAuthor

    AC-3 decision (owner, 2026-10-04): dropped

    dropped: ownership is not derivable from the body. isAutomatedPRBody recognises sequant's bodies by their trailer, and it can't tell a phase agent's edit from a person's. To reclaim a body, sequant would have to store a hash of the last body it wrote in state, and any reclaim would also overwrite a person's later edit, which is the case the check protects. AC-1 and AC-2 remove the cause on the producer side. Reopen if a phase agent edits a body again after this lands.

    Runner verification and follow-up ledger (PR #1310)

    Commands run: all lint:* scripts pass, the skill gate tests pass (327), and both mutation checks were re-run.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugplanned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions