Skip to content

[M1.4a2] Durable agent action queue with at-least-once delivery - #148

Merged
samuelmbabhazi merged 5 commits into
mainfrom
feat/m1.4a2-action-queue
Nov 5, 2026
Merged

samuelmbabhazi merged 5 commits into
mainfrom
feat/m1.4a2-action-queue

Conversation

@samuelmbabhazi

Copy link
Copy Markdown
Collaborator

Closes #134 (with #147).

What changed

M1.4a2: the control-plane side of action dispatch.

  • agent_actions table.
    • Forced tenant RLS, a composite foreign key to the node (cascade), and an idempotency key unique per node.
    • CHECK constraints on kind, key, state, epoch and attempts. The runtime role gets SELECT, INSERT and UPDATE; assertTenantDatabaseRole now covers 11 tables.
    • The action message is stored encrypted with EnvelopeService: scope organization:<id>, purpose bound to the action id.
  • AgentActions service:
    • enqueue validates the kind against the proto catalog, the key grammar and a deadline within 24 h, and requires a node that has not been removed. It stamps the node's lease epoch, is idempotent per key (including a concurrent insert) and audits fleet.action.queued.
    • deliverable first expires overdue actions (audited as fleet.action.expired), then returns the node's unfinished actions not yet sent on this stream as ActionRequests.
    • record applies an agent ActionUpdate only to that node's own non-terminal action. Terminal states never change again, and each terminal state is audited as fleet.action.<state> with the node as actor. The step and error are bounded, and the result is stored as JSON.
  • NodeStream. After Hello, each poll (at most every second) sends unfinished actions once per stream, and the stream accepts actionUpdate frames. A new stream redelivers everything unfinished; the agent journal ([M1.4a1] Agent action dispatch with journaled, validated execution #147) replays known keys.
  • Docs. The SPEC describes delivery, and the PLAN ticks M1.4a.

How it was tested

  • Unit tests: a stream test delivers an action once (welcome, then actionRequest) and records the agent's update. Existing stream tests are updated. API tests (218) and the local gate pass.
  • New TLS integration case in gateway.integration.spec.ts:
    • an action queued for a really enrolled node is delivered with its key and kind, and redelivered on a new stream after a dropped connection;
    • RUNNING then SUCCEEDED updates move it to succeeded;
    • the audit shows queued then succeeded;
    • re-enqueueing the same key returns the same action;
    • the stored payload does not contain the plaintext.
  • Not run locally: the integration tests (no Docker). They run in CI-1.

Security considerations

  • Payloads are encrypted at rest.
  • A node can only update its own actions, through its authenticated identity and RLS.
  • Final states are immutable.
  • Delivery stays inside the closed action list.

@samuelmbabhazi
samuelmbabhazi merged commit 303e1f9 into main Nov 5, 2026
0 of 5 checks passed
@samuelmbabhazi
samuelmbabhazi deleted the feat/m1.4a2-action-queue branch November 5, 2026 19:43
samuelmbabhazi added a commit that referenced this pull request Nov 5, 2026
…ctors (#166)

## What changed

M3.4c4b: planner steps become typed agent actions, and the agent checks
that it accepts them.

- **`agentAction(step, secrets)`**
(`deployments/infrastructure/agent-steps.ts`) maps each pipeline step to
its proto action: `EnsureNetwork`, `PullImage`, `RunReleaseTask`,
`CreateContainer`, `StartContainer`, `HealthCheck`, `UpsertRoute`
(container upstreams, ADR 0017, automatic HTTPS), `RemoveRoute` and
`StopContainer`, with durations converted exactly.
- **Container specs:** name, pinned image, argv, env, an exposed TCP
port (never published on the host), CPU and memory, labels, network, and
restart policy (`always`, or `never` for release tasks).
- **Secrets:** the decrypted values are injected here, at enqueue time,
as `SecretEnv{name, version, value}`. An unset secret is refused with
409 `secrets_missing`. They travel only inside the action payload, which
the queue encrypts per organization (#148), over mTLS.
- **Compatibility vectors.** `agent-steps.vectors.spec-helpers.ts` runs
the planner over a full deployment: release task, health check, domains,
and a previous release on another node. A vitest file snapshot writes
every action it sends to
`agent/internal/actions/testdata/control-plane-actions.txt`.
- The new Go test `TestControlPlaneActionsPassAgentValidation` decodes
each vector and plans it with the agent's own handlers. All 9 action
kinds pass, so the planner and the agent validators cannot drift apart
silently.
- **Docs.** SPEC section on the planner; PLAN: c4b is done.

## How it was tested

- `agent-steps.spec.ts`:
  - the container spec, including secrets as bytes with their version;
  - refusal of an unset secret;
  - every other step, after a wire round trip;
  - durations (120.5 s), the release task spec and the health probe;
  - container upstreams;
  - the vector snapshot.
- Go: the compatibility test, `go test -race` and golangci-lint.
- API tests: 274 pass. The local gate passes.

## Security considerations

- Secret values appear only in the encrypted queue payload and on the
mTLS stream: not in logs, audit, the planner or the vectors, which use a
fixture value.
- The agent still validates everything. The vectors only prove that what
we send is accepted.

---------

Signed-off-by: Samuel Mbabhazi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[M1.4a] Dispatch agent actions over the Connect stream

1 participant