Make OpenCode cmux hooks nonblocking
LA
1mo ago+442+442+012345678901234567890123456789-21-21-01234567890123456789
Summary
- Dispatch generated OpenCode lifecycle hooks through a bounded asynchronous queue.
- Limit hook fan-out to four active children and 256 pending entries, coalescing repeated same-session transitions.
- Deduplicate
session-startdelivery from repeatedsession.updatedevents. - Release queue lanes immediately when a timed-out hook is killed.
Verification
swiftc -frontend -parse CLI/cmux.swiftswiftc -frontend -parse cmuxTests/OpenCodeHookRegressionTests.swift- Generated plugin
node --check --input-type=module - Runtime fixture: callback returned in about 2 ms with a 1 second fake cmux process.
- Runtime overload fixture: 130 accepted starts and 130 matching ends from 301 sessions.
- Tagged fleet build attempted with
ocnb2; blocked by existingSources/Cloud/VMTunnelManager.swift:329error (VMTunnelManagerhas no membercompletedConfig).
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.
Summary by cubic
Makes OpenCode lifecycle hooks nonblocking so they no longer block OpenCode's event loop.
- Replaces synchronous
spawnSynchook calls with a bounded async queue (4 active children, 256 pending entries). - Coalesces repeated same-session lifecycle transitions and dedupes
session-startdelivery fromsession.createdandsession.updated. - Drops hooks when the queue is full, except
session-endfor sessions with a previously accepted start. - Releases queue lanes immediately when a hook times out after 5 seconds.
Summary by CodeRabbit
-
Performance
- OpenCode session hook delivery is now asynchronous, preventing session events from blocking while external processes respond.
- Hook processing remains ordered per session while supporting concurrent activity across sessions.
-
Reliability
- Repeated session updates no longer trigger duplicate session-start events.
- Queue limits, timeouts, and event coalescing improve behavior during high activity.
- Accepted session lifecycle events are reliably paired and delivered.