Skip to content

feat(ops): subscribeChanges — wake an operator tick on a substrate change signal, never trust it as a fact #1981

Closed

Description

@lex00

Split out of #1863 (thread 1). That issue holds the research; this one holds the shippable part.

What exists

Every drift-detection path chant has is time-triggered. WatchOp runs lifecycle snapshot + lifecycle diff --live on a TemporalSchedule cron. ReconcileOp does the same and opens a PR. chant operator (#1485) runs ConvergeOp ticks in a loop, DEFAULT_OPERATOR_INTERVAL_MS apart, each tick fenced by a git-ref lease. Detection latency is bounded by the interval in all three.

The operator is already the right host for a signal. Its loop is while (!aborted) { round(); sleep(); } and the sleep is sleepAbortable(ms, signal) (packages/core/src/op/operator.ts:159) — a second wake source is a small change, not a new runtime. A ConvergeOp tick is level-triggered by design, so waking early cannot change what a tick concludes. It only changes when the tick runs.

What is missing

No seam lets a lexicon say "something moved". The plugin interface (packages/core/src/lexicon.ts) has describeResources, observeResourcesDeep, listArtifacts, observeAmbient — all pull, all one-shot.

Per-lexicon verdict

The research question was whether a substrate's native change-notification primitive is complete and trustworthy enough to replace a scheduled watch, not merely supplement it.

Lexicon Native primitive Replaces the poll Cost
k8s Watch API on any resource, resourceVersion-based, bookmarks Yes, for every declared kind One long-lived connection per watched group-version. Re-list on 410 Gone
k3d, k3s The same API server Yes, through k8s Same
helm None of its own. A release is a Secret in the cluster Indirectly, through the k8s watch Same
docker docker events on the local daemon Yes, for the local daemon A child process holding a stream
aws EventBridge, CloudTrail, Config configuration items No Requires a rule, a target and a delivery path deployed into the observed account, plus a receiver. A read-only watch stops being read-only. CloudTrail coverage is per-service and delivery is minutes-delayed
gcp Cloud Asset Inventory feeds to Pub/Sub No Same shape — a feed and a topic in the observed project, plus a subscriber
azure Event Grid system topics, Activity Log No Same shape, and system-topic coverage varies by resource provider
github, gitlab, forgejo Webhooks No Complete for repo and org events, but needs an ingress endpoint reachable from the forge. chant runs no such receiver and should not
fly The Machines API exposes no change stream No —
temporal, cedar, fountain No change feed on the surfaces chant reads No —

One family passes. Kubernetes, and the three lexicons that reach a cluster through it, have a complete change stream that needs nothing deployed into the target. Every cloud substrate fails on the same point — subscribing means writing infrastructure into the account being observed, which inverts the property that makes a watch safe to point at production.

Proposal

An optional subscribeChanges? capability on the plugin seam, consumed only by chant operator.

subscribeChanges?(options: {
  environment: string;
  onChange: () => void;
  signal: AbortSignal;
}): Promise<{ close(): Promise<void> }>;

Three rules make it honest.

The signal is a trigger, never a fact. onChange carries no payload and nothing about it reaches a change set, a snapshot, or a diff. The tick that follows re-observes and re-derives from scratch, exactly as a timer-driven tick does.

A dropped or failed subscription degrades to the timer and reports it. Losing the stream slows detection back to the interval. It never stops the loop and never reads as a clean estate.

The timer stays. A signal shortens the sleep, it does not replace it, so a substrate that silently stops sending still converges on the interval.

Scope

  1. The capability on the plugin seam, plus the operator wiring — a signal aborts the current sleep, the round runs, subscriptions are re-established per round and torn down on shutdown.
  2. watch on @intentius/chant-k8s-client — GET <path>?watch=1&resourceVersion=<rv>, NDJSON frames, 410 Gone handled by re-listing. The client already owns path resolution, credentials and an AbortSignal-aware send.
  3. The k8s adapter, scoped to the declared entities' group-versions.
  4. A docs table recording the per-lexicon verdict above, so the absence of a signal on aws, gcp and azure is a stated position rather than a missing feature.

Out of scope: any signal that needs infrastructure deployed into the observed account, any webhook receiver, and any path where an event feeds the change set.

Acceptance

  • subscribeChanges is optional. A lexicon without it behaves exactly as today.
  • An operator round wakes within a second of a k8s change to a declared resource, against a k3d cluster or the fake cluster.
  • A killed watch is reported once and the loop continues on the timer. The next round re-subscribes.
  • No test can construct a change-set entry, snapshot row or diff line from a signal — the signal type carries no resource data.
  • Unit coverage for the wake path with a stub capability, so the operator half is testable without a cluster.
  • The docs table lands with the code.

Related

#202 parked the estate-scale scheduled drift question, which is about spending a fixed poll budget across many stacks. This is about what triggers a tick at all, and does not unpark it.
#1485 built the operator. #1487 is the operating-loop epic.

Activity

  1. added
    enhancement
    area:lifecycle
    area:ops
    on Aug 29, 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

    area:lifecyclearea:opsenhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions