diff --git a/clickup_runner/__main__.py b/clickup_runner/__main__.py index 30495a5..2565a43 100644 --- a/clickup_runner/__main__.py +++ b/clickup_runner/__main__.py @@ -246,29 +246,25 @@ def _check_autocora_results( # Look up the pending job in the state DB job_data = db.kv_get_json("autocora:job:%s" % result.job_id) - # Also check task_ids from the result file itself - task_ids = result.task_ids - if job_data: - # Prefer state DB data -- it always has the task_id - task_ids = [job_data["task_id"]] - - if not task_ids: + if not job_data: + # Orphaned result from a previous run -- archive and skip. + # Without the KV entry we don't have keyword or run context. log.warning( - "Result %s has no task_ids and no matching state DB entry -- skipping", + "Result %s has no matching state DB entry -- archiving as orphan", result.job_id, ) archive_result(result) continue - for task_id in task_ids: - if result.status == "SUCCESS": - _handle_autocora_success(client, cfg, db, task_id, result, job_data) - else: - _handle_autocora_failure(client, cfg, db, task_id, result, job_data) + task_id = job_data["task_id"] + + if result.status == "SUCCESS": + _handle_autocora_success(client, cfg, db, task_id, result, job_data) + else: + _handle_autocora_failure(client, cfg, db, task_id, result, job_data) # Clean up state DB entry - if job_data: - db.kv_delete("autocora:job:%s" % result.job_id) + db.kv_delete("autocora:job:%s" % result.job_id) archive_result(result) diff --git a/tests/test_clickup_runner/test_autocora.py b/tests/test_clickup_runner/test_autocora.py index 5a33d8c..819ff86 100644 --- a/tests/test_clickup_runner/test_autocora.py +++ b/tests/test_clickup_runner/test_autocora.py @@ -478,7 +478,7 @@ class TestCheckAutocoraResults: client.add_comment.assert_not_called() db.log_run_finish.assert_not_called() - def test_result_without_state_db_uses_file_task_ids(self, tmp_path): + def test_result_without_state_db_is_archived_as_orphan(self, tmp_path): from clickup_runner.__main__ import _check_autocora_results cfg, client, db = self._setup(tmp_path) @@ -496,6 +496,7 @@ class TestCheckAutocoraResults: _check_autocora_results(client, cfg, db) - # Should still process using task_ids from result file - client.update_task_status.assert_called() - client.add_comment.assert_called() + # Should skip processing and archive the orphan + client.update_task_status.assert_not_called() + client.add_comment.assert_not_called() + assert (results_dir / "processed" / "job-orphan.result").exists()