Repository navigation
feat(review-dispatch): extend fetch_pr_review_context and add PR-repair fetch tools - #874
Conversation
…ir fetch tools Tasks 1.1-2.1 of openspec/changes/extend-fetch-pr-review-context (issue unbound-force#861): - fetch_pr_review_context gains the five PR-repair fields (state, mergeable, merge_state_status, head_repository, base_repository derived from the PR url — gh pr view --json rejects baseRepository) and optional pr_number with current-branch resolution (design D2/D3) - new fetch_pr_checks tool: exit-code-tolerant gh pr checks fetch with eligibility derivation from observed buckets, fail-closed on unknown buckets (design D4) - new fetch_failed_run_logs tool: gh run view --log-failed fetch persisted to a 0o600 O_EXCL temp file, never returned inline (design D5) - scaffold mirror synced byte-identical (cmp-verified)
Task 3.1 of openspec/changes/extend-fetch-pr-review-context/ (design D7): extract the Bun.spawn mock harness — text streams, routed mock responses with exit-code-tolerant shapes, Bun global patching, and the setupTool scratch-project pattern — from fetch-pr-review-context.test.ts into .opencode/test/helpers/gh-spawn-mock.ts. The existing suite's local copy migrates opportunistically (53/53 green).
Task 3.2 of openspec/changes/extend-fetch-pr-review-context/ (modified FR-002/FR-003, design D2/D3/D7): five new fields passed through with fork orientation, base_repository derived from the PR url (unparseable url degrades with a warning), omitted pr_number current-branch resolution and pr_not_found, explicit-path and schema-strictness pins retained. 61/61 green.
Task 3.3 of openspec/changes/extend-fetch-pr-review-context/ (FR-013, design D4): full suite through the shared gh-spawn-mock harness — four-field happy path; exit-code-tolerant matrix (exit 0 green, gh exit 8 pending, non-zero failing, each returning data); eligibility derivation matrix (failing / pending / cancel / passing / fail-dominates / unknown-bucket fail-closed with a warning naming the value); verified zero-checks gh shape (exit 1, empty stdout, no-checks-reported marker gating the data path); unparseable stdout on any exit code including 0 → structured api_error; all six error codes; input validation (non-integer, zero, negative, above 999999, string injection, extra fields, omitted); pinned argument vector and discrete array elements. 35/35 green.
…lidation Task 3.4 of openspec/changes/extend-fetch-pr-review-context/ (FR-014, design D5): full suite through the shared gh-spawn-mock harness — happy path with log_path/log_bytes/log_lines and the write-to-read round-trip (content, byte size vs multi-byte fixtures, split-formula line counts); 0o600 log file under a 0o700 parent (TMPDIR sandboxed per test — the real $TMPDIR/opencode pre-exists at 0755 where the opencode app runs, so the mode assertion points the tool at a fresh scratch dir where its own mkdir mode applies); unlink-then-O_EXCL stale-file replacement; EISDIR write failure → api_error; pinned argv with --repo as discrete elements when provided and absent when not; run_not_found for the verified HTTP 404, HTTP 410 expired, and could-not-find shapes plus the HTTP 403 boundary that stays api_error; zero-line fetch succeeds with warning; gh_not_found/gh_auth_failed/timeout/rate_limited; and input validation (run_id pattern with injection payloads, non-string type confusion, repo pattern, .strict()) rejected before any gh invocation. Log text never returned inline. 31/31 green; 127/127 across the three fetch suites. Also flips the task 3.3 checkbox (landed in e2bff99).
Task 3.5 of openspec/changes/extend-fetch-pr-review-context/ (FR-013/FR-014 registration surface): add fetch_failed_run_logs and fetch_pr_checks to the two hand-maintained tool-list pins — the sorted Object.keys(dispatchHooks.tool) enumerations in scratch-smoke.test.ts and plugin-integration.test.ts — turning the two pin tests the d75549d registration broke back green. registration-surface.test.ts enumerates dynamically and needed no edit. 30/30 across the three suites.
Task 3.7 of openspec/changes/extend-fetch-pr-review-context/
(determinism pack DE-007): the three seam layers verified green
in this increment —
- Registration surface: registration-surface.test.ts enumerates
all registered tools dynamically (args/description/execute,
20/20) and the scratch-smoke + plugin-integration tool-list
pins enumerate fetch_pr_review_context, fetch_pr_checks, and
fetch_failed_run_logs (30/30); input-schema parity held by
the per-tool validation suites (FR-002 optional pr_number
with .strict(), FR-013 required 1-999999, FR-014 run_id/repo
patterns, all rejected pre-spawn).
- Documented output shape: FR-003's 24-field contract matches
FetchPrReviewContextOutput field-for-field; FR-013's checks/
eligibility output and FR-014's exact key set
{run_id, repo, log_path, log_bytes, log_lines, warnings}
asserted by their suites, log text never inline.
- Write-to-read round-trips: persisted 0o600 log files re-read
asserting content, byte size, and line counts against the
reported values; diff_path content re-read.
make plugin-test: 1337/1337, statements 95.41%, branches 88%
(floors 94/85 unchanged).
Collapse Phase 1.0/1.1/1.2 of uf.fix-ci.md onto the review-dispatch plugin tools per extend-fetch-pr-review-context task 4.1 (FR-015, design D6/D2/D3): - 1.0: availability prose collapses — the tools validate gh/auth; gh_not_found/gh_auth_failed structured errors map to the existing STOP messages - 1.1: auto-detect calls fetch_pr_review_context without pr_number (argument-supplied invocations call it with the number in 1.2); pr_not_found maps to the no-open-PR STOP - 1.2: both raw fetches replaced with fetch_pr_review_context + fetch_pr_checks; STATE/HEAD_REF/BASE_BRANCH/MERGEABLE/MERGE_STATE/ HEAD_REPOSITORY/BASE_REPOSITORY recorded from tool fields with IS_FORK derived from the repository comparison (design D2); the eligibility gate keys on the derived eligibility with identical STOP outcomes; raw bash blocks, the non-zero-exit caveat, and the bucket-categorization table removed Phase 1.3/1.4 and Phase 2 onward untouched (tasks 4.2/4.3 own them). Scaffold mirror sync and contract-test re-pinning follow in task 4.3.
…d_run_logs Collapse Phase 2.1 of uf.fix-ci.md onto the review-dispatch plugin tool per extend-fetch-pr-review-context task 4.2 (FR-015, design D5/D6): - 2.1: the mktemp block and the raw gh run view invocation are replaced by one fetch_failed_run_logs call with the 2.0-validated run_id and repo: <BASE_REPOSITORY>; run_not_found and the zero-line result (log_lines: 0) map to the existing STOP wording (structured error's message or zero-line warning verbatim, check names, run link); other structured errors STOP with the envelope surfaced verbatim - the untrusted-text hygiene and remove-on-completion-and-STOP cleanup rules retarget from <LOG_FILE> to the tool-reported log_path, with 2.2's slice-reading reference renamed to match - the Phase 2 intro's now-false raw-bash claim is corrected to the tool route (the 4.1 Phase 1 intro precedent); Phase 2.0's run-id derivation prose and the Phase 5 gh run rerun pin are untouched (design D6 non-goals) The fr-002 contract pin this drops extends the known 4.1 intermediate state; scaffold mirror sync and contract-test re-pinning follow in task 4.3.
Retire the deviation records that justified /uf.fix-ci's raw-gh fetch prose per extend-fetch-pr-review-context task 4.4 (FR-015, design D6), addressing the MEDIUM spec-review advisory in the same task: - uf-fix-ci design D1: closed-with-reference notes on all three inventory entries the re-route retires - the three-raw-gh- fetch-classes entry, the Phase 1.0 gh availability checks, and the Phase 1.2 bucket-keyed eligibility routing - each pointing at openspec/changes/extend-fetch-pr-review-context/ (issue unbound-force#861) (advisory part a; the task text named only the fetch-classes entry) - uf-fix-ci spec FR-001: the 'before any other step' gh availability verification becomes the Phase 1 fetch tools' own validation with the gh_not_found/gh_auth_failed mapping; the matching scenario's WHEN clause follows the tool mechanism - FR-002: the pinned gh pr view / gh pr checks invocations become the fetch_pr_review_context + fetch_pr_checks tool calls, with the derived eligibility keying the gate - FR-003: the gh run view --log-failed pin becomes the fetch_failed_run_logs tool call (log_path returned, never the log text inline) - FR-010: the raw-bash reservation list loses the three fetch classes; the remaining gh reservation narrows to gh run rerun --failed, the only raw gh invocation left - this change's design R3: FR-001 added to the enumeration of retirement-affected requirements (advisory part b) and the D1 fragment reference pluralized to match the three closures Scenario Given/When/Then structure and verification intent are preserved throughout; no other fragment of the completed change is touched (its proposal's Dependencies already threads unbound-force#861 as the retirement carrier). Task 4.4 is marked complete in the same commit. openspec validate uf-fix-ci --type change holds the warnings-only profile unchanged: valid, 2 WARNINGs (FR-002 long requirement text, originating_issue unrecognized key), 0 errors.
Add the Unreleased/Added CHANGELOG entry per task 5.2 of extend-fetch-pr-review-context (issue unbound-force#861): the extended fetch_pr_review_context tool (five PR-repair fields, optional pr_number), the fetch_pr_checks and fetch_failed_run_logs tools, the behavior-preserving /uf.fix-ci re-route with the uf-fix-ci deviation retirement, and the measured instruction- text delta (design D8: 106 lines of raw-gh fetch prose replaced by 100 lines of tool-call instructions, the command file 1262 -> 1256 lines), with the Spec footer and the Docs dual-footer carrying documentation issue unbound-force#873 plus the consolidated website trackers unbound-force/website#342 and unbound-force/website#310. Task 5.1 (the documentation issue itself) is external to the repo: unbound-force#873 was filed against unbound-force/unbound-force with the website-target resolution and the content-pipeline dispositions worded against the curator's significance thresholds. Both 5.1 and 5.2 checkboxes flip in this commit.
Task 5.3 (documentation-impact assessment) is external to the repo: the no-change disposition covering the full documentation surface (root AGENTS.md/README.md/QUICKSTART.md plus the entire docs/ tree, addressing the LOW spec-review advisory about the task text's incomplete five-file list) is recorded as the follow-up comment on documentation issue unbound-force#873 (unbound-force/unbound-force#issuecomment-6510669928).
Ship the /uf.unleash retrospective learnings with the feature PR per the Commit scope rule. Captures patterns and gotchas from the extend-fetch-pr-review-context workflow: intent-level command design, gh-cli PR fetch paths, openspec deviation retirement, plugin tool registration, review-tool seam verification, and the shared gh-spawn-mock test harness. Assisted-by: glm-5 Generated with AI assistance (glm-5)
jflowers
left a comment
There was a problem hiding this comment.
AI Review Council Verdict: APPROVE WITH ADVISORIES
The review council (4 of 5 dispatched reviewers completed; all approving — APPROVE WITH ADVISORIES x3, APPROVE x1) found no blocking issues in this change. 19 advisory findings (12 MEDIUM, 7 LOW) are summarized below and as inline comments; several are corroborated independently by multiple reviewers.
Context: CI is fully green (17 checks: 11 pass, 2 neutral, 4 skipped). Linked issue #861 is fully covered (3/3 criteria). The fifth reviewer (divisor-adversary, heavy tier) failed to dispatch for an environmental model-resolution reason unrelated to this PR's changes.
Advisory highlights (cross-persona corroborated):
- FR-013 zero-checks carve-out (architect, guard, testing): the
fetch_pr_checksbehavior that treats empty stdout + "no checks reported" as passing-with-empty-checks is implemented but not stated in the spec delta — spec and implementation now disagree on the zero-checks outcome. - IS_FORK degradation path (architect, guard, testing): an empty (degraded)
BASE_REPOSITORYclassifies a forked PR as same-repo in/uf.fix-ci, weakening the never-push-to-parent guardrail; no regression test pins this path. - Auth-catch classification (architect, testing): the which-gh/auth prologue catch block maps transient spawn timeouts to
gh_auth_failed, steering/uf.fix-citoward re-auth instead of retry. - Test DRY (architect, testing):
findGhArgvis triplicated across the three new suites instead of living in the newgh-spawn-mockhelper; TMPDIR restore can stringifyundefined. - Proposal/docs consistency (architect, curator, guard):
proposal.mdboth declines and mandates blog/content follow-ups; the tasks.md 5.3 documentation list is narrower than the change's documentation footprint.
Remaining findings not attached inline:
- LOW (architect):
runGhCommandTolerantparallels the throwingrunGhCommand; a shared core with a tolerance flag would collapse the duplication —.opencode/plugins/review-dispatch/index.ts:7236. - LOW (testing): the auth-catch error-contract finding pairs with the architect's MEDIUM above —
.opencode/plugins/review-dispatch/index.ts:7344. - LOW (curator): the proposal contradiction finding corroborates the architect's, without a distinct line anchor.
- LOW (curator): tasks.md 5.3's five-file documentation-gate list should widen to the full documentation footprint of this change.
Canonical dispatch artifact: .uf/artifacts/dispatch/d506f9a5-aefa-4f00-b8ce-40400f032d85.json. Two retrospective learnings were stored from this review.
This review was generated by /uf.review-pr (AI-assisted).
| * @returns Structured output with derived eligibility, or structured error. | ||
| */ | ||
| async function fetchPrChecks(prNumber: number): Promise<FetchPrChecksOutput | FetchContextError> { | ||
| // ── Validate gh CLI availability and auth ────────────────── |
There was a problem hiding this comment.
[MEDIUM] (divisor-architect) The which-gh/auth prologue now appears three times across the fetch handlers instead of once behind a shared helper. This triplication (default pack DR-002) triples the surface every future auth or pathing change must touch, and the scaffold mirror doubles it again. Extracting a resolveGh() helper that returns the resolved binary and auth state — or throws the already-classified error — keeps the three entry points behavior-identical.
| with an empty checks array). If the call returns a structured error: | ||
| **STOP** with the error surfaced verbatim and the PR number named — | ||
| no check status was read. | ||
|
|
There was a problem hiding this comment.
[MEDIUM] (divisor-guard) The IS_FORK derivation treats an empty BASE_REPOSITORY as "not a fork." When fetch_pr_review_context degrades base_repository to "" (unparseable PR url, e.g. GHES), a forked PR classifies as same-repo and the never-push-to-parent guardrail weakens downstream. Treating a degraded base repository as unknown (fail-closed) preserves the intent of that rule.
| restore() | ||
| } | ||
| } finally { | ||
| process.env.TMPDIR = originalTmpdir |
There was a problem hiding this comment.
[MEDIUM] (divisor-testing) The TMPDIR restore can assign String(undefined) — the literal string "undefined" — instead of restoring the prior environment. On Linux CI, where TMPDIR is always set, subsequent tests in the same worker inherit a bogus path. Branching on the saved value (delete process.env.TMPDIR when it was undefined, otherwise restore) restores the true prior state.
| @@ -0,0 +1,320 @@ | |||
| ## ADDED Requirements | |||
|
|
|||
| ### Requirement: FR-013 fetch_pr_checks tool | |||
There was a problem hiding this comment.
[MEDIUM] (divisor-architect) The implemented fetch_pr_checks behavior carves out empty stdout plus the "no checks reported" stderr marker as passing-with-empty-checks, but the spec delta does not state that carve-out. The implementation and spec now disagree on the zero-checks outcome, so a future re-implementation from the spec alone would regress it. Amending the FR-013 requirement text to name the carve-out closes the gap.
| validated `pr_number`. A non-zero `gh pr checks` exit whose stdout | ||
| parses as a JSON array MUST be treated as check-status data, not a | ||
| fetch failure. Conversely, stdout that does not parse as a JSON | ||
| array MUST be treated as a fetch failure classified through the |
There was a problem hiding this comment.
[MEDIUM] (divisor-guard) The eligibility requirement lists failing/pending/passing but omits the empty-checks=>passing branch the code implements. The spec is the durable record of intent; when the code and spec disagree, later readers cannot tell which is authoritative. This finding corroborates the architect's spec-consistency flag on the same root cause.
| * (e.g. group "pr", verb "checks"), or undefined when the tool never | ||
| * issued that call. | ||
| */ | ||
| function findGhArgv(mockSpawn: MockSpawnFn, group: string, verb: string): string[] | undefined { |
There was a problem hiding this comment.
[MEDIUM] (divisor-architect) This suite carries the third copy of findGhArgv. Same root cause as the testing persona's flag: the helper belongs in .opencode/test/helpers/gh-spawn-mock.ts, which this PR adds precisely to centralize gh spawn mocking.
| process.env.TMPDIR = originalTmpdir | ||
| } | ||
| }) | ||
|
|
There was a problem hiding this comment.
[MEDIUM] (divisor-architect) The TMPDIR save/restore here shares the isolation defect flagged at line 199 — the restored value can be the string "undefined" when the variable was absent. Both restoration sites need the undefined-versus-value branch.
| ### V. Security by Default | ||
|
|
||
| **Assessment**: PASS | ||
|
|
There was a problem hiding this comment.
[LOW] (divisor-architect) The proposal's non-goals section declines blog/content follow-ups while a later section mandates proposing them. Curator and guard corroborate the contradiction. One of the two sections yields; future readers then get a single consistent answer.
|
|
||
| ### III. Observable Quality | ||
|
|
||
| **Assessment**: PASS |
There was a problem hiding this comment.
[LOW] (divisor-guard) The retrofit paragraph covers only the spec/proposal edits, while the documentation-gate retro and the combined doc retrofit are described inconsistently across sections. A single retro list naming every touched document resolves the ambiguity.
| * fatal-loss for PR repair. This tool treats gh pr checks stdout JSON | ||
| * as check-status data on ANY exit code and derives the eligibility | ||
| * classification from the observed buckets (design D4). | ||
| * |
There was a problem hiding this comment.
[LOW] (divisor-testing) The checks parser has no test fixture for malformed check entries (non-string name/state, missing fields). The defensive ?? "" mapping handles them, but no test pins that behavior. A fixture asserting graceful degradation on malformed entries locks the contract.
Summary
Closes #861
Implements the
extend-fetch-pr-review-contextOpenSpec change (artifacts underopenspec/changes/extend-fetch-pr-review-context/): the review-dispatch plugin's intent-level PR-fetch path gains PR-repair fields, check-suite and failed-run-log fetches move behind intent-level tools, and/uf.fix-ciPhase 1/2.1 re-route through them — retiring the documented raw-gh Constitution VI deviation.What Was Built
Implemented the extend-fetch-pr-review-context OpenSpec change (issue #861) — extending the review-dispatch plugin's intent-level PR-fetch path and retiring /uf.fix-ci's raw-gh deviation records:
How to Verify
From the acceptance scenarios in openspec/changes/extend-fetch-pr-review-context/tasks.md (all 22 tasks [x]):
make plugin-test— all suites pass with the coverage floors holding unchanged (94% statements, 85% branches; measured 95.46% / 88.22%).make check— lint (go vet + golangci-lint), go test -race -count=1, build, scope-based coverage gate, TypeScript plugin suite.cmp .opencode/plugins/review-dispatch/index.ts internal/scaffold/assets/opencode/plugins/review-dispatch/index.tsandcmp .opencode/commands/uf.fix-ci.md internal/scaffold/assets/opencode/commands/uf.fix-ci.md— both exit 0.go test ./internal/scaffold/...— drift, manifest, and TestCommandContracts_FixCiCommandStructure (tool-routed assertions: fetch_pr_review_context / fetch_pr_checks / fetch_failed_run_logs present, raw gh fetch invocations absent) pass.openspec validate extend-fetch-pr-review-context --type change --strict(zero-ERROR benign profile) andopenspec validate uf-fix-ci --type change(warnings-only after the deviation retirement).Test Results
From the most recent build/test checkpoint (Step 6 pre-flight soft gate, 2026-10-29, head 661a7ef):
Review Verdicts
uf.review-council, specs mode)uf.review-council, code mode)Code-review advisories (13 total — 4 MEDIUM, 9 LOW) are non-blocking and recorded in the dispatch artifact (
.uf/artifacts/dispatch/f6a17ba3-bf66-45c7-8b2f-9b45af944ddd.json); canonical council decision: ESCALATED (advisory-level, resolves at this PR's review).Notes
(Docs: #873, unbound-force/website#342, unbound-force/website#310)consolidating the on-point website trackers.