Skip to content

Action Engine — build plan and phase tracker #818

Closed

Description

@gkhngyk

Tracking issue for building out the Action Engine, from the V1 Action Engine specification and its companion Task Library specification.

It exists so the state of this work is answerable without reading the code or asking anyone: each phase has an exit condition that is measured, not judged, and the marker below moves as phases land.

📍 Where we are

The engine's seven phases are done, and the V1 library is in review (#839).

The phases built the engine. They did not deliver the specification's scope: they stopped at 8 definitions and 24 task primitives, on a decision — add definitions as their detectors land — that was never agreed with the specification's author, and this issue then said "all seven phases are done" as if the specification was delivered. It was not. #839 delivers it.

specification before #839 with #839
Action definitions 62 8 62 registered, 58 enabled
Task primitives 62 24 62 (+23 legacy, kept for old rows)
Signal kinds with a detector — 15 62
Task vocabulary SYSTEM/AGENT/HUMAN/HUMAN_OR_AGENT · READ/WRITE/EXECUTE manual/agent · none/approval spec vocabulary

The four registered but disabled, each waiting on data the product does not collect: G11 and F08 need attribute extraction from answers; G13 needs page-level Search Console data; F07 needs URL health checks.

Dry run before any write: across 23 tracked brands, 267 definitions have a finding and 110 actions open on the first night — five per brand, the specification's daily limit.

⚠️ Read the calibration note below before trusting any threshold in this issue.

Now Target
Action Definitions 62 registered, 58 enabled (#839) 62
Signal detectors registered 15 enough to trigger each enabled definition
Detectors that have actually fired 10 all of them
Protect family definitions 1 10
Outcome measurement built, waiting on its first window every closed action measured
Task planning planned per brand (#830) context-aware plan
Candidate layer queue + priority (#831) aggregating queue

Verified in production

The nightly run after #823 landed confirmed three phases at once:

  • sharp_drop fired for the first time in its existence — a 72% relative visibility loss that the old 15-point threshold would have passed over in silence. One signal across the whole customer base, which is the volume the calibration predicted.
  • Phase 1's central fix held. A signal detected two weeks after its action was opened attached to that action as evidence, logged a signals_linked event, and left the action's target scope untouched. No second action for the same kind; no rewrite of work someone may already be executing against.
  • Phase 2 correctly declined to measure. The one closed action shut two days ago, and its after-window has not elapsed. Waiting is the behaviour — measuring a window still in progress was the bug caught during that phase.

Already shipped: the Action Center itself (#808), its write-policy fix (#813), task editing (#814), the History tab (#815).

⚠️ The engine was not running on most nights — fixed in #829

Found while investigating why one brand had received no action for nine days.
The nightly signal pass calls computePulseMetrics, whose wide aggregate
queries rescan a brand's entire history; past roughly 25k results they exceed
the database's 8s statement timeout. The pass threw, its .catch logged, and
the night was lost — permanently, because unlike the daily pulse it had no
catch-up sweep.

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

Every calibration in phases 2.5 through 4 was measured against this. The
signal volumes each threshold was tuned to produce — "about four a week",
"roughly one brand in five" — were measured on nights when the engine ran for
a third of the brands. They are floors, not estimates, and every one of them
needs re-reading once a few complete nights exist.

#829 fixes both halves: the wide windows now read from the daily rollups (14s
where it was 103s, no statement over 336ms), and signal_runs records each
finished pass so a nightly sweep can re-run whatever failed. The first honest
night is the first run after that deploy.

The phases

Phases run in order. One PR per phase, and a phase is not started until the previous one's exit condition holds — then we look at the data before moving on.

Phase 1 — Data model correctness ✅ #819

The generator gives every action dedup_key = kind, so a brand holds at most one action per kind, forever. New signals overwrite the open action's payload, and a completed action is resurrected by setting its status back to new. That breaks four invariants at once: target scope expands silently, history is mutated, a definition cannot produce a second cycle, and no_improvement stores an outcome in the status column.

  • Partial unique index so the one-active-per-definition rule applies to open actions only
  • Remove the reopen branch — a closed action is immutable, a new cycle is a new row
  • Freeze an open action's target snapshot; new signals no longer rewrite it
  • Split outcome from status; migrate no_improvement rows
  • Task statuses: canceled → skipped plus failed, waiting_approval, and a stored skip reason
  • Resolve task text at creation so editing a template cannot rewrite history

Exit: a closed action stays closed and unchanged; a later signal of the same kind opens a new action beside it; outcome and execution status are separate columns.

Phase 2 — Validation loop ✅ #820

An action records its baseline when raised, but nothing re-reads those metrics afterwards. This is why History's Result column says "not measured": there is no "after". Until this lands, the product cannot show that its own recommendations worked.

  • Re-measure an action's success metrics after its validation window
  • Store the result as before/after/delta per metric
  • Derive Outcome from the measurement, never from task completion
  • Fill History's Result column and the drawer's metric cards from real numbers

Exit: a completed action shows a measured before/after in History, and an action whose metrics did not move reads No Meaningful Change while still being Completed.

Phase 2.5 — Centralised thresholds ✅ #821

Detection thresholds live inside individual detectors today. Manageable at 11; unmanageable at 40. Cheaper to move now than after Phase 3 multiplies them.

  • One configuration surface for decline thresholds, significance minimums, demand floors, validation windows, priority weights
  • System default → definition default, with room for a workspace override later

Exit: changing a detection threshold means editing configuration, not a detector.

Phase 3a — Visibility detectors and the Protect trigger ✅ #823

The real bottleneck. Writing a definition is easy; producing the signal that triggers it is the work. Protect has zero definitions because nothing detects early deterioration — only decline after the fact.

  • Early-deterioration detector, so the Protect family has something to fire on
  • Fix sharp_drop, which had never fired once — its 15-point threshold was unreachable for most brands
  • protect_visibility, the Protect family's first definition

Exit: met. Protect is no longer empty, and the Recover family has a working trigger for the first time.

Dropped from this phase: country-level gap detection. Exactly one brand in the database tracks two or more regions, so it would have been a detector for nobody. It returns when multi-region tracking is common enough to matter.

Phase 3b — Remaining detectors ✅ #826

  • Platform-level gap detection (24 brands track three or more platforms, so this one has a real population)
  • Competitor citation gap
  • Query fan-out coverage gaps
  • Third-party source presence and absence
  • Entity and brand-consistency signals

Exit: met for the families that have data. Growth gained expand_platform_visibility and Compete gained close_citation_gap, so every family now has at least one detector that can trigger it.

Deferred, not dropped: fan-out coverage, third-party source presence, and entity consistency all need data the product does not collect yet. They are collection work before they are detector work, and they return when the data exists.

Phase 4 — Definition registry, growth, and the daily cap ✅ #828

Rules live in a server-side array with their task lists fixed inline. Growing from 5 to 62 that way means editing one file 57 times and versioning nothing.

  • Registry with stable ids, versions, required and optional sources, eligibility
  • Historical actions keep the definition version that created them
  • Add definitions as their detectors land, rather than all at once
  • Cap new system-generated actions per brand per day, so the count rising with definitions does not become noise

Exit: met. a new definition can be added without touching the matching engine, Action Center, or any other definition; no brand receives more than the configured number of new actions in a day.

Definitions are one file each under server/src/lib/action-center/definitions/, found by listing the directory and validated on load. Eligibility is declared per definition and resolved per brand — measured across the live database, none of the 28 actions already raised would have been blocked by it, which is the point: it makes an existing coincidence into a contract, and phase 5's planner reads the same answer. The daily cap is 5, which binds on nothing today (the busiest brand-day produced 3) and exists for the count this plan is heading towards.

The web no longer hides an action whose kind it has no copy for — it presents it from its id and its family. That filter was the last thing making a server-side definition useless until the web shipped too.

Phase 5 — Task registry and planner ✅ #830

Every action of a given kind gets the same task list regardless of context, which is the thing both specifications explicitly rule out.

  • Shared registry of task primitives with stable ids and versions
  • Planner selecting tasks from the action's targets, available sources, and connected integrations
  • Execution mode, permission level, and dependencies on each task
  • Structured task outputs, so one task's result can feed the next
  • Target-aware task titles
  • State for third-party outreach: prepared, sent, accepted, placed — deferred: the product has no outreach feature, so this would be a schema for something that does not exist. It returns with the feature.

Exit: met. Verified against production sources — the same definition, two brands:

with analytics   analyze_losses -> measure_traffic_impact -> coverage_gaps
                 -> update_content -> internal_links -> validate
without          analyze_losses -> coverage_gaps -> update_content
                 -> internal_links -> validate

Of 151 brands: 7 have analytics connected, 20 have audits, 126 have competitors.

Phase 6 — Candidates and priority ✅ #831

With one action per definition and no queue, a signal about a target that is not already in the open action has nowhere to go. It currently overwrites. It should accumulate.

  • Candidate aggregation per definition, with its own lifecycle
  • Priority scoring across candidates
  • Daily promotion of the highest-priority candidates into new actions

Exit: met. A finding the engine cannot act on — because the slot is busy, the definition is resting, the brand lacks the source, or the day's cap is spent — is written to action_candidates as a waiting row and promoted when the slot reopens. Priority is scored rather than sorted, with weights set so nothing starves and nothing outranks a high-impact finding.

Follow-up worth doing: the queue has no UI. It is visible in the nightly log line and in the table, but a brand cannot see what is waiting behind its open actions — which repeats in miniature the invisibility that made #829 run for six days.

Phase 7 — Agent and tool execution ✅ #833, #835

Tasks will carry an execution mode from Phase 5, but nothing acts on it. This is the layer that does.

  • Agents reach external systems only through tools exposed by integrations
  • External writes require approval unless explicitly authorised
  • Inputs, tool calls, outputs and logs recorded; no hidden reasoning exposed
  • A failed tool run fails its task without failing the action

Exit: met, with two gaps stated rather than papered over.

Verified against production, read-only: ga_traffic_window reached the brand's own Analytics property through the connection they authorised and returned 748 sessions against 722 the week before, across 199 pages, in 2.5s. visibility_window read our own rollups in 0.5s.

  • Fourteen agent-mode tasks have no tool yet. The runner names the missing one rather than improvising. Tools arrive as each is worth building, the way detectors and definitions did.
  • No shipped tool writes externally, so the approval gate currently holds nothing back. It is enforced and tested now, against a stand-in, rather than written later under deadline against a real one.
  • No model in the loop. Both tools are deterministic. The runner, the audit trail and the gate are what a model-driven tool would need first, and they exist.

On the nightly cron since #835, bounded at 50 attempts a night. The blocker was not verification — both tools only read — but that a task the product completed looked identical to one a colleague had done. #835 writes every outcome a user needs to know into the action's own History trail.

Related, outside the phases

  • feat(mcp): expose the Action Center through the MCP server #832 — expose the Action Center through the MCP server. The MCP server's 23 tools cover visibility, prompts, topics, content and audits; none covers signals, actions, tasks or outcomes. An agent connected to Ansvisor can read what a brand's visibility is but not what the product thinks should be done about it — including the tasks this engine marks as ones an agent could carry out.

Notes

The two specifications describe the product, not the order of work. The phases and their sequence are an engineering reading of them:

  • 2 before 3 — without measurement, more definitions still cannot answer whether any of them helped.
  • 2.5 before 3 — moving thresholds costs half a day at 11 detectors and a week at 40.
  • 6 last — ranking candidates matters when many definitions compete. With five, there is nothing to rank. The simple daily cap lands earlier, in Phase 4, because noise starts as soon as the count grows.
  • 7 last — it depends on the execution modes and permissions that Phase 5 introduces.

Different priorities are reasonable; the sequence is a starting point, not a constraint.

Activity

  1. added
    enhancement
    tracking
    on Sep 16, 2026
  2. self-assigned this
    on Sep 16, 2026
  3. gkhngyk commented on Oct 2, 2026

    @gkhngyk
    ContributorAuthor

    V1 is complete

    The Action Engine and the V1 definition library are live and stable. Closing this tracking issue.

    What shipped

    Last three nights (all brands)

    night passes actions opened signals closed (resolved / changed) reopened
    Sep 30 24 / 24 recorded 33 0 / 34 18
    Oct 1 24 / 24 recorded 30 35 / 37 7
    Oct 2 24 / 24 recorded 18 29 / 42 10

    The two nights before #853 resolved 74 and 78 signals, most of which had lived a single night. Superseded subjects show no back-and-forth: of 68 subjects, 3 changed kind twice and none flipped back.

    • New brands: a brand created at 23:22 finished its first run at 23:33, got its pass the same minute, and its first actions opened then, instead of the next night.
    • Queue: waiting candidates now spread over 15 distinct scores (previously two: 67 and 73), and no brand exceeded the daily cap of 5.

    Not part of V1 — follow-up work

    • The four disabled definitions each need new data collection:
      • G11 and F08: attribute extraction from answers
      • G13: page-level Search Console sync
      • F07: URL health checks
    • A UI for the candidate queue ("what opens next").
    • Other right-side drawers (signals, KPI, history) are still held to 384px by the Sheet's side-scoped width. The fix belongs in sheet.tsx.
    • Action Center tools in the MCP server: feat(mcp): expose the Action Center through the MCP server #832.
    • Threshold calibration continues from production data as the library runs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementtracking

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions