fix(admin-ui): evict stale priority-group source on remove 404#2784
Conversation
A device that re-registers under a new transport (a renumbered ttyUSB port, a fresh canName) leaves its old sourceRef in the saved priority group. The reconciled group still lists that ref, so the UI offers a trash icon for it (isMissingFromStatus). But the removeSource DELETE 404s — the source is genuinely gone — and the handler reverted the optimistic removal, pinning the stale ref in the group forever: the DELETE can never succeed for a source the server no longer has. Treat a 404 on a missing-from-status ref as success so the ref drops out of the group on Save.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughAdds a new exported utility ChangesSource Removal Failure Classification
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested labels
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 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 |
|
Ready for human review |
Motivation
On the Source Priorities page, removing a source could fail with
Could not remove <sourceRef>: server returned 404, and the source would stay stuck in the group.This happens when a device re-registers under a new transport — a renumbered
ttyUSBport, a fresh canName. The device's oldsourceReflingers in the saved priority group, so the reconciled group still lists it and the UI offers a trash icon (the source isisMissingFromStatus). But theremoveSourceDELETE 404s because the source is genuinely gone, and the handler then reverted the optimistic removal — pinning the stale ref in the group permanently, since the DELETE can never succeed for a source the server no longer has.Solution
Treat a 404 on a missing-from-status ref as success rather than failure: the server is confirming the source is already gone, which is exactly the desired outcome. The optimistic removal sticks and the ref drops out of the group on Save. Auth (401/403) and other errors still revert and alert as before.
The decision is factored into a pure, unit-tested
isRemoveSourceFailurehelper.Tested
isRemoveSourceFailureunit tests (success, missing-from-status 404, tracked-ref 404, auth/server errors)vitest runadmin-ui suite passes (242 tests)vite buildof the admin UI succeedsOverview
This PR fixes a 404 error that occurs when removing a source from a priority group after the device re-registers under a new transport (such as a renumbered
ttyUSBport). The issue arises when a stale source reference remains in the saved priority group but no longer exists on the server.Problem
When a user attempts to delete a source marked as
isMissingFromStatus, the DELETE request returns a 404 error (since the source no longer exists). The existing handler treats this as a failure and reverts the optimistic removal, permanently pinning the stale reference in the group. This creates an impossible scenario where the DELETE can never succeed for a source that is genuinely gone.Solution
The PR introduces a new
isRemoveSourceFailurehelper function that distinguishes between different 404 scenarios:Changes
sourceLabels.tsAdds a pure, unit-tested
isRemoveSourceFailure(status: number, ok: boolean, isMissingFromStatus: boolean): booleanutility function that encapsulates the failure-detection logic for source removal operations.sourceLabels.test.tsIncludes comprehensive test coverage for
isRemoveSourceFailure, verifying success cases, missing-from-status 404s, tracked-ref 404s, and authentication/server error handling.PriorityGroupCard.tsxUpdates the
handleRemoveSourcefunction to accept anisMissingFromStatusflag and usesisRemoveSourceFailureto determine whether to revert the optimistic removal and display an error alert. Authentication errors and other unexpected failures continue to trigger alerts as before.Testing
The admin-ui test suite (242 tests) passes, and the build succeeds. The new logic allows stale references to be successfully dropped from priority groups when their 404 response indicates the source is genuinely gone.