Skip to content

agent-device session folders under the worker's data directory are never removed #1411

Closed

Description

@V3RON

The agent-device daemons a worker runs leave one folder per session under ~/.simlock/agent-device/sessions, and nothing removes them. #1409 counted 12,556 folders (4.9 GiB) on one worker.

No code in src/agent-device/ names that folder except the route check in src/agent-device/shared/routes.ts:38. A lease end (src/agent-device/host/lease-end.ts:150) sends agent_device.lease.release and deletes nothing on disk. So either agent-device prunes its own sessions, or simlock does at lease end. Which side owns it is open.

Found while triaging #1409.

Written by an agent.

Activity

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

    @V3RON
    ContributorAuthor

    Reproduction

    Confirmed. A gap: the test's expectation is a proposal (simlock sweeps at lease end).

    src/agent-device/session-folders.test.ts, "a lease end removes every agent-device session folder of both daemons that nothing wrote to for longer than the agent-device lease ceiling, and keeps one written since", on bug/1411-repro:

    $ pnpm exec vitest run --project unit src/agent-device/session-folders.test.ts
    AssertionError: expected [ { exists: true, …(1) }, …(3) ] to deeply equal [ { exists: false, …(1) }, …(3) ]
    -     "exists": false,  agent-device/sessions/adc-…01
    -     "exists": false,  agent-device/sessions/tok_one_adc-…01
    -     "exists": false,  agent-device-phones/sessions/tok_two_my-session
          "exists": true,   agent-device/sessions/tok_two_adc-…02   (fresh, kept)
    

    Root cause

    Gap. AgentDeviceLeaseEnd.leaseEnded (src/agent-device/host/lease-end.ts:150) only sends agent_device.lease.release, and no simlock code reads <stateDir>/sessions for either daemon. agent-device 0.21.35 makes one folder per session address (sessions/<lease id> for the allocate, sessions/<tenant>_<session> for commands) and on close removes only its tombstone files, never the folder. Simlock cannot map a folder to its lease: the CLI's --session picks any name. So the only complete fix in simlock is age-based. A session cannot outlive its agent-device lease, and that lease cannot outlive agentDeviceLeaseMaxTtlMs (one day by default), so a folder nothing wrote to for longer than that belongs to no live lease.

    Simplest fix

    AgentDeviceLeaseEnd takes a SessionSweep (filesystem, clock, <home>/<stem>/sessions, agentDeviceLeaseMaxTtlMs). After each lease end it removes every folder whose newest entry is older than that limit. worker.ts builds one sweep for each daemon. It pins the age rule, no config key.

    $ pnpm exec vitest run --project unit src/agent-device/{session-folders,edge-lease-end,edge,dispose}.test.ts src/agent-device/host/lease-end.test.ts
    Test Files  5 passed (5)   Tests  168 passed (168)
    

    Alternatives rejected

    • agent-device removes a session's folder on close: another repo, and existing folders stay.
    • Delete sessions/<leaseId> and sessions/<tenant>_<leaseId> at lease end: misses folders named with --session.
    • Sweep only at daemon start: a worker that runs 30 h keeps a day of folders.

    Risk

    • The first sweep on a worker with 12k folders stats each one inside a lease end: check leasing's end wait, or run it in the background.
    • Only the folder and its direct entries are statted, so a write deep in requests/ alone is missed.
    • The manual needs a "Lease end" line for the sweep.

    Fast track

    • Defect: no — gap, ownership open
    • Fix tried: yes
    • Nothing public added or broken: yes
    • No ADR or rule changed: yes
    • One fix: no — agent-device could carry it

    Written by an agent.

  4. removed their assignment
    on Nov 7, 2026
  5. V3RON commented on Nov 7, 2026

    @V3RON
    ContributorAuthor

    Maintainer decision

    Simlock's agent-device adapter owns session-folder cleanup, not agent-device upstream. File transfer makes this more pressing: uploaded files keep a session folder large until it is removed.

    Written by an agent.

  6. V3RON commented on Nov 7, 2026

    @V3RON
    ContributorAuthor

    The maintainer decided (2026-11-07): simlock's agent-device adapter removes session folders. No age sweep.

    • At each lease end, simlock removes the session folders of that lease in the daemon that served it: sessions/<lease id>, sessions/<tenant>_<lease id>, and sessions/<tenant>_<name> for every --session name a command on that lease carried through the front.
    • At each daemon start, before agent-device runs, simlock removes every folder under that daemon's sessions/: a restart ends every agent-device lease, so none of them is live. This also clears folders left by earlier versions.
    • Tests: a lease end removes its own folders, including one named with --session, and keeps another live lease's folder. A daemon start empties sessions/ for both daemons.

    Written by an agent.

  7. added
    bug:ready
    and removed
    bug:new
    on Nov 7, 2026
  8. self-assigned this
    on Nov 7, 2026
  9. V3RON commented on Nov 7, 2026

    @V3RON
    ContributorAuthor

    Delivery run

    Merged: #1413 (#1411)
    Parked: none
    Waiting: none
    Decided: none

    Written by an agent.

  10. added a commit that references this issue on Nov 10, 2026
    e4599cf
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