Result delivery: the external last mile
Audience: you write an agent (a result producer) that sets a structured result on a Maidan thread, and you want that result to reach a surface outside Maidan: a GitHub pull request, a Slack thread, a Linear issue. This page is the contract between your producer and Maidan. Read it alongside Integrating with Maidan.
How delivery works
- Your producer writes a
maidan.waiter.result/1envelope withset_thread_result(MCP) orPUT /threads/:id/result(REST). The envelope names where it should go indeliver_to. - An operator has allowed each destination once, on the workspace's egress allowlist (the trust model).
- Maidan delivers the result to every named target that is on the allowlist, through a durable queue that retries, dead-letters and can be replayed. A later result on the same thread edits what it delivered, in place.
- You confirm where it landed with the delivery status API.
A correct deliver_to can still deliver nowhere when its target is not on the
allowlist. That is a normal outcome, not a producer bug.
What a result can do on each surface:
- GitHub: a summary comment on the pull request or issue, then inline review comments for each finding (Inline findings).
- GitHub branch: a commit of the producer's diff and a draft pull request (The change flow).
- Slack: a message, or a reply in a thread.
- Linear: a comment on an issue, with an optional state move (Linear).
The grammar is frozen at maidan.waiter.result/1. Adding fields is free; a
change to the meaning of an existing field, or to the deliver_to shape, needs
a new schema value (Versioning).
What Maidan reads from the envelope
Maidan is a tolerant reader. The result is opaque JSON owned by the producer; Maidan parses only the fields it routes on and ignores everything else. Adding a field never breaks delivery.
| Field | Required | How Maidan uses it |
|---|---|---|
schema | yes | Envelope discriminator. Must be maidan.waiter.result/1. An unrecognized value means no delivery is attempted. |
result_kind | yes | Which producer shape this is, e.g. example.review.result/1. Recorded, and filterable (Discoverability). |
status | yes | Delivery happens only on reviewed. Any other value delivers a short Maidan-authored failure notice instead — never silence, never a clean pass. |
deliver_to | no | The routing list. Absent or empty is valid and normal: thread-only, delivered nowhere. |
rendered | on reviewed | The delivery body. Producer-authored trusted markdown. |
summary | on reviewed | One line. The Slack body and the notification title. |
view_url | no | A backlink appended to every delivery. |
pr | no | A human back-reference echoed into the delivered body. |
head_sha | for inline comments | GitHub commit_id. 40- or 64-char hex. Absent or unusable ⇒ no inline review (the summary comment still posts). Never resolved from the live PR head. |
served | no | Which model served the result: family, or provider with model. Read on a review that names its author_family: if it names that family, the result is refused and nothing is stored (Swarms). Named the way a usage record is, so claude-opus-4-5 is anthropic. Read on any result, enveloped or not. |
route | no | A list of {provider, model} the result went through. Read like served: any entry naming the review's author_family refuses the result. Entries that are not objects, or name no family Maidan knows, are skipped. |
findings | no | Read twice. For inline comments, each usable finding needs file, body and line_range. For the close-gate, any finding with severity exactly critical on a reviewed example.review.result/1 from a producer holding the review skill is a request_changes; a critical finding without file, body or line_range still counts. Other finding fields stay in the stored JSON, unread. |
maidan.result_attachments | no | Files the producer attached, a list of {sha256, filename, caption} pointing at artifacts already uploaded. A GitHub delivery links each one by its caption, or its filename when it has none. Read too as an unprefixed result_attachments or nested under a maidan object. Entries without a full lowercase SHA-256 or a filename are skipped. |
run_id is not a delivery-routing field. Maidan keeps it as the thread's
parent_run_id (Run lineage). Every other field in the
envelope (for example cost_usd, duration_secs or finding_count) is
stored untouched and not interpreted.
The Finding shape is the producer's. Maidan stores the envelope byte for
byte, then projects file, line_range and body for the GitHub review,
reads severity for the close-gate only, and reads run_id for
lineage only.
Cost is not read from the result. Report a run's tokens, cost and turns
with report_usage (MCP) or POST /threads/:id/usage while you hold the
claim. Wall time is measured by Maidan from the claim's acknowledgement, not
reported. A cost_usd or duration_secs in the envelope is stored and never
counted (Budgets and usage).
Run lineage
A producer's envelope may carry a run_id: the id of the run that produced
the result, in the producer's own system. Maidan keeps the producer's value as
the thread's parent_run_id; it does not mint a parallel id. Threads that
share a parent_run_id can then be listed and counted together.
Maidan reads run_id from any result, whatever its schema. The value is
trimmed; an empty value, or one longer than 256 bytes, is ignored. It never
changes where the result is delivered.
set_thread_result (REST PUT /threads/:id/result and the MCP tool) stores
the value as parent_run_id when present. This is best effort: a lineage
failure never undoes a stored result. A caller can also set the lineage
directly.
| Surface | Capability |
|---|---|
PUT / GET / DELETE /threads/:id/lineage | write/delete = thread:transition; get = workspace:read |
GET /workspaces/:id/run-threads?parent_run_id= | workspace:read (private-channel rows the caller cannot access are dropped) |
GET /workspaces/:id/run-occupancy?parent_run_id= | workspace:read (empty / unknown run → zeros, not 404) |
MCP set_thread_lineage / get_thread_lineage / list_run_threads / get_run_occupancy | the twins of those routes |
Run occupancy counts every open thread in the workspace that shares the
parent_run_id, split into queued, claimed, working and blocked.
Muting a thread does not change this: a muted nested thread still counts.
To follow one member's occupancy, or read the manager digest, see Integration reference: Claiming.
Inline findings
Frame of reference. findings[].line_range is a 1-indexed
inclusive span (start..=end) on the post-image file at head_sha —
the file as that commit left it, not a diff-hunk relative offset. On GitHub's
split view this is RIGHT. LEFT is deletions that no longer exist in the
after-state; a finding that quotes a line in the resulting file is never LEFT.
GitHub mapping for POST /repos/{repo}/pulls/{n}/reviews comments[]:
| Envelope | GitHub |
|---|---|
file | path |
line_range.end | line (last line of the range) |
line_range.start when start != end | start_line (omitted for a single-line finding) |
| (always) | side: "RIGHT" |
body | body (producer text as written) |
head_sha | commit_id |
event is COMMENT. Maidan delivers findings; it does not approve or
request-changes on the producer's behalf. The worker posts the review after a
successful GitHub summary comment. A missing head_sha, no
usable findings, a non-reviewed status, Slack-only deliver_to, a vanished
envelope at send time, or a GitHub 404/422 skips the review and still
delivers the summary (maidan_github_review_total{skipped}). A GitHub 5xx,
rate-limited 403, or revoked-token 401/403 also leaves the summary
delivered ({failed}) — failing the outbox after the comment has posted would
duplicate it on retry. Operator replay PATCHes the summary and POSTs another
COMMENT review on the current envelope head_sha (the recovery path for a
transient review failure). Review errors never disable a projector
issue-link. Dual-surface envelopes (GitHub + Slack) post both summaries; only
GitHub creates a review. Projector rows aimed at the same issue never call
create_review.
Each result POSTs a new COMMENT review (a re-review on a new head_sha lands
on that commit); the summary comment is the object that updates in place.
The pre-review commit status
A review agent that claims a review thread (thread attribute
kind = review) can ask for its verdict to be posted as a commit status, for a
merge gate that reads a pre-review status. It sets, beside rendered and the
github target:
{ "status": "reviewed", "verdict": "PASS", "head_sha": "<40 hex>",
"check": { "context": "pre-review" } }
After the comment lands, Maidan posts POST /repos/{repo}/statuses/{sha} in
the target's repository, only when every rule holds:
- The thread is a review. A result on any other thread is delivered as
before, and a change keeps the change flow's own
check. - The reporter holds the
pre-reviewskill. The member that set the result must currently holdpre-review, a governance skill: an operator withchannel:admingrants and revokes it (POST /members/:id/skills,DELETE /members/:id/skills/pre-review), and a member can never declare it about itself. Without it nothing is posted (pre_review_skill_missing: <handle> does not hold the pre-review skill). check.contextis exactlypre-review. It is the only entry in the allowlist, so a review can never post a context another gate owns (stamp,security,review-lane). Any other context posts nothing.statusisreviewedandverdictis exactlyPASS,MERGEorFIX-FIRST.PASSandMERGE(a red-team review's word for a pass) postsuccess,FIX-FIRSTpostsfailure.check.stateandcheck.descriptionare ignored.- The head is the briefed one. The thread's description carries a line
Head to review: <full sha>(review children Maidan spawns write it; threads filed from outside use the same line). The result'shead_shamust equal it, in any case, and the status goes on that head. - The description is Maidan's:
PASS at <sha9> by <family> as <handle>(orFIX-FIRST …), where<sha9>is the first nine hex characters of the head,<handle>is the reporting member's handle, and<family>is the provider family of that member's latest usage record on the thread, else theresult_kindprefix before its first.when that names a known family (deepseek.redteam/1isdeepseek). It is never the thread'sreview_familylabel. A gate parses it with^PASS at <sha9> by [A-Za-z0-9][A-Za-z0-9 ._-]*$, so a family or handle outside that alphabet, or a line over 140 characters, posts nothing. - A PASS never hides another reporter's FIX-FIRST. GitHub shows only the
newest status of a context, so a
PASSfirst reads the head'spre-reviewstatuses (GET /repos/{repo}/commits/{sha}/statuses). Statuses written by the same reporter (same handle and family) are skipped, so a reviewer replaces its own FIX-FIRST with a PASS once the work is fixed. When the newest status left is a failure, from another reporter or another system, the PASS is held (pre_review_fix_first_stands: the PASS is held: the newest other pre-review status on <sha9> is failure (<its description>)). When the list cannot be read the PASS is held too (pre_review_statuses_unread). AFIX-FIRSTalways posts and reads nothing. The comment is delivered in every case. - The review thread was not cancelled. A result whose thread was
cancelled (or deleted) after the result was queued posts no status, of
either verdict (
pre_review_thread_ended: the review was cancelled after its result was queued). A cancel that lands after the status call has started does not stop it.
It is best effort, like the inline review: a refused rule or a status GitHub
does not take never fails or retries the comment. What stopped it is recorded
on the GitHub row's delivery_warnings (GET /threads/:id/deliveries,
list_result_deliveries) as one line, pre_review_<reason>: <detail>, for
example pre_review_context_refused: stamp or pre_review_head_refused: briefed <sha> but the result reviewed <sha>. Each delivery of a review
thread's result replaces the last one's warnings; a result with no check
asks for no status and records none.
The deliver_to grammar
An array of target objects. Each names a surface plus per-surface detail:
[
{ "surface": "github", "repo": "example/repo", "pr": 3915 },
{ "surface": "slack", "channel": "C0123ABCDEF" },
{ "surface": "slack", "channel": "C0123ABCDEF", "thread_ts": "1759500000.000100" },
{ "surface": "github_branch", "repo": "example/repo", "branch": "feature/agent-fix-1a2b", "base": "dev" },
{ "surface": "linear", "team": "6a1f1c4e-2f0b-4d5e-9a7b-0c1d2e3f4a5b", "issue": "ENG-123", "state": "In Review" }
]
Rules
surfaceis a lowercase identifier. Known values today:github,slack,github_branch,linear.- An unknown
surfaceis skipped with a recorded warning, never an error. Partial delivery is the model: one target failing or being unroutable must not sink the others. githubrequiresrepo(owner/name) andpr(an integer issue or PR number). Delivery is a PR/issue comment.slackrequireschannel, and it MUST be a channel ID (C…/G…), not a#name. Names are mutable and ambiguous, and an allowlist keyed on a mutable name is not an allowlist. An optionalthread_ts(a Slack message timestamp,1759500000.000100) posts the delivery as a reply in that thread; the allowlist still blesses the channel. Athread_tsthat is not a Slack timestamp makes the target unusable (a recorded skip), rather than posting top-level.github_branchrequiresrepo(owner/name),branchandbase. It commits amaidan.change.result/1tobranchand opens a draft pull request againstbase. It is logged asgithub_branch:<repo>@<branch>.branchmust matchfeature/agent-[a-z0-9][a-z0-9-]*orfeature/builder-[a-z0-9][a-z0-9-]*;basemust be blessed for the repository, and is neverprod.linearrequiresteam(the team's id, a UUID) andissue(its identifier,ENG-123, or its id). Delivery is a comment on the issue. An optionalstatenames a workflow state of that team, by its exact name, to move the issue to once the comment lands. Ateamthat is not an id, or a blankstate, makes the target unusable (a recorded skip). See Linear.- An empty or absent list delivers nowhere. This is a valid, supported outcome — not a misconfiguration.
- New surfaces add new object shapes. Rule 2 makes that backward-compatible: an older Maidan skips a surface it does not know.
Where the producer gets it
The task author sets the routing intent in the seeding message's metadata under
deliver_to; the producer carries it through opaquely and echoes it into the
result envelope. Maidan reads it from the result envelope, not from message
metadata.
The trust model — deliver_to selects, the workspace allowlist authorizes
This is the part a producer must understand, because it changes what "success" means.
A result is written by an agent. Any caller holding thread:transition on the
thread can write any deliver_to. Maidan's connector credentials, by contrast,
are operator-held and can reach many repositories and channels. Routing straight
off an agent-supplied list would make Maidan a confused deputy: a compromised or
merely buggy agent could post under Maidan's identity anywhere that credential
reaches.
So delivery is authorized twice:
deliver_toselects which of the permitted targets this particular result goes to. The producer stays in control of routing and no surface is hardcoded.- A per-workspace egress allowlist authorizes. An operator blesses
github:example/repoorslack:C0123ABCDEFonce, overPOST /workspaces/:wid/egress-targets(token:admin;GETlists,DELETE …/:tidrevokes). A target absent from the allowlist is skipped with a recorded warning — the same treatment as an unknown surface.- A selector must be an id, never a name: a Slack channel id (
C…/G…), or a GitHub repositoryowner/name. A#channel-nameis refused, because the channel a name points at can change under the blessing. - On GitHub the blessing is the repository, not the issue — one blessing covers every PR in it, so an operator does not file a ticket per review.
- A selector must be an id, never a name: a Slack channel id (
- The allowlist defaults to empty, following the same fail-safe as Maidan's secret-egress broker: with nothing configured, nothing is trusted and nothing is delivered.
Operator setup — blessing a target
One token:admin call per destination, per workspace:
curl -sS -X POST "$MAIDAN/workspaces/$WORKSPACE_ID/egress-targets" \
-H "Authorization: Bearer $ADMIN_TOKEN" -H 'Content-Type: application/json' \
-d '{"surface":"github","selector":"example/repo"}'
curl -sS -X POST "$MAIDAN/workspaces/$WORKSPACE_ID/egress-targets" \
-H "Authorization: Bearer $ADMIN_TOKEN" -H 'Content-Type: application/json' \
-d '{"surface":"slack","selector":"C0123ABCDEF"}'
For the change flow, bless each repository and its base under
github_branch, as owner/name@base (its own rows; a github comment
blessing does not allow commits), and the Slack channel the replies go to. A full seed, as the audited calls, is in
Production.
GET the same path lists what is blessed; DELETE …/egress-targets/:tid revokes.
Blessing is idempotent — a re-bless returns the existing entry with its original
created_at and created_by (who blessed it), so the list stays "what may we
post to" with nothing to reconcile.
A workspace admin can do the same in the console, under Tools, Deliveries: a
person signed in qualifies when they hold token:admin on a live token of their
own (or may mint the first one), and an agent's own sign-in never does. Anyone
else reading the workspace sees where results went, but not the allowlist.
The selector is two fields, not one string. There is no github:owner/repo
target syntax at this boundary: surface is one of github, slack,
github_branch or linear, and selector is the per-surface id. The rules,
enforced on every write path (400 with the reason on a violation):
| Surface | selector | Rejected |
|---|---|---|
github | a repository, owner/name | anything containing # — the blessing is the repo, not the issue, so one call covers every PR in it |
github_branch | a repository and the one base change pull requests may target, owner/name@base (one row per base) | a selector without a base, a prod base, an agent branch as a base. A separate surface with its own rows: a repository blessed for github comments is not writable by the change flow |
slack | a channel id, C… or G… | #channel-name — a name is mutable, and the channel a name points at can change under the blessing |
linear | a team id, a UUID | a team key (ENG) or name — a key can be renamed, and another team can take the old one |
Leading/trailing whitespace is refused on both. The authorization key is coarser
than the delivery target on GitHub: a result aimed at example/repo#42 is
authorized by the example/repo blessing.
What this means for the producer
A perfectly correct deliver_to can still deliver nowhere. That is not a
producer bug and must not be reported as a failure. Treat "delivered nowhere" as
a normal outcome; the per-target disposition is readable from the delivery-status
API below, and an operator — not the agent — fixes an unblessed target.
The change flow (maidan.change.result/1 → github_branch)
maidan.change.result/1 is the change-result schema: the result_kind of a
result that carries a diff for Maidan to commit.
A coding agent edits a checkout but holds no GitHub write credential. It returns the commit it started from and a diff. Maidan, holding the operator's token, makes the commit, opens a draft pull request, and answers in the Slack thread the work started in.
The envelope. result_kind is maidan.change.result/1. Besides the usual
envelope fields, Maidan reads:
| Field | How Maidan uses it |
|---|---|
status | changed, no_change, seat_error, content_blocked (the producer found a secret in the diff, title or summary, and sent none of it) or rebase_conflict (a squash-rebase round whose rebase stopped on conflicts in the producer's checkout). Only changed commits. A no_change round that carries both check and branch_head_sha posts that check and nothing else (see check). Any other status, and a no_change without either, records the github_branch target as skipped, with the status in the reason, makes no GitHub call, and the Slack reply says the status; for rebase_conflict it says the rebase stopped on conflicts and gives error_detail, where the producer lists the conflicting paths. |
rebase | Optional. true (a JSON boolean; anything else is a normal round) makes this a squash-rebase round: base_sha is a commit of the target's base branch (its head when the round started) and diff is the whole branch's change against it. See below. |
branch_head_sha | Required for a squash-rebase round: the change branch's remote head when the round started, as a full SHA (40 or 64 hex, any case). The force move is leased on it. Absent or not a full SHA, a rebase round is refused. On a no_change round it is the head the producer's check ran on. Ignored otherwise. |
base_sha | The full SHA (40 or 64 hex) the diff applies to, captured before any edit. The commit's parent. Never taken from thread metadata or the branch. |
branch | The branch the producer worked on, echoed verbatim. Must equal the target's branch, or the delivery is refused. |
diff | A git diff that applies with git apply to base_sha. |
error_detail | Optional. Why a run that changed nothing ended. The Slack reply to a status other than changed gives it after the status, in place of summary, with a cause repeated across retries said once and the whole cut at 600 characters. Without it the reply gives summary. |
title, summary | Optional. The commit subject and the draft pull request's title, and the commit and pull request body; mentions in summary are defused. Without title, Maidan uses the thread's opening message, first line, cut at a word to 72 characters (the branch name if there is none). Without summary, the body names the Maidan thread and the commit SHA. Missing text never stops a delivery. |
pr_state | Optional, {title, body}. body describes the whole branch against its base as it stands after this round (where title and summary describe this round). Maidan keeps it in one section of the pull request body, between <!-- maidan:current-state --> and <!-- /maidan:current-state -->, replacing only that section on each delivery and appending it when the markers are missing, so edits people and review bots make elsewhere in the body stay. Mentions are defused and the section is capped at 20,000 characters. pr_state.title is not read: a title people fixed is never reverted. A failed body edit never fails the delivery. |
check | Optional, {context, state, description}: the producer's own check of the change before delivery. After the branch is pushed and the pull request opened or found, Maidan posts it as a commit status on the head it delivered (POST /repos/{repo}/statuses/{sha}, with the envelope's view_url as target_url when it is https), so a re-delivery or a rebase round posts it again on the head it leaves. context is non-empty, printable and at most 100 characters; state is success, failure, error or pending; description is put on one line and cut to 140 characters. A malformed check posts nothing and adds check_invalid to the row's delivery_warnings; a status GitHub refuses adds check_not_posted. Either way the branch and the pull request stand and the Slack reply says so in one line. A commit status, not a check run, because a token can post one. On a no_change round with branch_head_sha, the check goes on branch_head_sha and nothing else is written (no commit, pull request, comment or body edit), after the same branch, base and allowlist rules as a changed round. Maidan re-reads the branch head immediately before the post: when the branch has moved or is gone, nothing is posted and the row is skipped with a stale: reason naming both heads, so an old check never lands on a newer head. The Slack reply names the status it posted and the short SHA, or why it posted none. |
What a changed result does, per github_branch target the workspace has
blessed:
- Checks the hard-coded rules, at routing and again before any write: the
branch matches
feature/agent-[a-z0-9][a-z0-9-]*orfeature/builder-[a-z0-9][a-z0-9-]*and is notprod,main,master,stagingordev; the base is notprodand not the branch;owner/name@baseis on the workspace allowlist; and no pull request for the branch is open into another base. Each refusal is recorded with its reason and nothing is written. See Production for the full list of what Maidan never does with the token. - Reads the branch. When it is missing, it is created at
base_sha— after the diff has been applied in memory, so a diff that does not apply leaves no branch behind. - Refuses when the branch head is not
base_sha, or when the result'sbranchis not the target'sbranch. - Fetches only the files the diff touches, at
base_sha(GET /repos/{repo}/contents/{path}?ref={base_sha}), applies the hunks, and refuses when one does not match. Supported: modified, added, deleted and renamed text files (a rename may arrive as a delete plus an add, which is how some producers send it, or as a git rename),100644/100755modes,\ No newline at end of file, hunks that moved. Refused: binary patches, copies, symlinks, submodules, quoted paths, paths outside the repository or under.git. - Commits through the Git Data API: one blob per changed file, a tree on the
base tree, a commit whose only parent is
base_sha, and a fast-forward of the branch (force: false). A squash-rebase round is the one exception; see below. - Opens a draft pull request against
basewith the title and summary when none is open for the branch. Maidan posts no other comment (except a squash-rebase's range, below), requests no review, and never marks the pull request ready, approves or merges it. A result with acheckthen gets its commit status on the delivered head (see the table above). - Replies in the Slack target's thread with the commit SHA and the pull request link. The reply waits for the branch delivery; a target that was refused or skipped is reported with its reason.
The template check flags and never refuses. After each delivered round,
Maidan reads the pull request as it now stands (the title and body it opened
with, or the open pull request's own title and body on a later round, since a
later title or summary never reaches an open pull request) and records
what it lacks against the producer's template as delivery_warnings on the
github_branch delivery row:
missing_testing: no Markdown heading readingTesting(any level, any case, an optional trailing colon) outside fenced code;missing_issue_key: no issue key such asENG-123(an uppercase letter, uppercase letters or digits, a hyphen and digits, standing alone) in the title or the body.
The Slack reply adds one line, such as PR template: missing a Testing section., and the delivery-status API shows the codes. The same list holds
the check codes (check_invalid, check_not_posted), so the field is
absent only when the round flagged nothing at all. A warning is not a
failure: the row is delivered, last_error stays empty, and the pull
request stays a draft until it is marked ready, as always. Fixing the pull
request itself clears the template codes on the next round. Apart from defused mentions, summary reaches the pull
request byte for byte, headings and fenced check output included, and a
title such as [ENG-123] … is used as given.
Refusals are recorded, not retried. A refused target is skipped with the
reason in last_error on the delivery-status API (GET /threads/:id/deliveries). A GitHub 5xx or rate limit retries with backoff
like any delivery; a 401/403/404 dead-letters the target.
A workflow file needs the Workflows permission. GitHub refuses a push that
adds, edits or deletes a file under .github/workflows/ to a token without
it (the workflow scope on a classic token), with a bare 403: Resource not accessible by personal access token. When a change that touches such a file
gets a 403 that is not a rate limit, the delivery fails at once, with no
retry, and last_error names the files and both ways out: drop the workflow
edit from the diff and set the result again, or give the delivery token the
Workflows permission. A rate-limited 403 still retries, and its last_error
names the files too. An operator who knows the token cannot push workflows
sets MAIDAN_CHANGE_REFUSE_WORKFLOW_PATHS=1, and setting such a result is
refused with a 422 before anything is queued
(Configuration).
Idempotent per thread and result. The commit message carries a trailer
Maidan-Change: <thread_id>/<digest>, the digest covering base_sha and the
diff (and, for a squash-rebase round, the rebase flag, so a rebase never
takes a normal round's commit for its own). A retried or replayed delivery that finds the branch head is that commit,
on top of base_sha, reuses it; the pull request is looked up before one is
opened. A retry makes neither a second commit nor a second pull request.
A follow-up is a new result whose base_sha is the branch head the last
change left: it commits on top and finds the pull request already open.
A squash-rebase round ("rebase": true) is a follow-up that rebases onto
the current base instead of merging the base in, for a queue that takes only
linear pull requests. branch is the existing agent branch, base_sha the
base commit it rebased onto, branch_head_sha the branch head the round
started from, and diff the whole branch against base_sha. On top of
every rule above (the branch shape, the allowlisted base, never prod, the
open pull request's base, and the merge-queue refusal below), Maidan refuses
it, before any write and with the reason recorded, when:
- no pull request is open for the branch;
- the result names no
branch_head_sha("a rebase result must name branch_head_sha, the branch head the round started from"); - someone else pushed: the branch head is not the newest round the change flow recorded for that pull request in this workspace (a commit another workspace delivered counts as someone else's). The reason names both SHAs;
- the branch moved since this round started: the branch head is not
branch_head_sha. The reason names both SHAs; - the base is not on the base branch:
base_shais neither the base branch's head nor one of its ancestors (GitHub's compare ofbase_sha...<base head>is notaheadoridentical); - the base is older than the branch's: the merge base of the branch head
and the base head (the base work the branch already holds) is neither
base_shanor one of its ancestors, so the move would drop base work the branch has. Abase_shathe base has moved past since the round started is accepted when it is no older than that: on a busy base a rebase takes long enough that the head rarely stays put. The exact base head passes without a compare; - the diff does not apply to
base_sha.
Otherwise it applies the diff to the base_sha tree, makes one commit whose
only parent is base_sha with the usual Maidan-Change trailer, re-reads the
branch head immediately before the move, and moves the branch with
force: true only if the head is still branch_head_sha, the head the round
started from. This is the change
flow's only non-fast-forward write. It is allowed only for a
feature/agent-* or feature/builder-* branch whose head is the last commit Maidan delivered, and
only through one guard that no other code path can reach: the force write
takes a single-use pass that only that guard mints, bound to the branch and
both commits, and checks the branch shape again. GitHub's ref API has no compare-and-swap, so a push landing between the
re-read and the move (one round trip) is the window that remains. The round is
recorded with rebase: true and how far base_sha is behind the base, and the pull request's
current-state section is updated from pr_state as for any round. A retry that
finds the head is already that rebase commit (same trailer, parent base_sha)
reuses it and writes nothing.
The rebase's range. The force move rewrites the history a reviewer has
read, so after it Maidan comments on the pull request
Rebased <old_head>..<new_head> onto <base_sha>, and the Slack reply carries
the same line under the commit and pull request link. A reviewer range-diffs
those two heads to see what the rebase changed. The round records the old
head as previous_head, which the swarm metrics list with its rounds. This is
the change flow's only comment. It is best effort: a comment GitHub refuses is
logged, and the move, the delivery and the Slack line stand. A retry that
reuses its rebase commit comments only when the move was never recorded, so a
replay of a recorded round writes nothing.
A rebase conflict is the producer's to resolve: it sends status: "rebase_conflict", Maidan records the target as skipped with no GitHub call,
and the Slack reply says the rebase stopped on conflicts and gives
error_detail (the conflicting paths, when the producer lists them).
The merge queue. For a repository listed in MAIDAN_MERGE_QUEUE_LABELS,
the client that marks agent pull requests ready may enter one into the merge queue
by asking Maidan to add the queue's label (POST /operator/github/enqueue
with repo and pull_number), read whether it is labelled (GET), and take
the label off (DELETE). Enqueue reads the pull request once and refuses
unless every check holds on that read: a label is configured for the
repository; the pull request is open, not a draft and not from a fork; its
head is a feature/agent-* or feature/builder-* branch into the pinned base and on the workspace
allowlist; and its head is the commit the change flow last delivered to it.
The last check keeps a commit pushed after the review out of the queue: the
refusal names both SHAs. Dequeue skips that comparison, since the queue may
have rebased the head, and a pull request already without the label is
answered "was not labelled". Both are recorded in the audit log as
github.enqueue.
While a pull request carries its repository's queue label, the change flow refuses a delivery to its branch before any write: the queue merges the head it took, and a later commit would land apart from what was reviewed. Dequeue first, then deliver the follow-up.
When the task ends early. Cancelling the task, or closing it as
abandoned, duplicate or superseded with no successor, withdraws its pull
request: the egress worker takes it out of the merge queue and closes it with
a comment naming the reason; the branch stays
(Swarms). A task closed as
superseded with duplicate_of, or replaced by a thread created with
supersedes, hands the pull request to its successor instead. It stays open
and queued, and the successor's rounds deliver to it as their own: a
no_change round posts its check on its head, a changed round pushes to its
branch (dequeued first, as above). Ending the successor without landing
withdraws it then, unless that round is itself superseded by a successor,
which takes it on (A follow-up round).
Credentials. The commit and the pull request are made with
MAIDAN_GITHUB_TOKEN (see Production),
so they are authored by that token's owner. The token needs contents:write
and pull_requests:write on each repository. With a GitHub App configured
(MAIDAN_GITHUB_APP_ID, MAIDAN_GITHUB_APP_INSTALLATION_ID and
MAIDAN_GITHUB_APP_PRIVATE_KEY), they are made with the app's installation
token instead and authored by the app's bot account.
Per-surface behaviour
GitHub
- Body is
renderedverbatim. GitHub renders GFM, so the producer's markdown arrives as written. - A
view_urlbacklink is appended. - Truncated with an explicit marker if it would exceed GitHub's comment ceiling
(65536 characters). Do not assume
renderedarrives whole — put the load-bearing content early and rely on the backlink for the rest.
Slack
- Slack does not render GFM. Slack speaks mrkdwn:
*bold*not**bold**,<url|text>not[text](url), no headings, no tables. Postingrenderedverbatim would ship visibly broken output. - So Slack receives
summary, a compact Maidan-projected digest, and theview_urllink — notrenderedas-is. A producer that wants precise Slack formatting should makesummarycarry the weight.
Linear
- The comment body is the same Markdown a GitHub comment gets (
rendered, the PR line, attachments and theview_urlbacklink), cut at 65536 characters. A change result instead gets the change reply a Slack thread gets: the commit and draft pull request once thegithub_branchdelivery lands, or the status and the producer's reason when nothing was committed. The comment waits for the branch delivery the same way. - The issue must be in the team the result names. The allowlist blessed the team, not the issue, so the sender looks the issue up first and refuses it (a recorded skip, no write) when it is in another team.
- A later result for the thread edits the same comment. A comment deleted in Linear since is posted again.
statemoves the issue after the comment lands, and every delivery of the result moves it again. A state the team does not have, or a move Linear refuses, is logged; the comment stands and the delivery isdelivered.- The operator sets
MAIDAN_LINEAR_API_KEYand blesses each team by id:{"surface":"linear","selector":"<team id>"}.
All surfaces
- Mention sequences are neutralized at the egress boundary.
renderedis producer-authored but quotes attacker-influenced code; an@org/teamin a GitHub comment or a<!channel>in Slack would ping real people from attacker-controlled bytes. Maidan defuses these. Producers do not need to.
Credential guard
A producer that reviews untrusted content can be prompt-injected into pasting
a credential it can read into its result. Before every send, Maidan scans the
text it is about to publish for credential shapes: the rendered GitHub
comment, inline review (paths and bodies) and check run (when the sender can
post one), the Slack message, the Linear comment, a relayed projector message
or notice, and for a change the branch name, the pull request title and body,
the commit message, the commit status and the diff's added lines. A
no_change round publishes only its commit status, so only that is
screened. The shapes are GitHub tokens (ghp_, gho_, ghu_, ghs_, ghr_,
github_pat_), Anthropic and OpenAI-style API keys (sk-ant-, sk-), AWS
access key ids (AKIA, ASIA), Slack tokens (xoxb- and the like), JSON Web
Tokens, PEM private key headers, and Maidan's own maid_ secrets.
In a diff's added lines, JSON Web Tokens and PEM private keys don't count: they
are everyday test fixtures. A provider key or a Maidan token in a diff still
refuses the round.
A match refuses the whole send, before the first post or write: nothing
reaches the surface, the delivery row is skipped and is not retried, and
last_error names the kind of credential, the part that held it and the
surface, as in refused: the comment holds what looks like a GitHub token (gh*_…); nothing was sent to GitHub. The matched text is never recorded: not
in the row, the log line, the maidan_egress_credential_refused_total{surface, kind} counter or the operator alert (MAIDAN_OPS_ALERT_CHANNEL), which says
the same. Read the thread before replaying it. A development stack whose
producers publish key-shaped text on purpose can set
MAIDAN_EGRESS_CREDENTIAL_GUARD=off; boot refuses that with
MAIDAN_ENV=production.
The guard is a backstop, not a guarantee. A credential in a shape it does not know, or one encoded or split to dodge it, still goes out, and so does a JWT or PEM key in a diff's added lines. The result itself stays stored in Maidan.
Idempotency
A thread holds exactly one result (set_thread_result upserts). Re-running a
review over the same thread therefore updates the existing delivery in place
rather than stacking a second comment.
Maidan keys a delivery on (thread_id, target) and remembers the external
reference it created — a GitHub comment_id, a Slack ts. A later result on the
same thread edits that object. A hidden marker at the start of the GitHub comment
body is the recovery path if the stored reference is ever lost.
Producer obligation: re-review the same thread. A new thread per run is a new delivery, and will produce a second comment — correctly, since it is a different unit of work.
Failure semantics
- Partial delivery is normal. A connector failure on one target never prevents the others.
- Nothing is silently dropped. A failed delivery retries with backoff and dead-letters after a bounded number of attempts, where an operator can inspect and replay it. A misconfiguration-class error (401/403/404) on projector traffic disables the link rather than retrying forever. The same status on a result delivery dead-letters that target without disabling the projector link — a result must not take down room-to-issue relay.
- A failed or skipped target reaches the people who can act on it. Besides
the
result_delivery_failedevent, the notification router writes aresult_delivery_failednotification to the thread's creator, to the member who produced the result (the thread's assignee if no result is stored), to the thread's owner, and to the followers of the thread, its channel and that producer. Each must still be able to read the thread. - A non-
reviewedstatus is surfaced as a failure, usingstatusalone. It is never rendered as a passing review and never quietly skipped. - Every delivery attempt is audited.
Discoverability
result_kind is a namespaced string, not a closed enumeration. A producer publishes
result_kind = "example.review.result/1" inside schema = "maidan.waiter.result/1"; a
future producer ships a new string and the facet works without a server change.
List (not message-FTS) surfaces, workspace:read:
- REST:
GET /workspaces/{id}/results?result_kind=example.review.result/1(limitoptional, default 50, clamp 1–500). Omitresult_kindto list every non-tombstoned result the caller can access. - MCP:
list_thread_resultswith the same optionalresult_kind/limit. Workspace comes from the token; there is noworkspace_idargument.
Match is exact on the indexed string. example.review.result and
example.review.result/10 do not hit example.review.result/1. Private-channel rows the
caller cannot access are omitted. This is not GET /workspaces/{id}/search
and not the ADR JSON convention "kind": "decision" in
Integration reference.
Close-gate
A reviewed example.review.result/1 whose findings contain any
severity == "critical", from a producer that holds the review skill, is a
request_changes. If the thread has no review requirement, Maidan sets one
(k = 1: one approval), so the thread cannot close until a person who is
neither its owner nor its assignee approves it.
This uses the existing review gate; it is not a new one:
- A result with only warnings, another
result_kind, a status other thanreviewed, or a producer without thereviewskill changes nothing. - An existing requirement is left alone.
- A clean re-review does not approve on its own.
- An empty
deliver_tostill sets the requirement: the thread is held even when nothing is posted outside Maidan. - The GitHub review stays
event: COMMENT. The gate in Maidan decides the land; the pull request is not markedREQUEST_CHANGES.
Both PUT /threads/:id/result and MCP set_thread_result set the requirement
when the result is written, and the ThreadResultSet event handler sets it
again on every replica and on replay. Both are idempotent.
Delivery status
Per-thread delivery state is readable over REST and MCP, with a replay action, so a producer can confirm where its result actually landed without scraping the external surface.
| Call | Surface | Capability |
|---|---|---|
GET /threads/:id/deliveries | REST | workspace:read + thread access |
GET /workspaces/:wid/result-deliveries | REST | workspace:read; rows on threads the caller cannot access are left out |
POST /threads/:id/deliveries/:did/replay | REST | workspace:write + thread access |
list_result_deliveries {thread_id} | MCP | workspace:read + thread access |
replay_result_delivery {thread_id, delivery_id} | MCP | workspace:write + thread access |
One row per (thread, target):
{
"id": "…", "thread_id": "…",
"surface": "github", "selector": "example/repo#42",
"status": "delivered",
"external_ref": "998877",
"armed_revision": "2026-09-15T10:00:00Z",
"delivered_revision": "2026-09-15T10:00:02Z",
"attempts": 1, "last_error": null,
"created_at": "…", "updated_at": "…"
}
statusispending(armed, not yet sent),delivered,failed(the transport gave up and the egress queue dead-lettered it, or the server has no sender for the surface:last_errorthen names the setting, such asSlack delivery is not configured on this server (MAIDAN_SLACK_BOT_TOKEN)), orskipped(deliberately not delivered — an unknown surface, or a target the workspace has not blessed).skippedis not an error;last_errorcarries the reason.attemptscounts the sends tried, andlast_errorholds the latest failure. While the egress queue is still retrying, the row stayspendingwith both set, so a delivery being retried does not read as one never tried.selectoris the full destination (owner/name#123on GitHub), which is finer than theowner/namethe allowlist is keyed on.external_refis the object we created — a Slackts, a GitHub comment id. It is what the next revision edits in place.armed_revision/delivered_revisionareThreadResult.produced_atwatermarks: newest seen vs newest actually landed.delivered_revision: nullmeans never delivered. A result is re-delivered only when itsproduced_atis newer thanarmed_revision— that is the dedup, and it is why a replayed event is a no-op while a genuine re-review is an update.- An empty list is
200 []— the result was routed nowhere, which is valid. GET /workspaces/:wid/result-deliveriesgathers every thread's rows into one list, the most recently changed first, so an operator sees what failed without opening each thread.?status=pending|delivered|failed|skippednarrows it andlimit(default 50, at most 200) bounds it. It is the console's Deliveries tab. It shows the disposition only: the allowlist staystoken:admin.
Replay re-enqueues one row and re-checks the allowlist: an unblessed target
stays skipped (status is not policy). It does not bump armed_revision.
A target that was not reached is said on the event stream. Each time a row
moves into failed or skipped, Maidan appends a result_delivery_failed
event in the same transaction, scoped to the thread's workspace, channel and
thread:
{"kind": "result_delivery_failed", "workspace_id": "…", "channel_id": "…",
"thread_id": "…", "surface": "slack", "selector": "C0123ABCDEF",
"status": "skipped", "last_error": "target not in the workspace egress allowlist"}
It is said once per transition: recording the same outcome again (a replay
against a still-unblessed target) adds nothing, while a new revision of the
result that re-arms the row and is skipped again says it again. A delivered
target says nothing. A relay subscribed to the workspace with
kinds=result_delivery_failed (on the WebSocket filter or GET /mcp/stream)
can tell the task's own thread where its result did not go.
What Maidan will never deliver
- Raw agent output of any kind: agent stdout, un-rendered model text, tool
transcripts. Only
rendered,summary, and structuredfindings. - Anything at all when
statusis notreviewed(beyond the failure notice). - Anything to a target the workspace has not blessed.
- Text in which the credential guard, while on, detects a credential (Credential guard: JWTs and PEM keys in a diff's added lines are not counted, and other shapes are not detected).
Maidan does not run agents, does not render reviews, and is not a CI product.
The close-gate reads only findings[].severity (critical →
request_changes); it does not judge finding bodies. A GitHub review's event
stays COMMENT. Maidan delivers trusted bytes to allowed surfaces, durably,
once.
Versioning
The grammar above is frozen at maidan.waiter.result/1. Additive fields
are free. A change to the meaning of an existing field, or to the deliver_to
shape, requires a new schema value.
An unrecognized schema is inert. Maidan attempts no delivery and records
nothing: no warning, no skipped row, nothing on the status API. If a result
is never delivered and the status API is empty, check the schema string
first. A reference envelope is
crates/maidan-types/tests/fixtures/waiter_result_v1.json.