ADR-0300:
Composable ActionMiddleware & Async
ActionJob (app.actions/v1.2)
- Status: Accepted
- Date: 2026-11-28
- Related: ADR-0291 (Freeze Rust, Grow in Tenon), ADR-0292
(Application Actions API & State Deltas), ADR-0293
(
app.actions/v1.1), ADR-0271 (Dual-Era MCP)
Context
app.actions/v1 and v1.1
(plugins/app_actions/,
plugins/app_actions_mcp/,
plugins/app_actions_trace/) established a pure
(capabilities = []) control-plane contract for typed
ActionApp sessions. Two recurring gaps remained for
production agents and interactive apps:
- Hard-wired session cross-cutting concerns (Idea
#30): Policy gating, secret redaction, bounded undo
checkpoints, spin-loop/error circuit breaking
(
agent_obs), and in-memory structured trace recording (app_actions_trace) were either fixed insideActionSession.executeor had to be wired manually by every host. - Async long-running actions (Idea #24):
Actions that trigger background work (builds, indexing, remote
fetches) had no first-class job lifecycle, no bounded single-turn
wait_quiescent_mssettlement, nonotifications/progressstreaming over MCP, and no cancellation path.
Decision
We extend app.actions to protocol version
app.actions/v1.2 in pure Tenon
(capabilities = [], zero Rust changes, 100% backward
compatible with v1/v1.1 callers):
1.
Composable ActionLayer &
MiddlewareStack
(app_actions.middleware)
ActionSession<A>carries an immutableMiddlewareStack(layers: vec<ActionLayer>) plus runtime state (obs_breaker,trace_ring,last_middleware_trace).new_session/new_session_atinitializedefault_middleware_for(...)([policy_layer, redact_layer, undo_ring_layer]) so existingv1/v1.1sessions preserve identical behavior.- Execution follows strict onion composition (outer
-> inner -> outer):
- Before phase (
0..len-1):policy_layer(harness_policy+ ADR-0225 presented approval),obs_breaker_layer(sticky circuit breaker check), andtag_layerrun in outer-to-inner order. Any denial short-circuits immediately and unwinds only entered layers in reverse order. - Core phase:
app.apply(name, compact_args). - After phase (
len-1..0):redact_layer(state_delta.redacton projected state +app_actions_trace.encode.redact_trace_stron notes and non-job effects),undo_ring_layer(boundedRevAppcheckpoint ring),obs_breaker_layer(agent_obs.breakersspin/error streak + consecutive no-op streak trippingActionErrorKind.CircuitBroken),trace_ring_layer(boundedapp_actions_trace.ring.TraceRing), andtag_layerrun in inner-to-outer order.
- Before phase (
- Fluent composition is supported via
MiddlewareStackOps(.layer(...),.wrap(...)) and session helperswith_middleware,add_layer,wrap_layer,reset_breaker,trace_entries, andlast_middleware_trace.
2.
Async ActionJob Lifecycle & Single-Turn
Settlement (app_actions.jobs,
app_actions.session,
app_actions_mcp)
ActionEffectremains a backward-compatible struct{ kind, payload_json }. Apps spawn jobs viaspawn_job_effect(spec: JobSpec)(kind == "spawn_job"), decoded byparse_spawn_job_effect.JobState(Running | Completed | Failed | Cancelled),JobSpec,JobStepSpec,JobProgressEvent,JobRecord, and boundedJobRegistrylive inapp_actions.jobs.ActionSessionsupports both host-driven settlement (report_job_progress,complete_job,fail_job,cancel_job) and bounded deterministic settlement (execute_with_wait,wait_quiescent, clamped tomax_wait_quiescent_ms() == 60000).app_actions_mcpadds optionalwait_quiescent_mstoapp_actand addsapp_wait { job_id?, wait_quiescent_ms?, cancel_job?, reason? }while staying within the<= 900combined tool schema token budget.- Progress events are encoded via
mcp_server.stream.emit_progressasnotifications/progressframes and emitted before the final tool response inMcpServeReply.notifications, chunked stdio (feed_stdio_bytes), and loopback SSE (handle_sse_post) across both2026-07-28and2025-11-25MCP eras. - When
wait_quiescent_mssettles spawned jobs in a singleapp_actturn,execute_with_waitcoalesces theWireUpdatefrom pre-action state to post-settlement state so the caller receives one settledstate_deltain one turn.
Consequences
- Zero Rust compiler/runtime changes (ADR-0291 compliant) and
identical behavior on both native C (
tenon test) andtenon interp. - Zero breaking changes for
v1/v1.1callers (ActionEffect,ActionCall,ActionSpec,ActionApp, and non-jobapp_actJSON responses are unchanged). app_actionsadds a pure path dependency onagent_obs(capabilities = []) to reuse canonical circuit breaker logic rather than duplicating it.