Skip to content

ci(release): stage pnpm packages before publishing - #13702

Merged
zkochan merged 4 commits into
mainfrom
fix-13693
Aug 7, 2026
Merged

zkochan merged 4 commits into
mainfrom
fix-13693

Conversation

@zkochan

@zkochan zkochan commented Aug 7, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Stage the TypeScript @pnpm/exe and pnpm packages through OIDC without giving CI approval or direct-publish permission.
  • Stage the Rust native packages, @pnpm/napi and @pnpm/exe wrappers, and pnpm gate in one workflow run.
  • Record stage IDs in the completed job summary and safely skip versions that are already public on a rerun. A maintainer approves the stages later with interactive 2FA, following dependency order and leaving pnpm until last.
  • Pin all publication traffic to the npm registry, ignore ambient auth configuration while staging, and prevent forged workflow commands from passing through stage output.
  • Keep staged publishing ranked above direct OIDC publishing for trustPolicy=no-downgrade, fixing Exclude pnpm from global trustPolicy by default, otherwise causes self-update command not work #13693 without weakening the policy.

Before this workflow is used, the npm trusted publishers for pnpm, @pnpm/exe, @pnpm/napi, and their platform packages need to be configured for staged publishing only. That lets CI create stages but reserves approval and publication for a maintainer using interactive 2FA.

Squash Commit Body

Keep staged publishing above direct OIDC publishing in the trust-policy ranking.
Use the stronger release path instead of lowering the rank.

Stage the TypeScript `@pnpm/exe` and `pnpm` packages in dependency order.
Stage Rust native packages, wrappers, and the `pnpm` gate as separate layers.
Let CI finish after creating every stage without polling for approval.
Maintainers approve the completed stages later with interactive 2FA.

Pin publication traffic to the npm registry and ignore ambient auth configuration.
Sanitize stage output before logging registry-provided content.

Closes pnpm/pnpm#13693.

Checklist

  • I checked the referenced issue and verified that none of the PRs
    already linked to it solves it.
  • The change is implemented in both the TypeScript CLI and the Rust
    pnpm/ port, or the description notes what still needs porting.
  • Added or updated tests.
  • Updated the documentation if needed.

Written by an agent (Codex, GPT-5).

Summary by CodeRabbit

  • Release Process

    • Added staged npm publication with approval checkpoints, public access, provenance, and explicit registry verification.
    • Updated TypeScript and Rust releases to use ordered staging for published packages.
    • Improved handling of already-published packages, failures, and pending stages.
  • Documentation

    • Added guidance for approving staged releases, completing 2FA, and recovering pending stages.
  • Tests

    • Added end-to-end coverage for staging, publication status checks, registry validation, failures, and diagnostic output.

Keep staged publishing above direct OIDC publishing in the trust-policy ranking.

Use the stronger release path instead of lowering the rank.

Stage the TypeScript `@pnpm/exe` and `pnpm` packages in dependency order.

Stage Rust native packages, wrappers, and the `pnpm` gate as separate layers.

Each layer waits for interactive 2FA approval before the next one is created.

Closes #13693.
Copilot AI lite review requested due to automatic review settings August 7, 2026 11:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: e450def9-6c89-420d-83f4-c3e4d331e04c

📥 Commits

Reviewing files that changed from the base of the PR and between d9ecd3c and e39f46d.

📒 Files selected for processing (2)
  • .github/scripts/npm-staged-publication.sh
  • .github/scripts/npm-staged-publication.test.sh
🚧 Files skipped from review as they are similar to previous changes (2)
  • .github/scripts/npm-staged-publication.sh
  • .github/scripts/npm-staged-publication.test.sh

📝 Walkthrough

Walkthrough

The PR adds a Bash utility for staged npm publication. Release workflows use staged OIDC publication for TypeScript and Rust packages. CI tests the utility, and RELEASING.md documents approvals and recovery.

Changes

Staged npm publication

Layer / File(s) Summary
Publication staging and validation
.github/scripts/npm-staged-publication.sh, .github/scripts/npm-staged-publication.test.sh
The utility checks publication state, stages unpublished packages, validates stage IDs, and reports failures. End-to-end tests cover registry arguments, staged packages, published packages, and missing stage IDs.
Release workflow sequencing
.github/workflows/release.yml
TypeScript and Rust jobs use ordered OIDC staging for package dependency layers.
Registry validation, CI, and release guidance
.github/scripts/npm-package-publication-state.sh, .github/scripts/npm-package-publication-state.test.sh, .github/workflows/ci.yml, RELEASING.md
Publication checks use the npmjs registry. CI runs both publication test scripts. Release documentation describes approvals and recovery for pending stages.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant ReleaseWorkflow
  participant PublicationScript
  participant NpmRegistry
  ReleaseWorkflow->>PublicationScript: Stage package dependency layer
  PublicationScript->>NpmRegistry: Check publication state
  PublicationScript->>NpmRegistry: Submit unpublished package stage
  PublicationScript-->>ReleaseWorkflow: Return stage ID or failure
Loading

Assessment against linked issues

Objective Addressed Explanation
Exclude pnpm and @pnpm/exe from the default trustPolicy checks so self-update does not fail with ERR_PNPM_TRUST_DOWNGRADE [#13693] ❌ The PR does not modify the default trustPolicyExclude behavior.

Out-of-scope changes

Code Change Explanation
Add staged npm publication utility (.github/scripts/npm-staged-publication.sh:1-105) This implements release staging, not default trustPolicyExclude handling for self-update.
Replace TypeScript and Rust release publication steps (.github/workflows/release.yml:429-435, 451-460, 944-970) These workflow changes do not address the reported trust-policy behavior.

Possibly related PRs

  • pnpm/pnpm#13483: Both PRs modify .github/scripts/npm-package-publication-state.sh and its test to validate npm publication-state checks.
  • pnpm/pnpm#13635: Both PRs modify .github/workflows/release.yml to handle npm publication state during releases.

Suggested reviewers: copilot

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-13693

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

CI(release): stage npm publishes and wait for 2FA approval between dependency layers

✨ Enhancement ⚙️ Configuration changes 🧪 Tests 📝 Documentation 🕐 40+ Minutes

Grey Divider

AI Description

• Introduce staged npm publishing with interactive 2FA pauses between dependency layers.
• Update release workflow to stage TS and Rust package layers in safe dependency order.
• Add tests and docs for stage IDs, polling, reruns, and timeout behavior.
Diagram

graph TD
  A["release.yml jobs"] --> B["npm-staged-publication.sh"] --> C[("npm registry: stage") ] --> D["Maintainer approves (2FA)"] --> E[("npm registry: public")]
  B --> F["publication-state check"] --> C
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. GitHub Environment approvals + direct OIDC publish
  • ➕ Uses built-in workflow gating (required reviewers)
  • ➕ Avoids npm stage objects and polling/timeouts
  • ➖ Still allows CI to directly publish once approved (no npm interactive 2FA)
  • ➖ Doesn’t enforce “stage-only” trusted publisher policy on npm side
2. Manual publishing from maintainer machine (no CI publishing)
  • ➕ Strongest human control; interactive 2FA is natural
  • ➕ Simplifies CI release workflow
  • ➖ Higher operational load and more room for manual mistakes
  • ➖ Harder to make releases reproducible/auditable from CI logs
3. Keep direct publishing but downgrade trust-policy ranking

Recommendation: Keep the staged-publication approach in this PR. It preserves a strict trust-policy posture (stage-only OIDC + interactive 2FA), and the dependency-layer sequencing prevents wrappers/gates from becoming public before their exact-version dependencies. The added polling/skip logic also makes reruns safer without requiring CI to have approval capabilities.

Files changed (5) +389 / -46

Tests (1) +131 / -0
npm-staged-publication.test.shAdd hermetic bash tests for staged publication script +131/-0

Add hermetic bash tests for staged publication script

• Adds a shell test harness that fakes 'npm' and 'pnpm' binaries to validate staging behavior, stage-id parsing failures, wait polling, and timeout handling. Verifies job summary output and ensures already-published versions are skipped.

.github/scripts/npm-staged-publication.test.sh

Documentation (1) +24 / -0
RELEASING.mdDocument staged npm approvals and rerun behavior +24/-0

Document staged npm approvals and rerun behavior

• Adds maintainer instructions for approving staged packages using 'pnpm stage approve <stage-id>' and explains the dependency-layer staging order for TypeScript and Rust releases. Documents how to handle runs that stop with pending stages and notes the requirement for stage-only trusted publisher configuration.

RELEASING.md

Other (3) +234 / -46
npm-staged-publication.shAdd helper script for staging and waiting on npm staged publications +163/-0

Add helper script for staging and waiting on npm staged publications

• Introduces a bash utility that stages packages via 'pnpm stage publish', captures stage IDs into the job summary, and skips packages already public. Adds a wait mode that polls publication state with configurable poll/timeout to pause the workflow until maintainers approve stages with interactive 2FA.

.github/scripts/npm-staged-publication.sh

ci.ymlRun staged-publication script tests in CI +4/-2

Run staged-publication script tests in CI

• Renames the release-script test step and adds execution of the new 'npm-staged-publication.test.sh' alongside the existing publication-state tests.

.github/workflows/ci.yml

release.ymlSwitch release publishing to staged OIDC with dependency-layer gating +67/-44

Switch release publishing to staged OIDC with dependency-layer gating

• Updates both the TypeScript and Rust release jobs to stage packages (rather than publish directly) and to wait for interactive 2FA approval between layers. Adds long timeouts to accommodate manual approvals and ensures ordering prevents wrappers/gates from going public before their dependencies.

.github/workflows/release.yml

@greptile-apps

greptile-apps Bot commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains; the previous shared-deadline issue is eliminated because the workflow no longer waits for approval, and the previously withdrawn dependency-layer concern reflects the documented stage-only release model.

Reviews (4): Last reviewed commit: "fix(release): silence staged publication..." | Re-trigger Greptile

Comment thread .github/workflows/release.yml Resolved

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.github/scripts/npm-staged-publication.sh:
- Around line 94-100: Update the poll_seconds validation in the publication
script to require a positive integer, rejecting zero while preserving the
existing error and return behavior for invalid values. Leave timeout_seconds
validation unchanged.

In @.github/scripts/npm-staged-publication.test.sh:
- Around line 97-107: Extend the missing-stage-ID test around
npm-staged-publication.sh to make the fake pnpm response emit
::warning::forged-stage-output, then assert the captured output logs it only
with the controlled “stage output:” prefix and contains no line beginning with
the forged workflow command. Preserve the existing failure and missing-stage-ID
assertions.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 44a2e97e-fd33-4fe0-9309-dd006fc166ea

📥 Commits

Reviewing files that changed from the base of the PR and between a8ce5f6 and 0fe7ef2.

📒 Files selected for processing (5)
  • .github/scripts/npm-staged-publication.sh
  • .github/scripts/npm-staged-publication.test.sh
  • .github/workflows/ci.yml
  • .github/workflows/release.yml
  • RELEASING.md

@qodo-code-review

qodo-code-review Bot commented Aug 7, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (0) 📜 Skill insights (0)

Grey Divider


Action required

1. Publish trusts repo npmrc ✓ Resolved 🐞 Bug ⛨ Security
Description
stage_packages() runs pnpm stage publish without pinning the registry or isolating
repo-controlled npm/pnpm config, so a repository .npmrc/config change could redirect staged
publication away from the intended npm registry (and, depending on pnpm’s OIDC flow, could also
expose OIDC exchange material to the wrong endpoint).
Code

.github/scripts/npm-staged-publication.sh[R52-57]

+        stage_output=$(pnpm stage publish "${package_dir%/}/" \
+          --tag "$tag" \
+          --access public \
+          --provenance \
+          --no-git-checks \
+          --json)
Relevance

●●● Strong

Repo has accepted CI script hardening against attacker-controlled execution paths; isolating
npmrc/registry matches that security posture.

PR-#12612

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The security guide explicitly treats repo-controlled npm config as attacker-controlled and warns
against letting it affect outbound registry/auth values. The repo already uses a defensive cd into
RUNNER_TEMP for npm view, but the new pnpm stage publish path doesn’t pin/isolate registry
config, creating an integrity risk for this OIDC-based release step.

.github/scripts/npm-staged-publication.sh[52-57]
REVIEW_GUIDE.md[61-66]
REVIEW_GUIDE.md[98-103]
.github/scripts/npm-package-publication-state.sh[7-10]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The staged publishing path invokes `pnpm stage publish` from the repo context without explicitly pinning the registry. Per the repo’s security rules, repo-controlled `.npmrc`/env config must be treated as attacker-controlled; allowing it to influence outbound registry/auth endpoints is a release-integrity risk.

## Issue Context
The existing `npm view` helper already mitigates repo `.npmrc` influence by `cd`ing into `RUNNER_TEMP` before calling `npm view`. The new staged publish helper should apply similar hardening for the OIDC-backed publish path.

## Fix Focus Areas
- .github/scripts/npm-staged-publication.sh[51-57]

## Suggested fix approach
- Add an explicit registry pin to the staging invocation, e.g. `pnpm stage publish ... --registry https://registry.npmjs.org/ ...`.
- (Optional hardening) Also set a clean config context for that command (e.g., `NPM_CONFIG_USERCONFIG=/dev/null` / `npm_config_userconfig=/dev/null`) if you want to fully ignore repo/user config during release publishing.
- Keep the change localized to the staged-publication script so both TypeScript and Rust release jobs inherit the protection.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. Overstrict lookup failure cap ⊘ Outdated 🐞 Bug ☼ Reliability
Description
wait_for_packages() fails the entire wait after 3 polling iterations where *any* package lookup
fails, which can abort far before the intended 90‑minute approval window when npm/network errors are
transient. This can unnecessarily fail release jobs even though the packages might become public
shortly afterward.
Code

.github/scripts/npm-staged-publication.sh[R142-145]

+      consecutive_lookup_failures=$((consecutive_lookup_failures + 1))
+      if [ "$consecutive_lookup_failures" -ge "$max_consecutive_lookup_failures" ]; then
+        echo "::error::npm publication state lookup failed $consecutive_lookup_failures consecutive times" >&2
+        return 1
Relevance

●● Moderate

Retry/timeout behavior in release scripts is sensitive; mixed precedent on network-hardening tweaks
without clear consensus.

PR-#13483
PR-#13235

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The script treats any single-package lookup error as an iteration failure and aborts after 3 such
iterations, which conflicts with the workflow’s documented 90-minute per-layer approval deadline and
is enforced by the new test.

.github/scripts/npm-staged-publication.sh[122-128]
.github/scripts/npm-staged-publication.sh[115-116]
.github/scripts/npm-staged-publication.sh[141-149]
.github/scripts/npm-staged-publication.test.sh[164-176]
.github/workflows/release.yml[957-963]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
`wait_for_packages()` aborts after 3 iterations with any lookup failure. This is too strict for release workflows that are designed to wait up to 90 minutes for interactive 2FA approvals.

### Issue Context
- A single package’s transient `npm view` failure marks the whole iteration as failed.
- The counter increments once per iteration (not per package), but still aborts quickly relative to the configured approval deadline.

### Fix Focus Areas
- .github/scripts/npm-staged-publication.sh[115-149]
- .github/scripts/npm-staged-publication.test.sh[164-176]

### Suggested fix
- Only increment the consecutive-failure counter when **all** lookups fail (indicating systemic outage), or reset the counter when **any** lookup succeeds.
- Alternatively (or additionally), make the failure budget time-based/configurable and continue retrying until `deadline` unless the failure condition clearly indicates a permanent misconfiguration.
- Update the `lookup-failure` test expectations accordingly (e.g., assert it continues until timeout, or until a longer/systemic-failure threshold).

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended

3. Silent reporter hides failures 🐞 Bug ◔ Observability ⭐ New
Description
npm-staged-publication.sh runs pnpm stage publish with --reporter=silent, which can suppress
pnpm’s fatal error output; if the command exits non-zero, the workflow may fail with no actionable
diagnostics. This can significantly delay release recovery/debugging when staging breaks
(network/auth/registry errors).
Code

.github/scripts/npm-staged-publication.sh[R61-62]

+          --reporter=silent \
+          --json)
Relevance

●●● Strong

Team recently accepted changes ensuring warnings/errors stay visible under --json/reporters; silent
failures hurt CI debugging.

PR-#13495

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
pnpm’s error handler explicitly suppresses logging when the reporter is initialized as silent, so
failures can exit without printing an error. The pnpm CLI help also documents that
--silent/--reporter silent produces no output, even fatal errors; meanwhile --use-stderr is a
supported global option that keeps logs/errors visible on stderr while leaving stdout clean for JSON
capture. The repo’s test currently enforces the --reporter=silent argument, so it will need
updating alongside the script.

.github/scripts/npm-staged-publication.sh[54-69]
pnpm11/pnpm/src/errorHandler.ts[26-45]
pnpm11/cli/common-cli-options-help/src/index.ts[133-141]
pnpm11/pnpm/src/cmd/index.ts[42-56]
.github/scripts/npm-staged-publication.test.sh[81-81]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The staging script passes `--reporter=silent` to `pnpm stage publish`. In pnpm, the silent reporter suppresses even fatal error logging, so a non-zero exit can produce an opaque CI failure without pnpm’s diagnostics.

## Issue Context
The script captures `--json` stdout into a variable for parsing. The intent is to keep stdout machine-readable, but `--reporter=silent` is a heavy hammer and also suppresses error reporting.

## Fix Focus Areas
- .github/scripts/npm-staged-publication.sh[54-62]
- .github/scripts/npm-staged-publication.test.sh[81-81]

## Suggested fix
- Replace `--reporter=silent` with `--use-stderr` (optionally also set a non-noisy reporter like `--reporter=append-only` if desired).
- Keep `--json` so stdout remains parseable.
- Update the test expectation to match the new argument list.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


4. Wait loop flake abort ✓ Resolved 🐞 Bug ☼ Reliability
Description
wait_for_packages() runs under set -e and assigns state=$(publication_state ...) unguarded, so
any transient npm view failure (network/rate-limit/server) aborts the whole wait step immediately
instead of retrying until the deadline.
Code

.github/scripts/npm-staged-publication.sh[R114-117]

+    for package_spec in "${package_specs[@]}"; do
+      state=$(publication_state "$package_spec")
+      case "$state" in
+        published) ;;
Relevance

●●● Strong

Clear reliability bug: set -e makes transient npm view failures abort polling; team has accepted
making CI steps non-fatal.

PR-#12612

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The new wait loop calls publication_state in a way that will terminate under set -e if `npm
view` fails. The helper script’s logic and tests show that non-E404 errors exit with failure, so the
wait loop will not continue polling on transient errors.

.github/scripts/npm-staged-publication.sh[112-123]
.github/scripts/npm-package-publication-state.sh[7-16]
.github/scripts/npm-package-publication-state.test.sh[67-73]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`wait_for_packages()` is intended to poll until packages become public, but it exits immediately on any `publication_state` non-404 error due to `set -e`. This makes long approval waits flaky (one transient npm failure kills the release job).

## Issue Context
`publication_state` exits non-zero for non-E404 errors by design, and its tests assert that behavior. The wait loop should treat transient lookup failures as retryable until the overall timeout, while still failing when errors persist.

## Fix Focus Areas
- .github/scripts/npm-staged-publication.sh[110-139]

## Suggested fix approach
- Wrap `publication_state` in an `if ! ...; then` block inside `wait_for_packages()`.
- On failure, log a non-workflow-command message (avoid re-emitting `::error::`), treat the package as still pending, and continue polling.
- Optionally cap consecutive lookup failures (e.g. fail after N consecutive failures per package) to avoid masking persistent auth/misconfig errors while still handling transient flakiness.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Context used
✅ Compliance rules (platform): 18 rules

To customize comments, go to the Qodo configuration screen, or learn more in the docs.

Previous review results

Review updated until commit e39f46d

Results up to commit 0fe7ef2 ⚖️ Balanced


🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)


Action required
1. Publish trusts repo npmrc ✓ Resolved 🐞 Bug ⛨ Security
Description
stage_packages() runs pnpm stage publish without pinning the registry or isolating
repo-controlled npm/pnpm config, so a repository .npmrc/config change could redirect staged
publication away from the intended npm registry (and, depending on pnpm’s OIDC flow, could also
expose OIDC exchange material to the wrong endpoint).
Code

.github/scripts/npm-staged-publication.sh[R52-57]

+        stage_output=$(pnpm stage publish "${package_dir%/}/" \
+          --tag "$tag" \
+          --access public \
+          --provenance \
+          --no-git-checks \
+          --json)
Relevance

●●● Strong

Repo has accepted CI script hardening against attacker-controlled execution paths; isolating
npmrc/registry matches that security posture.

PR-#12612

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The security guide explicitly treats repo-controlled npm config as attacker-controlled and warns
against letting it affect outbound registry/auth values. The repo already uses a defensive cd into
RUNNER_TEMP for npm view, but the new pnpm stage publish path doesn’t pin/isolate registry
config, creating an integrity risk for this OIDC-based release step.

.github/scripts/npm-staged-publication.sh[52-57]
REVIEW_GUIDE.md[61-66]
REVIEW_GUIDE.md[98-103]
.github/scripts/npm-package-publication-state.sh[7-10]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The staged publishing path invokes `pnpm stage publish` from the repo context without explicitly pinning the registry. Per the repo’s security rules, repo-controlled `.npmrc`/env config must be treated as attacker-controlled; allowing it to influence outbound registry/auth endpoints is a release-integrity risk.

## Issue Context
The existing `npm view` helper already mitigates repo `.npmrc` influence by `cd`ing into `RUNNER_TEMP` before calling `npm view`. The new staged publish helper should apply similar hardening for the OIDC-backed publish path.

## Fix Focus Areas
- .github/scripts/npm-staged-publication.sh[51-57]

## Suggested fix approach
- Add an explicit registry pin to the staging invocation, e.g. `pnpm stage publish ... --registry https://registry.npmjs.org/ ...`.
- (Optional hardening) Also set a clean config context for that command (e.g., `NPM_CONFIG_USERCONFIG=/dev/null` / `npm_config_userconfig=/dev/null`) if you want to fully ignore repo/user config during release publishing.
- Keep the change localized to the staged-publication script so both TypeScript and Rust release jobs inherit the protection.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended
2. Wait loop flake abort ✓ Resolved 🐞 Bug ☼ Reliability
Description
wait_for_packages() runs under set -e and assigns state=$(publication_state ...) unguarded, so
any transient npm view failure (network/rate-limit/server) aborts the whole wait step immediately
instead of retrying until the deadline.
Code

.github/scripts/npm-staged-publication.sh[R114-117]

+    for package_spec in "${package_specs[@]}"; do
+      state=$(publication_state "$package_spec")
+      case "$state" in
+        published) ;;
Relevance

●●● Strong

Clear reliability bug: set -e makes transient npm view failures abort polling; team has accepted
making CI steps non-fatal.

PR-#12612

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The new wait loop calls publication_state in a way that will terminate under set -e if `npm
view` fails. The helper script’s logic and tests show that non-E404 errors exit with failure, so the
wait loop will not continue polling on transient errors.

.github/scripts/npm-staged-publication.sh[112-123]
.github/scripts/npm-package-publication-state.sh[7-16]
.github/scripts/npm-package-publication-state.test.sh[67-73]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`wait_for_packages()` is intended to poll until packages become public, but it exits immediately on any `publication_state` non-404 error due to `set -e`. This makes long approval waits flaky (one transient npm failure kills the release job).

## Issue Context
`publication_state` exits non-zero for non-E404 errors by design, and its tests assert that behavior. The wait loop should treat transient lookup failures as retryable until the overall timeout, while still failing when errors persist.

## Fix Focus Areas
- .github/scripts/npm-staged-publication.sh[110-139]

## Suggested fix approach
- Wrap `publication_state` in an `if ! ...; then` block inside `wait_for_packages()`.
- On failure, log a non-workflow-command message (avoid re-emitting `::error::`), treat the package as still pending, and continue polling.
- Optionally cap consecutive lookup failures (e.g. fail after N consecutive failures per package) to avoid masking persistent auth/misconfig errors while still handling transient flakiness.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Results up to commit a4f1d15 ⚖️ Balanced


🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)


Action required
1. Overstrict lookup failure cap ⊘ Outdated 🐞 Bug ☼ Reliability
Description
wait_for_packages() fails the entire wait after 3 polling iterations where *any* package lookup
fails, which can abort far before the intended 90‑minute approval window when npm/network errors are
transient. This can unnecessarily fail release jobs even though the packages might become public
shortly afterward.
Code

.github/scripts/npm-staged-publication.sh[R142-145]

+      consecutive_lookup_failures=$((consecutive_lookup_failures + 1))
+      if [ "$consecutive_lookup_failures" -ge "$max_consecutive_lookup_failures" ]; then
+        echo "::error::npm publication state lookup failed $consecutive_lookup_failures consecutive times" >&2
+        return 1
Relevance

●● Moderate

Retry/timeout behavior in release scripts is sensitive; mixed precedent on network-hardening tweaks
without clear consensus.

PR-#13483
PR-#13235

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The script treats any single-package lookup error as an iteration failure and aborts after 3 such
iterations, which conflicts with the workflow’s documented 90-minute per-layer approval deadline and
is enforced by the new test.

.github/scripts/npm-staged-publication.sh[122-128]
.github/scripts/npm-staged-publication.sh[115-116]
.github/scripts/npm-staged-publication.sh[141-149]
.github/scripts/npm-staged-publication.test.sh[164-176]
.github/workflows/release.yml[957-963]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
`wait_for_packages()` aborts after 3 iterations with any lookup failure. This is too strict for release workflows that are designed to wait up to 90 minutes for interactive 2FA approvals.

### Issue Context
- A single package’s transient `npm view` failure marks the whole iteration as failed.
- The counter increments once per iteration (not per package), but still aborts quickly relative to the configured approval deadline.

### Fix Focus Areas
- .github/scripts/npm-staged-publication.sh[115-149]
- .github/scripts/npm-staged-publication.test.sh[164-176]

### Suggested fix
- Only increment the consecutive-failure counter when **all** lookups fail (indicating systemic outage), or reset the counter when **any** lookup succeeds.
- Alternatively (or additionally), make the failure budget time-based/configurable and continue retrying until `deadline` unless the failure condition clearly indicates a permanent misconfiguration.
- Update the `lookup-failure` test expectations accordingly (e.g., assert it continues until timeout, or until a longer/systemic-failure threshold).

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Qodo Logo

@qodo-code-review

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

/improve is deprecated. Use /agentic_review instead (removal date not yet scheduled).

No code suggestions found for the PR.

Pin publication checks and staging to the npm registry.

Ignore ambient auth configuration during staged publishing.

Retry transient publication lookups while bounding persistent failures.

Reject zero-second polling and test sanitized registry output.

Cap each approval layer at 90 minutes so all Rust layers fit within the job deadline.
Copilot AI review requested due to automatic review settings August 7, 2026 11:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@zkochan

zkochan commented Aug 7, 2026

Copy link
Copy Markdown
Member Author

Addressed the wait-loop reliability finding in a4f1d15. A transient npm view failure is now logged with a controlled prefix and retried. Three consecutive lookup failures still stop the release, so persistent registry or configuration failures are not hidden. The tests cover both recovery and the bounded-failure path.

The same commit also pins publication traffic to npm, rejects zero-second polling, adds the forged workflow-command regression, and gives every approval layer its own 90-minute window.


Written by an agent (Codex, GPT-5).

@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit a4f1d15

@qodo-code-review

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

/improve is deprecated. Use /agentic_review instead (removal date not yet scheduled).

No code suggestions found for the PR.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
.github/scripts/npm-package-publication-state.sh (1)

6-8: 🔒 Security & Privacy | 🔵 Trivial | 💤 Low value

Keep the npm registry probe configuration-safe.

npm view is pinned to registry.npmjs.org/, but npm can still apply local/global npmrc or environment variable configuration during the lookup. Add regression coverage in .github/scripts/npm-package-publication-state.test.sh for npm behavior under npmrc/config and auth-related configuration, so future changes cannot introduce unprivileged credential leaks.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/scripts/npm-package-publication-state.sh around lines 6 - 8, Update
the npm view probe in the publication-state script to prevent local/global npmrc
and environment configuration from affecting the registry lookup, while
preserving the explicit npmjs registry. Add regression cases in
npm-package-publication-state.test.sh covering npmrc/config and auth-related
settings, verifying credentials are not exposed without privileged access.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In @.github/scripts/npm-package-publication-state.sh:
- Around line 6-8: Update the npm view probe in the publication-state script to
prevent local/global npmrc and environment configuration from affecting the
registry lookup, while preserving the explicit npmjs registry. Add regression
cases in npm-package-publication-state.test.sh covering npmrc/config and
auth-related settings, verifying credentials are not exposed without privileged
access.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 85b52c32-52ce-4732-98cf-e120409bd274

📥 Commits

Reviewing files that changed from the base of the PR and between 0fe7ef2 and a4f1d15.

📒 Files selected for processing (6)
  • .github/scripts/npm-package-publication-state.sh
  • .github/scripts/npm-package-publication-state.test.sh
  • .github/scripts/npm-staged-publication.sh
  • .github/scripts/npm-staged-publication.test.sh
  • .github/workflows/release.yml
  • RELEASING.md
🚧 Files skipped from review as they are similar to previous changes (3)
  • RELEASING.md
  • .github/scripts/npm-staged-publication.sh
  • .github/workflows/release.yml

@github-actions github-actions Bot added the reviewed: coderabbit CodeRabbit submitted an approving review label Aug 7, 2026
Remove approval polling from CI.

Stage native packages, wrappers, and pnpm in one workflow run.

Maintainers approve the completed stages later in dependency order.
Copilot AI review requested due to automatic review settings August 7, 2026 11:56

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@zkochan

zkochan commented Aug 7, 2026

Copy link
Copy Markdown
Member Author

Follow-up d9ecd3c simplifies the handoff: CI now stages every dependency layer and finishes without polling for approval. The completed job summary contains all stage IDs; a maintainer can approve them later with interactive 2FA, in dependency order and with pnpm last.

This supersedes the earlier 90-minute wait design and removes the polling code entirely. The npm registry pinning, isolated auth configuration, already-published rerun guard, and forged workflow-command regression remain.


Written by an agent (Codex, GPT-5).

@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit d9ecd3c

