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
parent
e0c19705b1
commit
19f6ee94c6
|
|
@ -246,28 +246,24 @@ def _check_autocora_results(
|
||||||
# Look up the pending job in the state DB
|
# Look up the pending job in the state DB
|
||||||
job_data = db.kv_get_json("autocora:job:%s" % result.job_id)
|
job_data = db.kv_get_json("autocora:job:%s" % result.job_id)
|
||||||
|
|
||||||
# Also check task_ids from the result file itself
|
if not job_data:
|
||||||
task_ids = result.task_ids
|
# Orphaned result from a previous run -- archive and skip.
|
||||||
if job_data:
|
# Without the KV entry we don't have keyword or run context.
|
||||||
# Prefer state DB data -- it always has the task_id
|
|
||||||
task_ids = [job_data["task_id"]]
|
|
||||||
|
|
||||||
if not task_ids:
|
|
||||||
log.warning(
|
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,
|
result.job_id,
|
||||||
)
|
)
|
||||||
archive_result(result)
|
archive_result(result)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
for task_id in task_ids:
|
task_id = job_data["task_id"]
|
||||||
|
|
||||||
if result.status == "SUCCESS":
|
if result.status == "SUCCESS":
|
||||||
_handle_autocora_success(client, cfg, db, task_id, result, job_data)
|
_handle_autocora_success(client, cfg, db, task_id, result, job_data)
|
||||||
else:
|
else:
|
||||||
_handle_autocora_failure(client, cfg, db, task_id, result, job_data)
|
_handle_autocora_failure(client, cfg, db, task_id, result, job_data)
|
||||||
|
|
||||||
# Clean up state DB entry
|
# 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)
|
archive_result(result)
|
||||||
|
|
|
||||||
|
|
@ -478,7 +478,7 @@ class TestCheckAutocoraResults:
|
||||||
client.add_comment.assert_not_called()
|
client.add_comment.assert_not_called()
|
||||||
db.log_run_finish.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
|
from clickup_runner.__main__ import _check_autocora_results
|
||||||
|
|
||||||
cfg, client, db = self._setup(tmp_path)
|
cfg, client, db = self._setup(tmp_path)
|
||||||
|
|
@ -496,6 +496,7 @@ class TestCheckAutocoraResults:
|
||||||
|
|
||||||
_check_autocora_results(client, cfg, db)
|
_check_autocora_results(client, cfg, db)
|
||||||
|
|
||||||
# Should still process using task_ids from result file
|
# Should skip processing and archive the orphan
|
||||||
client.update_task_status.assert_called()
|
client.update_task_status.assert_not_called()
|
||||||
client.add_comment.assert_called()
|
client.add_comment.assert_not_called()
|
||||||
|
assert (results_dir / "processed" / "job-orphan.result").exists()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue