Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 43 additions & 22 deletions docs/design/edge-exposure.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Design note: exposing a session to the outside world

Status: **proposal; decisions recorded below.** Nothing here is implemented yet. The group
renames it assumes are **pending**: until [agentops-operator#9](https://github.com/SteadyInfraTech/agentops-operator/pull/9)
and [ai-agent-edge-tunnel#5](https://github.com/SteadyInfraTech/ai-agent-edge-tunnel/pull/5) are
merged, the code still registers `agents.agentops.io` and the bare `agentops.io`. It describes how
[`ai-agent-edge-tunnel`](https://github.com/SteadyInfraTech/ai-agent-edge-tunnel) (a separate
operator that creates short-lived Cloudflare tunnels) attaches to an `AgentSession` without the
two projects sharing a repository, a Go module or a release cycle.
Status: **the edge side is implemented** in
[`ai-agent-edge-tunnel`](https://github.com/SteadyInfraTech/ai-agent-edge-tunnel)
(`spec.sessionRef`, ai-agent-edge-tunnel#6), and both API groups are renamed to `steadyinfra.com`
(agentops-operator#9, ai-agent-edge-tunnel#5). It has not been run against a real cluster with both
operators together. The shared client library (decision 4) is not built yet. This note describes how
`ai-agent-edge-tunnel` (a separate operator that creates short-lived Cloudflare tunnels) attaches to
an `AgentSession` without the two projects sharing a repository, a Go module or a release cycle.

## Goal

Expand All @@ -32,8 +32,7 @@ Everything the edge operator needs from AgentOps is already in `AgentSession`:
| Field read by the edge operator | Meaning |
|---|---|
| `status.phase` | `Bound` means there is a target to expose. `Pending` waits. `Completed`, `Expired`, `Failed` end the tunnel. |
| `status.endpoint` | In-cluster URL of the bound agent, `http://<svc>.<ns>.svc:<port>`. This becomes the connector's ingress target. |
| `status.assignedAgent` | The `AgentService` name; shown in the edge object's status for debugging. |
| `status.endpoint` | In-cluster URL of the bound agent, `http://<svc>.<ns>.svc:<port>`. This becomes the connector's ingress target. The parser currently also accepts an omitted port (defaults to 80) and an optional trailing `/`; these are current behaviour, not guaranteed contract. `<ns>` must equal the tunnel's own namespace. |
| `metadata.uid` | Identity of the session the tunnel was created for (see below). |

`spec.maxDurationSeconds` is deliberately **not** read. AgentOps already turns it into a phase change
Expand Down Expand Up @@ -85,8 +84,11 @@ With `sessionRef`, **the session's phase ends the tunnel, not a timer.** Consequ
Active, which is why a lifetime copied from the session would go stale.
- `maxDurationSeconds: 0` (no limit) means the tunnel lives until the session reaches a terminal
phase or is deleted. Nothing in the edge operator needs a finite remaining lifetime.
- `spec.ttl`, if set, is a hard cap: the tunnel ends at `ttl` even if the session is still `Bound`.
Set it when a bounded exposure matters more than session continuity. It is optional.
- `spec.ttl`, if set, starts after provisioning succeeds and limits the tunnel's active lifetime,
even if the session is still `Bound`. Provisioning retries can leave Cloudflare resources
allocated, and the connector serving traffic, before the TTL starts. Exposure can exceed
`spec.ttl` if the expiry is not recorded. The TTL is optional and is not a strict exposure
bound.

### Pinning the session identity

Expand All @@ -101,19 +103,38 @@ current "expose this Service" behaviour for anything that is not an `AgentSessio

Reconciliation, in addition to what the operator does today:

1. **Pending**: the session is not `Bound` (or does not exist yet). Nothing is created in
Cloudflare; status says what it is waiting for. A missing session is retried, not failed, so
the two objects can be applied in either order.
2. **Active**: the session is `Bound`. The connector's ingress target is taken from
`status.endpoint`. The session reference and the resolved endpoint are recorded in status.
3. **Terminated**: the session reaches `Completed`, `Expired` or `Failed`, or is deleted. The
edge operator removes the connector, DNS, Access application and tunnel in its usual order,
then marks the object `Terminated`.
4. **Re-binding**: if the session's `status.assignedAgent` changes, the connector is updated to
the new endpoint; the hostname and Access policy are unchanged.
1. **Pending**: the session does not exist yet, is `Pending` (not yet `Bound`), or exposes an
endpoint the edge operator will not accept. These are waited for only until the session's UID has
been recorded in status; after that, see Terminated and the unexpected-phase rule below (a pinned
session whose endpoint is rejected or changes terminates the tunnel). A session that is already
`Completed`, `Expired` or `Failed` is not waited for: terminal beats pending, so an object first
reconciled after the session ended goes straight to Terminated. Clients should treat only
`Terminated` as final. While waiting for an unpinned session the operator provisions no
Cloudflare resources; once pinned, Cloudflare resources can exist while the tunnel is still
`Pending`. Status says what it is waiting for. A missing session is retried, not failed, so the two objects can be applied in
either order.
2. **Active**: the session is `Bound`. Its UID and endpoint are recorded in status
(`status.sessionUID`, `status.sessionEndpoint`) **before** anything is created, and the
connector's ingress target is the recorded endpoint.
3. **Terminated**: the session reaches `Completed`, `Expired` or `Failed`, is deleted, has a
different UID, is being deleted, or is bound to a different endpoint. The edge operator removes
the connector, DNS, Access application and tunnel in its usual order, then marks the object
`Terminated`. A session that merely reports an unexpected phase ends nothing: the tunnel keeps
running and the TTL cap and connector upkeep continue.
4. **Re-binding ends the tunnel; it does not re-point it.** If the session's `status.endpoint`
changes after the tunnel was bound, the tunnel is terminated. An earlier draft of this note
updated the connector in place. cloudflared does not reload its config, and silently re-pointing
an Access-protected hostname at a different agent is the riskier default. A client that needs a
new hostname for the new binding creates a new `AgentEdgeTunnel`.

The session is read as `unstructured` and polled every 10 seconds, not watched, so the edge
operator starts without AgentOps installed. A tunnel can outlive its session by roughly that long, and longer if the controller, the API
server or Cloudflare cleanup is failing: the interval is a polling period, not a deadline. The
optional `spec.ttl` is also enforced by reconciliation, so it is a cap that holds while the operator
is healthy, not an independent cutoff.

Because the edge object only *reads* the session, it never needs write access to AgentOps
resources. RBAC: `get`, `list`, `watch` on `agentsessions` in the namespaces it manages.
resources. RBAC: `get` on `agentsessions` in the namespaces it manages (polling needs no `list` or `watch`).

## API group

Expand Down
Loading