Comment thread .github/workflows/release.yml Resolved
@qodo-code-review

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

/improve is deprecated. Use /agentic_review instead (removal date not yet scheduled).

No code suggestions found for the PR.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
.github/scripts/npm-staged-publication.sh (1)

62-72: 🔒 Security & Privacy | 🟡 Minor | ⚡ Quick win

Reject multi-line stage_id values before logging them.

Line 63 accepts any non-empty JSON string. jq -r converts escaped line breaks into real line breaks. A stage ID such as ok\n::warning::forged reaches line 70, where GitHub Actions reads the second line as a workflow command.

Reject \r and \n in stage_id before writing it to stdout or GITHUB_STEP_SUMMARY. Add a success-path regression case with a forged command in the stage ID.

Proposed fix
         if ! stage_id=$(jq -er --arg name "$name" \
           '.[$name].stageId | strings | select(length > 0)' <<< "$stage_output"); then
           # existing error handling
           return 1
         fi
+        if [[ $stage_id == *$'\r'* || $stage_id == *$'\n'* ]]; then
+          echo "::error::pnpm stage publish returned an unsafe stage ID for $package_spec" >&2
+          return 1
+        fi
         echo "Staged $package_spec with ID $stage_id"

Based on learnings: external responses must be sanitized before they are logged by GitHub Actions.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/scripts/npm-staged-publication.sh around lines 62 - 72, Validate the
extracted stage_id in the staging flow before the success message or
GITHUB_STEP_SUMMARY write, rejecting any value containing carriage-return or
newline characters and returning failure through the existing error path. Add a
success-path regression case using a stage ID containing a forged GitHub Actions
command, asserting it is rejected and never emitted as workflow output.

Source: Learnings

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.github/workflows/release.yml:
- Around line 944-970: Stage each release dependency layer only after its own
approval: persist the stage IDs and poll with a bounded timeout after native
packages before the Rust wrappers, after wrappers before the Rust pnpm package,
and at the TypeScript pnpm flow before staging the package, covering release.yml
ranges 944-970 and 451-460. Update npm-staged-publication.sh lines 83-88 to emit
the stage IDs and per-layer approval information needed by this workflow instead
of instructing approval only after the workflow completes.

---

Outside diff comments:
In @.github/scripts/npm-staged-publication.sh:
- Around line 62-72: Validate the extracted stage_id in the staging flow before
the success message or GITHUB_STEP_SUMMARY write, rejecting any value containing
carriage-return or newline characters and returning failure through the existing
error path. Add a success-path regression case using a stage ID containing a
forged GitHub Actions command, asserting it is rejected and never emitted as
workflow output.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 98dec113-db98-4229-8995-0f49a8aca8e9

📥 Commits

Reviewing files that changed from the base of the PR and between a4f1d15 and d9ecd3c.

📒 Files selected for processing (4)
  • .github/scripts/npm-staged-publication.sh
  • .github/scripts/npm-staged-publication.test.sh
  • .github/workflows/release.yml
  • RELEASING.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • RELEASING.md

Comment thread .github/workflows/release.yml Resolved
Copilot AI review requested due to automatic review settings August 7, 2026 12:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@zkochan

zkochan commented Aug 7, 2026

Copy link
Copy Markdown
Member Author

Local pnpr verification found and fixed an output-parsing issue in e39f46d. pnpm stage publish --json also emits progress output unless the silent reporter is selected; the release helper now passes --reporter=silent, and its regression test asserts that invocation.

I then exercised the staged release shape against a live local pnpr registry:

  • staged a native package and a wrapper with an exact-version optional dependency while both packuments remained unavailable (HTTP 404);
  • parsed both real stage UUIDs from the CLI JSON output;
  • approved the native stage and confirmed the wrapper was still unavailable;
  • approved the wrapper, verified its next-12 dist-tag and exact optional dependency, and installed it with both packages present.

The local run used pnpr bearer authentication and omitted npm provenance, since GitHub OIDC issuance and npm trusted-publisher policy cannot be reproduced locally. The production-only OIDC/provenance portion remains covered by the release configuration and existing publish implementation; the stage protocol, CLI output contract, dependency ordering, and post-approval installation were exercised end to end. The helper test, just ready, and pre-push TypeScript checks pass.


Written by an agent (Codex, GPT-5).

@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit e39f46d

@qodo-code-review

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

/improve is deprecated. Use /agentic_review instead (removal date not yet scheduled).

No code suggestions found for the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

reviewed: coderabbit CodeRabbit submitted an approving review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants