Skip to content

feat(action-center): make a definition a file, not a line in the engine - #827

Merged
gkhngyk merged 1 commit into
feature/gap-signalsfrom
feature/action-definition-registry
Sep 22, 2026
Merged

gkhngyk merged 1 commit into
feature/gap-signalsfrom
feature/action-definition-registry

Conversation

@gkhngyk

@gkhngyk gkhngyk commented Sep 20, 2026

Copy link
Copy Markdown
Contributor

Summary

Phase 4 of #818. Definitions leave the engine.

The eight action definitions lived in one array inside generate.js, with
their payload shaping in a switch beside it. That is fine at eight and
impossible at the sixty-two the plan calls for: every new definition means
editing the matching engine, and a mistake in one breaks the others.

Each definition is now a file in server/src/lib/action-center/definitions/,
carrying its own category, signal kinds, task list, payload shaping, version,
and the data a brand must have for it to apply. The registry discovers them by
listing the directory and validates each on load. The engine no longer knows
any definition by name.

Adding a definition is now: add a file.

Discovery over a manifest

A manifest of imports is one more place to forget, and forgetting it fails
silently — the definition simply never fires. A directory listing plus strict
validation fails loudly instead, at startup, with the filename in the message:
an unknown category, a version that is not a positive integer, a source that
does not exist, a missing payload function. A test asserts the rest — unique
ids, reproducible order, no two definitions consuming the same signal kind,
and that every signal kind a definition listens for is one a detector actually
emits. That last one is the quiet failure worth catching: a definition naming
a kind nothing produces would simply never fire, and nothing would say so.

Eligibility

A definition declares the sources it requires and the ones that merely enrich
it. sources.js answers, per brand, what is actually available: tracking
(always), competitors, site audits, an analytics connection.

Measured over the live database before writing it:

source brands of
tracking 151 151
competitors 126 151
site audits 20 151
analytics 7 151

And against the actions already raised: none of the 28 would have been
blocked by eligibility.
That is the expected result and the reason the check
is worth having anyway. A brand with no competitors never receives a
competitor signal, so the definition would not have matched regardless — but
today that is a coincidence of how the detectors happen to work, and the
declaration makes it a contract. Phase 5's task planner reads the same answer
to give two brands different plans for the same action kind, which is why it
is computed once here rather than inferred twice.

Eligibility gates opening a cycle, never maintaining one: a brand that
disconnects an integration mid-cycle keeps the action it was already given.

The daily cap

Five new actions per brand per day. It binds on nothing today — eight
definitions produce at most three on a brand's busiest day, because a brand
rarely has more than a couple of distinct conditions firing at once:

new actions in one day brand-days
1 12
2 5
3 2

The ceiling is the definition count, and the plan takes that to sixty. At that
point a bad night hands someone a list nobody reads, and the engine talks its
way out of being believed. Anything over the line is not lost: the condition
is still firing, so the slot reopens tomorrow, in priority order — impact
first, then weight of evidence. Phase 6 replaces that ordering with scoring
across candidates; with eight definitions there is nothing yet for a score to
say that this does not.

The budget is the day's, not the run's, and it is counted from rows the
generator already fetches rather than from a separate query. An action raised
this morning and dismissed by lunch still spent its slot — the brand was told
about it.

Definition versions

actions.definition_version (migration 00086) records which version of a
definition raised an action. Nothing reads it yet; recording it costs a
column, and reconstructing it later would cost the history. Without it,
History re-reads its own past against today's rules every time a definition
is tuned — the same reasoning as resolving a task's text at creation (00083).

Web: an unknown kind is shown, not hidden

getActions and getActionHistory filtered out any row whose kind this
build did not recognise. That filter was the last thing making a server-side
definition useless until the web shipped too, and it was hiding a worse
problem: an unrecognised kind would have crashed the icon lookup and the text
switch rather than skipping them.

An action this build has no copy for is now presented from its id and its
family — expand_platform_visibility reads as "Expand platform visibility",
the icon falls back to the category's, and the description and goal come from
one generic string. Written copy still wins wherever it exists. Retiring the
filter is what lets the two sides move on separate release cycles, which is
the whole point of the registry.

Related issue

Refs #818

Type of change

  • feat — New feature
  • refactor — Code change that neither fixes a bug nor adds a feature

How to test

cd server && yarn test          # 502 tests, 37 new
cd web && yarn test && yarn typecheck && yarn lint && yarn build

The behaviour to look for on the next nightly run: the [actions] generated
log line now reports ineligible and capped alongside created,
refreshed and resting, and new rows carry definition_version.

Migration 00086 is applied to the hosted database.

Based on feature/gap-signals (#826), which is not merged yet — the
registry covers all eight definitions including the two that PR adds. GitHub
will retarget this to main once #826 lands.

Checklist

  • Branch follows the naming convention (feature/)
  • 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

🤖 Generated with Claude Code

https://claude.ai/code/session_01SQ2H6mSd9JDpmqonk2VWBj

The eight action definitions lived in one array inside the generator, with
their payload shaping in a switch beside it. Fine at eight; impossible at
the sixty-two the plan calls for, where every new definition means editing
the engine and a mistake in one breaks the others.

Each definition is now a file in definitions/, carrying its own category,
signal kinds, task list, payload shaping, and the data a brand must have for
it to apply. The registry finds them by listing the directory and validates
each on load, so a malformed file fails at startup with its filename rather
than going quiet forever. The engine no longer knows any definition by name.

Three things now stop an action being raised, counted separately so a quiet
night is legible:

- the brand lacks the source the definition needs. Declared per definition
  and resolved once per brand; of the 28 actions already raised, none would
  have been blocked by it, which is the point — it makes the data contract
  explicit without taking anything away.
- the last cycle closed too recently (unchanged).
- the brand has had its day's worth. Five new actions per brand per day, a
  ceiling that binds on nothing today — eight definitions produce at most
  three on a brand's busiest day — and exists for the count the plan is
  heading towards. What is over the line is not lost: the condition is still
  firing, so the slot reopens tomorrow, highest impact first.

Actions now record the version of the definition that raised them, so one
raised in March can still be read against the rules that raised it rather
than against today's.

Web side: an action whose kind this build has no copy for is presented from
its id and its family instead of being dropped. That filter was the last
thing making a server-side definition useless until the web shipped too —
and an unknown kind would have crashed the icon lookup rather than skipping
it. Retiring it means the two sides can now move separately, which is what
the registry is for.

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 20, 2026
@gkhngyk
gkhngyk merged commit 6b9fe42 into feature/gap-signals Sep 22, 2026
6 checks passed
@gkhngyk

gkhngyk commented Sep 22, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by #828. This branch was based on feature/gap-signals and merged into it rather than into main — by then #826 had already been squash-merged, so the commit landed on a branch that no longer leads anywhere and none of this reached main. #828 is the same commit cherry-picked onto main.

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