Skip to content

fix(api): don't let scheduled browser runs overwrite not_relevant tasks#3507

Merged
tofikwest merged 3 commits into
mainfrom
fix/browser-automation-prod-review
Jul 27, 2026
Merged

fix(api): don't let scheduled browser runs overwrite not_relevant tasks#3507
tofikwest merged 3 commits into
mainfrom
fix/browser-automation-prod-review

Conversation

@tofikwest

@tofikwest tofikwest commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

What & why

I reviewed the automated-review (cubic) findings on the stage→prod deploy PR (#3506) — 40 findings. One is genuinely harmful to users, and it's fixed here. The rest are already-fixed or documented-deferred (details below).

The issue (P1) — fixed

A scheduled browser automation flipped any non-done/non-failed task to done or failedincluding tasks a person deliberately marked not_relevant (which carries a human justification). That silently overwrote the compliance decision and orphaned its justification.

The fix

Guard both the done and failed transitions so an automated run never overwrites a not_relevant task — matching the existing codebase norm (cloud-security already "skips not_relevant (user intent)"). Added a small exported helper isTaskStatusProtectedFromAutomation + unit tests.

Scope: apps/api/src/trigger/browser-automation/run-browser-automation.ts (+ spec). 8 tests pass, typecheck clean.

The other 39 findings — why they're not here

  • Already fixed on the feature branch. The deploy diff re-includes the original code, so cubic re-surfaces issues that are already addressed: the API-error .error checks, task:* vs integration:* permission gating, empty-state connect gating, evidence best-effort capture, session cleanup on callback throw, markVerified freshness, the roll-up pass verdict, the MFA-instruction cache, etc.
  • Documented-deferred edges (recorded, none prod-blocking): orphaned 1Password item on credential re-save (H-2), session cleanup on a mid-connect unmount, the sibling-automation task-status race, 1Password resolve-error classification, and the DNS-blind IsSafeUrl (mitigated — the browser runs in Browserbase's isolated egress, not our network).
  • Low / not-an-issue: the vendor-logo route is a favicon proxy to a fixed upstream host (not an open SSRF); the remainder are accessibility / test-coverage nits.

Only the not_relevant overwrite would actively harm a user's data — hence a focused PR.


Summary by cubic

Scheduled browser runs no longer overwrite tasks marked not_relevant; human decisions and justifications are preserved. Done/failed transitions are now guarded atomically and only apply when the task isn’t already done/failed.

  • Bug Fixes
    • Use atomic updateMany with a WHERE that excludes done, failed, and protected statuses (isTaskStatusProtectedFromAutomation) to prevent race conditions; derive statusChangedToFailed from affected row count.
    • Add unit tests for isTaskStatusProtectedFromAutomation and worker-level tests that assert the atomic updateMany filters and zero-count handling; compute reviewDate from frequency without pre-checking current status.

Written for commit 2ea3283. Summary will update on new commits.

Review in cubic

A scheduled browser automation flipped any non-done/non-failed task to done or
failed — including tasks a human deliberately marked not_relevant (with a
justification). That silently destroyed the compliance decision. Guard both the
done and failed transitions with isTaskStatusProtectedFromAutomation, matching
the codebase norm (cloud-security skips not_relevant as user intent). +tests.
@vercel

vercel Bot commented Jul 27, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
comp-framework-editor Ready Ready Preview, Comment Jul 27, 2026 4:14am
2 Skipped Deployments
Project Deployment Actions Updated (UTC)
app Skipped Skipped Jul 27, 2026 4:14am
portal Skipped Skipped Jul 27, 2026 4:14am

Request Review

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 2 files

Reply with feedback, questions, or to request a fix.

Fix all with cubic | Re-trigger cubic

Comment thread apps/api/src/trigger/browser-automation/run-browser-automation.ts Outdated
Comment thread apps/api/src/trigger/browser-automation/run-browser-automation.ts Outdated
The status check and the update were separate queries, so a human marking a task
not_relevant between them could still be overwritten. Move the guard into the
WHERE clause of an atomic updateMany (excluding done/failed + not_relevant), and
derive statusChangedToFailed from whether a row actually changed.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 2 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

Fix all with cubic | Re-trigger cubic

Comment thread apps/api/src/trigger/browser-automation/run-browser-automation.ts
Assert the worker's done and failed transitions both go through updateMany with a
status filter that excludes not_relevant (and done/failed), and that a zero-count
result is treated as no transition — so a regression in either atomic filter is
caught instead of silently letting not_relevant be overwritten.
@vercel
vercel Bot temporarily deployed to Preview – app July 27, 2026 04:13 Inactive
@vercel
vercel Bot temporarily deployed to Preview – portal July 27, 2026 04:13 Inactive
@tofikwest
tofikwest merged commit 99393e5 into main Jul 27, 2026
11 checks passed
@tofikwest
tofikwest deleted the fix/browser-automation-prod-review branch July 27, 2026 04:35
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