Skip to content

Window mechanics: wedge-resistant window actions + CLI positioning flags#113

Open
cristbc wants to merge 2 commits into
Hacker-Valley-Media:mainfrom
cristbc:fix/window-mechanics-resilience
Open

Window mechanics: wedge-resistant window actions + CLI positioning flags#113
cristbc wants to merge 2 commits into
Hacker-Valley-Media:mainfrom
cristbc:fix/window-mechanics-resilience

Conversation

@cristbc

@cristbc cristbc commented Jun 18, 2026

Copy link
Copy Markdown

Summary

Two related fixes to Chrome window control, found while building reliable side-by-side window tiling on top of the CLI.

1. fix(extension): guard window actions against a wedged service worker

  • Symptom: after a long-lived MV3 service-worker session, window_focus / window_resize stop responding (CLI reports "no response" after 15s) while window_list and tab operations keep working.
  • Cause: chrome.windows.* calls can hang; the handler awaited them with no timeout, and a hung await never throws — so the message dispatcher's try/catch can't recover it and no response is ever sent. It looks like a dead tool.
  • Fix: wrap every chrome.windows.* call in an 8s Promise.race timeout, and wrap the whole handler in try/catch, so it always returns a structured { success, error }. A wedge now surfaces as a fast, honest error instead of a silent 15s hang.

2. feat(cli): expose --left/--top/--state on window resize

  • The extension's window_resize handler already forwards left/top/state to chrome.windows.update, but the CLI only read positional width height — so windows could be resized, never positioned or tiled.
  • Adds --left/--top/--width/--height/--state flags. Positional window resize <id> <width> <height> is kept for back-compat.
  • Unlocks absolute positioning and side-by-side tiling from the CLI.
  • Caller note: chrome.windows.update rejects state combined with explicit bounds ("Invalid value for state") — set state and bounds in separate calls.

Testing

  • tsc -p tsconfig.host.json and tsc -p tsconfig.extension.json clean.
  • Live-verified against a running daemon: --left/--top moves windows to exact coordinates; two windows tiled to exact non-overlapping halves; the wedge guard is confirmed present in the built bundle.

Summary by CodeRabbit

  • New Features

    • Window resize operations now support flag-based parameters (--left, --top, --width, --height, --state) in addition to positional arguments.
  • Bug Fixes

    • Improved stability by preventing indefinite hangs in window operations with timeout protection.

cristbc added 2 commits June 18, 2026 15:47
chrome.windows.* calls can hang indefinitely in a long-lived MV3 service worker
(observed: window_focus/window_resize stopped responding while window_list and
tab ops kept working). A hung await never throws, so the message dispatcher's
try/catch cannot recover it — the CLI just times out at 15s with no structured
error, looking like a dead tool.

Wrap every chrome.windows.* call in an 8s timeout and the whole handler in
try/catch so it ALWAYS returns a structured ActionResult: a hang or throw
becomes an honest { success:false, error } the daemon/CLI can surface.
The extension's window_resize handler already forwards left/top/state to
chrome.windows.update, but the CLI only read positional width/height — so
windows could be resized, never positioned or tiled. Add --left/--top/--width/
--height/--state flags (positional `width height` kept for back-compat).
Unlocks absolute positioning and side-by-side tiling from the CLI.
@coderabbitai

coderabbitai Bot commented Jun 18, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

An error occurred during the review process. Please try again later.

📝 Walkthrough

Walkthrough

The CLI window resize subcommand gains flag-based argument parsing (--left, --top, --width, --height, --state) while retaining positional backward compatibility. The extension background handler gains a withTimeout helper that races every chrome.windows.* call against a deadline, and handleWindowActions is rewritten to always return a structured ActionResult on timeout, API error, or unknown action.

Changes

Window Resize CLI Flags and MV3 Timeout Safety

Layer / File(s) Summary
CLI window resize flag parsing
cli/commands/tabs.ts
case "resize" replaces fixed-index parsing with named-flag helpers (--width, --height, --left, --top, --state), makes windowId optional, and conditionally sets numeric fields only when parseInt produces valid values.
withTimeout helper and handleWindowActions hardening
extension/src/background/capabilities/windows.ts
Adds WINDOW_OP_TIMEOUT_MS constant and a withTimeout(op, p, ms?) race helper; rewrites handleWindowActions with a top-level try/catch and substitutes every chrome.windows.* await with withTimeout(...), so unknown actions, API errors, and stalled calls all resolve to { success: false, error } instead of hanging.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 Hoppity-hop, no more hanging around,
Timeouts now catch what once could not be found.
Flags for the window—left, top, width, height—
The resize command shines with new flag-based might!
No stuck service worker shall trouble my burrow,
Each promise resolves, every path nice and thorough. 🌟

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately captures the two main changes: making window actions timeout-resistant ('wedge-resistant') and adding CLI positioning flags.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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.

1 participant