Module: utils/shardRetryFilter

CAP-002 Phase 2 (Prerequisite #3) — pure survivor filter for the shard-scoped BullMQ retry path.

Single source of truth for the "which results survive a shard retry?" contract. Used by:

  • database/repositories/runRepo.js purgeShardResults — the atomic transactional read-modify-write on the live results column.
  • workers/runWorker.js legacy single-shard catch block — preserves the pre-CAP-002 wipe-all behaviour (every execution row dropped, only non-executed skips kept) when shardIndex == null.
  • backend/tests/run-worker-shard-retry.test.js — verifies the contract directly without mirroring the logic.

Survivors are kept when ANY of:

  • isNonExecutedSkip(r) returns true (over_budget / skipped_no_impact — AUTO-001 / AUTO-004 contract: a final dispatch decision, not a transient execution state).
  • shardIndex != null && r._shardIndex != null && r._shardIndex !== shardIndex (sibling shard's already-completed row that must not be erased).

Legacy single-shard path (shardIndex == null) keeps only the non-executed skips — bit-for-bit identical to the pre-CAP-002 wipe-all behaviour.

Parameters:
Name Type Description
results Array.<Object>

The current results array (may be empty/null).

shardIndex number | null

0-based shard index, or null for legacy.

isNonExecutedSkip function

Predicate from utils/skipReasons.js. Passed in (rather than imported) to avoid a runtime cycle when this helper is consumed from runRepo.js, which loads very early.

Source:
Returns:

Filtered survivors. Never returns the input array reference — callers can mutate the result without affecting the input.

Type
Array.<Object>

Methods

(static) countShardRetrySurvivors(survivors) → {Object}

CAP-002 Phase 2 — Re-derive { passed, failed } from a survivor array. Matches the processResult contract: warning counts as passed.

Parameters:
Name Type Description
survivors Array.<Object>
Source:
Returns:
Type
Object