Repository navigation
Closed
Labels
bug:readyAn agent may fix it.
Description
A worker keeps every deleted device row in memory and in state.db for its whole life, and status.get lists all of them. Both grow with every device the worker has ever made. #1409 saw 351 deleted rows next to 13 live ones after about 31 h.
src/core/registry.ts:174:#devicesis loaded with every row and no path removes one. A deletion only setsstate: "deleted".src/core/registry.ts:199:snapshotclones every row, deleted ones included, on each read.src/daemon/dispatcher.ts:415:status.getanswerssnapshot.devices, so the gateway's refresh of each worker's view carries them all too.
Nothing needs an old deleted record. Almost every reader filters state !== "deleted". The only rows that point at one are lease_grants (removed with their request after lease.requestRetentionMs, src/core/registry-rows.ts:389) and the device's own device_enrolled_apps.
Found while triaging #1409.
Fix (decided by the maintainer, 2026-11-07)
A deleted device record expires, the way a settled lease request does (lease.requestRetentionMs).
- New config key
devices.deletedRetentionMs: how long adeletedrecord is kept, counted from when it was deleted. Positive number of ms, default3600000(1 h). Smaller thanlease.requestRetentionMsis refused at config load. devicesgets adeleted_atcolumn (schema migration). A row alreadydeletedat the first start after the upgrade gets that start's time.- The registry drops an expired record from memory and deletes its
devicesanddevice_enrolled_appsrows, in one commit, at startup and on each newdevice.deleted. No event for the removal. - A user sees a deleted device in
status.getand the console for up to the retention time, and then it is gone; asking about its id after that answers as for an unknown device. - ADR 0022 gets an
Amended:line: a deleted record stays fordevices.deletedRetentionMs, not for good. The core manual line "deletedrecords stay instate.db" changes to match. - Docs: the configuration reference gets the key; the physical-devices page says a removed phone stays in the answer for
devices.deletedRetentionMs.
Done when
- A
deletedrecord older thandevices.deletedRetentionMsis gone fromstatus.getand fromstate.dbafter the next startup or the nextdevice.deleted. - A
deletedrecord younger than that is still listed. - A row deleted before the upgrade is kept for one retention period after the first start.
-
devices.deletedRetentionMsbelowlease.requestRetentionMsis refused at config load. - ADR 0022, the core manual and the two website pages say the same as the code.
Tests
- Replace the triage test on
bug/1410-repro(it pins a cap of 100, which was not taken) with: 3 devices deleted at t0, t0+30 min, t0+70 min; at t0+90 min with the default the first is gone from memory andstate.db, the other two remain. - Migration: a database with
deletedrows and nodeleted_atloads, and the rows survive one retention period. - Config: the refused value names both keys in its error.
Written by an agent.
Activity
V3RON commentedon Nov 7, 2026
Reproduction
Confirmed. This is a gap: nothing says
deletedrows stay in memory or instatus.get, and nothing bounds them. The test's expectation is a proposal: keep 100 deleted records.src/core/registry-state-db.test.ts> "the snapshot holds every live device and only the 100 most recently deleted ones, while state.db keeps every deleted row, before and after a restart" (branchbug/1410-repro). The fixture has 2 live devices and 103 deleted ones. One of the deleted devices is created first and deleted last.Root cause
src/core/registry.ts:993(#commit) sets#devices = committedand drops nothing.src/core/registry.ts:185loads every row fromSELECT * FROM devices.snapshot(:194) copies them all, andstatus.get(src/daemon/dispatcher.ts:415) passessnapshot.devicesthrough as it is. Writing a devicedeletedis a state change, not a removal, so every device the worker ever made stays in memory. The symptom shows instatus.getand in the gateway's view of the worker.Simplest fix
Proposed shape: the registry keeps in memory only the 100 most recently deleted records. At runtime it tracks deletion order in memory. On load it keeps the last 100 by rowid.
state.dbkeeps every row, as the core manual requires.Alternatives rejected
deletedout ofstatus.getonly: memory still grows, and the e2ewaitForDeviceState(…, "deleted")checks rely on seeing them.state.dbpast the cap: this breaks the core manual's "deletedrecords stay instate.db".lease.maxRequestRecords: this adds config surface where a constant is enough.Risk
UnknownDeviceErrorfrom#requireDeviceRecord. Check callers that act on old ids.physical-devices.mdxsays "a removed phone stays in the answer". It needs "for a while".Fast track
status.getstops listing older deleted devicesSide findings
Written by an agent.
V3RON commentedon Nov 7, 2026
Spec updated: the fix is now a retention time for deleted records (
devices.deletedRetentionMs, 1 h), not a cap of 100.Written by an agent.
fix(core): the registry drops a deleted device record after devices.d…
test: devices.deletedRetentionMs is accepted from lease.requestRetent…
feat(core): devices.deletedRetentionMs sets how long a deleted device…
fix(core): only a worker checks devices.deletedRetentionMs; tests pro…
refactor(core): the alert-destination config validators move to confi…
V3RON commentedon Nov 7, 2026
Delivery run
Merged: #1415 (#1410)
Parked: none
Waiting: none
Decided: none
Written by an agent.
fix(core): a deleted device record expires after devices.deletedReten…