Skip to content

bug(loop): orchestrated Step 1A re-fetches QA findings from GitHub instead of trusting the promptContext already embedded in its own prompt #960

Closed

Description

@admarble

Motivation

/loop's Orchestration Context table says (point 4): "Trust issue context — Orchestrator has already validated issue." But its concrete Step 1A instructions contradict this: in orchestrated mode, they unconditionally re-fetch QA findings via gh issue view <N> --json comments -q '.comments[] | select(.body | startswith("## QA Review for Issue")) | .body' | tail -1 — ignoring the promptContext the orchestrator already embedded directly into loop's own invocation prompt (basePrompt += "\n\n---\n\n" + promptContext, src/lib/workflow/phase-executor.ts:1093-1094; built by buildLoopContext in both ready-gate.ts and batch-executor.ts).

This is silently correct only when QA happens to post a ## QA Review for Issue comment to GitHub before /loop runs. It does not under sequant ready: QA there runs orchestrated and — by design — defers comment-posting to the orchestrator (qa/SKILL.md §9: "Skip posting GitHub comment"). sequant ready's own postReport (added in #937 AC-4) only fires at the terminal state, not after each mid-loop QA pass. So during any qa → loop cycle inside sequant ready, /loop's GitHub fetch finds no matching comment from the run in progress and falls back to whatever other comments exist on the issue.

Reproduced live (2026-08-23, dogfooding #937's AC-4 against #958/PR #959 via sequant ready 958):

  1. QA ran, independently re-verified the PR, and correctly found AC-1 MET (with a SEQUANT_QA_GAPS marker classifying the one real remaining gap as pause_for_human — outside /loop's scope by design).
  2. ready-gate.ts computed fixableGaps correctly (empty — nothing loop should touch) and passed it via promptContext/failedAcs into loop's invocation, exactly as designed.
  3. /loop ran anyway (NEEDS_VERIFICATION doesn't satisfy ac policy's threshold), and its own transcript opened with "I'm in orchestrated mode. Let me fetch the QA findings from the issue comments" — then reported an AC table with AC-1 as PENDING, directly contradicting the QA pass that had just run in the same sequant ready invocation, and stated "No SEQUANT_QA_GAPS marker present (0 matches)" even though one demonstrably existed in the live QA output.
  4. Root cause confirmed: issue fix(fullsolve): Phase 5.3 auto-merges the PR — the skill's own stop-list says to halt at the final summary #958 had exactly 3 comments at that point — a /spec comment, a stale ## /fullsolve Complete self-assessment from an earlier, unrelated session (whose AC-1 status was PENDING), and (after the run finished) the sequant ready terminal report. None start with ## QA Review for Issue, so /loop's grep matched nothing and it reconstructed state from the stale /fullsolve Complete comment instead — landing on exactly its (wrong, outdated) AC-1 status.

Consequence in this run: harmless by coincidence — there was nothing genuinely fixable either way, so /loop made no diff and the gate correctly halted at LOOP_NO_DIFF. But the mechanism is a live data-integrity bug: whenever /loop genuinely has fix_now work to do under sequant ready, it may reason from stale or absent GitHub context instead of the accurate, already-computed promptContext/failedAcs sitting in its own prompt — risking a skipped fix, a redundant fix, or action on contradicted AC statuses.

This is distinct from #942 (which reduces how often /loop runs at all when the only gaps are human-decision items) — #942 would narrow the exposure window but not fix the underlying bug, which still applies whenever /loop runs with real work under sequant ready.

Proposal

Make /loop's Step 1A actually honor its own Orchestration Context table's point 4 ("trust issue context"):

  1. When SEQUANT_ORCHESTRATOR is set, check the invocation prompt itself for the embedded promptContext block first — it is always present when dispatched by ready-gate.ts or batch-executor.ts (both build it via buildLoopContext before every loop dispatch). Treat it as the authoritative QA-findings source and skip the gh issue view comment fetch entirely in that case.
  2. Only fall back to the gh issue view "## QA Review for Issue" fetch when no such embedded context is present — i.e., genuinely standalone /loop <N> invocations, or an orchestrator that doesn't inject promptContext (verify none currently exist before assuming this branch is dead).
  3. Update the Orchestration Context table's point 4 to say precisely what "trust issue context" means operationally (currently vague enough that Step 1A's contradicting behavior wasn't caught by review).

Non-Goals

Tailored caveats

  • All three skill mirrors (.claude/skills/, templates/skills/, skills/) must change in sync (npm run lint:skill-sync).
  • Verify batch-executor.ts's (plain sequant run) loop dispatch has the same promptContext-embedding property before assuming the fix is safe there too — confirmed present at the code level (buildLoopContext(result) wired the same way), but worth a live check similar to the one that surfaced this issue.

Acceptance Criteria

  • AC-1: /loop, when orchestrated and given a promptContext block in its own invocation prompt, does not fetch gh issue view for QA findings and instead parses that embedded block. Evidence: gate test scoped to the delimited Step 1A section (clone the mutation-verified pattern from fix(fullsolve): Phase 5.3 auto-merges the PR — the skill's own stop-list says to halt at the final summary #958's own gate test), mutation-verified.
  • AC-2: A live sequant ready dogfood run against an issue with a genuine fix_now gap (not just human-decision/document gaps) shows /loop correctly reflecting the fresh QA data, not a stale GitHub comment. Evidence: transcript.
  • AC-3: Standalone /loop <N> (no SEQUANT_ORCHESTRATOR) is unaffected — still fetches from GitHub comments as before. Evidence: existing standalone-mode tests/gate-test coverage stays green.

Human decisions required

  • Whether the "no embedded promptContext, no matching GH comment, no log file" three-way-miss case should hard error (per the skill's existing documented fallback) or degrade to "no actionable issues found" — recommend hard error, since a silent miss is exactly this bug's failure mode.

Context

Discovered live while dogfooding #937's AC-4 (structured gap findings, sequant ready comment-persisting) against #958/PR #959 (sequant ready 958, 2026-08-23). Related: #937 (the gap-schema this bug undermines the intended consumption of), #942 (adjacent — reduces loop's run frequency in the human-decision case but doesn't fix this), #958 (the PR whose ready-gate run surfaced this).

Activity

  1. added
    bug
    on Aug 24, 2026
  2. admarble commented on Aug 24, 2026

    @admarble
    ContributorAuthor

    Spec: Plan for #960

    Complexity: Standard (3 ACs, 4 directories)

    Acceptance Criteria

    • AC-1: Orchestrated /loop with an embedded promptContext block parses that block and skips the gh issue view QA-comment fetch. — Verification: Unit Test (gate test scoped to the delimited Step 1A span, cloned from fix(fullsolve): Phase 5.3 auto-merges the PR — the skill's own stop-list says to halt at the final summary #958's mutation-verified pattern, all 3 skill mirrors)
    • AC-2: Live sequant ready dogfood run with a genuine fix_now gap shows /loop acting on fresh QA data, not a stale GitHub comment. — Verification: Manual Test (transcript; ⚠️ lint: "correctly" is vague — concrete check: loop's transcript cites the gap text from the embedded block, and its AC table matches the same-run QA verdict, with zero gh issue view --json comments fetches in Step 1)
    • AC-3: Standalone /loop <N> (no SEQUANT_ORCHESTRATOR) still fetches from GitHub comments / log file as before. — Verification: Unit Test (⚠️ premise gap: no existing loop-skill gate test found in src/lib/__tests__/ — the new gate test should pin Step 1B's fetch path too, otherwise AC-3's "existing coverage stays green" is vacuous)

    Implementation Plan

    Phase 1 — Runtime sentinel (single chokepoint):

    1. src/lib/workflow/phase-executor.ts getPhasePrompt() is the only place promptContext is embedded (basePrompt += "\n\n---\n\n" + promptContext) — both ready-gate.ts:710 and batch-executor.ts:1625 flow through it. Wrap the appended block in a stable sentinel, e.g. <!-- SEQUANT_PROMPT_CONTEXT -->\n{context}\n<!-- /SEQUANT_PROMPT_CONTEXT -->, so the skill detects embedded context deterministically instead of pattern-matching prose ("Ready gate (#683)…" vs "Previous phase … failed." differ per producer).
    2. Unit test in phase-executor.test.ts (getPhasePrompt is @internal-exported for testing): sentinel present when promptContext given, absent otherwise.

    Phase 2 — Skill edit (all 3 mirrors: .claude/skills/, skills/, templates/skills/ — npm run lint:skill-sync):
    3. Restructure loop/SKILL.md Step 1A inside new delimiters <!-- BEGIN: step-1a-context-source (#960) -->…<!-- END -->: first check the invocation prompt for the SEQUANT_PROMPT_CONTEXT sentinel → treat as authoritative QA findings, skip gh issue view entirely; only when absent, fall back to the existing GH-comment fetch → log file → hard error (keeps the documented fallback chain; the three-way miss stays a hard error per the issue's recommendation).
    4. Rewrite Orchestration Context point 4 to state the operational rule: "Trust embedded context — when the orchestrator injected a SEQUANT_PROMPT_CONTEXT block, it is the QA-findings source; do not re-fetch from GitHub."
    5. Keep the #937 SEQUANT_QA_GAPS exclusion semantics intact: the embedded promptContext is already fixableGaps-filtered by both producers (selectFixableGaps / ready-gate's filter), so Step 2's exclusion filter applies only to the fetched-comment path — note this explicitly in the skill to avoid double-filtering confusion.

    Phase 3 — Gate test + dogfood:
    6. New src/lib/__tests__/loop-context-source-skill.test.ts cloned from fullsolve-merge-gate-skill.test.ts (anchored to import.meta.url, all 3 roots, delimited-span extraction that throws on missing delimiters): asserts sentinel-first instruction in Step 1A span + gh issue view fetch retained in the fallback/Step 1B span. Commit before mutation-verifying; record Mutation-verified: markers in the PR body (CLAUDE.md gate-test rule).
    7. AC-2 dogfood: live sequant ready against an issue with a real fix_now gap; capture transcript (copy out of .sequant/ promptly — evidence rotates).

    Key decisions

    • Sentinel at getPhasePrompt (generic) over per-producer prefixes — one TS touchpoint covers both dispatch paths (and any future orchestrator), vs. editing two buildLoopContexts that already drifted apart once (fix(cli): bare parseInt on run --timeout lets a malformed value abort every phase instantly (sibling of #818) #833-style dual-producer trap).
    • Fix on the consuming side only — QA comment-posting behavior untouched (Non-Goal).
    • Hard error on three-way miss — matches the skill's already-documented fallback and the issue's recommendation; a silent miss is this bug's failure mode.

    Open Questions

    1. Sentinel scope: all phases or loop-only? — Recommendation: all phases (it's a generic "orchestrator-embedded context" marker; no consumer is harmed by it). Impact if wrong: a stray HTML comment in other phases' prompts — cosmetic.
    2. Should AC-3's gate test also pin Step 1B? — Recommendation: yes (no existing loop-skill test exists; without it AC-3 is unverifiable). Impact if wrong: slightly larger test file.
    3. Three-way-miss behavior (human decision from issue) — Recommendation: hard error. Impact if wrong: silent "no actionable issues" masks exactly this bug class.

    Recommended Workflow

    Phases: spec → exec → qa
    Quality Loop: disabled
    Reasoning: bug label, Standard tier; gate tests are hand-written + mutation-verified in exec (testgen adds nothing for skill-text gate tests); no UI. AC-2's live dogfood is a manual post-implementation step, not an automatable phase.

  3. added
    planned
    on Aug 24, 2026
  4. added a commit that references this issue on Aug 24, 2026
  5. admarble commented on Aug 24, 2026

    @admarble
    ContributorAuthor

    /fullsolve Complete

    Issue: #960
    Status: NEEDS_VERIFICATION (AC-1 and AC-3 fully met; AC-2 requires a live post-merge dogfood run)

    Progress Table

    Phase Iterations Status
    Spec 1/1 Complete — plan posted, ACs extracted and stored
    Exec 1/1 Complete — implementation + gate test + CHANGELOG entry
    Test Skipped No ui/frontend/admin labels
    QA 1/1 Complete — verdict NEEDS_VERIFICATION

    AC Coverage

    AC Description Status
    AC-1 Orchestrated /loop trusts embedded promptContext, skips gh issue view ✅ MET
    AC-2 Live sequant ready dogfood shows /loop reflecting fresh QA data ⏳ PENDING — needs a real issue with a genuine fix_now gap to dogfood against; not reproducible synthetically inside this PR
    AC-3 Standalone /loop <N> unaffected ✅ MET

    Coverage: 2/3 fully met, 1 pending external verification

    Quality Metrics

    • Build: ✅ clean
    • Lint: ✅ clean (0 warnings)
    • Full test suite: 273 files, 5626 passed, 1 pre-existing expected-fail, 2 skipped — no regressions
    • New/updated tests: phase-executor.test.ts (+2 tests), new loop-context-source-skill.test.ts (21 tests)
    • npm run lint:skill-sync: 44 synced, 0 diverged
    • Mutation verification: 3/3 mutations confirmed each test fails on the targeted regression, then restored (see PR body markers)
    • CI: all 9 checks green on PR fix(#960): /loop's orchestrated Step 1A trusts embedded promptContext instead of re-fetching from GitHub #962

    Risk Assessment

    • Likely failure mode: if a future orchestrator producer builds promptContext without going through getPhasePrompt, the sentinel wouldn't be added and /loop would silently fall back to the (still-correct) GitHub-fetch path — degrades gracefully, doesn't break.
    • Not tested: AC-2's live dogfood scenario — no in-flight issue with a genuine fix_now gap was available during this session to exercise the fix end-to-end under real sequant ready orchestration.
    • Self-review finding fixed in-PR: the sentinel constant's JSDoc was initially inserted between getPhasePrompt's own docstring and the function, leaving that docstring describing the wrong symbol — caught in QA code review and fixed as a follow-up commit (3812e2a9), verified clean before push.

    PR

    PR: #962

    Next Steps

    1. Merge PR fix(#960): /loop's orchestrated Step 1A trusts embedded promptContext instead of re-fetching from GitHub #962 after human review (not auto-merged — no --auto-merge flag or run.autoMerge setting was in effect for this run).
    2. Dogfood AC-2: run sequant ready against the next issue that reaches a qa → loop cycle with a genuine fix_now gap, and confirm /loop's transcript reflects the embedded SEQUANT_PROMPT_CONTEXT block rather than a GitHub comment fetch. Post the transcript to bug(loop): orchestrated Step 1A re-fetches QA findings from GitHub instead of trusting the promptContext already embedded in its own prompt #960.
    3. Close bug(loop): orchestrated Step 1A re-fetches QA findings from GitHub instead of trusting the promptContext already embedded in its own prompt #960 once AC-2 is confirmed (or if PR merges first, leave bug(loop): orchestrated Step 1A re-fetches QA findings from GitHub instead of trusting the promptContext already embedded in its own prompt #960 open with a follow-up comment until the dogfood evidence lands).

    Ready for human review; AC-2 verification recommended before final close.

  6. added 2 commits that reference this issue on Aug 24, 2026
  7. admarble commented on Aug 24, 2026

    @admarble
    ContributorAuthor

    Post-merge note: PR #962 merged (4c20536). AC-1 and AC-3 are confirmed via mutation-verified gate tests. AC-2 (live sequant ready dogfood against a genuine fix_now gap) was never executed — no qualifying in-flight issue was available during this work. Auto-closed by the PR's Closes #960, but that verification is still outstanding.

    Recommend: watch the next sequant ready run that hits a qa → loop cycle with a real fix_now gap, confirm /loop's transcript reflects the embedded context (not a GitHub comment fetch), and post the transcript here.

  8. admarble commented on Aug 24, 2026

    @admarble
    ContributorAuthor

    AC-2 dogfood attempt — outcome: pending, four real attempts, no genuine fix_now gap surfaced.

    Searched across sequant, ad-motion, varius, and thenewwayai for an in-flight issue with a genuine fix_now QA gap to exercise /loop's fixed Step 1A live. Ran four real end-to-end attempts:

    1. This PR (fix(#960): /loop's orchestrated Step 1A trusts embedded promptContext instead of re-fetching from GitHub #962) itself — clean, NEEDS_VERIFICATION only on CI-pending, resolved to green with no fix needed.
    2. admarble/ad-motion feat(#223): Track derived ACs through spec → exec → qa workflow #225 ("stopped turn vanishes from thread store") — spec→exec→qa via sequant run, all 4 ACs MET on first pass, NEEDS_VERIFICATION→READY_FOR_MERGE once CI resolved. PR: https://github.com/admarble/ad-motion/pull/227 (real, ready for merge).
    3. admarble/ad-motion feat(#175): Add title/body content analysis for phase detection #226 ("hung renderStill wedges the tail queue forever") — same pattern; exec's implementation was genuinely complete but stalled at the commit step (unrelated bug in that repo's pre-tool.sh no-changes-guard — only recognizes literal single-line cd path && git commit, not a prior-line cd via variable), salvaged and committed manually. QA: all ACs MET, NEEDS_VERIFICATION→ resolved once CI green. PR: https://github.com/admarble/ad-motion/pull/228 (real, ready for merge).
    4. feat(#175): Add title/body content analysis for phase detection #226 again via sequant ready --policy a-plus — the actual production mechanism AC-2 names — landed straight on READY_FOR_MERGE in one iteration, tokensUsed: 0, no /loop dispatch. Nothing to fix.

    Secondary finding (unrelated to #960): ad-motion's orchestrated sequant run --phases qa re-run produced a genuinely fresh internal verdict (AC_MET_BUT_NOT_A_PLUS) that was never posted anywhere (not the issue, not the PR) — GitHub showed a stale prior verdict until the later sequant ready run posted its own report. Worth filing on ad-motion separately if useful; not touched here since it's outside #960's scope.

    Conclusion: across four real, honest attempts the pipeline never organically produced a fix_now gap for /loop to act on — QA rigor at /exec time appears high enough that this is a genuinely rare live scenario, not a search failure. AC-2 remains the one open item on #960; recommend leaving it pending for a natural future occurrence rather than continuing to spend real repo/CI time chasing it. AC-1 and AC-3 remain fully verified (mutation-tested).

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