Authenticated intake for the fleet: launch an OpenCode session on Drew's laptop now, or just enqueue work into the Supabase repo-health queues — either way the work is tracked by a queue task and (usually) a GitHub issue, so nothing runs untracked and no queue worker double-books it.
Lives in pm-stack/dispatch/. On the laptop (amd), the
pm-dispatch.service user unit is declared by the NixOS pm-stack
module (nixos/services/pm-stack) and runs from the primary code
checkout (~/git/code/pm-stack/dispatch), like the aggregator;
install.sh (below) is the fallback installer and still renders
the env files. Port 4879, loopback + tailnet bind only, plus the
public tunnel hostname (see Public reachability).
Unauthenticated. { ok: true, status: "ok", version: <build version> }
(the source commit of the deployed checkout).
Launches an OpenCode session on the laptop's standing server (127.0.0.1:13420) and assigns the tracking queue task immediately.
Body:
Flow:
- Scope the directory: OIDC callers must omit
directoryor repeat the repo's laptop primary clone — anything else is a 400 with no issue, task, or session created (issue #2903). - Create the tracking GitHub issue (
source/dispatchlabel; body = the prompt + a dispatch footer). Skipped with awarningsentry for developing-today/zettel, where the pm-stack GitHub App is not installed. - Enqueue a repo-task/v1 queue task (
small_fixwith the canonicalrepo-health:v1:fix:<repo>:issue:<n>dedupe key when an issue exists, elsetriagewith a uniquerepo-health:v1:triage:<repo>:dispatch:<rand8>key). The payload carriesorigin: "dispatch", the caller identity, the model hint, and the directory. - Create the OpenCode session (directory + model when given) and send
the prompt, prefixed with
[dispatch] Queue task #<id> · Issue <url> · Repo <repo>so the session knows its tracking ids. - Assign immediately: the task row is PATCHed to
status: claimed,worker_id: dispatch-opencode,claimed_atnow,lease_until+6h,progress: {lane: "opencode", session_id, issue_number, launched_by}. - Comment the task/session ids on the issue; label it
queue/claimed+work/assigned.
Stage/failure semantics (design #2668): step 4's claim PATCH is the
launch's commit point. Steps before it are pre-commit — a failure
cancels the task and fails the launch. Step 5 is post-commit: the
comment and the labels are each guarded independently, a failure is
recorded on the task and (for wait: true) returned as a response
warnings entry, the remaining annotation steps still run, and the
launch itself never fails because of an annotation.
Responses: wait: true → 201 {task_id, session_id, issue_number|null, queue, status: "claimed"} after the launch. wait: false → 202 {task_id, issue_number|null, status: "launching"} right after the
enqueue; steps 3–5 finish asynchronously.
If the launch fails after the enqueue, the task is cancelled via
cancel_repo_task and the failure is noted on the issue — the same
handling for both wait modes. For wait: true the response is
502 {task_id, error}; for wait: false the 202 has already been
returned, so the cancellation and the issue note are the record — a
task is never left queued for a session that did not launch, nor
claimed without a session id, nor claimed-and-running reported as
failed.
{
"repo": "developing-today-forks/opencode", // required
"title": "investigate the red build", // required
"prompt": "…", // required ("body" accepted as an alias)
"kind": "triage", // optional: triage|small_fix|pr_shepherd|ci_investigation
"priority": 40, // optional, same mapping as above
"model": "deepseek/deepseek-chat", // optional; stored as payload.model_hint only
"issue": false, // optional; default false
"dedupe_key": "…", // optional; default: canonical key from the
// created issue, else a unique dispatch key
"issue_number": 123, // optional; attach to this existing issue
// in repo instead of creating one (see below)
}Returns 201 {task_id, issue_number|null, queue}. With issue: true
the issue is created first (labels queue/queued + source/dispatch)
and gets an agent-note comment naming the task id.
With issue_number set, no issue is created: the task attaches to
that existing issue in repo — the canonical dedupe key is derived
from it, and after the enqueue the issue gets the same agent-note
comment naming the task id plus the queue/queued and
source/dispatch labels. The response is 201 {task_id, issue_number, issue_url, queue}, where issue_url is
https://github.com/<repo>/issues/<issue_number>. issue_number
takes precedence over issue when both are sent. For
developing-today/zettel, where the GitHub App is not installed, the
attach is skipped with a warnings entry; the task is still enqueued
and issue_number is still returned.
Authenticated read of the queue task row dispatch (or a worker)
created: {task_id, queue, title, status, worker_id, lane_id, repo, kind, attempts, max_attempts, claimed_at, lease_until, created_at, updated_at, completed_at, progress, result, last_error, dedupe_key}.
The packet body and payload are NOT returned — this is a status
surface, not a packet dump; only the payload's repo/kind are
surfaced, and a task whose packet names a repo is readable only by
callers allowed for that repo (the same gate as the write routes).
Unknown id → 404; non-numeric id → 400; unauthenticated → 401.
Authenticated read proxied from the OpenCode server:
{session_id, title, directory, time}. A session the OpenCode
server does not know → 404; an OpenCode-side failure (server down,
auth) → 502, never conflated with "session gone".
The queue's claim_repo_task RPC claims the next task in a queue —
it cannot claim a specific row. A dispatch launch knows exactly which
task it created and which session owns it, so it PATCHes that row
directly (the service-role key can), setting the same fields a claim
would. This is deliberate and is the only place dispatch writes task
rows outside the RPCs. One FK wrinkle: tasks.worker_id references
agent.workers, so dispatch idempotently registers its own worker row
(dispatch-opencode, role build) before the first claim PATCH.
Right after the PATCH it also calls assign_repo_task_lane — the lane
ledger assignment the queue workers record after claiming — reading
the lane from the progress the PATCH just set, so dispatch tasks are
indistinguishable from worker-claimed ones downstream (including
completion with an execution record).
Every endpoint except GET /health requires Authorization: Bearer …:
- GitHub Actions OIDC (preferred): a JWT from
token.actions.githubusercontent.com, RS256-verified against GitHub's JWKS (cached),aud=pm-dispatch(envDISPATCH_OIDC_AUDIENCE). The token'srepositoryclaim must be in the allowlist. Grants mesh: every allowlisted repo may target every allowlisted repo — the claim need not equal the request body'srepo. Repos outside the allowlist can neither call nor be targeted. Bearer callers are bound only by the allowlist on the target. Directory scoping (issues #2903, #2664): every caller (OIDC and bearer alike) may only omitdirectory(or send a blank one, which resolves to the default) or use the target repo's laptop primary clone or a directory inside it — any other value (relative paths, other repos' clones, arbitrary absolute paths) is rejected with 400 before the issue, task, or session is created. Seeexamples/dispatch-workflow.yml. - Static bearer secret:
DISPATCH_API_TOKEN(in the laptop's~/secrets/dispatch.env), compared in constant time — the shape a repo stores as a GitHub Actions secret. The vault home for the value by name is Bitwardenpm-dispatch.api-token(filed under issue #5555, verified byte-identical to the service's by hash): a rotation updates the vault entry and~/secrets/dispatch.envtogether, and then restartspm-dispatch.service— the unit reads the env file only at start, so without a restart the new token is rejected and the old one stays valid. If~/secrets/dispatch.envis lost, restore the token from this vault item before running install.sh: a missing file makes the installer generate a fresh token, desyncing the vault copy and every client (401s) until they are updated to match.
The caller identity ({type:"bearer"} or {type:"oidc", repository, actor, workflow_ref}) is recorded in the task payload.
Four composite actions in this repo wrap dispatch so call sites do not hand-roll the OIDC + curl plumbing. Two are low-level primitives that wrap the dispatch endpoints directly; the third is the task-level entry point built on top of them, and the fourth is a thin in-CI wrapper over that entry point:
.github/actions/pm-dispatch-start("the starter") — POSTs to/v1/sessions; outputstask_id,session_id,issue_numberandissue_url..github/actions/pm-dispatch-queue("the queuer") — POSTs to/v1/tasks, including theissue/issue_numberinputs; outputstask_id,issue_numberandissue_url..github/actions/pm-dispatch-task("the task action") — dispatches a named, recurring task (bolt,palette,suggestions,ci-fix, …) through the starter/queuer asuses:steps, using the prompt library bundled with the action. It contains no OIDC or HTTP plumbing of its own. Outputstask_id,session_id,issue_numberandissue_url, whichever apply to the path taken..github/actions/pm-dispatch-ci-fix("the ci-fix wrapper") — a thin wrapper over the task action withtask: ci-fix(one step, no logic of its own). Its ci-fix context inputs default from the caller's own run context, so aci-fixjob inside a repo's main CI workflow needs nowith:block. Outputstask_id,session_id,issue_numberandissue_url, mapped from the task action step.
Alongside the actions sits one reusable workflow,
.github/workflows/pm-scheduled.yml ("pm-scheduled", below), which
runs the scheduled tasks through the task action so per-repo
callers carry only their triggers.
Usage, pinned to @main so fleet call sites pick up central updates:
jobs:
dispatch:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
steps:
- uses: developing-today/code/.github/actions/pm-dispatch-start@main
with:
title: "fix(widget): flaky test"
prompt: "Fix the flaky widget test"
- uses: developing-today/code/.github/actions/pm-dispatch-queue@main
with:
title: "investigate the red build"
prompt: "…"
issue_number: "123" # optional: attach instead of creatingThe calling job MUST grant permissions: id-token: write; without
it the OIDC token-request environment is absent and the actions fail
with a clear error. repo defaults to the caller's repository, and
under the grants mesh any allowlisted repo may target any
allowlisted repo. See examples/dispatch-workflow.yml for a
complete workflow.
Both primitives take the prompt from one of three inputs. prompt
is not required at the YAML level (a composite action cannot express
one-of); the action's step enforces that one source yields text.
The sources are resolved in this order:
prompt-file— a path to a file containing the prompt, relative to the caller's workspace. The action reads it at runtime, so the calling job must check out its repo first (e.g.actions/checkout). A missing or empty file fails the step. This is the form scheduled workflows use to keep prompts in repo files instead of inline YAML strings.prompt-url— an https URL the prompt is fetched from at runtime (curl -fsS). A fetch error or an empty body fails the step.prompt— the inline prompt text.
A selected source that is missing, empty or unfetchable fails loudly rather than falling through to a lower-priority source, and if none of the three yields non-empty text the step fails with a clear error. For example, with a prompt kept in the calling repo:
steps:
- uses: actions/checkout@v4
- uses: developing-today/code/.github/actions/pm-dispatch-queue@main
with:
title: "nightly triage"
prompt-file: "prompts/nightly-triage.md"The primitives keep these overrides unchanged. The task action below uses the same three overrides and adds its prompt library as a fourth, final source.
.github/actions/pm-dispatch-task is the entry point callers
should normally use. A call names a task and a target repo, and the
action supplies the prompt from its bundled library:
jobs:
bolt:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
steps:
- uses: developing-today/code/.github/actions/pm-dispatch-task@main
with:
task: bolt
repo: developing-today/codeInputs: task (required), repo (default: the caller's
repository), title, model, priority, the prompt overrides
prompt / prompt-file / prompt-url, the ci-fix context inputs
below, and default-branch (default: the caller's repository's
default branch). task accepts ANY string: the name selects the
library prompt, so a future library entry works with no change to
the action. For non-ci-fix tasks an empty title defaults to
Scheduled <Task> — <repo>, and the task is dispatched through the
starter with wait: "true".
The library lives in .github/actions/pm-dispatch-task/prompts/,
one Markdown file per task:
bolt.md— one small, measurable performance improvement, with before/after evidence.palette.md— one micro-UX / accessibility improvement.suggestions.md— a verified code-review pass (Cleanup / Performance / Security / Code Health / Testing) that files at most 5 issues with file/line evidence.ci-fix.md— the ci-fix prompt template (see "ci-fix mode" below); it carries{{workflow}},{{run_id}},{{run_url}},{{branch}},{{sha}}and{{pr}}placeholders that the action substitutes from the ci-fix context inputs before dispatching.
Prompt resolution in the task action follows the primitives' order and adds the library as the final fallback:
prompt-file(relative to the caller's workspace),prompt-url(curl -fsS),prompt(inline),- the library file
prompts/<task>.md.
The first non-empty source wins. If none yields text — an unknown
task with no override — the step fails with
no library prompt for task '<task>'.
To add a common task: drop a prompts/<task>.md file into the
library in this repo, and add one step/call for it in the caller.
No change to the action itself is needed.
task: ci-fix replaces the old standalone pm-dispatch-ci-fix
action (removed; no caller ever used it). Give the task action the
failed run's context — workflow, run-id, run-url, branch,
sha, and optionally pr — and it:
- Resolves the prompt (normally the
ci-fix.mdlibrary template) and substitutes the run-context placeholders. - Dedupes on the conventional tracking-issue title
ci-fix: <workflow> failing on <branch>: it searches the target repo's open issues for that exact title. - Dispatches by case, with priority
highwhen the failed branch is the repo's default branch andnormalotherwise (unless the caller passes an explicitpriority):- an open issue with the conventional title already exists — the
queuer attaches a new
ci_investigationtask to that issue (issue_number), so repeat failures of the same workflow on the same branch do not pile up duplicate issues; - no such issue and the failed branch is the default branch —
the starter runs with
wait: "true", creating the tracking issue (titled with the conventional title) and launching a session immediately; - no such issue and the failed branch is any other branch — the
queuer runs with
issue: "true", queueing aci_investigationtask and creating the tracking issue.
- an open issue with the conventional title already exists — the
queuer attaches a new
jobs:
ci-fix:
runs-on: ubuntu-latest
permissions:
id-token: write
issues: read
contents: read
env:
GH_TOKEN: ${{ github.token }}
steps:
- uses: developing-today/code/.github/actions/pm-dispatch-task@main
with:
task: ci-fix
workflow: ${{ github.event.workflow_run.name }}
run-id: ${{ github.event.workflow_run.id }}
run-url: ${{ github.event.workflow_run.html_url }}
branch: ${{ github.event.workflow_run.head_branch }}
sha: ${{ github.event.workflow_run.head_sha }}On top of the starter/queuer requirement (permissions: id-token: write), a ci-fix calling job MUST also provide GH_TOKEN in the
job environment (as above) with issues read permission in the
target repo; the dedupe search fails loudly without it. The step
summary records the task, the path taken, and the dispatched task /
session / issue ids.
For a repo's own CI, .github/actions/pm-dispatch-ci-fix wraps the
call above in a single step with task: ci-fix. All of its context
inputs (repo, workflow, run-id, run-url, branch, sha,
pr) default from the calling run's own context, and all dedupe /
routing behavior stays in the task action's ci-fix mode — the
wrapper adds none. The intended shape is a ci-fix job inside the
repo's main CI workflow, gated on the main jobs failing and kept
from failing the workflow itself:
jobs:
ci-fix:
needs: [<the main CI jobs>]
if: failure()
continue-on-error: true
runs-on: ubuntu-latest
permissions:
id-token: write
issues: read
contents: read
env:
GH_TOKEN: ${{ github.token }}
steps:
- uses: developing-today/code/.github/actions/pm-dispatch-ci-fix@main.github/workflows/pm-scheduled.yml is the fleet's single
scheduled-agents runner: a reusable workflow (workflow_call) with
exactly one job, run. A run dispatches each task in its resolved
task list through one pm-dispatch-task step per task (THE LIST in
the workflow: bolt, palette, suggestions, in that order), and
a final always() step writes each task step's outputs (task_id,
session_id, issue_number, issue_url — blank when the step was
skipped) to the step summary under the repo name. It declares no
permissions of its own: a reusable workflow runs with the calling
job's token, so callers grant id-token: write + contents: read.
The callers are the thin per-repo agents.yml files, which carry
only triggers (their cron lines, workflow_dispatch, ...) and pass
the fired schedule through:
jobs:
scheduled:
uses: developing-today/code/.github/workflows/pm-scheduled.yml@main
permissions:
id-token: write
contents: read
with:
schedule: ${{ github.event.schedule }}Inputs (all optional strings, default ""): schedule (the cron
expression that fired), tasks (an explicit comma-separated task
list), and repo (target repo; default: the caller's repository).
Resolution, in the workflow's resolve step: a non-empty tasks
input is used verbatim; otherwise schedule is mapped through the
slot table — a bash case statement in that step, which is the
single place schedule → tasks resolution lives (and where future
repo-name / time filtering will be added; the caller repo is
available to the case as a variable). The table (cron is UTC;
America/Chicago / CDT equivalents in the workflow's comments):
- Task slots →
bolt,palette:0 1 * * *(code),0 2 * * *(openchamber),0 0 * * *(opencode),0 5 * * *(nix + dezren39),30 13 * * *(zettel). - Suggestions slots →
suggestions:0 13 * * *(code 08:00),0 14 * * *(openchamber 09:00),0 15 * * *(opencode 10:00),0 16 * * *(nix 11:00),0 17 * * *(zettel 12:00),0 18 * * *(dezren39 13:00). - An empty or unknown schedule runs all three:
bolt,palette,suggestions.
To add a common task (per the workflow's header comment): add its
prompt to the pm-dispatch-task prompt library
(.github/actions/pm-dispatch-task/prompts/<task>.md) and add one
step for it to THE LIST in pm-scheduled.yml — no caller changes.
Add a cron line to a repo's agents.yml only if the task needs a
time that repo doesn't already trigger.
Every call carries repo and task explicitly, and the prompt
library is central (it lives with the action in this repo, not in
the callers). Because of that, repo- or time-based filtering — for
example "only run suggestions on repos X and Y", or "skip bolt
overnight" — can later be added inside the task action without
touching any caller.
| Name | Default | Notes |
|---|---|---|
DISPATCH_HOSTS |
127.0.0.1 |
install.sh renders loopback + the laptop tailnet IP |
DISPATCH_PORT |
4879 |
|
DISPATCH_BUILD_VERSION |
dev |
set by install.sh to the deployed commit |
DISPATCH_API_TOKEN |
— | from ~/secrets/dispatch.env |
DISPATCH_OIDC_AUDIENCE |
pm-dispatch |
|
DISPATCH_REPO_ALLOWLIST |
the six fleet repos | |
SUPABASE_URL |
— (required, no default) | rendered by install.sh from ~/secrets/pm-stack.sops.yaml (supabase_url, muse-dev2) |
SUPABASE_SERVICE_ROLE_KEY |
— | rendered by install.sh from ~/secrets/pm-stack.sops.yaml (supabase_service_role_key; Bitwarden source supabase.muse-dev2.service-role-key) |
OPENCODE_URL |
http://127.0.0.1:13420 |
laptop standing server |
OPENCODE_AUTH_FILE |
~/.local/state/opencode/service-prod.json |
password read at runtime, never logged |
GITHUB_APP_ID / GITHUB_APP_PRIVATE_KEY_BASE64 |
— | rendered by install.sh from ~/secrets/pm-stack.sops.yaml |
GitHub issue creation uses the pm-stack GitHub App (installed on
developing-today/code and dezren39/darwin-nix — not on
developing-today-forks/opencode, developing-today-forks/openchamber,
developing-today/zettel or dezren39/dezren39, where issue creation is
skipped with a warning; APP_INSTALLED_REPOS in src/config.ts is the
list of record).
If the app route is unusable, the laptop's
authenticated gh CLI is the fallback; if both fail, the request
proceeds without an issue and says so in warnings (for /v1/tasks
with issue: true, same behavior).
On the laptop, the unit lifecycle belongs to the NixOS pm-stack
module: nixos-rebuild switch deploys the module's
pm-dispatch.service, which runs from the primary checkout — so a
git pull in ~/git/code (kept current by pm-git-sync) plus a
switch is the whole deploy, and home-manager renames the old
hand-installed unit to *.backup. The module does NOT render env
files: ~/pm-stack/dispatch/.env and ~/secrets/dispatch.env
are still produced by install.sh, below.
Fallback (no switch): on the laptop, from the primary checkout at
latest main:
cd ~/git/code && git pull
bash pm-stack/dispatch/install.shinstall.sh copies the tree to ~/pm-stack/dispatch, renders .env
from the sops file (GitHub App material and the fleet Supabase
config), ensures ~/secrets/dispatch.env exists (generating
DISPATCH_API_TOKEN if absent — value never printed), installs
pm-stack/systemd/pm-dispatch.service as a user unit, restarts only on
change, and fails loudly unless /health reports the deployed build
version. On amd that unit-install step is superseded by the
NixOS module; the env rendering is not.
Done (2026-10-30): the existing remotely-managed Cloudflare tunnel
amd-6-pm-stack maps dispatch.security.cab →
http://localhost:4879, so GitHub Actions (runners are outside the
tailnet) can reach the service and use either auth form — OIDC is
verified end to end against that hostname. Tailnet callers (the
laptop itself, other fleet machines) can also call the loopback /
tailnet binds directly. The tunnel connector itself is the
pm-tunnel unit, declared by the same NixOS pm-stack module.
bun test # auth (bearer + stubbed-JWKS OIDC + repo binding),
# priority mapping, model parsing, validation, packets
bunx tsc --noEmit
{ "repo": "developing-today/code", // required, allowlisted fleet repo "prompt": "Fix the flaky widget test", // required "title": "fix(widget): flaky test", // optional; default: prompt's first line "model": "opencode-go/gpt-5.6-luna", // optional "provider/model" or {"providerID","id"} "directory": "/home/user/git/code", // optional; default: the repo's laptop primary. // Callers may only omit it or use the repo's primary or a directory // inside it — anything else is rejected (400) before any side effect // (issues #2903, #2664). // Bearer callers are scoped by the same containment rule (issue #2664). "priority": "high", // optional: integer 10-90 (number or decimal string), or critical|high|normal|low → 10/20/40/70 "issue": true, // optional; default true "wait": true, // optional; default true }