Skip to content

agent-device: a lease re-allocated after a standalone worker restart loses retainOnClose #1463

Closed as not planned

Description

@V3RON

What happens. A test runner allocates its agent-device lease through simlock's front with retainOnClose: true, so closing its session keeps the lease (ADR 0070 §2). Once #1461 lands, a standalone worker restart re-allocates the lease from leasing's record and the device registry. Neither holds retainOnClose, and the heartbeat does not carry it. The re-allocated lease therefore has no retainOnClose. The runner's next close ends the agent-device lease, and the front then ends the simlock lease (src/agent-device/front/ended.ts:43).

Where. Only after a standalone worker restart. When agent-device restarts alone, or the worker sits behind a gateway, the front's in-memory entry survives and can repeat the flag.

Why it is accepted for now. A worker restart already interrupts the test run. The maintainer chose to rebuild entries from leasing (no new stored state) over saving front entries in state.db. The gap is recorded in ADR 0071's Consequences.

A possible fix. Keep retainOnClose per lease somewhere that survives a worker restart, e.g. on the simlock lease record. The front would then repeat it on the re-allocate.

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

    Handoff

    Done: read the issue, ADR 0071 (PR #1462, Proposed) and the front on main caa5b4e. No test, no branch.

    Not done: reproduction and report. There is nothing to reproduce: the re-allocate is #1461, not built. On main a standalone worker restart ends the lease at its next heartbeat whatever retainOnClose says (known gap).

    Findings:

    src/agent-device/front/heartbeat.ts:154   releaseOurs on LEASE_NOT_FOUND (today's end)
    src/agent-device/front/front-map.ts:20    FrontMapEntry: no retainOnClose
    src/agent-device/front/front.ts:388       adoptLeases: rebuilt entry, no flag
    src/agent-device/testing.ts:535           fake agent-device keeps retainOnClose
    

    Blocked on: #1461's re-allocate landing on main; then re-add bug:new, or close if the ADR's choice stands.

    Written by an agent.

  4. added
    bug:blocked
    and removed
    bug:new
    on Nov 9, 2026
  5. removed their assignment
    on Nov 9, 2026
  6. V3RON commented on Nov 9, 2026

    @V3RON
    ContributorAuthor

    The gap is wider than the body says. A gateway also rebuilds its entries after its own restart, with no retainOnClose. So "gateway restart, then worker restart" loses the flag too. Any lease re-allocated from a rebuilt entry has none.

    Written by an agent.

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

    @V3RON
    ContributorAuthor

    Reproduction

    A decision, not a defect. ADR 0071 (Accepted) narrows ADR 0070 §2, and its Consequences name both cases: an entry rebuilt from leasing "(a standalone worker restart, or a gateway restart followed by a worker restart) does not carry it". So the later comment's gateway case is already accepted. The handoff's "the front stores no retainOnClose" is out of date: a surviving entry keeps it since #1461 (front-map.ts:14).

    Branch bug/1463-repro, two tests; their expectation is a proposal for a superseding ADR.

    pnpm exec vitest run --project unit src/agent-device/edge-restart.test.ts src/agent-device/gateway-front-restart.test.ts
    
    × after a standalone worker restarts, a lease allocated with retainOnClose is re-allocated with it, and a close with no open since keeps the simlock lease (#1463)
      expected [ true, undefined ] to deeply equal [ true, true ]      (retainOnClose on the first allocate, then on the re-allocate)
    × through a gateway, after a gateway restart, then a worker restart, keeps a lease allocated with retainOnClose (#1463), …: the fleet lease list
      expected [] to deeply equal [ '00000000000000000000000000000001' ]
    Tests  2 failed | 29 passed (31)
    

    Root cause

    src/agent-device/front/front.ts:401 (adoptLeases) rebuilds the entry from an AdoptableLease (front/host-link.ts:22); neither leasing's record nor the registry holds retainOnClose. So heartbeat.ts:127 re-allocates without it, and ended.ts:77 ends the simlock lease at the next close. ADR 0071 took this trade over saving front entries in state.db. From the code, not tested: a gateway restart then an agent-device restart alone takes the same path.

    Simplest fix

    None without a new ADR. Keep retainOnClose on the simlock lease record (sent with the front's lease.request, read back by adoptable on worker and gateway). That adds a stored and a wire field and supersedes ADR 0071's narrowing: a feature, not a fix. Or close this if the ADR's choice stands.

    Alternatives rejected

    • Save front entries in state.db: ADR 0071 rejected it; it copies what leasing holds.
    • Never end a restored entry on close: it breaks the runs that did not ask for retainOnClose.

    Risk

    • A new lease field crosses the gateway–worker wire: protocol bump.

    Fast track

    • Defect: no — ADR 0071 accepts the loss
    • Fix tried: no — needs new stored state and an ADR
    • Nothing public added or broken: no — adds a lease wire field
    • No ADR or rule changed: no — supersedes ADR 0071's narrowing of 0070 §2
    • One fix: no — lease field and state.db differ in where the data lives

    Written by an agent.

  10. removed their assignment
    on Nov 18, 2026
  11. V3RON commented on Nov 18, 2026

    @V3RON
    ContributorAuthor

    Delivery run

    Closing as not planned: this is ADR 0071's accepted choice, not a defect.

    • ADR 0071 (Accepted) narrows ADR 0070 §2 in its header: a lease re-allocated from an entry rebuilt after a worker restart does not carry retainOnClose.
    • Its Consequences name both cases from this thread: a standalone worker restart, and a gateway restart followed by a worker restart.
    • Its Alternatives reject the only fix (saving front entries in state.db, or a new stored field on the lease record).

    Changing this needs a new ADR that supersedes that part of 0071, and it would be a feature, not a bug fix. The triage's two failing tests that pin the proposed behaviour are on branch bug/1463-repro (ef50ee8), ready for that feature if someone opens it.

    Merged: none
    Parked: none
    Waiting: none
    Decided: #1463 — defect or ADR choice → ADR 0071's choice stands; closed

    Written by an agent.

  12. removed
    bug:new
    on Nov 18, 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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions