Skip to content

Agent-device lease calls write to an untenanted session folder that no lease end removes #2003

Todo

Description

@V3RON

What happened

Two leases that use the same --session name share one folder under the worker's agent-device/sessions, and the end of a lease does not remove it.

agent-device runs agent_device.lease.allocate, heartbeat and release with the session the client sent and no tenant, so their events go to sessions/<session name>. Only agent_device.command calls get the <tenant>_<session name> folder.

  • A lease's end removes sessions/<lease id>, <tenant>_<lease id> and <tenant>_<session name> (src/agent-device/host/lease-end.ts, folderNames). sessions/<session name> is in none of them, so it stays until the next daemon start empties sessions.
  • sessions/<lease id> is made only for a session with that name.
  • The client picks this name, and nothing puts it under the tenant. A client that knows another lease's folder name, such as <tenant>_<session>, can have its lease calls' events written there.
  • A lease call with no session, such as simlock's own release at a lease's end, is logged under sessions/default.

What you expected

Each lease's agent-device folders are its own, and its end removes them all (#1411).

How to reproduce

Not yet reproduced on a running simlock. Seen with the real agent-device and @agent-device/proxy behind a small test front that forwards session as simlock does, and read in the code at d95c152:

  1. agent-device connect proxy … --session s1, then agent-device open com.apple.Preferences --platform ios --session s1.
  2. List sessions: it holds <tenant>_s1 and s1. s1/events.ndjson holds the lease_allocate events.
  3. Setting session to <tenant>:lease on the three lease calls left only <tenant>_lease and <tenant>_s1; open, heartbeat, diagnostics and the reopen after a restart kept working.

Environment

agent-device and @agent-device/proxy 0.21.41, iOS 18.5 simulators, Xcode 27.2, macOS. Code read at d95c152.

Logs and evidence

agent-device v0.21.41: packages/daemon/src/server/http/http-rpc-methods.ts toLeaseDaemonRequest (takes params.session, sets no session isolation) and packages/daemon/src/sessions/request-admission.ts scopeRequestSession (prefixes the tenant only under tenant isolation).

Found in the spike for #1906.

Written by an agent.

Activity

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

    @V3RON
    ContributorAuthor

    Reproduction

    Seen on: tool output (the reporter's run; not rerun here). The test's fakes name folders as agent-device 0.21.41's shipped code does.

    src/agent-device/session-folders.test.ts on bug/2003-repro: "every lease call reaches agent-device with a session under its own tenant, and a lease end removes the folder of each call made on that lease"

    pnpm exec vitest run --project unit src/agent-device/session-folders.test.ts
    
    AssertionError (folder of each lease call; expected "its own tenant" for all):
      lease 1  allocate, heartbeat, release     s1
      lease 2  allocate                         tok_5f_one.0…01_s1   (lease 1's folder)
      lease 2  heartbeat, simlock's release     default
      no lease heartbeat                        tok_5f_one.0…01_s1   (lease 1's folder)
    

    Root cause

    Defect. recordingFetch (src/agent-device/host/lease-end.ts:143) forwards the client's session on lease calls unchanged, and the release at line 266 sends none. The proxy stamps tenant isolation into params.meta, which agent-device reads for commands only, so a lease call's session is its folder name as sent. folderNames (line 48) then misses that folder: nameCall drops a lease call's session. ADR 0070 says a lease's session folders take the lease's tenant. The reporter's claims hold in the code; step 3 was not rerun.

    Simplest fix

    All in lease-end.ts: in recordingFetch, set session to <tenantId>:lease on every lease call that carries a tenant; do the same on simlock's own release; add lease to the names in folderNames. Both daemons and relayed calls go through it.

    reproduction                         2 passed
    pnpm exec vitest run --project unit src/agent-device
      as is                              8 failed (exact release params, no `session`)
      with `session` in those 8          540 passed, 1 skipped
    without the `folderNames` part       reproduction fails
    without the own-release part         reproduction fails
    

    The eight are in edge-lease-end.test.ts and host/lease-end.test.ts.

    Alternatives rejected

    • Remove sessions/<name> at lease end: deletes a folder another lease may share.
    • <tenant>:<client's session>: mixes lease events into that session's log, and the 64-name cap would leak folders.
    • agent-device applies tenant isolation to lease calls: right upstream, but simlock's own release bypasses the proxy and still needs a session.

    Risk

    • agent-device queues event writes, so the release's may land after its reply: check on a real run that <tenant>_lease stays gone.
    • A lease call for an ended or foreign lease can still leave a folder until the next daemon start.
    • Rewrite within nameCall's body read: a second await delays trackAllocate, which a lease end waits on.

    Fast track

    • Defect: yes
    • Fix tried: no — reproduction passes; 8 neighbouring tests pin exact release params and need session added
    • Nothing public added or broken: yes
    • No ADR or rule changed: yes
    • One fix: no — agent-device could apply tenant isolation to lease calls

    Written by an agent.

  4. removed their assignment
    on Nov 30, 2026
  5. added
    bug:ready
    and removed
    bug:new
    on Dec 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug:ready

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions