Skip to content

fix(signals): move the last raw aggregate call off the raw scan - #834

Merged
gkhngyk merged 1 commit into
mainfrom
fix/citation-gap-timeout
Sep 26, 2026
Merged

gkhngyk merged 1 commit into
mainfrom
fix/citation-gap-timeout

Conversation

@gkhngyk

@gkhngyk gkhngyk commented Sep 26, 2026

Copy link
Copy Markdown
Contributor

Summary

#829 moved the nightly path's wide windows onto the daily rollups, because
ai_visibility_aggregates rescans everything a brand has ever collected and
crosses the database's 8s statement timeout once a brand is large enough.

It missed one call site. The competitor citation gap detector, added in
#826, has its own direct call — and it is worse placed than the ones that were
fixed. The pulse reads through a helper that retries a timeout; this called the
client directly, so the first timeout threw and took the whole nightly pass
with it.

Measured on the largest brand this morning:

raw ai_visibility_aggregates    8174ms  ERROR: canceling statement due to statement timeout
rollup variant                   131ms  ok

How it showed up

Last night was the first run with #829, #830 and #831 live, and it went well
everywhere except one place:

Passes recorded 44 — 22 recovering the previous night through the new catch-up sweep, 22 from the runs themselves
Brands with no pass 1

That one brand is the brand #829 was written for. It recorded no pass for the
same reason as before, one layer further in. Its last signal is still six days
old.

The guard

A grep test now checks that no module in the nightly path calls the three raw
aggregate RPCs by name. It allows the routed daily(name, window) form, which
picks the rollup for a whole-day window and the raw RPC only for the 24-hour
run-anchored one that no day window can express.

A grep is a blunt instrument and I would not normally add one. It is here
because the alternative — a convention held by comments — failed twice from
the same cause, the second time after being written down. It is verified
against the exact regression: restoring the old call makes it fail.

Also

The platform gap detector read up to 20,000 rows and judged whatever came
back. The largest brand uses 8,032 of that, so nothing is truncated today —
but a brand that reached the ceiling would have had its platform rates
computed from an arbitrary subset and reported a gap that was an artefact of
where the read stopped. It now logs and declines rather than answering
confidently from part of the data.

Related issue

Refs #818

Type of change

  • fix — Bug fix

How to test

cd server && yarn test     # 609 tests, 6 new

The affected brand picks its signals back up on the next nightly run, or
immediately via node src/scripts/backfill-signals.js <brandId>.

No migration.

Checklist

  • Branch follows the naming convention (fix/)
  • Commits follow Conventional Commits
  • yarn lint passes
  • yarn format:check passes
  • Changes are focused — one concern per PR

🤖 Generated with Claude Code

https://claude.ai/code/session_01SQ2H6mSd9JDpmqonk2VWBj

#829 moved the nightly path's wide windows onto the daily rollups because
`ai_visibility_aggregates` rescans everything a brand has ever collected and
crosses the database's 8s statement timeout once a brand is large enough. It
missed one call site — the competitor citation gap detector, added in #826
with its own direct call.

That site was worse placed than the ones that were fixed. The pulse reads
through a helper that retries a timeout; this called the client directly, so
the first timeout threw and took the whole nightly pass with it. On the
largest brand it did so every night: 8.2s to fail here against 0.13s to
succeed from the rollup.

The visible result was that the brand #829 was written for still had no
signals this morning, on the first night the fix was live. Twenty-two brands
recorded a pass; this one recorded none, for the same reason as before, one
layer further in.

A grep test now guards the convention, because the alternative failed twice.
It checks that no module in the nightly path calls the three raw aggregate
RPCs by name, allowing the routed `daily(name, window)` form that picks the
rollup for a whole-day window and the raw RPC only for the 24-hour
run-anchored one that no day window can express. Verified against the exact
regression: restoring the old call fails it.

Separately, the platform gap detector read up to 20,000 rows and judged
whatever came back. The largest brand uses 8,032 of that, so nothing is
truncated today — but a brand that reached the ceiling would have had its
platform rates computed from an arbitrary subset and reported a gap that was
an artefact of where the read stopped. It now says so and declines rather
than answering confidently from part of the data.

Refs #818

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01SQ2H6mSd9JDpmqonk2VWBj
@gkhngyk
gkhngyk merged commit a77eda5 into main Sep 26, 2026
6 checks passed
gkhngyk added a commit that referenced this pull request Sep 26, 2026
…ons (#839)

The V1 specification asks for 62 action definitions (19 Growth, 10 Protect,
11 Recover, 13 Fix, 9 Compete) and a shared library of 62 task primitives.
The seven phases of #818 built the engine and stopped at 8 definitions and 24
tasks, on a decision — add definitions as their detectors land — that was
never put to the person who wrote the specification. This delivers the
library.

Definitions. All 62 are registered, with the specification's stable codes
(G01…C09), signal mappings, required and optional sources, and the task plan
the Task Library specification gives each. 58 are enabled. Four stay
registered but off, each saying which data it is waiting for: brand
associations and brand-information consistency need attribute extraction the
product does not do (and the specification rules out an LLM judging truth);
organic-page expansion needs page-level Search Console data, which the sync
does not store; broken citation targets need URL health checks, which do not
exist.

Detectors. 47 new signal kinds across twelve families, each reading a
compact summary through a new `ae_*` Postgres function rather than scanning
from the server — the shape that took the nightly pass down twice (#829,
#834). Every read was measured on the largest brand; the slowest runs in
1.6s. Each family is isolated: a failed read costs that family's signals for
the night, and its kinds are reported unread so the recorder does not take
the silence for recovery. Three conditions I earlier said had no data do:
fan-out queries are stored on every result, entity signals are Site Audit
checks, and Search Console queries are synced.

Tasks. The 62 primitives, in the specification's vocabulary — SYSTEM, AGENT,
HUMAN, HUMAN_OR_AGENT; READ, WRITE, EXECUTE — with its dependency rules and
structured outputs. Plans branch the way the specification says: an existing
page is optimised, a missing one is briefed and drafted, never both.
Publishing falls to a person when no publishing tool exists, rather than
blocking the action. The 23 tasks raised before the library remain resolvable
and runnable; no definition may plan them.

Titles name their targets throughout — actions, tasks and signals — per the
specification: "Recover lost citations on 7 prompts", not "Recover
citations".

Dry run across the 23 brands tracked in the last two days, before any write:
267 definitions have a finding, and tonight opens 110 actions, five per brand
— the specification's daily limit. The rest queue and open as slots free.

Two things done carefully. The signal categories are pinned to the database
check constraint by a test, because one rejected insert throws a brand's
whole pass. And the task vocabulary migration was applied before this code
is deployed, so a transition migration keeps the old values valid until it
is; a follow-up drops them.

Refs #818


Claude-Session: https://claude.ai/code/session_01SQ2H6mSd9JDpmqonk2VWBj

Co-authored-by: Claude Opus 5.5 <[email protected]>
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