You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(browser): retire timed-out snippet sessions and return partial output
A browser_execute timeout fails the Effect fiber but cannot preempt the
snippet's Promise. The orphan kept running against the same Session object
the next tool call would receive from SessionStore, letting abandoned code
and a fresh call interleave CDP commands on one socket — plausible-but-wrong
results, not crashes. Timeouts also discarded all console output.
On timeout we now:
- retire the exact Session the snippet received (Session.invalidate rejects
future connect/_call, closes the socket; in-flight calls are rejected by
the existing close handler) and remove it from SessionStore by identity,
so a stale caller can never evict a successor Session
- freeze the capture buffer (post-timeout console.log and onChunk stop) and
return the last 8 KiB of output in the error, cut on a UTF-8 boundary
- document the 60s default / 600s max and reconnect-after-timeout in the
skill's guardrails
Deliberately minimal: no abort plumbing through the connect path (the
windows are milliseconds wide and socket close + identity eviction already
prevent cross-call interleaving) and no per-session locking (opencode
serializes tool calls within an assistant message; concurrent same-session
calls have never been observed).
Diagnosis and the identity-checked eviction shape come from #118.
Tests (no Chrome required) verify: timeout error carries partial output and
the retired Session rejects connect/_call while the store hands out a fresh
one; capture and onChunk stop after timeout; tail-capping preserves UTF-8.
All three fail with the source change reverted.
- Top-level `import` statements inside the snippet body are not allowed. Use `await import(...)` instead.
199
199
- No CPU-bound infinite loops without `await` — they ignore the timeout. Insert `await new Promise(r => setTimeout(r, 0))` to yield.
200
+
- `browser_execute` defaults to 60s (max 600s). For longer work, set the tool's top-level `timeout`; inner CDP timeouts do not extend it. Keep batches small and log progress — timeout errors return recent logs, and a timeout resets the CDP session (reconnect in the next snippet).
200
201
201
202
## Console
202
203
- `console.log`, `console.error`, `console.warn`, `console.info`, `console.debug` are all captured and streamed to the user. Treat them as your stdout. Other `console.*` methods write to bcode's stderr without being captured into the tool result.
0 commit comments