Skip to content

Durable broker state and recovery #2563

Open

Description

@ChrisJBurns

Depends on: #2559's workload-authentication PR (nothing is saved under the unverified placeholder workload); #2569 (the schedule grant store interface)
Removes shortcut: the broker's and AS-1's state are in memory, so a restart signs users out and gives every agent instance a new ag_ identity (#2451; the shared identity is gone since #2527)
Removes shortcut: schedule grants are held in memory; a restart loses them (#2545)
Removes shortcut: run and delegation records are capped at 4096 per session in memory, oldest forgotten first (#2557)
Removes shortcut: after a restart each agent instance registers again and its tool limit is computed afresh against the definitions and gateway servers loaded then, so a longer server list can widen it under the same definition revision (#2842)

Problem

Broker sessions, refresh tokens, agent identities, call decisions, and schedule grants live only in memory, as do AS-1's users and grants. A restart signs every user out, gives them new AS-1 subjects, voids every session's refresh token, and stops every schedule.

Implements

Scope

Decide before starting

  • How are sessions whose host session is gone found: a periodic reconcile, or a lease mecak8s renews?
  • The grant record's open item: persistence ordering of correlation records across a restart.
  • Schedules pin the exact definition revision they were set up with (docs(agent-identity): keep a re-registered instance's revision, and pin a schedule's definition #2866). Once schedules survive restarts, a restart that loads a newer revision leaves the pinned one unavailable. What happens then: the run stops and the owner re-approves the schedule, or the schedule follows the new revision but never gets more tools than it was set up with, or both? Record the answer in the design.

Done when

  • After a restart, sessions, refresh tokens, schedule grants, instances, and decision records recover with the same IDs and owners, without a new sign-in; schedules keep running.
  • A parked call resumed after a broker restart is authorized again.
  • AS-1 keeps each user's subject and accepts refresh tokens issued before the restart.
  • Unrecoverable state, or another workload, fails closed.
  • Refresh tokens and schedule grants never appear in logs or read APIs.

Earlier notes: #2847 (closed; storage part merged here, revocation part into #2568).

Activity

  1. ChrisJBurns commented on Nov 18, 2026

    @ChrisJBurns
    ContributorAuthor

    Design decision for this ticket: how a durable schedule picks up a changed agent definition. #2866 pins the exact revision for now; once schedules survive restarts (this ticket), a restart can load a newer revision and leave the pinned one unavailable. Options: the owner re-approves the schedule, or the schedule follows the new revision but never gets more tools than it was set up with, or both. Record the answer in credentials-and-lifecycle.md: Schedule setup when this ticket is picked up.

  2. rdimitrov commented on Nov 20, 2026

    @rdimitrov
    Member

    Run and delegation state after #2557

    #2557 (PR #2930) added two pieces of in-memory state and names this ticket as where they become durable. Neither is in the scope list above yet:

    • The broker's run and delegation records. Each broker session keeps its run records (agent, owner, delegation) and delegation records, at most 4096 of each, forgetting the oldest. They are dropped when the session closes (internal/identitybroker/runs.go). They should recover with the session. Otherwise a helper still running after a restart has its calls refused until it is delegated again.
    • mecak8s's delegations. agentcredential.Holder keeps each helper's current delegation and an ordered list of every delegation in the tree, at most 4096 per root. Run entry uses the list to report delegations again after the broker session reopens. This is the same in-memory holder the scope already mentions for agent credentials. Recovery should keep these delegations along with the identities, or report them again from durable state.

    Recovery also has to keep the order: a delegating run must be recorded before the runs it delegated to.

  3. rdimitrov commented on Nov 25, 2026

    @rdimitrov
    Member

    #2985 adds in-memory broker state that durable storage must keep: the open record reference on each grant and user, each registration's record, each delegation's latest accepted record by root host session, and close records waiting to be sent.

  4. rdimitrov commented on Nov 25, 2026

    @rdimitrov
    Member

    Follow-up from #2985: the broker's queued records are in-memory state too. That is the bounded queue of close and refusal records (denied-call decisions included) that Broker.Close drains at shutdown, and a held close that a refused open keeps back until its refusal is queued. A restart loses both, and the queue's order is the only record of which close follows which refusal. Making the broker's state durable should cover them, or this ticket should decide that #2848's lossless delivery does.

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions