Skip to content

nuke --delete-devices skips a quarantined device, so a stranded one keeps its capacity slot #1517

Closed

Description

@V3RON

`NukeService#resetDevice` (`src/core/nuke-service.ts:176-184`) destroys a device only when it is `shutdown` (`#currentShutdown`, line 191). A `quarantined` device is skipped. The user docs say `--delete-devices` deletes every simulator and emulator Simlock created (`website/src/content/docs/docs/worker/cleanup.mdx:116`).

This matters most for a device left by `device.quarantine-stranded`: the core manual says it keeps its capacity slot and gets no further retry (`src/core/AGENTS.md`, Reclaim and quarantine). Nothing then removes it: nuke skips it, and `ManagedDeviceLifecycle.destroy` accepts only `provisioning` and `shutdown` (`src/core/managed-device-lifecycle.ts:196`).

Found by reading the code while triaging #1487. Not reproduced as a test.

Written by an agent.

Activity

  1. added
    bug:new
    on Nov 10, 2026
  2. self-assigned this
    on Nov 10, 2026
  3. V3RON commented on Nov 10, 2026

    @V3RON
    ContributorAuthor

    Reproduction

    Confirmed. Branch bug/1517-repro, src/core/nuke.test.ts, "with --delete-devices deletes quarantined virtual devices, one waiting for a retry and one stranded". It runs Nuke.run against the real lease engine.

    pnpm exec vitest run --project unit src/core/nuke.test.ts
    AssertionError: expected [] to deeply equal [ 'dev_1', 'dev_2' ]
     ❯ src/core/nuke.test.ts:135  expect(result.deletedDevices).toEqual([waitingId, strandedId])
    

    Correction to the body: a daemon restart does retry a stranded device once more (startup-converger.ts:48 → QuarantineCoordinator.restore, quarantine-coordinator.ts:161). Nothing else removes it.

    Root cause

    Defect. NukeService#currentShutdown (src/core/nuke-service.ts:195) picks only shutdown devices to destroy. ManagedDeviceLifecycle.destroy (src/core/managed-device-lifecycle.ts:196,206) accepts only provisioning and shutdown. So nuke never destroys a quarantined device, even though quarantined → deleted is a legal edge (domain.ts:523) and the user docs promise every device is deleted (cleanup.mdx:116).

    Simplest fix

    Accept quarantined in destroy's claim and commit states. Have #currentShutdown take shutdown or quarantined. Drop quarantineAttempts, quarantineNextRetryAt and quarantinedAt in transition (domain.ts:585) so the deleted row carries none of them. Change the core manual's Nuke line to match.

    3 files, +19 −7
    pnpm exec vitest run --project unit src/core/nuke.test.ts src/core/nuke-service.test.ts \
      src/core/managed-device-lifecycle.test.ts src/core/domain.test.ts \
      src/core/quarantine-coordinator.test.ts src/core/registry.test.ts \
      src/core/registry-state-db.test.ts src/core/cleanup-executor.test.ts
    Tests  259 passed (259)
    pnpm test:changed: 12 failures in src/agent-device/{edge,edge-lease-end,gateway-front}.test.ts, all also failing with the fix removed
    

    Alternatives rejected

    • Give nuke a destroy through QuarantineCoordinator: a second destroy path; core requires every driver verb to go through ManagedDeviceLifecycle.
    • Call registry.deleteQuarantined from the lifecycle: ManagedDeviceRegistry would need a new method just to do what transitionDevice already does.

    Risk

    • Other destroy callers (cleanup, failed boot) choose by state before calling it, so none of them passes a quarantined device now. Check that this holds.
    • A quarantine retry still running holds the reclaim claim, so nuke skips that device and the retry deletes it.
    • A plain nuke still leaves a quarantined device as it is.

    Fast track

    • Defect: yes
    • Fix tried: yes
    • Nothing public added or broken: yes
    • No ADR or rule changed: yes
    • One fix: yes

    Written by an agent.

  4. removed their assignment
    on Nov 10, 2026
  5. added
    bug:ready
    fast-track
    and removed
    bug:new
    on Nov 10, 2026
  6. self-assigned this
    on Nov 10, 2026
  7. V3RON commented on Nov 10, 2026

    @V3RON
    ContributorAuthor

    Handoff

    Done: PR #1520 (draft, branch bug/1517, head 3abd48d). nuke --delete-devices now destroys quarantined virtual devices, and transition clears the three quarantine fields on → deleted. Review found R1 (fields stripped twice) and R2 (manual line restated code); both are fixed. origin/main (#1518, provisioning) was merged in, and the conflicts were resolved and reviewed.

    Not done: R3, open at the round cap.

    Findings: R3, from the code lens at the final fix-check. Fix 17d876d removed the strip from Registry.deleteQuarantined (src/core/registry.ts:460). transitionPhysical (src/core/domain.ts:634) strips nothing, so a physical device unenrolled after its quarantine retries run out keeps quarantineAttempts, quarantineNextRetryAt and quarantinedAt on its deleted row. A probe showed this. Fix: strip on → deleted in transitionPhysical too, and assert it for a physical device.

    Blocked on: the maintainer decides whether to approve a fix run for R3 and a new fix-check beyond the cap (rule 14).

    Written by an agent.

  8. added
    bug:blocked
    and removed
    bug:ready
    on Nov 10, 2026
  9. removed their assignment
    on Nov 10, 2026
  10. V3RON commented on Nov 10, 2026

    @V3RON
    ContributorAuthor

    Delivery run

    Merged: none
    Parked: #1517 — R3 open at the review cap: a physical device's deleted row keeps its quarantine fields (PR #1520)

    Written by an agent.

  11. added
    bug:ready
    and removed
    bug:blocked
    on Nov 12, 2026
  12. self-assigned this
    on Nov 12, 2026
  13. V3RON commented on Nov 12, 2026

    @V3RON
    ContributorAuthor

    Delivery run

    Merged: #1520 (#1517)
    Decided: #1517 — one more fix run and fix-check for R3 beyond the round cap → taken, as the maintainer re-ran deliver on the parked PR

    Written by an agent.

  14. added a commit that references this issue on Nov 17, 2026
    e2fe08c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug:readyfast-track

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions