Skip orphaned AutoCora results that have no matching state DB entry

Previously, results from prior runs (or the old CheddahBot system) would
be processed without context, causing "unknown" keyword in comments and
cascading errors. Now they are archived silently.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
clickup-runner
PeninsulaInd 2026-04-09 11:00:27 -05:00
parent e0c19705b1
commit 19f6ee94c6
2 changed files with 16 additions and 19 deletions

View File

@ -246,28 +246,24 @@ 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:
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)
archive_result(result)

View File

@ -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()