Skip to content

feat(activation): prevent orphaned MPS device records on re-provision - #2873

Merged
madhavilosetty-intel merged 2 commits into
mainfrom
feat/prevent-orphaned-devices
Aug 21, 2026
Merged

feat(activation): prevent orphaned MPS device records on re-provision#2873
madhavilosetty-intel merged 2 commits into
mainfrom
feat/prevent-orphaned-devices

Conversation

@rsdmike

@rsdmike rsdmike commented Aug 19, 2026

Copy link
Copy Markdown
Member

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.

PR Checklist

  • Unit Tests have been added for new changes
  • API tests have been updated if applicable
  • All commented code has been removed
  • If you've added a dependency, you've ensured license is compatible with Apache 2.0 and clearly outlined the added dependency.

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 )

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.
Copilot AI lite review requested due to automatic review settings August 19, 2026 20:04

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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_devices config flag (default off) and plumb it through RPSConfig + environment defaults.
  • During activation validation, optionally query MPS for an existing device record when currentMode=0 and 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 got calls (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.

Comment thread src/Validator.ts
Comment thread src/Validator.ts
Comment thread src/Validator.ts
Comment thread src/validator.test.ts
- 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
madhavilosetty-intel merged commit 624c6d6 into main Aug 21, 2026
11 checks passed
@madhavilosetty-intel
madhavilosetty-intel deleted the feat/prevent-orphaned-devices branch August 21, 2026 19:47
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))
@RosieAMT

Copy link
Copy Markdown

🎉 This PR is included in version 2.40.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants