A Kubernetes operator that runs Claude Code sessions on long-horizon work
simmer plans operator.md
14 kB · 325 lines
Markdown
at main

simmer as a Kubernetes operator #

simmer grew one convenient piece at a time, and two problems came out of that.

  • The forge carries agent-to-agent traffic. A goal opened a child issue for each step, so that a second session would start, and the child's close woke the goal again. In one night, 16 of the 18 issues that claude opened were these hand-offs, each with its own pull request, CI runs, and comments. None of them needed the owner.
  • One ReadWriteMany volume holds all of simmer's state. Transcripts, inboxes, keys, the stop record, merge locks, interrupted marks, and a history file are all files on it, and every Job mounts all of it. A Job can delete the stop record, so the dispatcher has to write it back.

This plan makes simmer a Kubernetes operator. Custom resources are the control plane: what simmer is told to do, and what it observes. Events, inboxes, and transcripts are the data plane, and they are never resources.

The design starts from the problems to solve: responsibilities, the model budget, and incoming information. It has no Agent resource. A session is something that a responsibility starts when it has work, and it ends when the work is done.

The forge's role #

The forge holds what needs a person, and the long-term list of work:

  • goals, which are larger lines of work
  • proposals for the owner to review
  • bugs, found during other work, in testing, or by a session that names a problem outside its own work and goes back to its task
  • pull requests, which carry every change

Sessions do not hand work to each other through issues or comments. How one session's work reaches another, inside simmer, is an open question below.

The resources #

Resource What it does How many Lives for Written by
Account A model provider subscription: its credential Secret, and the latest reading of its usage 1 to 3 years the cluster owner
Allowance A class of work on one Account, with its own budget in dollars a few for each Account months the cluster owner
Mandate A responsibility that the cluster owner delegates: what it hears, what it is equipped with, and its duties about 5 to 10 months the cluster owner
Signal A type of incoming information: where its events arrive from, how to key and scope them, and its named conditions 2 to 5 months the cluster owner
Session One conversation under one Mandate: the keys it holds, what it waits on, and its turns tens active, hundreds a month hours to days the operator only
Stop The andon cord. While one exists, no Job starts. 0 or 1 until the cluster owner deletes it created by any Job, deleted only by the cluster owner
Hold The events that would start one Duty's Sessions, kept until a person releases or drops them 0 most days, at most 1 for each Duty until its events are released or dropped the operator, a person, or a Job in the Duty's namespace; released or dropped by a person
Job One turn of a Session. This is the built-in Kubernetes Job. several for each Session minutes the operator

An Account has many Allowances. An Allowance has many Mandates, and each Mandate draws on exactly one Allowance. A Mandate has many Sessions, and a Session has many Jobs.

An event is one occurrence of a Signal, such as one webhook. A key is the name that an event is routed by, such as an issue's web address. Events and keys are data-plane traffic.

Account #

kind: Account
metadata: { name: personal-max }
spec:
  provider: anthropic
  credential: { secretRef: personal-max-token }

Allowance #

kind: Allowance
metadata: { name: upkeep }
spec:
  account: personal-max
  budget:
    perHour: 4

An Allowance is a class of work on its Account, with a budget in notional US dollars: what its turns would cost at the API's prices. Its balance rises at perHour, and each finished turn takes its cost from it. The brake holds a Mandate's new Jobs while its Allowance's balance is at or below 0. Only the Allowance's own turns spend the budget, so the person's own sessions neither spend it nor hold it.

An Allowance draws on exactly one Account, so it is always clear which subscription pays for a Session. A list of Accounts can be added later if a real need comes up.

An Allowance's burst: {maxStarts, per} is the burst limit of each Duty whose Mandate draws on it: at most maxStarts Sessions that events start for one Duty in any span of per. A Duty's own burst replaces it, and without either the limit is 30 per hour. The Hold below keeps the events past it.

Mandate #

kind: Mandate
metadata: { name: ops }
spec:
  allowance: upkeep
  purview:
    alerts: ["*"]
    gitea: [example/infra]
  grants:
    roles: [cluster-reader]
    forge: { secretRef: claude-agent-gitea }
    mcp: { secretRef: claude-agent-mcp }
  tools:
    plugins: [knowledge]
    mcp: [prometheus, grafana]
  duties:
    - skill: alert-triage
      when:
        - { signal: alerts, condition: firing }
    - skill: alert-tuning
      every: 24h

A Mandate is a responsibility, and the grants and tools to carry it out over time. It holds references, names, and patterns. Every instruction in prose is in a skill, which is markdown in git and changes by a reviewed pull request.

  • Purview is what the Mandate hears. For each Signal, it lists patterns that an event's scope must match. Many Mandates can hear the same Signal, but their patterns for a Signal do not overlap, so each event has one owner. The operator refuses an overlapping Mandate and says why in its status.
  • Grants are who its Sessions are. The operator creates a ServiceAccount for each Mandate and binds the Roles it names. The forge identity and the MCP sign-in are Secrets that the deployment provides. The deployment decides whether Mandates share one forge user or each have their own.
  • Tools are what its Sessions are equipped with: the plugins that hold its skills, and the MCP servers it may call. A Session gets exactly these MCP servers. A repository's own .mcp.json is for a person's sessions in that repository, and simmer does not read it.
  • Duties are what the Mandate owes. A duty is a skill with its triggers. when names a condition on each of one or more Signals, and the duty runs when an event meets any of them. Each skill appears once in a Mandate, so a skill that answers events from two sources, such as triage of alerts and of failed health checks, names both Signals in one when. every is a cadence, and the duty runs about that often. schedule is a cron expression, with an optional timeZone, and the duty runs at that time. A duty has every or schedule, not both. A duty can have when and one of them, such as a dependency update on each security advisory, with a weekly sweep as a backstop.

A cadence is loose pressure. A duty's pressure is the time since its last run divided by every. At 1 it is due. When the Allowance has room and no event is waiting, the operator starts the duty with the highest pressure. A busy week runs duties late. Later, other things can add pressure too, such as a busy week of alert triage making alert tuning due sooner.

A schedule is a time of day, for work that must happen then, such as a board review at 5am before the day starts. The operator owns one CronJob for each scheduled duty, in the Mandate's namespace. The CronJob's Job runs simmer start from the operator's image, as the Mandate's ServiceAccount, and asks the operator through the data plane to start the duty. The operator starts no Session while one that the schedule started earlier is active, and the brake and maxActive hold its turns as they hold any other Session's.

simmer does not limit what a Session may change in a repository. That belongs to the skill, the repository's own rules such as CODEOWNERS and branch protection, and the review of each pull request.

Signal #

kind: Signal
metadata: { name: alerts }
spec:
  wicket: { path: alertmanager }  # token: { secretRef: wicket-alerts } sends a shared secret instead
  key: '"alert/\(.labels.alertname)/\(.labels.namespace)"'
  scope: '.labels.namespace'
  release: '.status == "resolved"'
  conditions:
    firing: '.status == "firing"'

A Signal owns the shape of its events: how to read them, how to name their keys, the scope that purviews match, and the named conditions that duties trigger on. A Mandate names a condition and never holds jq. The expressions are the same jq that routes.yaml has today.

Session #

kind: Session
metadata:
  name: ops-7f3a
  labels: { simmer.dev/mandate: ops }
spec:
  mandate: ops
  skill: alert-triage
  origin:
    signal: alerts
    key: alert/DiskFull/storage
status:
  phase: Waiting
  waitingOn: event
  keys:
    - alert/DiskFull/storage
    - forge.example.com/example/infra/issues/200
  turns:
    - { job: ops-7f3a-1, outcome: Succeeded }
  finishedAt: null

The spec is how the Session started, and it never changes. The status is what the operator observes. A finished Session is removed after a time to live, as Kubernetes removes finished Jobs.

