Skip to content

fix(signals): stop the nightly pass dying on the brands that need it most - #829

Merged
gkhngyk merged 1 commit into
mainfrom
fix/signal-recording-timeout
Sep 25, 2026
Merged

gkhngyk merged 1 commit into
mainfrom
fix/signal-recording-timeout

Conversation

@gkhngyk

@gkhngyk gkhngyk commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

Summary

The Action Center stopped producing actions on the largest brand six days ago,
while its tracking ran and stamped every night. Two bugs, one visible symptom.

What was happening

recordSignalsForBrand calls computePulseMetrics. Two of that function's
aggregate RPCs — ai_visibility_aggregates and insights_aggregates —
rescan every result the brand has ever collected. Past roughly 25k results
that exceeds PostgREST's 8s statement timeout.

Reproduced against production, read-only:

pulse rpc timed out, retrying   (ai_visibility_aggregates, ×4)
OK in 102825 ms
totalResults: 28074
warnings:   lost_citations ×5
highlights: prompt_gain ×3

The detectors had real findings every one of those nights. None of them ever
reached a signal row: the pass threw, its .catch logged, the night was gone,
and nothing on the page said why.

The daily pulse shares that same function and survived it, because the pulse
has retries and a catch-up sweep. Signal recording had the retries and
nothing else, so a failed night was permanently lost.

It was not one brand. Counting brands whose nightly run stamped but which
left no trace at all in the signals table that day:

day brands with a stamped run no trace
Sep 19 23 16
Sep 20 23 16
Sep 21 23 14
Sep 22 22 14
Sep 23 23 16
Sep 24 23 10
Sep 25 23 1

That is the ground every detector threshold in #818 was calibrated against.

Fix 1 — read the wide windows from the rollups

Exactly what #824 did for the competitor comparison, for the same reason. A
window measured in days is now expressed in whole UTC days and answered from
the daily rollup tables (00066), whose cost scales with days in the window
rather than with accumulated history. The day convention matches
deltaDayWindows in the dashboard, so a comparison the pulse reports covers
the same days as the one the user reads on Insights.

The 24-hour window deliberately stays on the raw RPCs: it is anchored to the
tracking-run ledger rather than to midnight, so no whole-day window can
express it, and it is cheap for precisely the reason the wide ones are not.

Same brand, same window, after:

elapsed_ms: 14272
totalResults: 12384 | weekRate: 18.2 | prevWeekRate: 17.9 | weekTrend: 0.3
warnings:   lost_citations ×5
highlights: prompt_gain ×3

Same findings, no statement timeouts. Per-RPC, on that brand:

RPC before after
ai_visibility_aggregates 8s timeout, every call 225 ms
insights_aggregates 8s timeout 70 ms
visible_prompt_stats — 100 ms
tracked_prompt_count — 101 ms
prompt_visibility_summaries stays raw (no rollup exists) 336 ms

Fix 2 — a pass that can be asked whether it ran

signal_runs (migration 00087) holds one row per finished pass, keyed to
the tracking run it covered. A nightly sweep re-runs every stamped run that
has no row.

The row is written last and only on success, so a pass that threw is exactly
what the sweep finds. A deliberate no-op — a run with no fresh results — logs
skipped, so the sweep does not retry the same empty night every morning.

This is the counterpart of what the pulse has had since #702. It also makes
"did the pass run last night?" a question the database can answer; this week
it could only be inferred, which is why the failure ran for six days.

Related issue

Refs #818

Type of change

  • fix — Bug fix

How to test

cd server && yarn test     # 519 tests, 17 new

On the next nightly run: signal_runs gains a row per brand, and the sweep
reports [signals] catch-up sweep completed with what it recovered. The
brands in the table above pick their signals back up on that run.

Migration 00087 is applied to the hosted database.

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

…most

The Action Center went stale on the largest brand: no new action for six
days, while its tracking ran every night and stamped every night.

`recordSignalsForBrand` calls `computePulseMetrics`, and two of that
function's aggregate RPCs rescan every result a brand has ever collected.
Past roughly 25k results they cross PostgREST's 8s statement timeout. On the
largest brand they crossed it on every call — reproduced against production:
103 seconds, four statement timeouts, two retries exhausted. The pass threw,
the `.catch` logged, and the night was gone. Nothing said so; the page simply
showed week-old work.

The pulse shares that function and survived, because it has retries AND a
catch-up sweep. Signals had the retries and nothing else, so a lost night was
lost permanently.

Both halves are fixed.

Windows measured in days now read from the daily rollups (00066), which is
what the dashboard already does for the same reason (#824) — so they are
expressed in whole UTC days, on the convention the dashboard's own delta math
uses. The 24-hour window stays raw: it is anchored to the tracking-run ledger
rather than to midnight, and it is cheap for the same reason the wide ones
are not. Same brand, same window, after: 14 seconds, no statement over 336ms,
and the same warnings and highlights out the other end.

`signal_runs` records one row per finished pass, and a sweep re-runs whatever
stamped but has no row. The row is written last and only on success, so a
pass that threw is exactly what the sweep finds. It also answers a question
that had no answer this week: did the pass run last night? Across 23 brands
it had left no trace on 14 to 16 of them on most recent nights, which is the
ground every detector in #818 was calibrated on.

Refs #818

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01SQ2H6mSd9JDpmqonk2VWBj
@github-actions github-actions Bot added the needs-migration Adds or edits a migration — apply it to the hosted database label Sep 25, 2026
@gkhngyk
gkhngyk merged commit 03ec2ed into main Sep 25, 2026
6 checks passed
@gkhngyk
gkhngyk deleted the fix/signal-recording-timeout branch September 25, 2026 15:48
gkhngyk added a commit that referenced this pull request Sep 26, 2026
…f it (#833)

Phase 5 marked every task with who could carry it out and whether carrying it
out reaches outside Ansvisor. Nothing acted on either. This is the layer that
does, under four rules:

Nothing reaches outside except through a tool. The registry is the enumerable
surface, and arguments are built from the action's own payload — no query, no
URL and no property id comes from anywhere a model could reach, the same rule
the analytics sync already follows and the reason this layer can be audited.

Nothing changes outside Ansvisor without approval. A tool that writes to a
third-party system is blocked until a person authorises that task, and the
authorisation is recorded on the task rather than inferred from whoever
triggered the run. Reading a system the brand connected is not a change and
needs no approval: asking for one before every read teaches people to approve
blindly. No shipped tool writes externally yet, so the gate currently holds
nothing back — it is enforced and tested now rather than written later under
deadline.

Every attempt is recorded: inputs, the tool, its result, any error. Never the
model's reasoning. That is not evidence, it is not reliable as explanation,
and storing it invites people to read it as both. Anything a run wants to
claim it claims in `output`, where the next task reads it.

A failed run fails its task, not its action. A tool that throws costs one
step; the action stays open and somebody does that step by hand.

Two tools ship. `visibility_window` reads our own rollups; `ga_traffic_window`
reads the brand's analytics property through the connection they authorised —
live rather than from `ga_page_stats`, because that table stores the top pages
of each day and truncates, which is the right trade for a dashboard and the
wrong one for a measurement of specific pages. Verified against production:
the analytics tool returned 748 sessions against 722 the week before, across
199 pages, in 2.5s.

Fourteen agent-mode tasks still have no tool. The runner says so by name
rather than improvising, which is the difference between an honest gap and a
silent one.

Deliberately not wired to the nightly cron. The engine that produces these
tasks spent six days failing silently before anyone noticed (#829); an
execution layer that runs unattended belongs after the verification that the
thing it executes for is running at all. `src/scripts/run-action-task.js`
invokes it deliberately, and `--dry` reports why a task would not run.

Refs #818


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

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
gkhngyk added a commit that referenced this pull request Sep 26, 2026
#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


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

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
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

needs-migration Adds or edits a migration — apply it to the hosted database

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant