Repository navigation
feat(action-center): make a definition a file, not a line in the engine - #827
Merged
Merged
Conversation
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
8 tasks done
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Phase 4 of #818. Definitions leave the engine.
The eight action definitions lived in one array inside
generate.js, withtheir payload shaping in a
switchbeside it. That is fine at eight andimpossible 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.jsanswers, per brand, what is actually available: tracking(always), competitors, site audits, an analytics connection.
Measured over the live database before writing it:
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:
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(migration00086) records which version of adefinition 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
getActionsandgetActionHistoryfiltered out any row whosekindthisbuild 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_visibilityreads 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 featurerefactor— Code change that neither fixes a bug nor adds a featureHow to test
The behaviour to look for on the next nightly run: the
[actions] generatedlog line now reports
ineligibleandcappedalongsidecreated,refreshedandresting, and new rows carrydefinition_version.Migration
00086is applied to the hosted database.Based on
feature/gap-signals(#826), which is not merged yet — theregistry covers all eight definitions including the two that PR adds. GitHub
will retarget this to
mainonce #826 lands.Checklist
feature/)yarn lintpasses (run fromweb/)yarn typecheckpasses (run fromweb/)yarn format:checkpasses (run fromweb/)🤖 Generated with Claude Code
https://claude.ai/code/session_01SQ2H6mSd9JDpmqonk2VWBj