[fix] Drain approval events before done#5267
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Important Review skippedNo new commits to review since the last review. ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughPaused turns now await cancellation-related event draining before performing a final sweep that settles remaining paused tool calls. The pause controller tracks session-destruction completion and handles rejection or synchronous errors without rejecting the pause signal. ChangesPaused turn lifecycle
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant runTurn
participant PauseController
participant Session
participant ToolCalls
runTurn->>PauseController: waitForEventDrain()
PauseController->>Session: finish destroySession and queued updates
Session-->>PauseController: drain complete
PauseController-->>runTurn: resolve event drain
runTurn->>ToolCalls: settle paused calls as not executed
Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
🤖 The AI agent says: This is the complete approval event-drain fix extracted from #5242, including the caller hunk that was initially hidden in the mixed @coderabbitai review |
|
✅ Action performedReview finished.
|
🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
gh pr view 5267 --repo Agenta-AI/agenta --json title,body,files -q '.files[].path'
echo "---DIFF---"
gh pr diff 5267 --repo Agenta-AI/agenta > /tmp/pr5267.diff
wc -l /tmp/pr5267.diff
grep -n "PendingApprovalPauseController\|waitForEventDrain\|pending-approval-pause" -r . --include="*.ts" || trueLength of output: 2903 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "=== pause.ts ==="
cat -n services/runner/src/engines/sandbox_agent/pause.ts
echo "=== sandbox_agent.ts around 1500-1560 (pause construction) ==="
sed -n '1480,1560p' services/runner/src/engines/sandbox_agent.ts
echo "=== sandbox_agent.ts around 1800-1900 (terminalization) ==="
sed -n '1780,1900p' services/runner/src/engines/sandbox_agent.ts
echo "=== pending-approval-pause.test.ts ==="
cat -n services/runner/tests/unit/pending-approval-pause.test.ts
echo "=== full diff ==="
cat /tmp/pr5267.diffLength of output: 20549 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "=== settleOpenToolCalls definition ==="
rg -n "settleOpenToolCalls" -A 25 services/runner/src/engines/sandbox_agent.ts | head -100
echo "=== search other definition files ==="
rg -rn "settleOpenToolCalls" services/runner/src --type ts
echo "=== TOOL_NOT_EXECUTED_PAUSED ==="
rg -n "TOOL_NOT_EXECUTED_PAUSED" services/runner/srcLength of output: 5504 🏁 Script executed: #!/bin/bash
set -euo pipefail
rg -n "settleOpenToolCalls" -B5 -A 30 services/runner/src/tracing/otel.tsLength of output: 3703
Terminalization block (
Tests (
One minor note for awareness rather than a blocker: the drain is a single extra event-loop turn (one No blocking issues found — approving from a code-review standpoint. ✅ Action performedReview finished.
|
Context
When a tool requested human approval, the runner signaled the pause immediately and began cancelling the managed session. It could emit the terminal
doneevent before cancellation and already-queued ACP tool updates finished, leaving a late sibling tool call without its deterministic terminal result.Changes
The pause controller now tracks a separate event-drain promise. The human-facing pause signal remains immediate, while terminalization waits for managed cancellation plus one event-loop turn. After the drain, the runner re-sweeps paused sibling tool calls before emitting
done.Cancellation failures remain best-effort. A rejected or synchronously thrown destroy operation cannot block the pause.
Tests / notes
How to review
PendingApprovalPauseController.pause()andwaitForEventDrain().sandbox_agent.tsthat awaits the drain and re-sweeps siblings.pending-approval-pause.test.tsfor timing and failure behavior.What to QA
doneremains the final event.