fix(ops_run): unique triggering_event_id per cron fire
All checks were successful
CI Smoke / host-smoke (push) Successful in 0s
CI Smoke / container-smoke (push) Successful in 2s
Build and Publish Container Image / build-and-push (push) Successful in 21s

Cron schedules always passed trigger_key="scheduled", so ops_run
idempotency collapsed every weekday into one key. After the first fire,
create_ops_run was a silent no-op, the claim loop starved, and dual-clock
host timers produced empty FI briefs.

Map scheduled fires to run_id (or scheduled:{iso}) via
emit_triggering_event_id; log duplicate skips; document the contract.
This commit is contained in:
tegwick 2026-08-05 15:30:00 +02:00
parent 00da21e39e
commit 21dc228cb1
6 changed files with 117 additions and 7 deletions

View file

@ -473,6 +473,11 @@ async def emit_tasks(payload: dict) -> list[str]:
try:
# ACTIVITY-WP-0026: claimable ops_run (primary for harness)
try:
from activity_core.ops_run_queue import (
build_idempotency_key,
ops_run_queue_enabled,
)
ops_id = await create_ops_run_from_spec(
session,
spec,
@ -480,10 +485,16 @@ async def emit_tasks(payload: dict) -> list[str]:
)
if ops_id is not None:
activity.logger.info(
"emit_tasks: ops_run created id=%s key=%s:%s",
"emit_tasks: ops_run created id=%s key=%s",
ops_id,
spec.source_id,
triggering_event_id,
build_idempotency_key(spec),
)
elif ops_run_queue_enabled():
# Unique constraint hit: redelivery of same fire (ok)
# OR a non-unique trigger key (bug — see emit_triggering_event_id).
activity.logger.info(
"emit_tasks: ops_run not inserted (duplicate or skip) key=%s",
build_idempotency_key(spec),
)
except Exception as ops_exc:
activity.logger.warning(