Skip to content

fix(action-center): mark a task tried before its check reads anything, cap each brand's night, and check after the task writer - #1682

Merged
gkhngyk merged 3 commits into
ansvisor:mainfrom
cihan-gyk:fix/task-check-sweep-queue
Oct 28, 2026
Merged

gkhngyk merged 3 commits into
ansvisor:mainfrom
cihan-gyk:fix/task-check-sweep-queue

Conversation

@cihan-gyk

@cihan-gyk cihan-gyk commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Follow-ups C from #1565's round 37 (round 36's items 6, 7 and 11): the Action Center's page checks claim a task before reading, cap each brand's night, and run after the task writer.

Item 6: tasks the sweep can't check no longer stay at the head of its queue.

  • Before, nothing was written in two cases, so those rows kept a null or old triedAt and came first every night:
    • no address could be made (a URL typed as acme.example pricing, or a path on a brand with no domain);
    • reading threw.
  • runTaskCheck now writes triedAt first, as a claim on the task as it was read. The claim is a conditional update on status and updated_at. The result is then written on the claim.
  • A run that read the task before another run claimed it gets changed and reads nothing, so two runs never check one task.
  • triedAt only defers the sweep by 20 hours; Check now ignores it.

Item 7: one brand can't take the whole night, and checks wait for the task writer.

  • The sweep checks at most SWEEP_PER_BRAND (20) of one brand's tasks a night. To fill its 200, it reads up to 5 pages of 1,000 rows, ordered by triedAt, then id.
  • server.js starts the checks once sweepActionTasks settles, because the writer can delete a task a check just completed.
  • A brand with many tasks gets each one checked less often (300 tasks ≈ every 15 days). The guide says so.

Item 11: the sweep's query ran against the dev database: the or with a JSON path, the order on details->autoCheck->>triedAt, and the range. It ran over a temporary demo-brand action and task with a stub page: the task was claimed, checked and completed, with one History line. The temporary rows were deleted afterwards.

Merge note: this PR and #1679 both add a name to task-checks.test.js' import list (SKETCH_VERSION and SWEEP_PER_BRAND), and both edit the guide's Automatic paragraph. Whichever merges second needs a one-line merge; keep both. #1683 is stacked on this one.

Where people see it: no visible change; nightly checks spread across brands.

Related issue

Follow-up from #1565 (round 37, item C).

Type of change

  • feat — New feature
  • fix — Bug fix
  • chore — Maintenance / dependencies
  • docs — Documentation only
  • refactor — Code change that neither fixes a bug nor adds a feature
  • test — Adding or updating tests

How to test

cd server && npx vitest run src/lib/action-center/task-checks.test.js

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • yarn lint passes (run from web/)
  • yarn typecheck passes (run from web/)
  • yarn format:check passes (run from web/)
  • Changes are focused — one concern per PR

Full checks were run in one tree with this batch's eight follow-up branches merged (after the review fixes):

  • server format, lint and npm test (no SUPABASE_* env, as in CI): 249 files, 3,365 tests passed;
  • web format, lint (0 errors; 7 warnings already on main), typecheck, vitest (445 files, 4,353 tests) and build: all pass.

Browser check (local, 1024 px): Prompts › Topics › Add Topic stops at 100 characters; the Action Center drawer opens without errors, and Check now doesn't show on tasks the API doesn't check.

A pre-push review was run on all eight branches of this batch, and its before-merge findings are fixed.

🤖 Generated with Claude Code

…, cap each brand's night, and check after the task writer

Follow-ups C (round 36's items 6, 7 and 11) from ansvisor#1565's round 37.

Item 6: tasks the sweep can't check stayed at the head of its queue.
Nothing was written when no address could be made (a URL typed as
`acme.example pricing`, a path on a brand with no domain) or when reading
threw, so those rows kept a null or old triedAt and came first every
night. runTaskCheck now writes triedAt first, as a claim on the task as
it was read (the bot-log crawler case's own write goes, the claim keeps
its try); the result is written on the claim. A run that read the task
before another claimed it gets 'changed' and reads nothing, so two runs
never check one task.

Item 7: one brand could take the night, and the checks didn't wait for the
task writer.
- The sweep checks at most SWEEP_PER_BRAND (20) of one brand's tasks a
  night, and reads up to 5 pages of 1,000 rows (ordered by triedAt, then
  id) to fill its 200.
- server.js starts the checks once sweepActionTasks settles: the writer
  can delete a task a check just completed.

Item 11: the sweep's query (the `or` with a JSON path, the order on
details->autoCheck->>triedAt, the range) ran against the dev DB, over a
seeded demo-brand task with a stub page: claimed, checked, completed,
one History line; the temp action and task were deleted after.

The guide's Automatic line says 20 of one brand's, least recently tried
first.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@mintlify

mintlify Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Preview approval required

This pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit 0c200a7.

Approve preview

@gkhngyk gkhngyk 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.

Looks good, with follow-ups. The change is right. It needs main merged in first, and that merge has one resolution to get right (below).

What I checked:

  • The change. b793044 on 3f6a4d4. It covers round 36's items 6, 7 and 11.
  • The claim (task-checks.js:497-509).
    • triedAt is written first, conditional on the task's status and updated_at as read. A task with no address, or one whose read throws, now leaves the head of the queue.
    • The result is written conditional on the claim's updated_at (now). action_tasks has no trigger that rewrites updated_at, so that matches.
    • A second run that read the task before the claim gets changed and reads nothing. Check now during the sweep wins over the sweep's write, which gets changed. Either way, one result is kept.
    • The bot-log crawler case keeps its try through the claim, as before.
  • The night (:584-622).
    • Up to 5 pages of 1,000 rows, in a steady order (triedAt, nulls first, then id). Nothing is written while the pages are read, so the pages don't shift under the reads.
    • At most 20 of one brand's tasks, and the filter on the last 20 hours is kept.
  • After the task writer (server.js:187-197). The checks start once the writer's sweep settles, and a writer that fails is logged and the checks still run.
  • Tests. task-checks.test.js passes (33). With main's task-checks.js, the new claim, cap and order cases fail.
  • Before the API deploy. Server and docs only. Nothing changes until the API is deployed.

Merging main. On b591947, task-checks.js conflicts twice with #1616's shopping links tasks:

  • In runTaskCheck, keep the shopping dispatch before the claim and pass it the task as read. checkShoppingTask writes its own triedAt, conditional on the updated_at it was given, so a claim before it would make its writes miss:
    if (!OPEN.includes(read.status)) return { reason: 'not_open' };
    if (kind === 'shoppingLinks') return checkShoppingTask(read, action, { fetch, now });
    const d = read.details ?? {};
    const previous = d.autoCheck ?? null;
    // …the claim, as in this PR
  • In the sweep, keep main's exclusion in the row loop. The query already leaves those tasks out (no task_key, no change.after), so this is the guard main has:
    const kind = checkKind(row);
    // A shopping links task is checked after each catalog sync, not here.
    if (!kind || kind === 'shoppingLinks') continue;
    if (Date.parse(row.details?.autoCheck?.triedAt ?? '') >= since) continue;
  • With that resolution, and #1679, #1680 and #1681 merged too, src/lib/action-center, src/lib/audit and page-content pass here. The only failures read web/ files, which my scratch layout doesn't have, and they fail on main's tree the same way.
  • With #1679, the test file's import list conflicts, as you said. It merges clean with #1680 and #1681.

Follow-ups:

  1. A test for a read that throws. The new test covers a task with no address. A check where the page read throws, still leaving triedAt behind, would hold the other half of item 6.

@gkhngyk
gkhngyk merged commit 87202b8 into ansvisor:main Oct 28, 2026
6 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.

2 participants