Skip to content

fix(action-center): score actions on nights the generator skips, and backfill unscored ones - #1145

Merged
gkhngyk merged 1 commit into
ansvisor:mainfrom
cihan-gyk:fix/action-priority-rescore
Oct 18, 2026
Merged

gkhngyk merged 1 commit into
ansvisor:mainfrom
cihan-gyk:fix/action-priority-rescore

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

Every action in the Action Center shows "—" for Priority Score on app.ansvisor.com. This PR closes the gaps behind it and adds a one-off backfill. The product owner reported the problem.

Why the scores are empty

Read-only, in the product owner's browser: all 47 actions of their brand come back with priorityScore: null. "Highest Priority" reads "—" too.

So the first nightly pass after the deploy should score the active ones. Two gaps remain after that:

  1. A skipped night scores nothing. runSignalPass calls the generator only when signals were recorded. A brand whose pass is skipped (no_fresh_results) never has its actions rescored. They stay "—", or keep old scores.
  2. Closed actions never get a score. Completed or dismissed actions created before feat(action-center): score every action's priority on the server #1071 keep "—", because the nightly rescore covers active actions only.

Changes

  • rescoreBrandActions(brandId, { now, statuses, unscored }) (priority-data.js)
    • Scores a brand's actions in one go, as the generator does.
    • Reads the open signals linked to actions and the prompts' demand once, then groups the signals by action.
    • Defaults to active actions (new, in_progress, on_hold).
    • statuses: null takes every status; unscored: true takes only actions with no score.
    • Best effort, like the generator:
      • a score that can't be saved is logged and skipped;
      • unreadable demand scores with demand unknown.
  • Skipped nights (pass.js)
    • A pass skipped for no fresh results now rescores the brand's active actions.
    • The ledger row's detail.actions records { rescored }.
    • A failure is logged and never fails the pass, so the ledger row is still written and the catch-up sweep doesn't retry the night.
  • scripts/rescore-actions.js <brandId|--all>
    • Scores every action with no score yet, in any status, from its open signals as they stand today.
    • Only unscored actions are touched, so it is safe to re-run.
    • --all includes paused brands, because their actions are still listed.

No migration. No web change.

Deploy

After this deploys, run once on production:

node src/scripts/rescore-actions.js --all

This scores the actions now rather than at the next nightly pass, and gives closed ones a score.

Related issue

None. The product owner reported it.

Type of change

  • feat — New feature
  • fix — Bug fix
  • chore — Maintenance / dependencies
  • docs — Documentation only
  • refactor — Code change that neither fixes a bug nor adds a feature
  • test — Adding or updating tests

How to test

  1. Pick a brand that has actions, and clear their scores on a dev database: set priority_score, priority_level, priority_reason and priority_updated_at to null.
  2. Open Action Center → Actions. Priority Score and "Highest Priority" read "—".
  3. From server/, run node src/scripts/rescore-actions.js <brandId>. It prints {"scored":N}.
  4. Reload. Every action has a score and a level, and "Highest Priority" shows a level.
  5. Run the script again. It prints {"scored":0}.

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • yarn lint passes (run from web/): not run, no web change
  • yarn typecheck passes (run from web/): not run, no web change
  • yarn format:check passes (run from web/): not run, no web change
  • Changes are focused — one concern per PR

Also run:

  • server: npm run format, npm run lint and npm test (1539) pass.
    • priority-data.test.js: each action is scored from its own open signals, and signals and demand are read once per brand. Also covered: the status and unscored filters, a brand with no actions, and a failed save or demand read.
    • pass.test.js: a skipped night rescores and records it, a failed rescore still writes the ledger row, and a recorded night leaves scoring to the generator.
  • npm run version:check: fails as on main (compose images 0.2.0, packages 0.3.0). The failure predates this PR and is not touched here.
  • Dev database: I backed up the demo brand's two actions' scores and cleared them.
    • The Actions page read "—".
    • The script printed {"scored":2} and the page showed 82 (High) and 63 (Medium). A second run printed {"scored":0}.
    • The original scores were restored and checked.

🤖 Generated with Claude Code

…backfill unscored ones

Priority scores (ansvisor#1071, migration 00144) are worked out when an action is
created and again by the nightly generator. Actions opened before then
show "—" in the Priority Score column until the next nightly pass, and
completed or dismissed ones never get a score. The generator also doesn't
run when a brand's signal pass is skipped for no fresh results, so such a
brand's actions stayed unscored, or kept old scores.

- rescoreBrandActions (priority-data.js) scores a brand's actions in one
  go: their open signals and the prompts' demand are read once.
- A skipped signal pass now rescores the brand's active actions, best
  effort; the ledger row records how many.
- scripts/rescore-actions.js scores every action with no score yet, in
  any status, for one brand or --all. Safe to re-run.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@cihan-gyk

Copy link
Copy Markdown
Collaborator Author

@gkhngyk Every action on app.ansvisor.com shows "—" for Priority Score. They were all created before #1071, and no nightly pass has run since that deploy. The 05:00 (TR) pass should score the active ones.

This PR also rescores on skipped nights and adds a backfill. After it deploys, could you run this once on production?

node src/scripts/rescore-actions.js --all

It scores only actions without a score, closed ones included, so re-running it is safe. Server only, no migration.

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked on main with the rest of tonight's PRs stacked on top: the priority-data and signal pass tests pass, and CI is green. rescoreBrandActions reads the brand's open signals and prompt demand once, and a failed rescore on a skipped night only logs, so it can't fail the pass. With #1144, the backfill script also scores deleted actions; they stay hidden, so that's harmless.

@gkhngyk
gkhngyk merged commit eb217f5 into ansvisor:main Oct 18, 2026
6 checks passed
@cihan-gyk

Copy link
Copy Markdown
Collaborator Author

@gkhngyk A quick check on #1145: did node src/scripts/rescore-actions.js --all get run on production after this deployed? The approval doesn't say. Until it runs, every action opened before #1071 shows "—" for Priority Score, since the nightly pass scores only active ones.

If it hasn't run yet, it's safe to run now. It only touches actions with no score, closed and deleted ones included. A re-run picks up where a capped run stopped (1,000 actions per brand).

To check afterwards, select count(*) from actions where priority_score is null; should return 0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants