Skip to content

baseline remove of a baseline whose device is still reclaiming fails with INTERNAL #1476

Closed

Description

@V3RON

What happens. simlock baseline remove <name> --yes run right after releasing a lease made from that baseline fails with INTERNAL (exit 1). A retry a few seconds later works. The device is busy only because its reclaim still holds the claim, so the caller should get a named, retryable error, not INTERNAL.

Where. src/core/baselines.ts:435 throws a plain Error (Device ${device.id} made from baseline ${name} is busy) when claims.tryClaim(device.id, "cleanup") fails, and a plain error maps to INTERNAL. errors.mdx:69 has BASELINE_IN_USE (409) for a baseline a lease still uses, but a device that is still reclaiming has no code. The code is wrong; the docs do not list this state.

Seen. main at 30f8fad9: simlock baseline remove t6base --yes right after simlock release:
{"error":{"code":"INTERNAL","message":"Device dev_... made from baseline t6base is busy"}}, exit 1. A retry a few seconds later removed it.

Found during the pre-release e2e pass after v0.6.0.

Written by an agent.

Activity

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

    @V3RON
    ContributorAuthor

    Reproduction

    Confirmed on 30f8fad9. Branch bug/1476-repro, src/daemon/dispatcher.test.ts, "Dispatcher: baseline.remove while a copy is reclaiming > refuses the remove with DEVICE_BUSY naming the reclaiming device, and removes the baseline once its reclaim ends". It holds the reclaim's shutdown on the fake clock, removes, then lets the reclaim end and removes again.

    pnpm exec vitest run --project unit src/daemon/dispatcher.test.ts -t "while a copy is reclaiming"
    
    AssertionError: expected Error: Device dev_3 made from baseline ch… to match object { code: 'DEVICE_BUSY', …(1) }
    - { "code": "DEVICE_BUSY", "details": { "id": "dev_3", "reason": "reclaiming" } }
    + Error { "message": "Device dev_3 made from baseline checkout is busy" }
    

    Root cause

    Defect. src/core/baselines.ts:435 (#claimIdleDevices) throws a plain Error when tryClaim(device.id, "cleanup") fails. The reclaim's reclaim claim is held until the copy is deleted, so every remove during that window fails there. The handler at src/daemon/dispatcher.ts:1058 maps only BaselineInUseError and UnknownBaselineError, and passes the rest on, so classifyError answers INTERNAL ("something unexpected failed"). The state is expected and passes on its own. DEVICE_BUSY (exit 11, reason reclaiming) already names it.

    Simplest fix

    // baselines.ts:435
    throw new DeviceBusyError(device.id, device.state === "reclaiming" ? "reclaiming" : "busy");
    // dispatcher.ts, baselineRemove catch
    if (error instanceof DeviceBusyError)
      throw new DispatchError("DEVICE_BUSY", error.message, { id: error.id, reason: error.reason });

    Add DEVICE_BUSY to the route's 409 list (src/http/admin-declarations.ts:202). Name baseline remove in the DEVICE_BUSY row of errors.mdx, in cli.mdx:658 and in baselines.mdx:88/99.

    Fix tried: repro passes; dispatcher, core, gateway dispatcher, http app, cli tests: 57 files, 1991 passed.
    

    Alternatives rejected

    • Wait for the reclaim, then remove: the remove succeeds instead of failing, and can block for a whole reclaim.
    • Skip a reclaiming copy, as remove already skips a quarantined one: destroys the source while a copy of it is still being destroyed.
    • BASELINE_IN_USE: its details need a leaseId, and the lease has already ended.

    Risk

    • The gateway passes the worker's code through as it does BASELINE_IN_USE (gateway/dispatcher.test.ts:1923). Check DEVICE_BUSY reaches a fleet caller.
    • id is the registry id (dev_…) here, but the enrolled device's id in device add/remove.
    • The exit code goes from 1 to 11 for scripts that retry on 11.

    Fast track

    • Defect: yes
    • Fix tried: yes
    • Nothing public added or broken: yes
    • No ADR or rule changed: yes
    • One fix: no — waiting for the reclaim would answer success, not DEVICE_BUSY

    Written by an agent.

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

    @V3RON
    ContributorAuthor

    Delivery run

    Merged: #1490 (#1476)
    Parked: none
    Waiting: none
    Decided: none

    Written by an agent.

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

Metadata

Metadata

Assignees

Labels

bug:ready

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions