Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions pkgs/fleet/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion pkgs/fleet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,8 @@ and every build compiles it, so no build can know a domain another
build forgot. The registered domains are `fleet queue`, `fleet serve`,
`fleet proxy`, `fleet dispatch`, `fleet dispatch-test`,
`fleet secrets`, `fleet gh`, `fleet bridge`, `fleet agent`,
`fleet shell`, `fleet search`, `fleet laptop-agent` and `fleet cert`, and the
`fleet shell`, `fleet search`, `fleet laptop-agent`, `fleet cert` and
`fleet actions`, and the
laptop route forms (#13717): `fleet laptop` (tier T0, the generic
tiered command), `fleet commander` (T1), `fleet http` (T2) and
`fleet ssh` (T3), plus the
Expand Down
1 change: 1 addition & 0 deletions pkgs/fleet/book/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
- [fleet search](reference/search.md)
- [fleet laptop-agent](reference/laptop-agent.md)
- [fleet laptop route forms](reference/laptop-route-forms.md)
- [fleet actions](reference/actions.md)

- [Tutorial: enrol a new seat](tutorials/enrol-a-seat.md)
- [Tutorial: claim and complete a queue task](tutorials/claim-and-complete.md)
Expand Down
92 changes: 92 additions & 0 deletions pkgs/fleet/book/reference/actions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# fleet actions

Live short-lived exec sessions inside GitHub Actions runners
(#13774), coordinator-handed-off. A seat opens a session at the
queue broker (the coordinator), dispatches the `fleet-exec.yml`
workflow in `dezren39/fleet`, and binds the resulting run — the
**handoff** is the session handle plus the portable
`OWNER/REPO#RUN_ID` form and the run attempt. Commands then run
on the runner with their IO streamed back through the broker;
files leave through the workflow artifact and, when configured,
R2. Nothing connection-shaped is ever printed: the workflow
inputs carry only the handle and non-secret parameters, and the
runner proves its run membership to the broker with the job's
GitHub OIDC token, verified against GitHub's JWKS with its
`repository`, `job_workflow_ref`, `run_id` and `run_attempt`
claims bound to the session row.

## The lease

Every session carries two clocks, both enforced by the broker
and by the runner-side agent (which exits at expiry even if
partitioned from the broker):

- the **lease** — set by `start --timeout`, required, no default;
renewable through the coordinator, clamped at the max;
- the **max lifespan** — `--max-lifespan`, default 30 min,
ceiling 2 h (the fleet leg cap). Past it, only an **emergency
extension** helps: `exec extend` records the request and the
broker raises a needs-drew alert (source `fleet-actions-exec`);
Drew's approve/deny returns through `exec decide`, and approval
adds up to +30 min to the max and the lease. While a decision
is pending the session holds a 300 s grace past its lease.

## Commands

- `fleet actions exec start --repo OWNER/REPO --timeout S
[--max-lifespan S] [--ref R] [--target-repo OWNER/REPO]
[--hide-logs] [--detach] [--broker-url URL]` — open, claim
(the #13765 coordinator claim is attempted first; while those
verbs are not live the session proceeds on the singular path
and the output names it via `placement_path`), dispatch, bind,
print the handoff, then attach unless `--detach`. `--repo` is
the workflow host repo (default `dezren39/fleet`); sessions are
recorded in the local store under the state dir so the
portable form resolves later.
- `fleet actions exec run <ref> [--timeout S] -- <command...>` —
enqueue one command, stream its output, exit with its code.
- `fleet actions exec attach <ref>` / `watch <ref>` — stream the
session's IO after handoff; `watch` also reports the run and
session status.
- `fleet actions exec renew <ref> --timeout S` — extend the
lease within the max.
- `fleet actions exec extend <ref> [--minutes M] [--reason T]` —
request the emergency extension (raises the alert).
- `fleet actions exec decide <ref> --approve|--deny` — record
Drew's answer.
- `fleet actions exec close <ref>` — close the session.
- `fleet actions agent …` — the runner half, invoked by the
`fleet-exec-session` composite action in `dezren39/fleet`: it
registers with the OIDC token, long-polls the broker, executes
commands in the workdir, streams IO back, installs
`fleet-exec-put` on the session PATH, and enforces the lease
locally.
- `fleet actions put <file>` — the egress helper: copy the file
into the session outbox (uploaded as the run's
`fleet-exec-out` artifact) and, when the workflow populated the
`FLEET_EXEC_R2_*` environment from masked repo secrets, PUT it
to R2 under `fleet-exec/<handle>/` with a SigV4 signature.

## Log visibility

The agent echoes command IO to its own stdout by default, so it
lands in the public Actions run log; `start --hide-logs` turns
the echo off. Either way the broker is the transport — its IO
chunk store is the cache of record — and the seat's `run`,
`attach` and `watch` read from it. The OIDC token and the R2
credentials are never written to any log; the log audit is part
of the mode's acceptance bar.

## The broker surface

The verbs live in `crates/fleet-queue/src/turso_queue/
actions_exec.rs` beside placement's: `/actions-exec-open`,
`-bind`, `-command`, `-stream`, `-renew`, `-extend-request`,
`-extend-decide`, `-close` (seat side, broker token) and
`/actions-exec-register`, `-poll`, `-io`, `-result` (agent side,
OIDC through the public door at `exec.security.cab`, which is
path-scoped to these verbs). Session state lives in the
`actions_exec_sessions` / `actions_exec_commands` /
`actions_exec_io` tables; every transition is a conditional
UPDATE, so two actors racing a session resolve to exactly one
winner.
4 changes: 4 additions & 0 deletions pkgs/fleet/crates/fleet-queue/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ description = "The fleet queue domain: the repo-queue client surface plus the qu
client = ["dep:fleet-config", "dep:ureq"]
queue-broker = [
"client",
"dep:ring",
"dep:tiny_http",
"dep:ureq",
"dep:fleet-config",
Expand All @@ -40,6 +41,9 @@ ureq = { version = "3", features = ["rustls", "json", "platform-verifier"], opti
# the broker surfaces need no system SQLite (atlas-core pins the same
# stack). Only the queue-broker surface carries the replica.
rusqlite = { version = "0.42", features = ["bundled"], optional = true }
# #13774: RS256 verification of the Actions OIDC token in the
# actions-exec broker verbs (JWKS modulus/exponent -> ring RSA).
ring = { version = "0.17", optional = true }

# Standalone artifacts — the migration's rollback inventory (design
# note §7): the same code as the fleet binary's queue domain, shipped
Expand Down
10 changes: 5 additions & 5 deletions pkgs/fleet/crates/fleet-queue/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use std::time::{Duration, SystemTime, UNIX_EPOCH};

use serde_json::{Map, Value, json};

pub mod actions_exec;
mod commands_lifecycle;
mod commands_query;
mod fallback_stack;
Expand Down Expand Up @@ -1482,14 +1483,13 @@ mod tests {
// the same outcome class, distinct from unavailable —
// and a denial is never retried under another identity.
let at_transport = Err((3, "session proxy: unauthorized token".to_string()));
let (rec, code) =
exact_task_status("repo-health", 7, at_transport, "2026-11-23T12:05:00Z");
let (rec, code) = exact_task_status("repo-health", 7, at_transport, "2026-11-23T12:05:00Z");
assert_eq!(code, 3);
assert_eq!(rec["result"], json!("unknown"));
assert_eq!(rec["detail"], json!("denied"));
let by_envelope = Ok(json!({"ok": false, "error": "permission denied for this queue", "exit": 4}));
let (rec, code) =
exact_task_status("repo-health", 7, by_envelope, "2026-11-23T12:05:00Z");
let by_envelope =
Ok(json!({"ok": false, "error": "permission denied for this queue", "exit": 4}));
let (rec, code) = exact_task_status("repo-health", 7, by_envelope, "2026-11-23T12:05:00Z");
assert_eq!(code, 4);
assert_eq!(rec["result"], json!("unknown"));
assert_eq!(rec["detail"], json!("denied"));
Expand Down
126 changes: 126 additions & 0 deletions pkgs/fleet/crates/fleet-queue/src/client/actions_exec.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
//! Seat-side typed helpers for the actions-exec broker verbs
//! (#13774): live short-lived exec sessions inside GitHub Actions
//! runners. The runner-side agent does NOT use this client — it
//! speaks to the broker's public door with the job's OIDC token;
//! these helpers are the seat's half, over the standard queue
//! client transport (broker token, laptop broker endpoint).

use serde_json::{Value, json};

use super::transport::call_result;

/// POST one actions-exec verb through the shared client transport.
/// The envelope is returned as-is ({ok:true, ...} or the broker's
/// {ok:false, exit, error}); transport failure is exit 3.
fn ae_call(path: &str, body: Value) -> Result<Value, (i32, String)> {
call_result(path, &body)
}

/// Open a session row. `lease_s` is the caller's --timeout (required
/// by the verb; there is no default), `max_s` the hard lifespan cap.
pub fn ae_open(
host_repo: &str,
workflow: &str,
seat: &str,
lease_s: i64,
max_s: i64,
hide_logs: bool,
) -> Result<Value, (i32, String)> {
ae_call(
"/actions-exec-open",
json!({
"host_repo": host_repo,
"workflow": workflow,
"seat": seat,
"lease_s": lease_s,
"max_s": max_s,
"hide_logs": hide_logs,
}),
)
}

/// Bind the dispatched workflow run to the session (the handoff).
pub fn ae_bind(handle: &str, run_id: i64, run_attempt: i64) -> Result<Value, (i32, String)> {
ae_call(
"/actions-exec-bind",
json!({"handle": handle, "run_id": run_id, "run_attempt": run_attempt}),
)
}

/// Enqueue one command on a bound/live session.
pub fn ae_command(handle: &str, text: &str, timeout_s: i64) -> Result<Value, (i32, String)> {
ae_call(
"/actions-exec-command",
json!({"handle": handle, "text": text, "timeout_s": timeout_s}),
)
}

/// Read session state + command states + IO chunks after `after_id`.
pub fn ae_stream(
handle: &str,
after_id: i64,
cmd_id: Option<&str>,
) -> Result<Value, (i32, String)> {
let mut body = json!({"handle": handle, "after_id": after_id});
if let Some(cmd) = cmd_id {
body["cmd_id"] = json!(cmd);
}
ae_call("/actions-exec-stream", body)
}

/// Renew the lease (clamped at the max lifespan by the broker;
/// `extension_required` in the reply says the ask passed the max).
pub fn ae_renew(handle: &str, lease_s: i64) -> Result<Value, (i32, String)> {
ae_call(
"/actions-exec-renew",
json!({"handle": handle, "lease_s": lease_s}),
)
}

/// Request an emergency extension past the max lifespan. The
/// broker records the request and raises the needs-drew alert.
pub fn ae_extend_request(
handle: &str,
extend_s: i64,
reason: &str,
) -> Result<Value, (i32, String)> {
ae_call(
"/actions-exec-extend-request",
json!({"handle": handle, "extend_s": extend_s, "reason": reason}),
)
}

/// Record the decision on a pending extension request.
pub fn ae_extend_decide(handle: &str, approve: bool) -> Result<Value, (i32, String)> {
ae_call(
"/actions-exec-extend-decide",
json!({"handle": handle, "approve": approve}),
)
}

/// Close a session (seat side; the agent side closes through the
/// OIDC door instead).
pub fn ae_close(handle: &str) -> Result<Value, (i32, String)> {
ae_call("/actions-exec-close", json!({"handle": handle}))
}

/// The #13765 placement-coordinator claim attempt. The verbs are
/// not live yet: an unknown-command answer (or any error) comes
/// back as Err/ok:false and the caller proceeds on the singular
/// path, naming it. Returns Ok(true) only when a coordinator
/// actually granted the claim.
pub fn ae_placement_claim(host_repo: &str, seat: &str, handle: &str) -> bool {
let body = json!({
"repo": host_repo,
"seat": seat,
"session": handle,
"kind": "actions-exec",
});
match call_result("/placement-claim", &body) {
Ok(v) => {
v.get("ok").and_then(|o| o.as_bool()) == Some(true)
&& v.get("granted").and_then(|g| g.as_bool()) != Some(false)
}
Err(_) => false,
}
}
49 changes: 49 additions & 0 deletions pkgs/fleet/crates/fleet-queue/src/needs_drew.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,55 @@ pub fn post_plain_alert_to(url: &str, token: &str, body: &Value) -> Result<(), S
post_json(url, token, body).map(|_| ())
}

/// Build the alerts-intake body for a fleet actions exec
/// emergency-extension request (#13774). The PM stack renders the
/// needsDrew block as Drew's approve/deny choice; the answer comes
/// back as a seat-run `/actions-exec-extend-decide` (the phone ->
/// broker write-back is the PM stack's next phase). Deduped by the
/// throat on (source, key), one live request per session handle.
pub fn build_extension_alert_body(
handle: &str,
host_repo: &str,
run_id: Option<i64>,
extend_s: i64,
grace_until: &str,
reason: &str,
) -> Value {
let minutes = (extend_s + 59) / 60;
let question =
format!("Extend actions exec session {handle} past its max lifespan by {minutes} min?");
let mut context = format!(
"Session {handle} on {host_repo} reached its max lifespan cap. Approving adds {extend_s}s to the max and the lease; denying lets the session expire (decision grace runs to {grace_until})."
);
if !reason.is_empty() {
context.push_str(&format!(" Reason given: {reason}"));
}
let mut links = vec!["https://github.com/developing-today/code/issues/13774".to_string()];
if let Some(id) = run_id {
links.insert(
0,
format!("https://github.com/{host_repo}/actions/runs/{id}"),
);
}
json!({
"source": "fleet-actions-exec",
"key": format!("actions-exec-ext:{handle}"),
"severity": "warning",
"title": question,
"body": context,
"needsDrew": {
"ledgerId": format!("actions-exec-ext:{handle}"),
"question": question,
"context": context,
"options": [
{"id": "approve", "label": format!("Approve +{minutes} min")},
{"id": "deny", "label": "Deny — let it expire"},
],
"links": links,
},
})
}

/// Parse the snake_case `needs_drew` object the /block body
/// carries (the shape cmd_block sends and the broker receives):
/// {ledger_id, question, context?, options?, links?}, with
Expand Down
Loading