Skip to content

fix(extension): per-workspace idle timeout for browser sessions#1064

Merged
jackwener merged 4 commits intomainfrom
fix/browser-idle-timeout
Apr 17, 2026
Merged

fix(extension): per-workspace idle timeout for browser sessions#1064
jackwener merged 4 commits intomainfrom
fix/browser-idle-timeout

Conversation

@jackwener
Copy link
Copy Markdown
Owner

Summary

Fixes #1058opencli browser sessions intermittently reset to about:blank because the global 30s idle timeout is too aggressive for interactive use.

  • Per-workspace timeout: browser:* / operate:* workspaces now default to 10 minutes; adapter workspaces keep the existing 30s
  • Custom timeout support: Set OPENCLI_BROWSER_TIMEOUT=<seconds> env var, or pass idleTimeout in the command protocol to override
  • Session-expired warning: When a new window is created because the previous session timed out, CLI outputs a warning instead of silently opening about:blank
  • Stale comment fix: Line 121 said "120s" but the actual value was 30s (diverged in PR fix(extension): minimize automation window + reduce idle timeout #521)

Changes

File What
extension/src/background.ts Per-workspace getIdleTimeout(), expiredWorkspaces tracking, workspaceTimeoutOverrides for custom timeout
extension/src/protocol.ts Add idleTimeout to Command, sessionExpired to Result
src/browser/page.ts Pass idleTimeout through _cmdOpts() / _wsOpt()
src/browser/daemon-client.ts Surface sessionExpired warning via log.warn()
src/browser/bridge.ts Accept idleTimeout in connect options
src/cli.ts Read OPENCLI_BROWSER_TIMEOUT env var

Test plan

  • npm test — 208 passed (1 pre-existing bilibili network timeout, unrelated)
  • npm run build — clean
  • Extension vite build — clean
  • Extension typecheck — same pre-existing errors as main, no new errors
  • Manual: open a browser page, wait >30s, send another command → should NOT reset to about:blank
  • Manual: wait >10min → should reset with warning message
  • Manual: OPENCLI_BROWSER_TIMEOUT=60 → verify 60s timeout override works

The global 30s WINDOW_IDLE_TIMEOUT was too aggressive for interactive
`opencli browser` commands where users type manually between invocations.

- browser:*/operate:* workspaces now default to 10 min idle timeout
- Adapter workspaces keep the existing 30s timeout
- Support custom timeout via OPENCLI_BROWSER_TIMEOUT env var (seconds)
  or command-level idleTimeout parameter
- Surface sessionExpired warning when a new window is created after
  the previous session timed out
- Fix stale comment (said 120s, actual was 30s)

Closes #1058
…ifecycle

Addresses @codex-coder review blockers:

1. sessionExpired flag was never set because getAutomationWindow()
   consumed expiredWorkspaces before handleCommand() could check it.
   Fix: use .has() in getAutomationWindow, only .delete() in handleCommand.

2. workspaceTimeoutOverrides was never cleaned up — once set, it
   persisted until extension restart. Fix: clear override on idle
   timeout expiry, explicit close-window, and borrowed-session detach.

Adds 5 tests covering:
- browser:* uses 10min timeout (not 30s)
- sessionExpired flag is set and consumed correctly
- workspaceTimeoutOverrides cleared on idle expiry
- workspaceTimeoutOverrides cleared on explicit close
- idleTimeout from command applies to workspace override
@WAWQAQ decided session-expired warning is not needed.
Remove expiredWorkspaces tracking, sessionExpired flag from protocol,
and related CLI-side warning code. Keep per-workspace timeout and
override lifecycle cleanup.
@jackwener jackwener force-pushed the fix/browser-idle-timeout branch from 832e165 to c595460 Compare April 17, 2026 02:45
The windows.onRemoved listener was missing workspaceTimeoutOverrides
cleanup, causing stale overrides to persist across sessions when users
manually close the automation window.
@jackwener jackwener merged commit cb9521d into main Apr 17, 2026
10 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: opencli browser 在 Bilibili 多步骤操作中会间歇性跳回 about:blank

1 participant