Skip to content

feat(action-center): detect platform and citation gaps - #826

Merged
gkhngyk merged 1 commit into
mainfrom
feature/gap-signals
Sep 22, 2026
Merged

gkhngyk merged 1 commit into
mainfrom
feature/gap-signals

Conversation

@gkhngyk

@gkhngyk gkhngyk commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Phase 3b of #818. Two detectors, and the definitions that consume them, for the two families that had one apiece.

platform_gap → Growth

A brand ranks well on one engine and poorly on another.

The gap alone is not the finding. Platforms differ for everyone — measured across live brands, the spread between a brand's best and worst engine averages 12 points — so reporting every gap would report the normal state.

What makes it actionable is the pair: visibility already proven achievable somewhere, and materially absent somewhere else. Without the proven half, a brand weak on every engine would be told it has a platform opportunity, when what it has is a visibility problem — a different signal, and a different action.

Gap threshold 20 points (average spread is 12)
Floor on the best engine 25%
Brands reported 4 of 19 comparable

competitor_citation_gap → Compete

A competitor cited by a multiple, not merely ahead.

Being behind on citations is ordinary: a competitor leads 13 of 20 brands in any given week. Being behind by a multiple says the gap will not close on its own and that there is a body of citations to go after.

The absolute floor keeps the multiple honest — twice as many can mean four against two, which is not a finding.

Multiple 2×
Absolute floor 20 citations
Brands reported 5 of 20

The definitions

expand_platform_visibility gives Growth a second definition. close_citation_gap gives Compete one — deliberately distinct from close_competitor_gap, which is about who ranks; this one is about who gets cited, and earning references is not the same work as ranking answers.

Definitions go from 6 to 8. Growth and Compete each have two.

Structure

Both decisions sit in exported pure functions rather than inside the fetch that feeds them, following classifyVisibilityFall from the previous phase. The fetch gathers; the function decides; the test exercises the decision without a database.

Ten tests pin the boundaries. The two that matter most are the silences:

proven high, weak engine       -> platform_gap (36pts)
typical spread (avg 12pts)     -> (silent)
weak everywhere                -> (silent)

competitor 3x ahead            -> citation_gap (100)
competitor slightly ahead      -> (silent)
tiny numbers, big multiple     -> (silent)

Calibration

Every threshold was measured against production before being chosen — the average platform spread, how often a competitor leads on citations, and the resulting signal volume for each candidate rule. The numbers in the tables above are counts from the live database, not estimates.

Related issue

Phase 3b of #818. Remaining in that phase: query fan-out coverage, third-party source presence, and entity consistency — all three need data the product does not collect yet, so they wait behind that collection rather than behind this PR.

Country-level gap detection stays dropped: exactly one brand tracks two or more regions.

Type of change

  • feat — New feature

Database

None.

How to test

cd server && yarn test   # 465 passing, 10 of them new

The classifiers are pure, so the boundaries are directly checkable:

  1. Three engines where the best clears 25% and the worst is 20+ points behind reports platform_gap; a typical 12-point spread reports nothing.
  2. A brand weak on every engine reports nothing, whatever the spread.
  3. A competitor with twice the citations and at least 20 more reports competitor_citation_gap; a competitor merely ahead reports nothing.
  4. On the next nightly run, each signal consolidates into its action — expand_platform_visibility under Growth, close_citation_gap under Compete.

Checklist

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

🤖 Generated with Claude Code

https://claude.ai/code/session_01SQ2H6mSd9JDpmqonk2VWBj

Phase 3b of #818. Two detectors, and the definitions that consume them, for
the two families that had one apiece.

`platform_gap`. A brand ranks well on one engine and poorly on another. The
gap alone is not the finding — platforms differ for everyone, and the spread
between a brand's best and worst averages 12 points across live brands, so
reporting every gap would report the normal state. What makes it actionable is
the pair: visibility already proven achievable somewhere, and materially
absent somewhere else. Without the proven half, a brand weak on every engine
would be told it has a platform opportunity when what it has is a visibility
problem — a different signal, and a different action. Twenty points above a
floor of twenty-five reports about one brand in five.

`competitor_citation_gap`. A competitor cited by a multiple rather than merely
ahead. Being behind on citations is ordinary: a competitor leads two thirds of
brands in any given week. Being behind by a multiple says the gap will not
close on its own and that there is a body of citations to go after. The
absolute floor keeps the multiple honest — twice as many can mean four against
two, which is not a finding. Reports about one brand in four.

`expand_platform_visibility` gives Growth a second definition, and
`close_citation_gap` gives Compete one. The second is deliberately distinct
from close_competitor_gap: that one is about who ranks, this one about who
gets cited, and earning references is not the same work as ranking answers.

Both decisions sit in exported pure functions rather than inside the fetch
that feeds them, following classifyVisibilityFall from the previous phase.
Ten tests pin the boundaries — including the two cases that matter most, a
typical spread staying silent and a large multiple over small numbers staying
silent.

Every threshold was measured against production before being chosen: the
average platform spread, how often a competitor leads on citations, and the
resulting signal volume for each rule.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01SQ2H6mSd9JDpmqonk2VWBj
@gkhngyk
gkhngyk merged commit 24baee6 into main Sep 22, 2026
6 checks passed
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]>
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