Skip to content

A recovered interrupted reclaim attributes device.shutdown to a module that does not exist #676

Closed

Description

@V3RON

What is wrong

A recovered interrupted reclaim attributes device.shutdown to a module that does not exist

Where this came from

Confirmed in the bug bounty sweep tracked on #648 (finding 2). The reproduction was reproduced independently by the orchestrating session, the proposed fix confirmed green against the surrounding suite, and the finding re-confirmed against current main.

Spec

Area: src/core/reclaim-coordinator.ts (reclaim recovery at daemon startup)

Severity: audit-trail misattribution, no state damage. The payload is
correct, so the record is misleading rather than wrong — but the module string is
the only thing saying who shut the device down, and it names a module whose job
is something else entirely.

Kind: defect — the module string stamped on the event contradicts the emitter
both docs/EVENTS.md and docs/internal/EVENTS.md publish.

Problem

A daemon start finds a device stuck in reclaiming with no lease, shuts it down
without a purge, and publishes device.shutdown. Events rule 7 binds the
emitting module onto every event, simlock events prints whole envelopes
verbatim (src/cli/index.ts:1195), and ~/.simlock/events.jsonl keeps that
string as the audit trail.

On this one path the module is a hardcoded string left over from
src/core/warm-pool-coordinator.ts — a file that no longer exists. So an
operator investigating why a device was shut down reads a name that points at the
warm pool, a module with a different job and different warmPool.* tunables,
while the real actor is the reclaim coordinator driven by daemon startup.

The string names nothing in the shipped system: warm-pool-coordinator occurs
exactly once in the whole repository
— at the bug itself. The warm pool's own
emitter string is warm-pool (src/core/warm-pool/converger.ts:418).

Reached by restarting the daemon while a device is mid-reclaim (a kill during an
iOS erase) and then running simlock events --since 1h.

Root cause

src/core/reclaim-coordinator.ts:166 — the literal "warm-pool-coordinator"
passed as EventBus.emit's module argument.

The cause is neither the payload nor the emission point (both correct) but the
module identity the coordinator stamps on its own fact. git log -L on that hunk
shows the string was written in src/core/warm-pool-coordinator.ts (present at
2a741672, still there at 74c09e63) and was carried across the decomposition
and the ADR 0017 rename to reclaim-coordinator.ts unchanged. Every other emit in
this file goes through the registry, which stamps "registry"
(src/core/registry.ts:1060), so this manual emit is the module's only
self-naming moment — and it names its former self.

What the docs oblige instead, both cuts:

docs/EVENTS.md:49          device.shutdown | … | Registry; the reclaim coordinator
                              for interrupted reclaim recovery
docs/internal/EVENTS.md:87 device.shutdown | … | Registry; ReclaimCoordinator for
                              interrupted reclaim recovery

How the docs bind the field: EVENTS.md's Emitter column is prose
(Registry; the reclaim coordinator…), and the envelope's module is its
machine-readable counterpart. The convention holds everywhere else in the area —
the column's QuarantineCoordinator is emitted as "quarantine-coordinator"
(quarantine-coordinator.ts:88), Registry as "registry"
(registry.ts:1060), and the warm pool's rows as "warm-pool"
(warm-pool/converger.ts:418). So "reclaim-coordinator" is the value the
convention and the column both point to, and "warm-pool-coordinator" matches
neither cut's wording nor any module.

Evidence

Test file:  src/core/reclaim-interrupted-shutdown-emitter.test.ts
Test title: the fact a recovered interrupted reclaim emits > names the reclaim
            coordinator as its emitting module
Command:    pnpm exec vitest run --project unit \
              src/core/reclaim-interrupted-shutdown-emitter.test.ts
AssertionError: expected [ { …(2) } ] to deeply equal [ { …(2) } ]
@@ -1,8 +1,8 @@
 [
   {
-    "module": "reclaim-coordinator",
+    "module": "warm-pool-coordinator",
     "payload": {
       "deviceId": "dev_test",
       "initiator": "startup-interrupted-reclaim",
     },
   },

The test drives the real Registry (register → ready → grant → beginRelease, so
the device genuinely sits reclaiming and unleased) through
ReclaimCoordinator.recoverInterrupted.

Honesty check: changing only the string at reclaim-coordinator.ts:166 turns
the test green, so it fails on the attribution and nothing else. To prove the
emission is genuinely reached rather than silently absent, an interim two-test
version asserted the state visible to a subscriber at emit time — relocating the
emit above the completeReclaimWithoutPurge commit made that test fail with
expected [ 'reclaiming' ] to deeply equal [ 'shutdown' ]. The shipped test's
assertion is an exact toEqual on a one-element array, so a path that emitted
nothing, or twice, fails on shape rather than on the string.

Independently re-verified by the orchestrator: red on unmodified code, green with
the one-line fix, with 103 tests passing across reclaim-coordinator,
create-core and the whole src/bus module. No existing test asserts the old
string.

Proposed fix

src/core/reclaim-coordinator.ts:166 — replace "warm-pool-coordinator" with
"reclaim-coordinator". It fits the emitter-name convention already in the area
(quarantine-coordinator, lease-acquisition-coordinator, warm-pool,
registry). No doc change is needed: both EVENTS.md cuts and ADR 0017 already
describe exactly that emitter.

Alternatives rejected

  • Change both EVENTS.md files to say the warm pool emits it — end-user docs would
    then blame a module that performs no such action, and ADR 0017 explicitly keeps
    this recovery in the reclaim coordinator.
  • Route the commit and fact through Registry.transitionDevice so the registry
    stamps "registry" — impossible: assertTransitionEvent demands
    device.reclaimed for any exit from reclaiming (registry.ts:1243), and this
    path deliberately did not reclaim, which is why completeReclaimWithoutPurge
    exists.
  • Introduce a shared reclaim-coordinator constant or logger name — no second use
    exists yet, so it would be an extension point with one implementation.

Risk

  • Whether anything downstream keys on the module string. The gateway relays it
    verbatim (src/gateway/worker-link.ts:544) and the console never reads it; no
    test or consumer in the repo matches on warm-pool-coordinator, but a user's
    own events.jsonl tooling might.
  • device.shutdown's module is a published field value, so the additive-stability
    rule could be argued. The counter: both EVENTS.md cuts already document the
    value this fix produces, and the current one names no module that exists.
  • Worth a follow-up: no test or guard checks emitted module strings against
    EVENTS.md
    , which is why this drifted unnoticed through a rename. A rule-8
    property test over the emitter strings would catch the next one.

Written by an agent.

Written by an agent.

Activity

  1. added
    bug:ready
    on Oct 17, 2026
  2. self-assigned this
    on Oct 17, 2026
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