Only the operator writes a Session. An agent that wants to follow a new key, such as the pull request it opened, sends a request through the data plane, and the operator adds the key. A Job has no write access to the control plane, except to create a Stop, and a Hold in its own Mandate's namespace.

Stop #

A Stop is the andon cord. Any Job can create one, and while one exists the operator starts no Job and deletes the running ones. Only the cluster owner can delete a Stop, and Kubernetes RBAC enforces that. Creating a Stop also opens an issue for the cluster owner, so the stop reaches the owner.

Hold #

kind: Hold
metadata: { name: github-security-fix, namespace: software-factory }
spec:
  duty: github-security-fix
  reason: "Started 30 Sessions from events in 4m; the burst limit is 30 per 1h."
  disposition: Hold            # Hold | Release | Drop
status:
  held: 1083

A Hold keeps the events that would start Sessions for one Duty, named by the Hold's own name. The operator creates one when the Duty would start more Sessions from events than its burst limit allows, and a person or a Job can create one to pause a Duty without losing its events. Each held event waits on the operator's volume, with the keys and the origin of the Session that it would start, its actor, and the keys that the Signal's release frees. An event for a key that a live Session holds still reaches that Session.

A person sets disposition. Release starts Sessions from the held events, oldest first, at the Duty's burst limit, and deletes the Hold when none is left. Drop deletes the held events and then the Hold. Deleting the Hold releases its events.

While a Hold of any disposition exists, the Duty's cadence and schedule start no Session. A held tick is skipped, not kept, and the first tick after the Hold is gone starts as usual.

What simmer does not know about #

  • midden. midden archives transcripts, and simmer knows nothing of it. The deployment adds midden's shipper to every Session's pod, for example with a kustomize patch on every Mandate. midden is for archaeology on transcripts and for diagnosing how sessions flowed. It is not a hand-off between sessions and not a record of the state of the work.
  • Privacy. Which Mandates may see which information is the cluster owner's choice: what each Mandate's grants and tools give it. A single "private" flag is too simple, and the boundaries are an open question.

Example: alerts #

The Allowance upkeep, the Signal alerts, and the Mandate ops are the ones above.

  1. DiskFull fires in the storage namespace. The event arrives on the alerts Signal with the key alert/DiskFull/storage and the scope storage. The scope matches the ops purview, and the event meets firing.
  2. No Session holds the key, so the operator creates a Session for the alert-triage duty.
  3. The operator checks the balance of the upkeep Allowance. When it is above 0, it creates a Job that runs as the ops ServiceAccount, with the MCP servers the Mandate lists.
  4. The agent finds the cause, opens an issue for the cluster owner, and requests the issue's key. The operator adds the key to the Session.
  5. A comment on the issue arrives on the gitea Signal and wakes the Session. When the alert resolves, its key is released. When the issue closes, the Session holds no key and finishes.

Meanwhile, the alert-tuning duty's pressure rises through the day. After about a day, when nothing waits and upkeep has room, the operator starts a tuning Session. This replaces today's CronJob.

Open questions #

  • Hand-offs inside simmer. When one session's work should start or wake another, the event needs a path that is not the forge. wicket already accepts bearer-token paths, so a simmer Signal that sessions post to is one candidate. Whether a goal needs more than one session at all is part of the question.
  • The data plane. Where events wait for a Session, and where transcripts are kept so that a turn can resume, now that the shared volume is not the place for everything.
  • Keys. Whether keys stay a list in a Session's status, or become something that answers "who holds this key" in one lookup.
  • Duties. Whether a run that an event triggers resets the cadence, and whether a duty across many repositories runs as one Session or one for each repository.
  • Mandate lifecycle. What happens to running Sessions when a Mandate is suspended, changed, or deleted.
  • Shared watching. A Session hears every key it follows, whichever Mandate owns it, and each Mandate reviews its own pull requests (plans/review.md). Still open: whether a Mandate can hear events that another Mandate owns without following a key, such as a review Mandate that reads every pull request.
  • Privacy and confidentiality between Mandates, as above.