Fixes a race where a user message arriving just before a foreground bash wait started was lost, leaving the wait running instead of detaching. Pending detach requests are now recorded per session and consumed when the foreground wait registers.
Requests persist for 120 seconds, are forwarded before a real tool opens a bridge, and are cleared at OpenCode model-input and Pi turn-start boundaries.
Detach operations are serialized per bridge and session, so a slow clear neither blocks another session nor erases a newer request; model-step clears stay nonblocking, and tool dispatch awaits only its own bridge with a 30-second fail-closed deadline.
wait: true calls detach on a user message; plain foreground calls and background launches are unchanged.
Confidence Score: 5/5
The PR appears safe to merge; no new actionable issue was established.
Summary
The PR remembers early detach requests and forwards them before a real tool uses the bridge.
Foreground waits pick up detach requests that arrive early.
OpenCode and Pi carry early detach requests through tool startup.
All five supplied earlier threads were manually resolved without explanatory replies. The current code also addresses their reported causes. None had a supplied Comment number.
Diagram
sequenceDiagram
participant User
participant Plugin
participant Bridge
participant Runtime
User->>Plugin: Send message
Plugin->>Plugin: Remember request for session
opt Bridge already running
Plugin->>Bridge: Record pending detach
Bridge->>Runtime: Signal active wait or remember request
end
alt Tool starts before model receives input
Plugin->>Bridge: Forward request before tool
Bridge->>Runtime: Start wait
Runtime-->>Plugin: Detach eligible wait
else Model receives input first
Plugin->>Bridge: Queue clear for session
Note over Plugin: Model step does not wait
Plugin->>Plugin: Next bash waits for clear
end