Skip to content

Cancel pending upload requests on watch-directory change - #93

Merged
wasimxyz merged 2 commits into
stagingfrom
wasimamiri/eng-1397-queued-file-missing-errors-when-switching-watch-directory
Jun 12, 2026
Merged

Cancel pending upload requests on watch-directory change#93
wasimxyz merged 2 commits into
stagingfrom
wasimamiri/eng-1397-queued-file-missing-errors-when-switching-watch-directory

Conversation

@wasimxyz

@wasimxyz wasimxyz commented Jun 11, 2026

Copy link
Copy Markdown
Member

Summary

In manual mode the uploader resolves each queued file as watch_dir / relative_path, but relative_path is anchored to the watch directory active at detection time. After an operator changes a watcher's watch_directory, every pending request becomes unresolvable and the queue re-poll re-emits a Queued file missing error on every heartbeat tick forever (the reported flood was 8611+ events).

Two coordinated fixes plus a per-file give-up path:

  • Server — revert on dir change: when PUT /watchers/:id/config changes watch_directory, all of that instrument's upload_requested files are reverted to detected (clearing upload_requested_at) so the queue drains immediately. Gated on a known previous directory so the first config push and unrelated config edits never revert spuriously. A config_synced event with details.kind="upload_requests_cancelled" records the cancellation.
  • Server — single-file cancel: PATCH /files/:id now allows upload_requested -> detected (clearing upload_requested_at) so the watcher can remove one stuck request from the queue.
  • Watcher — bounded retries: queued files are retried at most MAX_QUEUE_FILE_ATTEMPTS=3 heartbeat polls, covering both missing-on-disk and upload/network failures. The Queued file missing error is emitted once per file (throttled), and after the cap the watcher cancels the request server-side (cancel_upload_request) and emits an upload_request_cancelled give-up event. Attempt counters reset on restart, so a transient outage longer than ~3 ticks is recovered on the next start.

Trade-off

A transient failure that lasts longer than ~3 heartbeat ticks (~3 min) causes the file to be reverted to detected until a human re-requests it or the watcher re-detects it. This is the chosen behavior over retrying forever.

Changes

  • web/lib/api/watchers.ts: extractWatchDirectory + revertPendingUploadRequests helpers.
  • web/app/api/v1/watchers/[watcherId]/config/route.ts: revert + cancellation event on watch_directory change.
  • web/app/api/v1/files/[fileId]/route.ts: allow upload_requested -> detected, clear upload_requested_at.
  • watcher/: cancel_upload_request client method, MAX_QUEUE_FILE_ATTEMPTS constant, per-file attempt cap in Uploader, new event kinds in the taxonomy.
  • Tests (watcher/tests/test_uploader.py, web/tests/integration/{files,upload-request-cancellation}.test.ts) and docs/watcher.md.

Test plan

  • make check-all (ruff lint/format, pyright, prettier, eslint, tsc)
  • Python unit tests: 613 passed (incl. 5 new uploader cases)
  • Web integration suite: 244 passed (incl. dir-change revert, no-op-otherwise, and upload_requested -> detected cases)

Made with Cursor

Fix ENG-1397, where changing a watcher's watch_directory left pending
upload requests pointing at relative paths under the old root, so the
watcher re-emitted a "Queued file missing" error on every heartbeat poll.

- Server: revert an instrument's pending upload requests to `detected`
  (clearing upload_requested_at) when watch_directory changes, plus a
  config_synced cancellation event. Allow upload_requested -> detected in
  PATCH /files/:id so the watcher can cancel a single stuck request.
- Watcher: cap manual-mode queue retries at MAX_QUEUE_FILE_ATTEMPTS=3
  (covering both missing-on-disk and upload failures), throttle the
  missing-file error to once per file, then cancel the request server-side.
- Tests and docs for both paths.

Co-authored-by: Cursor <cursoragent@cursor.com>
@vercel

vercel Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
data-hub Ready Ready Preview, Comment Jun 12, 2026 12:08am

Request Review

@wasimxyz wasimxyz changed the title Cancel pending upload requests on watch-directory change (ENG-1397) Cancel pending upload requests on watch-directory change Jun 11, 2026
@wasimxyz wasimxyz self-assigned this Jun 11, 2026
Co-authored-by: Cursor <cursoragent@cursor.com>
@wasimxyz
wasimxyz merged commit f538087 into staging Jun 12, 2026
6 checks passed
@wasimxyz
wasimxyz deleted the wasimamiri/eng-1397-queued-file-missing-errors-when-switching-watch-directory branch June 12, 2026 00:10
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