Record a close-policy refusal as a refuse action and continue the closeout run

Merged
UN
6d ago
+213-23

Problem

The daily "Close pm items delivered by merged pull requests" workflow in pm-ops has failed since 2026-11-15 with:

Closeout refused item ops-d8k3, PR #112: SDK close refused: workflow_policy_refused.
Supply required fields: repro_steps. No branch was published.

A single SDK close refusal — deterministic, per-item, locally actionable — exits the command with 1 and discards the entire run: no branch is published, and every other delivered item stays open. In the pm-ops plan, one correct refusal (a tracking-only PR claims delivery of a still-live defect, which the close policy rightly refuses to close without evidence) held two genuinely delivered items hostage.

Design

A workflow_policy_refused close is now one item decision, projected onto all its candidate rows:

  • plan row: action: "refuse", code: "close_refused", the sanitized reason from the existing closeoutFailureReason (bounded codes and field names only), with a close_refused missing-evidence entry;
  • the item stays open; failed is not incremented; the remaining plan still closes;
  • the reusable workflow's closeout-review.json gains a refused array (written only when non-empty; the existing needs_review shape is byte-identical otherwise), and a run with refusals publishes its review PR with refuse counts in the summary and automatic landing disabled, so the refusal stays visible;
  • every other close failure (locks, revision conflicts after one re-selection, unclassified errors) keeps the existing fatal, exit-1 behavior.

Before / after

Before: any policy refusal → exit 1 → "No branch was published" → the whole streak stays red and delivered items pile up.

After: the refused item stays open with a published, reviewable refusal; the other delivered items close and land.

Revert proof

Removing only the policy-refusal catch from the apply loop (keeping all other changes and tests) makes a close-policy refusal records a refuse action and does not fail the remaining run fail (needs_review projected instead of refuse, failed 1 instead of 0). Restoring the branch byte-for-byte passes the regression and the updated lock/policy suite (2/2). Recorded on the item.

Gates

  • Focused: node --test test/closeout.test.ts (policy refusal regressions), node --test test/identity-inventory.test.ts 5/5, node --test test/bot-pr-workflow.test.ts (shared-maintenance + hold dispatch) 2/2, publication regressions incl. the new end-to-end refused-review publication 2/2, test/strict-import-admission.test.ts passes on the CI npm (10.9.9; the earlier local failure was a host npm 11.17 --allow-scripts policy refusal, not a code change).
  • npm run release:check was re-run at this head on the CI-adjacent Node/npm; the full-run status is recorded on the item. Typecheck, lint, docstring, duplication and privacy stages passed in the first full run; the eight failures it reported were the old-behavior contract tests and the stale ownership-inventory anchors, all updated here (inventory regenerated with node scripts/identity-inventory.ts --write).
  • Changelog regenerated and changelog:check passes at this head.

Notes

  • The second commit only records the follow-up item pm-github-omff (import-side close-policy refusal, reproduced against the pinned extension; no code change).
  • After this fix is released and callers bump their pins, the pm-ops closeout will still show one correct refusal (ops-d8k3, tracking-only delivery claim) while closing the two delivered items whose reproduction steps were recorded in pm-ops#316.

Tracked on pm-github-jx5q


Summary by cubic

Fixes the scheduled closeout run so a single close-policy refusal no longer fails the workflow and blocks every other close.

An SDK refusal with workflow_policy_refused (for example a completeness policy requiring repro_steps) previously exited with 1 and published no branch, leaving every delivered item open; the pm-ops daily closeout has failed this way since 2026-11-15.

Now a policy refusal is one per-item decision projected onto all its candidate rows: action refuse with code close_refused, the item stays open, the reason is sanitized, and the remaining plan still closes and publishes. The workflow's closeout-review.json gains a refused array (written only when non-empty), and runs with refusals publish the review PR with counts and automatic landing disabled so the refusal stays visible. Refused entries derive the PR from the close_refused evidence so an explicit delivery selection names the attempted PR, while keeping the candidates and missing evidence. Other close failures keep the existing fatal, exit-1 behavior.

Tracked on pm-github-jx5q (with the import-side policy-refusal follow-up on pm-github-omff and the attempted-PR attribution follow-up on pm-github-refused-close-attribution).

Summary by Sourcery

Treat deterministic close-policy refusals as reviewable per-item outcomes so closeout runs can publish the refusal and continue closing other delivered items.

New Features:

  • Record deterministic close-policy refusals as per-item refuse decisions with sanitized reasons and missing-evidence details.
  • Publish policy refusals in the closeout review artifact while preserving candidate attribution and disabling automatic landing.

Bug Fixes:

  • Allow closeout runs to continue closing eligible delivered items after a workflow policy refusal instead of failing the entire run.
  • Keep refused items open without incrementing the failed count, while retaining fatal behavior for other close failures.

Enhancements:

  • Extend closeout reporting and documentation with refuse actions and close_refused codes.
  • Update workflow summaries, review links, and notices to distinguish attribution holds from policy-refused closes.

Documentation:

  • Document the new refuse outcome, reporting semantics, and review-artifact behavior for closeout policy refusals.

Tests:

  • Add regression coverage for continued closeout processing and publication of policy-refused reviews, including candidate attribution.