Session Interactions#
Session interactions are the persisted records that track every approval gate raised during an agent turn — their current state (pending, resolved, cancelled), the decision that was made, and whether a warm session is parked while waiting for that decision. The mechanism spans the runner engine, the API/persistence layer, and the playground UI, and differs in important ways depending on which gateway issued the gate.
Approval Gate Lifecycle#
When an agent calls a tool that requires human approval, the runner creates an interaction record in a pending state and either:
- Parks the live session (warm path) — holds the original session open so an approve/deny resumes it directly without replaying the transcript; or
- Records a decision for replay (cold path) — stores the decision in a decision map so the next cold turn can skip past the gate.
The warm-path parking was introduced for Claude ACP gates in PR #5158 and extended to Pi gates via the ACP permission-plane in PR #5185. A strict, versioned envelope (pi-gate-envelope.ts) carries Pi gate identity and arguments; the runner rejects malformed or forged envelopes fail-closed .
Client-tool MCP pauses remain outside the ACP parking path .
In mobile chat, sending a message while approval gates are pending denies all pending gates, then steers the message into the resumed run so the agent reads it next. The message appears immediately, but steering waits for the denials to complete. If a denial fails or the run does not resume, the approval dock reopens and the steer is not sent (approval dock, mobile conversation).
Gateway-Specific Constraints#
| Gate type | Warm-path parking | Notes |
|---|---|---|
| Claude ACP builtin | âś… Yes | Introduced in PR #5158 |
| Pi builtin / custom-tool | âś… Yes | Added in PR #5185 via ACP permission-plane envelope |
| Client-tool MCP | ❌ No | Falls back to cold decision-map path |
Gateway tool approvals that lack an ACP permission ID cannot use the warm-path parking. Without a permission ID the turn is not parked and a cold-path turn is initiated instead. When a user denies such a gate, the stale-interaction sweep (see below) can cancel the pending record before the denial is resolved, leaving the row in a cancelled state rather than resolved/denied and the inbox recording the decision as "abandoned" rather than the true outcome .
Stale-Interaction Sweep and Cancellation#
At the start of every turn, the runner runs a stale-interaction sweep that cancels any pending interactions from previous turns. This is intentional behavior designed to clean up gates that will never be answered .
Two known failure modes arise from this sweep:
-
Cold-replay cancellation (Issue #6315): During a cold replay, the sweep can cancel a pending approval card before the UI receives a response. The card remains actionable in the UI because
getPendingApprovalsmay return interactions without checking their status, leaving a dead, unanswerable card visible to the user . -
Gateway denial cancellation: When a gateway gate lacks an ACP permission ID, a user denial triggers a cold turn. The sweep then cancels the gate the user just answered, so the subsequent transition call returns 404 and the record ends
cancelledwith no resolution .
Token exemption — the fix introduced in PR #5305 — adds an optional exemption list to stale-interaction cancellation. Approval tokens answered in-band on the current request are excluded from the sweep, allowing the normal resume/resolve path to complete. This exemption is threaded through the API and persistence layer .
Durable Decisions and Multi-Gate Approvals#
PR #5382 addressed correctness across the full interaction lifecycle:
- Durable answers: Approval outcomes are persisted and restored after a page reload, so an approved call is not re-raised after reload .
- Per-card dispatch: The UI dispatches each card's answer individually; the runner accepts partial answer sets, resumes answered gates, and re-parks on any remaining gates .
- Truthful placeholders: Calls approved but still executing are no longer mislabeled as "not executed"; genuinely deferred calls receive a truthful placeholder distinguishable from a real tool result .
- Pi sibling rule: Pi gates do not wait for a result until all sibling approvals are answered; Claude retains its bounded per-gate wait .
- Transcript safety: Rebuilt transcripts can reopen placeholder-only results for a re-raised gate without reopening completed results .
The runner still surfaces gates serially — genuinely simultaneous approval cards are not produced .
Key Source References#
| Area | Path |
|---|---|
| Runner ACP interaction parking | services/runner/src/engines/sandbox_agent/acp-interactions.ts |
| Session pool / warm-path keepalive | services/runner/src/engines/sandbox_agent/session-pool.ts |
| Pi gate envelope (versioned) | services/runner/src/engines/sandbox_agent/pi-gate-envelope.ts |
| Runner stale sweep / token exemption | services/runner/src/sessions/interactions.ts |
| Runner pause/resume logic | services/runner/src/engines/sandbox_agent/pause.ts |
| API interaction service (sweep + transitions) | api/oss/src/core/sessions/interactions/service.py |
| API interaction persistence (DAO) | api/oss/src/dbs/postgres/sessions/interactions/dao.py |
| API session router (exemption list) | api/oss/src/apis/fastapi/sessions/router.py |
| Playground per-card dispatch | web/packages/agenta-playground/src/state/execution/agentApprovalResume.ts |
| Transcript placeholder logic | web/oss/src/components/AgentChatSlice/assets/transcriptToMessages.ts |