Skip to content

feat(action-center): give a finding somewhere to wait - #831

Merged
gkhngyk merged 1 commit into
mainfrom
feature/action-candidates
Sep 25, 2026
Merged

gkhngyk merged 1 commit into
mainfrom
feature/action-candidates

Conversation

@gkhngyk

@gkhngyk gkhngyk commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

Summary

Phase 6 of #818. Findings the engine cannot act on yet stop disappearing.

One active action per definition is the right rule — nobody should be handed
the same piece of work twice — but it left a second finding nowhere to go.
Phase 1 stopped such a finding corrupting the open action's scope; it did not
stop it being lost. A condition detected while the slot was busy was linked
as evidence and then forgotten, because the next cycle is built from whatever
happens to be open on the night the slot frees up. Anything that resolved in
between was never worked on at all.

Two questions, answered separately

What did we find? writes a candidate for every definition that matched, every night, whether or not anything can be done about it
What should we act on? promotes from that queue — subject to the slot, the rest window, eligibility and the daily cap

Three things still stop a candidate becoming an action — ineligible,
resting, capped — and none of them loses the finding any more. Each one
just leaves it waiting, and the waiting is what lifts it up the order.

The queue cannot drift

A candidate covers exactly the matched signals no action has claimed, and is
recomputed each night rather than accumulated. A signal that resolves leaves
the queue by itself; one the active action took as evidence is already
accounted for. Nothing has to be reconciled, because nothing is remembered
that could go stale — except first_seen_at, which is the one thing that
cannot be recomputed and the only thing that matters for priority.

Its lifecycle mirrors a signal's: waiting while its evidence is live, stale
when it is gone, back again if the condition returns. Stale rather than
deleted — a condition that returns comes back with a fresh clock rather than
inheriting the patience of a finding that ended.

Priority is scored, not sorted

Because a queue needs one thing a sort does not: age. The weights are in
config/action-engine.js and set so two rules hold, with the arithmetic as
the only thing enforcing them:

  • Nothing starves. A full two-week wait is worth 42 and the gap between
    low and medium is 35, so a low-impact finding that waited out the cap
    outranks a medium one detected tonight with comparable evidence.
  • A high-impact finding is never outranked. It sits at 200, out of reach
    of any wait and any amount of evidence (65 + 15 + 42 = 122 at most). A
    queue that lets forty pages of low-impact opportunity outrank a visibility
    collapse is not a priority order, it is a vote.

Both are asserted as tests rather than left as a comment, because the rules
live in four numbers that anyone may reasonably want to tune.

One bug worth naming

The scorer is defensive about its inputs on purpose. A missing signal count
produced NaN, which sorts as "no opinion" — the comparator returns NaN,
the sort leaves the array alone, and the queue silently becomes alphabetical.
The engine still promotes something every night, just the wrong thing, so
nothing looks broken. It happened once while this was being built and is now
covered by a test written for that exact shape.

Not in this PR

A view of the queue. The waiting list is in action_candidates and in
the nightly [actions] generated line, which now reports queued, waiting
and stale alongside created. Showing a brand what is waiting behind its
open actions is a real feature and a separate change — and one worth doing,
given that an invisible queue repeats in miniature the failure #829 fixed.

Related issue

Refs #818

Type of change

  • feat — New feature

How to test

cd server && yarn test     # 586 tests, 22 new

On the next nightly run, action_candidates gains a waiting row per
definition that matched, and the log line reports what was queued, promoted
and staled. A brand with an active recover_visibility action that detects a
new visibility problem gets a waiting candidate rather than silence.

Migration 00089 is applied to the hosted database.

Checklist

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

One active action per definition is the right rule — nobody should be handed
the same piece of work twice — but it left a second finding nowhere to go.
Phase 1 stopped such a finding corrupting the open action's scope; it did not
stop it being lost. A condition detected while the slot was busy was linked
as evidence and then forgotten, because the next cycle is built from whatever
happens to be open on the night the slot frees up. Anything that resolved in
between was never worked on at all.

The generator now answers two questions instead of one. What did we find
writes a candidate for every definition that matched, every night, whether or
not anything can be done about it. What should we act on promotes from that
queue, subject to the slot, the rest window, eligibility and the daily cap.
None of those loses the finding any more; each one just leaves it waiting.

A candidate covers exactly the matched signals no action has claimed, and is
recomputed each night rather than accumulated: a signal that resolves leaves
the queue by itself, and one the active action took as evidence is already
accounted for. The queue therefore cannot drift out of step with what is true
tonight. Its lifecycle mirrors a signal's — waiting while the evidence is
live, stale when it is gone, back again if the condition returns.

Priority is scored rather than sorted, because a queue needs one thing a sort
does not: age. The weights are set so two rules hold, and the arithmetic is
what enforces them:

- nothing starves. A full two-week wait is worth 42 and the gap between low
  and medium is 35, so a low-impact finding that waited out the cap outranks
  a medium one detected tonight with comparable evidence.
- a high-impact finding is never outranked. It sits at 200, out of reach of
  any wait and any evidence (122 at most). A queue that lets forty pages of
  low-impact opportunity outrank a visibility collapse is not a priority
  order, it is a vote.

The scorer is defensive about its inputs on purpose: a missing signal count
produced NaN, which sorts as "no opinion" and silently degraded the whole
queue to alphabetical order. It was caught by a test written for exactly that
shape, having already happened once while this was being built.

No UI yet. The queue is visible in the nightly log line and in the table;
showing a brand what is waiting is a separate change.

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 mentioned this pull request Sep 25, 2026
33 of 37 tasks
@gkhngyk
gkhngyk merged commit 1855e36 into main Sep 25, 2026
6 checks passed
@gkhngyk
gkhngyk deleted the feature/action-candidates branch September 25, 2026 17:10
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