Skip to content

fix(ship): discharge check uses PR ref presence (gh doesn't surface PR state) - #463

Merged
sarath-soman merged 1 commit into
mainfrom
fix/discharge-check-no-pr-state-field
May 26, 2026
Merged

fix(ship): discharge check uses PR ref presence (gh doesn't surface PR state)#463
sarath-soman merged 1 commit into
mainfrom
fix/discharge-check-no-pr-state-field

Conversation

@sarath-soman

Copy link
Copy Markdown
Contributor

Follow-up to #461 — the discharge check I wrote there had a bug that became visible the first time it ran against real GH data.

What was wrong

`classifyGhSubIssueState` checked `ref.state === "MERGED"` against entries in `closedByPullRequestsReferences`. But `gh issue view --json state,closedByPullRequestsReferences` doesn't surface each PR's state — the array entries carry only `id`, `number`, `url`, `repository`. The state check never matched, so every discharged sub-issue was misclassified as `closed-orphan`.

Surfaced on the first re-fire of `ship run 426` after #461 landed:

```
halted_reason: "sub-issue lambda-brahman/ship#23 (V-1) is closed without a merged PR — operator decision needed"
```

…even though V-1's lambda-brahman/ship#23 was clearly closed by merged PR #448.

Fix

Drop the per-ref state check. Presence of any PR ref on a CLOSED issue is sufficient signal: GitHub only populates `closedByPullRequestsReferences` when a PR's "Closes #N" keyword triggered the close, which implies a merge happened. (If the PR were later reverted, the issue would re-open and the `state === CLOSED` branch wouldn't fire.)

Test updates

  • Existing tests assumed a fictitious `state` field on the PR ref entries; updated to use the verbatim `gh` JSON shape.
  • Dropped two now-unreachable test cases ("PR not merged" / "prefers first MERGED") since we no longer discriminate by state.
  • Suite: 25 pass / 0 fail.

Refs lambda-brahman/ship#2.

🤖 Generated with Claude Code

…R state)

The classifier was checking `ref.state === "MERGED"` against entries in
`closedByPullRequestsReferences`, but `gh issue view` does not surface
the linked PR's state — the array only carries id/number/url/repository.
Result: every discharged sub-issue was misclassified as `closed-orphan`,
halting the orchestrator on the first re-fire.

Fix: presence of any PR ref on a CLOSED issue is sufficient signal.
GitHub only populates `closedByPullRequestsReferences` when a PR's
"Closes #N" keyword triggered the close — which implies a merge action
happened. If the PR were later reverted, the issue would re-open and
the `state === CLOSED` branch wouldn't fire.

Discovered when re-firing `ship run 426` after #461 landed — V-1's
discharge check (issue #427 closed by merged PR #448) returned
`closed-orphan` instead of `discharged`, halting the orchestrator.

Updated tests reflect the verbatim `gh` JSON shape (no `state` field
on PR refs) and drop the "PR not merged" / "prefers first MERGED" test
cases that are no longer reachable.

Refs #454.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@sarath-soman
sarath-soman merged commit 28b0861 into main May 26, 2026
6 checks passed
@sarath-soman
sarath-soman deleted the fix/discharge-check-no-pr-state-field branch May 26, 2026 00:42
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.

1 participant