fix: treat upstream 404 as package deleted when syncing - #1119
Conversation
Add syncDeleteOnNotFound config, enabled by default. When the upstream registry responds 404 for a package manifest, the sync task treats the package as removed in the remote registry and processes it by syncDeleteMode (delete/block/ignore). Set CNPMCORE_CONFIG_SYNC_DELETE_ON_NOT_FOUND=false to restore the previous behavior of ignoring 404 responses (#739). Closes #1115
📝 WalkthroughWalkthroughThe syncer now treats upstream manifest 404 responses as remote package removals by default. The new ChangesUpstream 404 removal handling
Estimated code review effort: 2 (Simple) | ~10 minutes Sequence Diagram(s)sequenceDiagram
participant UpstreamRegistry
participant PackageSyncerService
participant syncDeletePkg
UpstreamRegistry-->>PackageSyncerService: Return manifest 404
PackageSyncerService->>syncDeletePkg: Process remote removal when enabled
syncDeletePkg-->>PackageSyncerService: Apply syncDeleteMode
Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Pull request overview
This PR updates the package sync flow so an upstream 404 packument response can be treated as a remote deletion and processed through the existing delete/block/ignore logic (same flow as upstream 451), preventing stale mirrored manifests for fully-unpublished packages.
Changes:
- Add
syncDeleteOnNotFoundconfig (defaulttrue, envCNPMCORE_CONFIG_SYNC_DELETE_ON_NOT_FOUND) to control whether upstream 404 should trigger the delete/block/ignore flow. - Update
PackageSyncerService.executeTask()to route upstream 404 into the existingsyncDeletePkg()flow when enabled. - Extend and adjust tests to cover: default 404-as-deleted behavior,
syncDeleteMode=block, and the opt-out behavior (syncDeleteOnNotFound=false).
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
app/core/service/PackageSyncerService.ts |
Treat upstream 404 as remote deletion when syncDeleteOnNotFound is enabled, using the existing syncDeleteMode flow. |
app/port/config.ts |
Add syncDeleteOnNotFound to the typed config contract with inline documentation. |
config/config.default.ts |
Provide default value + env binding for syncDeleteOnNotFound. |
test/core/service/PackageSyncerService/executeTask.test.ts |
Add coverage for 404 delete/block/ignore behaviors and adjust existing 404 test expectations. |
test/core/service/PackageSyncerService/executeTaskWithPackument.test.ts |
Adjust 404-related assertions to account for the new opt-out behavior. |
There was a problem hiding this comment.
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 `@app/core/service/PackageSyncerService.ts`:
- Around line 595-600: Before invoking syncDeletePkg in the syncDeleteOnNotFound
branch of PackageSyncerService.executeTask, re-check that the task’s remote
time.modified and local manifest state still match the current package state;
treat the task as stale and skip deletion when newer state is present, while
preserving deletion for the current 404 task.
In `@test/core/service/PackageSyncerService/executeTask.test.ts`:
- Around line 363-364: Update the failure-case assertions in
test/core/service/PackageSyncerService/executeTask.test.ts at lines 363-364 and
test/core/service/PackageSyncerService/executeTaskWithPackument.test.ts at lines
633-634 to verify the sync-task response has state "fail" and exposes the
"Package not exists, response data: ..." error, while retaining the existing log
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: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 8ec1f214-d80a-45a3-a9b0-c6014cfc6c92
📒 Files selected for processing (5)
app/core/service/PackageSyncerService.tsapp/port/config.tsconfig/config.default.tstest/core/service/PackageSyncerService/executeTask.test.tstest/core/service/PackageSyncerService/executeTaskWithPackument.test.ts
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1119 +/- ##
=======================================
Coverage 94.22% 94.22%
=======================================
Files 213 213
Lines 8933 8936 +3
Branches 1796 1764 -32
=======================================
+ Hits 8417 8420 +3
Misses 516 516 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
[skip ci] ## <small>4.34.2 (2026-08-05)</small> * fix: treat upstream 404 as package deleted when syncing (#1119) ([ae57494](ae57494)), closes [#1119](#1119) [#739](#739) [#1115](#1115) * chore: disable mysql docker updates in renovate (#1116) ([b25d672](b25d672)), closes [#1116](#1116) * chore(deps): update actions/setup-node action to v7 (#1110) ([1e55d2b](1e55d2b)), closes [#1110](#1110) * chore(deps): update dependency typescript to v7 (#1103) ([2c8df6d](2c8df6d)), closes [#1103](#1103) * chore(deps): update mcr.microsoft.com/devcontainers/typescript-node docker tag to v5 (#1098) ([ba36699](ba36699)), closes [#1098](#1098) * chore(deps): update npm to v11.18.0 (#1097) ([c29aad3](c29aad3)), closes [#1097](#1097) * chore(deps): update npm to v12 (#1104) ([33d87c3](33d87c3)), closes [#1104](#1104) * chore(deps): update npm to v12.0.2 (#1105) ([d8d4cd9](d8d4cd9)), closes [#1105](#1105) * chore(deps): update vite-plus related packages (#1101) ([7e4f92d](7e4f92d)), closes [#1101](#1101) * chore(deps): update vite-plus related packages to v0.2.2 (#1100) ([72961a4](72961a4)), closes [#1100](#1100) * chore(deps): update vite-plus related packages to v0.2.7 (#1113) ([8e93ae3](8e93ae3)), closes [#1113](#1113) * chore(docs): add swagger api docs. (#1118) ([e79483c](e79483c)), closes [#1118](#1118) * docs: update killa contact email (#1111) ([39c881b](39c881b)), closes [#1111](#1111)
|
🎉 This PR is included in version 4.34.2 🎉 The release is available on: Your semantic-release bot 📦🚀 |
When the upstream registry responds 404 for a package manifest, the sync task now treats the package as removed in the remote registry and processes it through the same flow as a 451 response, honoring
syncDeleteMode(delete/block/ignore). Before this change the task ignored 404 responses, so fully unpublished packages kept their stale versions and maintainer metadata on the mirror.The new
syncDeleteOnNotFoundconfig (defaulttrue, envCNPMCORE_CONFIG_SYNC_DELETE_ON_NOT_FOUND) controls this. Set it tofalseto restore the ignore behavior from #739, which guards against upstream registries that return transient 404s during maintenance. Registries that worry about that case can also usesyncDeleteMode = blockfor a reversible removal.Closes #1115
Summary by CodeRabbit
New Features
Bug Fixes
Tests