Skip to content

fix(extension): queue concurrent downloads within their timeout - #573

Open
columbia11 wants to merge 7 commits into
Tencent:mainfrom
columbia11:fix/download-wait-for-gate
Open

columbia11 wants to merge 7 commits into
Tencent:mainfrom
columbia11:fix/download-wait-for-gate

Conversation

@columbia11

Copy link
Copy Markdown
Contributor

Fixes #519

Problem

handleDownload guards the browser-global chrome.downloads transaction with a module-level downloadActive flag. When session A is downloading, a bsk download from session B fails immediately with invalid_params "another bsk download is active". The CLI then shows "check your command arguments", even though B's arguments are valid. Every other command runs concurrently across sessions.

Fix

This implements the reporter's second option: replace the flag with a FIFO gate.

  • A later call waits its turn within its own timeout_ms, then captures with the time that remains, so the overall deadline is unchanged.
  • If the deadline passes while waiting, it returns timeout. If the operation signal aborts (cancellation or human intervention), it returns cancelled. Both carry effect_state: "none" and phase: "queue", because nothing was clicked.
  • Each gate resolves only after its predecessor and its own call finish. A waiter that gives up early therefore never lets the next call overlap a capture that is still running.

Captures still don't run in parallel. The reporter's first option would need attribution changes in download-capture.ts, which I didn't attempt.

Tests

  • New download-gate.test.ts, with a first download holding the gate:
    • a second call with timeout_ms: 20 returns timeout (effect_state: none, phase: queue);
    • an aborted waiter returns cancelled;
    • a waiter with a long timeout passes the gate once the first call finishes. It then stops at the missing capability directory, which shows it got past the gate.
    • Without the change the test fails with the old invalid_params.
  • src/tools/__tests__/download*: 27 passed. Full extension vitest run: 3604 passed, 1 failed (the human-loop child-process timeout, which fails under full parallel load and passes alone).
  • tsc --noEmit: exit 0. biome check on the changed files: clean.
  • Not verified with real downloads in a browser.

I used Claude Code to write the fix and tests and run the checks above.

🤖 Generated with Claude Code

handleDownload guarded the browser-global chrome.downloads transaction with
a module flag, so a `bsk download` from another session failed at once with
invalid_params "another bsk download is active" and the CLI's "check your
command arguments" hint, even though its arguments were valid.

Replace the flag with a FIFO gate. A later call waits for its turn within its
own timeout_ms and then captures with the remaining time. If the deadline
passes or the operation is cancelled while waiting, it returns `timeout` /
`cancelled` with effect_state "none" and phase "queue". Each gate also waits
for its predecessor, so a waiter that gives up early never lets the next call
overlap a capture that is still running.

Fixes Tencent#519

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@columbia11
columbia11 force-pushed the fix/download-wait-for-gate branch from 518a761 to 3af0e35 Compare November 4, 2026 06:42
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant