Skip to content

feat(action-center): an action becomes a cycle, not a row - #819

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

gkhngyk merged 1 commit into
mainfrom
feature/action-lifecycle

Conversation

@gkhngyk

@gkhngyk gkhngyk commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

Phase 1 of #818.

Summary

Every action carried dedup_key = kind under a plain unique (brand_id, dedup_key), so a brand held at most one action per kind for its entire lifetime. Three things followed from that, all wrong:

  • the nightly pass overwrote an active action's payload — a recovery someone had already started silently became a recovery for a different set of prompts;
  • a completed action was resurrected, its status set back to new and completed_at cleared, which erased the historical record rather than adding to it;
  • a kind could therefore never produce a second cycle, which is why History had nothing to accumulate.

This is the reported symptom: a new action never appeared beside an old one, because it became the old one.

The change

One active action per kind, unlimited closed ones. A partial unique index says exactly that — active actions still collide, closed ones pile up behind them. Closing frees the slot. After a rest window (the same fourteen days the old reopen path used, now deciding when the next cycle may begin rather than whether to resurrect the last one) a still-firing condition opens a new action beside the old one, with its own baseline, tasks and outcome.

An active action keeps its scope. Signals detected since are still linked to it as evidence — they are why it exists — but its payload is left alone. It is a work package someone may be executing against; a new target is better left for the next cycle than folded in silently.

Outcome leaves the status column. no_improvement was never an execution status: an action arrives there by being completed and then measured. Holding both facts in one column made the second unanswerable for an action that was completed but never measured — which today is all of them.

Answers Values
status Was the work done? new, in_progress, on_hold, completed, dismissed
outcome Did it help? pending_measurement, improved, no_meaningful_change, declined, not_measurable

Phase 2 is what fills the second. Until then every row reads pending_measurement, and History says so rather than implying a measurement that did not happen.

Task statuses pick up the execution vocabulary they were missing. canceled becomes skipped and records why; failed covers a run that was attempted and did not work; waiting_approval covers work that needs a person. A skip without a reason cannot be told apart from an abandoned task later, so the drawer asks for one before committing the change. Skipped and failed both leave the progress denominator — neither is outstanding work.

Tests

The generator had none. It does now — seven, covering both behaviours this PR changes and the three it must not break:

  • opens an action when the kind has no active one, with its own baseline and task list
  • never rewrites an active action's scope (the reported bug)
  • links new signals to the active action as evidence
  • never resurrects a closed action (no status or completed_at write, no reopened event)
  • opens a new row once the rest window has passed, rather than updating the old one
  • rests instead of reopening the night after a cycle closed
  • does nothing for a kind with no matching open signals

Related issue

Phase 1 of #818.

Type of change

  • feat — New feature
  • fix — Bug fix

Database

00084_action_lifecycle — already applied to the hosted database. Swaps the unique constraint for a partial index, adds actions.outcome and action_tasks.skip_reason, and migrates the old status values. All 24 actions and 87 tasks intact.

How to test

  1. Scope holds — an action that is new or in_progress keeps its counts across a nightly run, even when new signals of the same kind arrive. Its Signals tab still grows.
  2. History accumulates — complete an action. It stays completed; nothing rewrites it. Fourteen days later, if the condition still fires, a second action appears in Actions while the first stays in History.
  3. Status vs outcome — a completed action reads Completed with Not measured, rather than claiming an improvement nobody measured.
  4. Skip needs a reason — set a task to Skipped: a reason field appears, and the change only commits once you give one. The reason then shows under the task, and the skip leaves the progress count.

Run from server/: yarn test (422 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 1 of #818.

00081 gave every action `dedup_key = kind` under a plain unique constraint,
so a brand held at most one action per kind for its entire lifetime. Three
things followed, all wrong. The nightly pass overwrote an active action's
payload, so a recovery someone had already started silently became a recovery
for a different set of prompts. A completed action was resurrected by setting
its status back to `new` and clearing `completed_at`, which erased the
historical record rather than adding to it. And a kind could therefore never
produce a second execution cycle, which is why History had nothing to
accumulate.

The rule the engine wants is one *active* action per kind, not one ever. A
partial unique index says exactly that: active actions still collide, closed
ones pile up behind them. Closing a cycle frees the slot; once a rest window
has passed — the same fourteen days the old reopen path used, now deciding
when the next cycle may begin rather than whether to resurrect the last one —
a still-firing condition opens a NEW action beside the old one, with its own
baseline, tasks and outcome.

An active action keeps the scope it was created with. Signals detected since
are still linked to it as evidence, because they are why it exists, but its
payload is left alone: it is a work package someone may be executing against,
and new targets are better left for the next cycle than folded in silently.

`no_improvement` leaves the status column. It was never an execution status —
an action arrives there by being completed and then measured — and keeping
both facts in one column made the second unanswerable for an action that was
completed but never measured, which today is every one of them. Status now
answers "was the work done", the new `outcome` column answers "did it help",
and phase 2 is what will fill the second.

Task statuses pick up the execution vocabulary they were missing: `canceled`
becomes `skipped` and now records why, alongside `failed` for a run that was
attempted and `waiting_approval` for work that needs a person. A skip without
a reason cannot be told apart from an abandoned task, so the UI asks.

The generator had no tests; it does now, covering the two behaviours this
commit changes and the three it must not.

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 13ced76 into main Sep 16, 2026
6 checks passed
@gkhngyk
gkhngyk deleted the feature/action-lifecycle branch September 16, 2026 18:24
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