Skip to content

feat(action-center): measure whether a closed action helped - #820

Merged
gkhngyk merged 1 commit into
mainfrom
feature/action-validation
Sep 16, 2026
Merged

gkhngyk merged 1 commit into
mainfrom
feature/action-validation

Conversation

@gkhngyk

@gkhngyk gkhngyk commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

Phase 2 of #818.

Summary

#819 split outcome from status and left every row reading pending_measurement, because nothing re-read an action's metrics once it closed. baseline recorded the "before" — the triggering signals at the moment the action was raised — but there was no "after", so History's Result column could only report that nothing had been measured.

A nightly sweep now supplies the second half. For each closed action it measures that action's own success metrics over a window ending before it was raised and an equal window after it closed, stores both halves, and derives the outcome from the comparison.

Both reads go through the same daily rollup functions the KPI page reads, so an action's result and the dashboard summarising the same days cannot disagree.

Metric Source
AI Visibility ai_visibility_aggregates_daily → the shared score function
Citations, Mentions insights_aggregates_daily
Share of Voice share_of_voice_aggregates_daily, percentage computed as Insights computes it
AI Referral Traffic the tracking snippet's log, falling back to the analytics integration

What it will not claim

  • No causality. A before/after pair says the metrics moved, not that this action moved them. The drawer says "measured after this action closed", never "because of it".
  • No outcome from task completion. Ticking six boxes is evidence of effort, not of effect. An action can be Completed and Declined at once, which is the pair the whole loop exists to surface.
  • No zeros standing in for absences. A metric with no data in either window is unmeasured. An action whose rule named no success metric is not_measurable rather than judged against a metric it never claimed.
  • No verdict from noise. These numbers drift week to week; movement counts only past a floor, or every outcome would be a verdict and none would mean anything.

A bug caught against live data

The after window must be over before it is read. Measuring one still in progress reads low because its later days have not happened yet.

The most recently closed action in production closed four days ago. Its after window runs three days into the future, and measured 0 citations against a before of 714 — which the first version of this would have filed as a decline. The sweep now refuses to measure until the window has elapsed, and a test pins it.

Display

The drawer's Result section was built in #815 for exactly this shape, so it mostly just fills in — but it had four fixed cards, two of which could never be measured. It now renders one card per metric the action actually claimed, as before → after with the delta, because a jump of seven means something different at a base of ten than at a base of a thousand. Time to close sits alongside. The table's Result column shows the top two, coloured by direction.

Related issue

Phase 2 of #818. Its exit condition — a completed action shows a measured before/after in History — is what this implements.

Type of change

  • feat — New feature

Database

00085_action_validation — already applied to the hosted database. Adds actions.validation (jsonb) and actions.validated_at, plus a partial index so the sweep does not scan every action ever created. No data migrated; existing rows keep pending_measurement until the sweep reaches them.

Deltas are derived at read time rather than stored, so a displayed change can never contradict the two values it came from.

How to test

The sweep runs inside the nightly tracking cycle, fire-and-forget after the rollups it reads are refreshed.

  1. Complete an action. It reads Completed / Not measured — no claim yet.
  2. Nothing happens for the next eight days: the after window is still running, and the sweep skips it.
  3. Once the window has elapsed, the next nightly run measures it. History's Result column fills with the movement and the drawer shows before → after per metric.
  4. An action whose metrics did not move reads Completed with No meaningful change — the pair that proves completion and success are separate.
  5. An action with no success metrics reads Not measurable.

Run from server/: yarn test (438 passing), yarn lint, yarn format:check.
Run from web/: yarn test (216 passing), yarn lint, yarn typecheck, yarn format:check, yarn build.

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • supabase/schema.sql regenerated with bash supabase/build-schema.sh
  • 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 2 of #818.

00084 split `outcome` from `status` and left every row reading
`pending_measurement`, because nothing re-read an action's metrics once it
closed. `baseline` recorded the "before" — the triggering signals at the
moment the action was raised — but there was no "after", so History's Result
column could only report that nothing had been measured.

A nightly sweep now supplies the second half. For each closed action it
measures that action's own success metrics over a window ending before it was
raised and an equal window after it closed, stores both halves, and derives
the outcome from the comparison. Both reads go through the same daily rollup
functions the KPI page reads, so an action's result and the dashboard
summarising the same days cannot disagree.

Deliberate limits. It does not claim causality: a before/after pair says the
metrics moved, not that this action moved them, and the drawer says "measured
after this action closed" rather than "because of it". It does not infer an
outcome from task completion — ticking six boxes is evidence of effort, not
of effect. A metric with no data in either window is reported as unmeasured
rather than as zero, and an action whose rule named no success metric is
reported as not measurable rather than judged against a metric it never
claimed.

Movement counts only past a noise band. These numbers drift week to week on
their own; without a floor every outcome would be a verdict and none of them
would mean anything.

The after window must be over before it is read. Measuring one still in
progress reads low because its later days have not happened — verified
against live data, where an action closed four days ago measured zero
citations for a window running three days into the future, which would have
been filed as a decline.

Applied to the hosted database.

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 16, 2026
@gkhngyk
gkhngyk merged commit eb65596 into main Sep 16, 2026
6 checks passed
@gkhngyk
gkhngyk deleted the feature/action-validation branch September 16, 2026 19:09
@gkhngyk gkhngyk mentioned this pull request Sep 18, 2026
33 of 37 tasks
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