Repository navigation
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
Conversation
…, 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]>
Preview approval requiredThis pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit |
This was referenced Oct 28, 2026
# Conflicts: # server/src/lib/action-center/task-checks.js
8 of 12 tasks
gkhngyk
approved these changes
Oct 28, 2026
gkhngyk
left a comment
Contributor
There was a problem hiding this comment.
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).triedAtis written first, conditional on the task'sstatusandupdated_atas 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_taskshas no trigger that rewritesupdated_at, so that matches. - A second run that read the task before the claim gets
changedand reads nothing. Check now during the sweep wins over the sweep's write, which getschanged. 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, thenid). 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.
- Up to 5 pages of 1,000 rows, in a steady order (
- 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.jspasses (33). With main'stask-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.checkShoppingTaskwrites its owntriedAt, conditional on theupdated_atit 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, nochange.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/auditandpage-contentpass here. The only failures readweb/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:
- 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
triedAtbehind, would hold the other half of item 6.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.
triedAtand came first every night:acme.example pricing, or a path on a brand with no domain);runTaskChecknow writestriedAtfirst, as a claim on the task as it was read. The claim is a conditional update onstatusandupdated_at. The result is then written on the claim.changedand reads nothing, so two runs never check one task.triedAtonly 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.
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 bytriedAt, then id.server.jsstarts the checks oncesweepActionTaskssettles, because the writer can delete a task a check just completed.Item 11: the sweep's query ran against the dev database: the
orwith a JSON path, the order ondetails->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_VERSIONandSWEEP_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 featurefix— Bug fixchore— Maintenance / dependenciesdocs— Documentation onlyrefactor— Code change that neither fixes a bug nor adds a featuretest— Adding or updating testsHow to test
cd server && npx vitest run src/lib/action-center/task-checks.test.jsChecklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (run fromweb/)yarn typecheckpasses (run fromweb/)yarn format:checkpasses (run fromweb/)Full checks were run in one tree with this batch's eight follow-up branches merged (after the review fixes):
npm test(noSUPABASE_*env, as in CI): 249 files, 3,365 tests passed;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