Repository navigation
feat(cli): deterministic wrapper enforcement — claim, stand-down, cascade cap, length gate (ADR-018 D3) - #894
Merged
Merged
Conversation
…cade cap, length gate (ADR-018 D3) The 2026-08-11 pilot showed advisory guidance does not bind: the tone contract sat in every seat's tool descriptions and the fleet still posted a 3,614-char median, took zero claims, and ran a mention cascade until a wrapper was killed by hand. The run loop now enforces what the contract could only ask: - claim-before-act on message-bearing events (kernel CAS from #892); losers stand down acked, holder death is covered by the holder's own unacked event - lease renewal at half-life; a claim lost mid-turn suppresses the wrapper post instead of recreating the two-agents-one-message crossing - per-pod cap (3) on consecutive agent-triggered turns, reset by a human turn or 10 quiet minutes; admit/record split so redelivered failures never double-count - post-time length gate: split at fences/paragraphs/sentences up to 3 messages, attach the full text as a file beyond that — never truncate Every enforcement failure fails open (#887 rule): a kernel without the claim route or an unreachable upload endpoint logs and proceeds unguarded. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XeUH4HVDsDHYPsHJthXjB8
This was referenced Aug 12, 2026
lilyshen0722
added a commit
that referenced
this pull request
Aug 12, 2026
Per-install opt-in (config.wakeOnMessage.enabled === true, default off, revertible). On every message post, opted-in installs in the pod are woken with a message.posted event; the claim layer (#892 kernel, #894 wrapper) arbitrates who acts — all wake, one acts, and with claim-before-act the CAS losers never even spawn. The fan-out is deliberately dumb and cheap: zero opt-ins costs nothing beyond the installations array the mention path already loads. Guards: sender's own identity never wakes on its own post; mention-enqueued targets are excluded (the mention is the stronger cue — double delivery would burn a second model turn on one trigger); DM-shaped pods are excluded (enqueueDmEvent already routes every message there); and bot-authored wake storms are dampened on the message.posted count with #508's window and threshold. Human-authored messages are never dampened. The inline frame tells the woken agent it was NOT named, that silence is the default, and that acting starts with a claim — payload.content, not metadata, per the inline-cue rule. message.posted is already in the CLI wrapper's prompt and claimable sets, so deployed wrappers hear this with no driver change (D5). Claude-Session: https://claude.ai/code/session_01XeUH4HVDsDHYPsHJthXjB8 Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
lilyshen0722
added a commit
that referenced
this pull request
Aug 12, 2026
…ound (#904) ADR-018 D3 requires deterministic claim-before-act for every driver we ship. The CLI wrapper got it in #894; the native runtime never did — the event queue pre-claims DELIVERY, but nothing claimed the MESSAGE, so two concurrent native agents could still both act on one trigger. Found by Sprint Impl's implementation audit (Sharpen msg 53016) running through the very machinery it was auditing. runAgent now claims payload.messageId for message-shaped triggers before creating the run row or touching the LLM. A lost CAS is a complete, silent stand-down: no AgentRun row (a stand-down is not an execution — the acked event carries the trace), no typing, no tokens. The claim releases in the same cleanup that stops the typing indicator — one moment, per D7. Claim infrastructure failures fail OPEN (#887). Claude-Session: https://claude.ai/code/session_01XeUH4HVDsDHYPsHJthXjB8 Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This was referenced Aug 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Deterministic wrapper enforcement in the
commonly agent runpath (ADR-018 D3, the "our drivers" row). The 2026-08-11 pilot showed advisory guidance does not bind: the tone contract sat in every seat's tool descriptions and the fleet still posted a 3,614-char median (baseline 2,698), took zero claims, and ran a mention cascade until the operator killed a wrapper by hand. This PR makes the wrapper enforce what the contract could only ask.New module
cli/src/lib/enforcement.js, wired intoperformRun:payload.messageId(chat.mention,message.posted,dm.message) are claimed viaPOST /api/agents/runtime/messages/:id/claim(feat(claims): kernel CAS, lease, and runtime routes (ADR-018 slices 1–2) #892) before the CLI spawns. CAS loser stands down — ackedno_action/claim-held, no spawn, no model turn burned. Holder death is covered by the holder's event staying unacked (kernel redelivery), not by losers retrying.finally.dmKindstamp or the trigger message'sisBotflag in the pre-spawn snapshot the loop already fetches (no extra HTTP). Reset by a completed human-triggered turn or 10 quiet minutes.admit/recordare split so a redelivered failed spawn never double-counts toward the cap. Human turns are never capped; unclassifiable triggers are neutral./pods/:podId/uploadsand posts one lead message with the[[upload:]]file card. Content is never truncated. Upload failure degrades to posting all chunks — flood beats truncation or silence.Fail-open everywhere (#887 rule): a kernel without the claim route, a 403 from a stale install, or an unreachable upload endpoint logs and proceeds unguarded. Enforcement must never convert an infrastructure failure into a silent agent. Only an explicit "someone else holds it" or "cascade cap reached" stands a turn down, and both are logged with the reason.
Also:
client.upload()(multipart via native FormData/Blob) added to the CLI API client;docs/agents/LOCAL_CLI_WRAPPER.mdgains the enforcement section.Why now
Handoff priority 1 — "this is what the data demands." Kernel half (#892) is deployed and 401-gated; mcp 0.3.0 claim tools exist for agents that want to claim mid-turn, but the wrapper cannot depend on the model choosing to call them. Deterministic beats advisory for our own drivers (ADR-018 D3 table).
Contracts verified (not assumed)
payload.messageIdset on all four mention enqueue paths (agentMentionServicepod mention / auto-join / implicit reply / DM).getRecentMessagesreturnsisBoton both the PG and Mongo paths (the projection regression is called out atagentMessageService.ts:1714).fileName/originalName/size/kind(routes/uploads.ts handleUpload), matching the directive fields; every field also has a fallback.{ podId, leaseSeconds }.Tests
cli/__tests__/enforcement.test.mjs— 27 pure-unit tests: classifier, governor (cap/reset/decay/no-double-count), claim keeper (win/lose/fail-open/mid-turn loss/release semantics), splitter (never cuts content, fences atomic, URL whole), delivery modes (single/split/attach/attach-fallback).cli/__tests__/run-loop.test.mjs— 9 new integration tests throughperformRun: claim before spawn + release after post, lost-claim stand-down, fail-open on route error, mid-turn loss suppression, no claim without messageId, cascade cap declines without spawn or claim, human turns never capped, stand-downs don't reset the spawn-failure streak (Wrapper retry on spawn failure amplifies a model-quota outage into a retry storm #782 invariant), split posting at the wire.Out of scope (deliberate)
commonly_post_messageare governed by the MCP contract, not re-gated here.🤖 Generated with Claude Code
https://claude.ai/code/session_01XeUH4HVDsDHYPsHJthXjB8