fix: prevent repeated task creation after failures
This commit is contained in:
@@ -15,8 +15,8 @@ def make_config(tmp_path: Path, **overrides: object) -> AppConfig:
|
||||
"scheduler": {"interval_seconds": 1, "concurrency": 1, "lease_seconds": 60},
|
||||
"workspace": {"root": tmp_path / "workspaces", "cleanup_on_success": False},
|
||||
"agents": {
|
||||
"implementer": {"command": ["implementer", "-"]},
|
||||
"reviewer": {"command": ["reviewer", "-"]},
|
||||
"implementer": {"command": ["implementer", "--cd", "{workspace_path}", "-"]},
|
||||
"reviewer": {"command": ["reviewer", "--cd", "{workspace_path}", "-"]},
|
||||
},
|
||||
}
|
||||
data.update(overrides)
|
||||
|
||||
@@ -18,8 +18,8 @@ def make_config(tmp_path: Path, **overrides: object) -> AppConfig:
|
||||
"scheduler": {"interval_seconds": 1, "concurrency": 1, "lease_seconds": 60},
|
||||
"workspace": {"root": tmp_path / "workspaces", "cleanup_on_success": False},
|
||||
"agents": {
|
||||
"implementer": {"command": ["implementer", "-"]},
|
||||
"reviewer": {"command": ["reviewer", "-"]},
|
||||
"implementer": {"command": ["implementer", "--cd", "{workspace_path}", "-"]},
|
||||
"reviewer": {"command": ["reviewer", "--cd", "{workspace_path}", "-"]},
|
||||
},
|
||||
}
|
||||
data.update(overrides)
|
||||
@@ -208,6 +208,9 @@ def test_run_task_success_posts_review_comments(db, tmp_path):
|
||||
assert task is not None
|
||||
assert task.state == TaskState.HUMAN_REVIEW_READY
|
||||
assert task.pr_number == 5
|
||||
command = json.loads(db.list_agent_runs(task.id)[0]["command_json"])
|
||||
assert command[1] == "--cd"
|
||||
assert Path(command[2]).is_absolute()
|
||||
assert [path for _, path, _ in requests].count("/api/v1/repos/acme/service/issues/5/comments") == 2
|
||||
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ def test_scan_ignores_repositories_not_allowed_by_current_config(db):
|
||||
assert created == []
|
||||
|
||||
|
||||
def test_retry_after_terminal_task_allows_new_scan_task(db):
|
||||
def test_terminal_task_does_not_create_scan_loop(db):
|
||||
repo = db.upsert_repository(owner="acme", name="service", clone_url="x", default_branch="main", enabled=True)
|
||||
db.upsert_issue(
|
||||
repo_id=repo.id,
|
||||
@@ -88,8 +88,7 @@ def test_retry_after_terminal_task_allows_new_scan_task(db):
|
||||
|
||||
created = scan_eligible_issues(db, LabelsConfig())
|
||||
|
||||
assert len(created) == 1
|
||||
assert created[0] != task_id
|
||||
assert created == []
|
||||
|
||||
|
||||
def test_claim_next_task_claims_expired_lease(db):
|
||||
@@ -111,6 +110,21 @@ def test_claim_next_task_claims_expired_lease(db):
|
||||
assert reclaimed.lease_owner == "worker-b"
|
||||
|
||||
|
||||
def test_retry_task_clears_active_lease(db):
|
||||
repo = db.upsert_repository(owner="acme", name="service", clone_url="x", default_branch="main", enabled=True)
|
||||
task = db.create_task(repo.id, 1)
|
||||
claimed = db.claim_next_task("worker-a", 60)
|
||||
assert claimed is not None
|
||||
db.transition(claimed.id, TaskState.PLANNING, error_message="stuck")
|
||||
|
||||
retried = db.retry_task(task.id)
|
||||
|
||||
assert retried.state == TaskState.DISCOVERED
|
||||
assert retried.lease_owner is None
|
||||
assert retried.lease_expires_at is None
|
||||
assert retried.error_message is None
|
||||
|
||||
|
||||
def test_state_transition_validation():
|
||||
validate_transition(TaskState.DISCOVERED, TaskState.CLAIMED)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user