Summary
In src/hflow/stage_planning.py, _camera_presence_by_episode queries the historical check_runs table directly rather than check_runs_latest.
When camera_frame_stats is re-run and encounters an error or worker timeout (status = 'error'), _camera_presence_by_episode bypasses the latest errored run, matches an older historical run from check_runs, and returns camera_presence_by_episode[episode_id] = False.
Consequently, plan_outstanding_stages evaluates camera_presence_by_episode.get(episode_id) is False and drops Stage.MEDIA from the execution plan, directly violating the documented safe fallback invariant:
"If that exact default check is not registered or its result is missing, the planner preserves the safe fallback and schedules media rather than risk omitting a contact sheet." (stage_planning.py:284-286)
Root Cause
In src/hflow/stage_planning.py:229-246:
rows = connection.execute(
f"""
SELECT runs.episode_id, count(measurements.key) > 0
FROM check_runs AS runs # <-- Reads all historical check_runs instead of check_runs_latest
LEFT JOIN measurements
ON measurements.episode_id = runs.episode_id
AND measurements.run_fingerprint = runs.run_fingerprint
AND measurements.check_name = runs.check_name
AND measurements.check_version = runs.check_version
AND ends_with(measurements.key, '/message_count')
WHERE runs.status IN ({statuses})
AND runs.episode_id IN ({episode_placeholders})
AND runs.check_name = ?
AND runs.check_version = ?
GROUP BY runs.episode_id
""",
[*episode_ids, check_name, check_version],
).fetchall()
Summary
In
src/hflow/stage_planning.py,_camera_presence_by_episodequeries the historicalcheck_runstable directly rather thancheck_runs_latest.When
camera_frame_statsis re-run and encounters an error or worker timeout (status = 'error'),_camera_presence_by_episodebypasses the latest errored run, matches an older historical run fromcheck_runs, and returnscamera_presence_by_episode[episode_id] = False.Consequently,
plan_outstanding_stagesevaluatescamera_presence_by_episode.get(episode_id) is Falseand dropsStage.MEDIAfrom the execution plan, directly violating the documented safe fallback invariant:Root Cause
In
src/hflow/stage_planning.py:229-246: