Skip to content

feat(audit): re-audit first the pages fixed through the Action Center, on the brand's own domains (learning B7) - #1698

Merged
gkhngyk merged 8 commits into
ansvisor:mainfrom
cihan-gyk:feature/reaudit-fixed-pages
Oct 28, 2026
Merged

gkhngyk merged 8 commits into
ansvisor:mainfrom
cihan-gyk:feature/reaudit-fixed-pages

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

Learning B7: a page fixed through the Action Center is re-audited first in the next auto-audit run.

A fix's result needs the fixed page audited again (A2, #1689). Until now, the auto-audit run took pages only from its inbox, so a fixed page could wait up to a month.

fixedPages(brands, now) (auto-audit-sweep.js) collects pages to re-audit:

  • Source: the target pages of category = 'fix' actions completed in the last 30 days (payload.targets[].id and http(s) targetIds). Deleted actions are left out.
  • Only pages on the action's own brand's domains (brand_domains + onBrandDomain); a brand with no domain gives none. Site Audit accepts any address, so a competitor page someone audited for comparison could otherwise have been re-audited on the customer's quota.
  • Excluded pages stay out, as the inbox's rules do: site_audit_page_prefs marked excluded, and site_audit_brand_settings.exclude_patterns unless the page is pinned. The guide says excluded pages stay out of auto-audits.
  • Each page counts for its latest fix; the newest fix comes first.
  • A page drops out once it's been audited or tried since its fix (by url or final_url). The audits are read in pages (readAllRpcRows), so nothing is cut at 1,000 rows.
  • Keys are brand|page, so brands that share a domain don't close each other's fixes.
  • At most 20 pages per action, applied after the pages already audited are left out.

pickRunPages(…, fixed) (auto-audit.js):

  • Fixed pages go first and take up to half the run's slots, rounded up (5 slots → 3; a 1-slot run takes the fixed page).
  • The 30-day rest and the tried-lately list don't apply to them. A page being audited right now is skipped.
  • The remaining slots fill from the inbox as before (pinned first, then priority).
  • If the fixed pages can't be read, the run goes on from the inbox, as before.

Cost: within the auto-audit's existing quota. Nothing new is spent; only the order changes. Ended plans don't run auto-audits (#1608).

Pre-push review fixes:

  • 5722ff6: own domains only.
  • bca9e47: exclusions.
  • d7bf911: brand-keyed maps.
  • bb513b7: paged audit read.
  • 02ecde1: the cap applied after the audited pages are left out.
  • e1cc04a: guide and comments.
  • 62b0ccf: tests for the failed read, final_url, address variants (www, trailing slash, http/https, query, #) and rounding.

Merge after #1689 (A2): the guide's sentence "so the action's result says whether the fix took" is true only once A2 judges a fix by its re-audited pages.

Where people see it:

  • Site Audit › Pages: a fixed page is audited again in the next automatic run (day 1/7/14/21/28), shown as "Auto" in Last audit.
  • With A2, Action Center › History's "Audited again since it closed" line fills within a week instead of a month.

No new button.

Related issue

Agentic learning report, phase B (B7). No GitHub issue.

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/audit/auto-audit.test.js src/lib/audit/auto-audit-sweep.test.js

The tests cover:

  • a competitor address dropped, a subdomain kept, and a brand with no domain;
  • excluded pages and patterns, with a pinned page kept;
  • two brands sharing a domain;
  • 1,001 audits read in two pages;
  • the cap of 20 after audited pages;
  • the failed read;
  • address variants and rounding.

The original query was run read-only against the dev database.

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

Server checks at 62b0ccf:

  • format, lint and npm test (no SUPABASE_* env, as in CI): 3,350 tests passed;
  • content-agent.test.js' timing test ran over under load and passed alone.

The web is unchanged (docs only). The first commit uses the scope site-audit; the rest use audit, the repo's usual scope.

🤖 Generated with Claude Code

cihan-gyk and others added 8 commits October 28, 2026 10:08
…its fix is completed

Learning B7. A page an Action Center fix was completed on waited out the
auto-audit's 30-day rest like any other, since its last audit was the one
that found the issue, so whether the fix took was read a month late, if at
all.

- fixedPages: the pages named by fix-category actions completed in the
  last 30 days (their targets' addresses, deleted actions left out, the
  newest fix first) that no audit has read since the fix.
- pickRunPages takes them first, up to half the run's slots (rounded up),
  past the 30-day rest and the tried-lately list; a page being audited is
  left. The rest of the run is the inboxes', as before. A read that fails
  leaves the run as it was.
- The Site Audit guide says so.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A fix action's targets were taken whenever they were http(s) addresses, so
a competitor's page or any other site named by a fix could be audited at
the org's cost. fixedPages now reads brand_domains for the run's brands in
one query and keeps a target only when it is on its action's brand's
domains or a subdomain of one (onBrandDomain); a brand without a domain
offers none. With no fix completed lately, nothing more is read.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The Site Audit guide says excluded pages stay out of Opportunities and
auto-audits, but a fixed page skipped both of the inbox's filters. fixedPages
now reads site_audit_page_prefs (every row, past PostgREST's 1000-row page)
and site_audit_brand_settings for the run's brands, and leaves out a page the
brand excluded, or one under its exclude patterns unless pinned, as the inbox
does. Prefs and patterns are the action's own brand's.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… pages

fixedPages keyed its pages and their last audits by the page alone, so when
two brands of an org share a domain one brand's audit counted for the
other's fix, and one brand's fix hid the other's (the action's result, A2,
reads only its own brand's audits). Pages, prefs and audits are now keyed by
the brand's page (runPageKey, `brandId|key`), the audits read with their
brand. pickRunPages keys its taken and running sets the same way, so one
brand's fixed page neither takes nor skips another brand's inbox row.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…xed pages

The audits since the oldest fix were read in one request, without an order,
so past PostgREST's 1000 rows the rest were dropped without an error and a
page audited since its fix could be taken again. They are now read through
readAllRpcRows, ordered by created_at and id, a slice at a time.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…d ones

FIXED_PER_ACTION (20) cut a fix's targets before the pages audited since
the fix (and the excluded ones) were left out, so a fix of 25 pages whose
first five were audited offered 15, not 20. The cap now counts only the
pages still due, each counted for its newest fix.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The Site Audit guide said fixed pages take "up to half its pages"; they
take up to about half the run, rounded up, and only pages of the brand's
own site. The headers of auto-audit.js and auto-audit-sweep.js now name the
fixed pages a run takes first, and the comments say "not audited or tried
since": any audit of the brand's counts, finished or not.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ariants and rounding

- A fixedPages read that fails leaves the run to the inboxes, as before.
- An audit counts for a fixed page by the address it ended at (final_url).
- www, a trailing slash, http or https, a query or a fragment name the same
  page, both among a fix's targets and in the audits since.
- A five-page run gives fixed pages three slots: half, rounded up.

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 62b0ccf.

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.

Own change. b8f706d through 62b0ccf on 3f6a4d4. Server and docs only. It merges cleanly on main (b591947), and with #1687–#1689 squashed before it. No code depends on #1689; as you say, merge it after #1689 so the guide's "so the action's result says whether the fix took" is true when it ships.

Checked

  • Which pages. Completed, non-deleted fix actions of the run's own brands from the last 30 days; their targets[].id and http(s) targetIds; kept to the action's brand's domains with onBrandDomain (a brand with no domain gives none); excluded pages and exclude patterns left out unless pinned, as the inbox does. Keys are brandId|page, so two brands on one domain don't close each other's pages.
  • When a page drops out. Any audit of the brand's created since the fix (finished or not, by url or final_url) takes it out, so a page that fails to audit isn't retried every run. The audits are read in pages, ordered by created_at and id, so the 1,000-row cut doesn't hide one.
  • The run. Fixed pages take at most half the slots, rounded up, then the inbox fills the rest as before; a page in both is taken once; a page being audited now is skipped. A failed read of fixed pages leaves the run to the inbox. Nothing is spent beyond the auto-audit's existing quota.
  • Tests. On this PR's tree, src/lib/audit passes (16 files, 199 tests). With main's auto-audit.js and auto-audit-sweep.js put back, 13 of the two files' tests fail.

Before the API deploy. Nothing changes; the sweep is server-only. The guide's new sentence goes out with the docs before the API does.

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