Skip to content

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

Closed

Description

@admarble

Tier: judgment Found: 2026-09-30, root-cause investigation of #1244 and #1246 (tracker #1236, closed). Supersedes #1244; #1246 is blocked by this.

Problem: sequant run has two PR producers

  1. The exec skill opens the PR itself. "PR Creation and Verification" (.claude/skills/exec/SKILL.md:979-1030) runs git push -u origin then gh pr create unconditionally, with Bash(gh pr create:*) allowlisted (:37). The orchestrated-mode rules (:173-179) skip pre-flight checks and worktree creation and reduce comments, but none of them skips the PR. The feat(exec/qa): explicit in-place checkout mode — run a phase on a branch in the current clone without creating or resolving a worktree #1136 in-place section says PR creation is "unchanged" (:262-265). The prompt sequant run sends exec says nothing about PRs (src/lib/workflow/phase-registry.ts:221-222).
  2. The orchestrator opens it after QA. createPR (src/lib/workflow/worktree-manager.ts) is called from batch-executor.ts:2334-2388 with a body built by buildAutomatedPRBody. But if a PR already exists for the branch, createPR returns it untouched (worktree-manager.ts:2096-2112). That early return dates from 2026-03-11 (refactor(run): split 3,459-line monolith into focused modules #318's split), before fix(run): AC_MET_BUT_NOT_A_PLUS QA verdict misrouted into quality loop → fails with no PR (should break to PR) #749 (2026-07-14) and feat(run): --ready-gate — run the post-QA ready gate inside sequant run (automates the any-gaps/fix-gaps second look, stops at human merge) #817 (2026-07-28).

Consequences (from the original bodies via userContentEdits, and the 2026-09-30 run logs):

QA does not need a PR to exist. It reads CI status only when a PR exists (qa/SKILL.md:907-916) and skips that section otherwise (:1067). So making the orchestrator the only producer doesn't break QA; it only defers gh pr checks until the PR exists.

AC

  • AC-1: When SEQUANT_ORCHESTRATOR is set, the exec skill commits and pushes but opens no PR by any means: no gh pr create, and no GitHub MCP pull-request tool in in-place mode (feat(exec/qa): explicit in-place checkout mode — run a phase on a branch in the current clone without creating or resolving a worktree #1136). The skip sits at the ### PR Creation and Verification header, in the same **Skip this section if SEQUANT_ORCHESTRATOR is set** form used at :271/:291. The in-place bullet that now says PR creation is "unchanged" (:262-265) is reworded to match. The text is identical in .claude/skills/exec/SKILL.md, skills/exec/SKILL.md and templates/skills/exec/SKILL.md. Standalone /exec keeps creating the PR. Evidence: npx vitest run src/lib/__tests__/exec-orchestrated-no-pr-skill.test.ts, a gate test scoped to the PR Creation section and the in-place block of each copy
  • AC-2: When a PR already exists for the branch, createPR updates it instead of returning early. That covers both early returns: the Step 1 check (worktree-manager.ts:2098-2112) and the "already exists" race fallback (:2163-2173). The update sets the body buildAutomatedPRBody would have produced (QA note, ready-gate report, exec summary, closing line), the title buildPRTitle would have produced, and prBase when --stacked set one. The update goes through a GitHubProvider method that uses gh api -X PATCH (not gh pr edit, which fails on the projectCards deprecation). Overwrite decision (spec): title and body are overwritten only when the existing body is empty or carries the automated trailer (🤖 Generated by sequant run``); otherwise they are left alone, PR #N body was edited by hand; not overwritten is logged, and `base` is still set under `--stacked`. Evidence: `npx vitest run src/lib/workflow/worktree-manager.test.ts`
  • AC-3: Exec's summary is saved where a later qa-only run can read it (for example, the last exec summary recorded on the issue's state, or on the branch as a structured marker), and buildAutomatedPRBody uses it when the current run has no exec result. The fix(#1195): sequant://install recomputes on every read and reports a broken manifest as {error} #1225/fix(#1233): a successful run without qa leaves the issue in_progress, not ready_for_merge #1239 shape (exec → qa AC_NOT_MET → qa-only run opens the PR) gets exec's summary, not the placeholder. Evidence: npx vitest run src/lib/workflow/batch-executor.test.ts
  • AC-4: --no-pr means no PR from either producer: under the orchestrator with noPr, nothing runs gh pr create. Evidence: npx vitest run src/lib/workflow/batch-executor.test.ts plus the AC-1 gate test
  • AC-5: (Owner decision, 2026-10-01: option B.) Under the orchestrator, batch-executor calls createPR right after each successful exec pass, when the branch has commits ahead of base and --no-pr is unset. A PR carrying exec's ## Summary, its AC table and its SEQUANT_MUTATION markers therefore exists while qa runs, and QA's PR-body reads (§6i, the precheck AC literal-diff, §2a, test-plan boxes) keep working. The post-QA call goes through the AC-2 update path and adds the QA note and ready-gate report. A failed after-exec call logs a warning and does not fail the run; the post-QA call stays fatal (fix(run): exec that leaves work uncommitted reports success and the run passes with no PR — #534's empty-branch escape, reopened via a new route #879). The after-exec PR opens non-draft, the same as exec-opened PRs today. Draft-vs-ready policy stays with decision(run): a sequant run where no qa ran still ends with a PR — draft+note, require qa, or unchanged (blocked by #1247) #1246. Evidence: npx vitest run src/lib/workflow/batch-executor.test.ts

Non-goals

Graph metadata

  • No dependency edges.

May touch

  • .claude/skills/exec/SKILL.md, skills/exec/SKILL.md, templates/skills/exec/SKILL.md
  • src/lib/workflow/worktree-manager.ts, src/lib/workflow/worktree-manager.test.ts, src/lib/workflow/worktree-manager.build-pr-body.test.ts
  • src/lib/workflow/batch-executor.ts, src/lib/workflow/batch-executor.test.ts
  • src/lib/workflow/platforms/github.ts (a PR-body update call, if needed)
  • src/lib/workflow/state-manager.ts / state-schema.ts (if the exec summary is saved in state)
  • src/lib/__tests__/exec-orchestrated-no-pr-skill.test.ts (new)

Activity

  1. added
    bug
    on Sep 30, 2026
  2. admarble commented on Oct 1, 2026

    @admarble
    ContributorAuthor

    Runner context (re-checked against main @ 5e8f0aa)

    AC-1 and AC-2 were rewritten before launch to cover producers the original body missed. QA verifies the AC lines as they now read.

    Line refs (current):

    Prior fixes / producers

    Implementation traps (each has bitten this repo)

    • The new gh call shifts ordered mocks. worktree-manager.test.ts / batch-executor.test.ts queue child_process results in order (bug(exec): sequant run worktrees never record sequantBase, so the zero-diff/uncommitted guard compares against origin/main and a --base ahead of main disables it #1234: 19 failures from one added git call). Fix the queues; don't stub around them.
    • PR update goes through gh api -X PATCH repos/<o>/<r>/pulls/<n> with the body from a file. gh pr edit --body fails on the projectCards GraphQL deprecation.
    • AC-1 gate test:
      • Scope it to the ### PR Creation and Verification section and the in-place block of each copy, not the whole file.
      • It must make a real call (for example, read the file and slice the section), or the tautology detector flags it.
      • Mutation-verify it: delete the skip line in one copy and confirm that exact test fails.
    • AC-4: --no-pr must reach the exec agent too. Today only batch-executor.ts:2334 reads it. Thread it through whatever env or prompt the exec phase gets (for example, a SEQUANT_* var), so both producers honour it.

    Standard block

    • No full npm test in exec or in QA. This applies to the qa phase too: the 30-minute MCP wall kills the phase. Run only the test files named in the ACs plus grep -rlE 'createPR|buildAutomatedPRBody|viewPRByBranchSync|PR Creation and Verification' --include='*.test.ts' src __tests__ scripts | xargs npx vitest run (zsh: don't rely on $files word-splitting).
    • Commit WIP early, and always before a mutation.
    • The mutation marker's failedTest must start with the test file path: src/lib/__tests__/exec-orchestrated-no-pr-skill.test.ts > … > ….
    • PR body: Closes #1247. Use Refs only for any tracker. Never write a closing keyword next to another real issue number, even as an example; write #<n>.
    • Settings reads must be JSONC-safe.
  3. admarble commented on Oct 1, 2026

    @admarble
    ContributorAuthor

    Complexity: Standard (4 ACs, 4 directories)

    AC Quality Check

    • AC-2, AC-3 and AC-4 cite existing test files as evidence. Those files pass today (batch-executor.test.ts already has noPr: true cases at :2183/:2294), so the citations gate nothing on their own. Exec must add new named cases that fail on main (listed below).
    • AC-2 left the overwrite policy to spec. The decision is below, and exec writes it into the AC-2 line before coding (see memory: a decision comment alone doesn't reopen exec).
    • AC-1 is a gate AC, so the PR needs a SEQUANT_MUTATION record whose failedTest starts with the test file path.

    Scope Assessment

    Non-Goals: present (#1246's policy, standalone /exec).

    Metric Value Status
    Feature count 1 (single PR producer) ✅
    AC items 4 ✅
    Directory spread skills ×3, src/lib/workflow, platforms/, __tests__ ⚠️

    Verdict: ✅ SCOPE_OK. The spread is mechanical: three mirrored skill copies.


    Acceptance Criteria

    AC-1: Exec opens no PR under SEQUANT_ORCHESTRATOR

    Verification: Unit Test (a gate test that reads each SKILL.md copy and slices the section)
    Scenario: Given any of the 3 copies → When the test slices ### PR Creation and Verification up to the next ###, plus the in-place-checkout (#1136) block → Then the section opens with **Skip this section if \SEQUANT_ORCHESTRATOR` is set**, and the in-place block no longer lists "PR creation" as unchanged. **Assumptions:** Every orchestrator that sets the var opens the PR itself. Verified for sequant run (phase-executor.ts:1696, and the MCP server's run.ts:801goes through it) and for/fullsolve (SEQUANT_ORCHESTRATOR=fullsolve`, which opens the PR at §5.1 "Create PR (if not exists)"). Both still produce a PR.

    AC-2: createPR updates an existing PR

    Verification: Unit Test (worktree-manager.test.ts)
    Scenario: Given viewPRByBranchSync returns PR #N → When createPR runs → Then it pushes the branch, then calls github.updatePRSync(N, {title, body, base?}), and returns {success, prNumber: N}. The same happens on the already exists race path.
    Overwrite decision (write this into the AC line): title and body are overwritten only when the existing body carries the automated trailer (🤖 Generated by \sequant run`) **or is empty**. Otherwise sequant leaves the title and body alone, logs PR #N body was edited by hand; not overwritten, and still updates baseunder--stacked. Rationale: under AC-1 every PR sequant meets on an orchestrated branch is its own, so an edited body means a human edited it. The leftover exec-made PRs (#1237-style, with the Generated with [Claude Code]` trailer) are a one-time migration and not worth clobbering human edits for.

    AC-3: Exec summary persists for a later qa-only run

    Verification: Unit Test (batch-executor.test.ts, plus a state-manager round-trip)
    Scenario: Given run 1 = exec → qa AC_NOT_MET (state stores the summary) → When run 2 = qa-only with PR creation → Then createPR receives the stored summary, and the body has no Automated PR for issue #N.

    AC-4: --no-pr means no PR from either producer

    Verification: Unit Test (an existing batch-executor noPr case, plus the AC-1 gate)
    Scenario: Given noPr → Then createPR isn't called, and exec can't open one because AC-1 suppresses it whenever the orchestrator is set.


    Implementation Plan

    Phase 1: Single producer (skill text)

    1. In all 3 exec/SKILL.md copies: add the skip line under ### PR Creation and Verification (:979): the orchestrator opens and updates the PR; commit and git push -u origin <branch>, then report the branch and stop. Reword the in-place bullet at :262-265 and the MCP pull-request-tool sentence at :246 so they apply only when standalone. Add bullet 6 to the orchestrated list at :173-179: "Skip PR creation". Keep the gh pr create allowlist entry, since standalone still uses it.
    2. Write src/lib/__tests__/exec-orchestrated-no-pr-skill.test.ts, scoped to the two regions in each copy. Commit, then mutation-verify by deleting the skip line in one copy.

    Phase 2: Update-in-place (createPR)

    1. Add GitHubProvider.updatePRSync(prNumber, {title?, body?, base?}, cwd) in platforms/github.ts. It runs gh api -X PATCH repos/{owner}/{repo}/pulls/<n> -F body=@<tmpfile> -f title=… [-f base=…] (the {owner}/{repo} placeholders are resolved by gh from cwd), and viewPRByBranchSync also fetches body.
    2. In worktree-manager.ts, factor title, linkMode and body into one place, computed before Step 1. Replace both early returns with updateExistingPR(): push, check the overwrite policy, PATCH. A failed PATCH returns success with a warning; it doesn't fail the run, because the PR exists (fix(run): exec that leaves work uncommitted reports success and the run passes with no PR — #534's empty-branch escape, reopened via a new route #879 is about a missing PR). Note that the current early return never pushes, so qa-loop commits made after exec's PR stay local today. The update path fixes that.
    3. Fix the ordered child_process mock queues in worktree-manager.test.ts, where the new push and gh calls shift them (bug(exec): sequant run worktrees never record sequantBase, so the zero-diff/uncommitted guard compares against origin/main and a --base ahead of main disables it #1234 trap). Add cases for both early returns, a hand-edited body, --stacked base, and a PATCH failure.

    Phase 3: Persist exec summary

    1. Add execSummary: z.string().optional() to IssueStateSchema: the extracted, sanitized summary, capped by EXEC_SUMMARY_MAX_LENGTH. Add StateManager.updateExecSummary(). Batch-executor writes it after a successful exec. At PR time it uses the current run's exec output if there is one, otherwise state.execSummary. Thread it as opts.execSummary (already extracted) next to execOutput.
    2. Add batch-executor cases for the fix(#1195): sequant://install recomputes on every read and reports a broken manifest as {error} #1225/fix(#1233): a successful run without qa leaves the issue in_progress, not ready_for_merge #1239 shape and for noPr + orchestrated (AC-4), then run the grep-scoped suite from the runner comment.

    Design Review

    1. Where does this belong? createPR in worktree-manager.ts as the only producer, with GitHubProvider owning the gh call (Consolidate remaining gh CLI calls into GitHubProvider #443). The skill only gives up PR creation.
    2. Simplest correct approach? Skip PR creation unconditionally under the orchestrator. That makes AC-4 free, with no new SEQUANT_NO_PR env var: the runner comment suggests threading noPr to exec, but once exec never opens a PR under an orchestrator there is nothing for the flag to gate. Rejected: (a) let exec create the PR and have the orchestrator only edit it, which keeps two producers; (b) a SEQUANT_NO_PR env var, which adds one more rule to keep in sync for no behavior.
    3. Existing pattern? The **Skip this section if SEQUANT_ORCHESTRATOR is set** header (:271/:291); gh api PATCH with a body file (memory feedback_gh_pr_edit_projectcards); additive optional state fields (capped, feat(orchestrator): preserve partial output for turn-capped phases in phase-executor #739).
    4. Senior challenge: "Why store the summary in state.json when it's per-checkout?" It's the same store pr/phases already rely on, and qa-only re-runs happen from the same checkout. A branch marker would need a commit or a PR to exist first. Second: "PATCH on a human PR?" That's the overwrite policy above.

    ADR: the plan chooses between designs (exec-as-producer vs orchestrator-as-producer; state vs branch marker), so the exec PR includes docs/adr/NNNN-single-pr-producer-under-orchestrator.md.


    Feature Quality Planning

    • Error paths: a failed PATCH warns but stays successful. A failed push in the update path fails, the same as the create path.
    • Sibling sites (not in scope, follow-ups only): fullsolve/SKILL.md:784 gives exec-created PRs no update path either. Under AC-1, exec stops creating them in fullsolve, and fullsolve's own §5.1 still runs. merger/release are standalone.
    • Docs: docs/ mentions of exec creating the PR under sequant run. Grep PR creation in docs/ and the CHANGELOG entry.

    Open Questions

    1. Overwrite a hand-edited body? Recommendation: no (policy above). Impact if wrong: a reviewer's PR description is clobbered on the next qa-only run.
    2. Should a PATCH failure fail the run? Recommendation: no, warn instead. Impact if wrong: the body is stale while the run reports success. It's visible in the log.
    3. Store execSummary on the issue state or in phases.exec? Recommendation: issue-level, since PhaseState is a status record. Impact: minor.

    Recommended Workflow

    Phases: spec → exec → qa
    Quality Loop: disabled
    Reasoning: It's a bug fix whose design is set above. The tests are named per AC, so testgen stubs add nothing.

    Conflict note: no open worktree touches worktree-manager.ts/batch-executor.ts past main except #1222/#1223/#1233, which are already merged. #1245 edits the qaVerdict line next and lands after this one.

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

    @admarble
    ContributorAuthor

    QA Verdict: NEEDS_VERIFICATION

    AC coverage: 4/4 met

    Gaps:

    • Required CI test check still pending; merge readiness unconfirmed
    • Under the orchestrator the qa phase now runs before any PR exists, so §6i resolves Missing for gate-test ACs; follow-up issue not yet filed
  6. added 2 commits that reference this issue on Oct 1, 2026
  7. admarble commented on Oct 1, 2026

    @admarble
    ContributorAuthor

    Follow-up ledger: QA's gap 2 ("qa runs before any PR exists, so §6i resolves Missing") is fixed in PR #1252, not filed. The owner chose option B: the orchestrator opens the PR right after exec and updates it after QA. That is AC-5, added to the AC list above. QA's gap 1 (CI pending) is resolved by CI on the new head. The draft-until-QA policy stays with #1246.

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