From 89bc1ee557d80b17b260d6f7a8fe9117bfc9fd5c Mon Sep 17 00:00:00 2001 From: oib Date: Thu, 5 Mar 2026 07:15:02 +0100 Subject: [PATCH] fix: client result command uses /v1/jobs/{id}/result endpoint --- cli/aitbc_cli/commands/client.py | 46 +++++++++++++++++--------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/cli/aitbc_cli/commands/client.py b/cli/aitbc_cli/commands/client.py index 002c98c3..20de46f2 100644 --- a/cli/aitbc_cli/commands/client.py +++ b/cli/aitbc_cli/commands/client.py @@ -175,35 +175,39 @@ def result(ctx, job_id: str, wait: bool, timeout: int): start = time.time() while True: try: - with httpx.Client() as client: - response = client.get( - f"{config.coordinator_url}/v1/jobs/{job_id}", + with httpx.Client() as http: + # Try the dedicated result endpoint first + response = http.get( + f"{config.coordinator_url}/v1/jobs/{job_id}/result", headers={"X-Api-Key": config.api_key or ""} ) if response.status_code == 200: - job_data = response.json() - state = job_data.get("state", "UNKNOWN") - - if state == "COMPLETED": - result_data = job_data.get("result") - if result_data: - success(f"Job {job_id} completed") - output(result_data, ctx.obj['output_format']) - else: - output({"job_id": job_id, "state": state, "result": None}, ctx.obj['output_format']) - return - elif state in ("FAILED", "EXPIRED"): - error(f"Job {job_id} {state}: {job_data.get('error', 'no details')}") - return - elif wait and (time.time() - start) < timeout: + result_data = response.json() + success(f"Job {job_id} completed") + output(result_data, ctx.obj['output_format']) + return + elif response.status_code == 425: + # Job not ready yet + if wait and (time.time() - start) < timeout: time.sleep(3) continue + # Check status for more info + status_resp = http.get( + f"{config.coordinator_url}/v1/jobs/{job_id}", + headers={"X-Api-Key": config.api_key or ""} + ) + if status_resp.status_code == 200: + job_data = status_resp.json() + output({"job_id": job_id, "state": job_data.get("state", "UNKNOWN"), "message": "Job not yet completed"}, ctx.obj['output_format']) else: - output({"job_id": job_id, "state": state, "message": "Job not yet completed"}, ctx.obj['output_format']) - return + error(f"Job not ready (425)") + return + elif response.status_code == 404: + error(f"Job {job_id} not found") + return else: - error(f"Failed to get job: {response.status_code}") + error(f"Failed to get result: {response.status_code}") return except Exception as e: error(f"Network error: {e}")