feat(activation): prevent orphaned MPS device records on re-provision - #2873
Merged
Conversation
Add the opt-in `prevent_orphaned_devices` config flag (default off). When enabled, a device reporting pre-provisioning mode (currentMode=0) that still has a record in the MPS devices table is refused until it is removed via rpc-go deactivation or the REST API, keeping the devices table free of orphaned/duplicate records. Disabled by default, so existing behavior is unchanged. Fails open if MPS is unreachable or the device is not registered.
There was a problem hiding this comment.
Pull request overview
Adds an opt-in activation safety check (prevent_orphaned_devices, default false) to reduce duplicate/orphaned device records in MPS by refusing to re-provision devices that report pre-provisioning mode (currentMode=0) while still being present in MPS.
Changes:
- Add
prevent_orphaned_devicesconfig flag (default off) and plumb it throughRPSConfig+ environment defaults. - During activation validation, optionally query MPS for an existing device record when
currentMode=0and block re-provisioning if present. - Add unit tests for the new opt-in behavior.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Validator.ts | Adds the prevent_orphaned_devices gated MPS existence check during currentMode=0 activation validation. |
| src/validator.test.ts | Adds tests covering default-off behavior, “no record”, “record exists”, and “fails open” paths. |
| src/utils/Environment.ts | Sets default value for prevent_orphaned_devices in the environment config singleton. |
| src/models/index.ts | Extends RPSConfig with the optional prevent_orphaned_devices field. |
| .rpsrc | Documents the new config flag in the default rc config. |
Suppressed comments (1)
src/validator.test.ts:578
- This test doesn’t assert that the MPS lookup was actually attempted, so it could still pass if the lookup is removed. Add an assertion on
gotcalls (and clear mock call history) to ensure the “fails open” path is exercised.
Environment.Config.prevent_orphaned_devices = true
devices[clientId] = { ClientId: clientId, ClientSocket: null as any, unauthCount: 0, status: {} } as any
vi.mocked(got).mockRejectedValue(new Error('Response code 404'))
await validator.verifyCurrentModeForActivation(msg, profile, clientId)
expect(devices[clientId].status.Status).toBeUndefined()
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
- Treat a non-empty unparseable MPS body as registered (fail closed), matching getDeviceFromMPS in the activation machine - URL-encode tenantId in the MPS lookup - Correct docstring: check fails open on any lookup error, and log it - Assert got is invoked in the enabled-path tests; add fail-closed and URL-encoding tests
madhavilosetty-intel
approved these changes
Aug 21, 2026
graikhel-intel
approved these changes
Aug 21, 2026
RosieAMT
pushed a commit
that referenced
this pull request
Aug 21, 2026
# [2.40.0](v2.39.4...v2.40.0) (2026-08-21) ### Features * **activation:** prevent orphaned MPS device records on re-provision ([#2873](#2873)) ([624c6d6](624c6d6))
|
🎉 This PR is included in version 2.40.0 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add the opt-in
prevent_orphaned_devicesconfig flag (default off). When enabled, a device reporting pre-provisioning mode (currentMode=0) that still has a record in the MPS devices table is refused until it is removed via rpc-go deactivation or the REST API, keeping the devices table free of orphaned/duplicate records. Disabled by default, so existing behavior is unchanged. Fails open if MPS is unreachable or the device is not registered.PR Checklist
What are you changing?
Anything the reviewer should know when reviewing this PR?
If the there are associated PRs in other repositories, please link them here (i.e. device-management-toolkit/repo#365 )