-
Notifications
You must be signed in to change notification settings - Fork 1
v0.16.8: Decouple server from dictating summary structure #373
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,7 +22,6 @@ | |
| from app.models.job import Job, JobStatus | ||
| from app.schemas.job import JobListItem, JobListResponse, JobResultsResponse | ||
| from app.services.storage.factory import get_storage_service | ||
| from app.services.video_summary_service import derive_video_summary | ||
| from app.settings import settings | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
@@ -231,21 +230,18 @@ async def get_job(job_id: UUID, db: Session = Depends(get_db)) -> JobResultsResp | |
|
|
||
| # Clean Break: All completed jobs return result_url + summary | ||
| # No more inline results for any job type | ||
| # v0.16.8: Summary comes from job.summary (pre-computed by worker) | ||
|
|
||
| # Load results from storage to derive summary | ||
| # Verify results file exists | ||
| try: | ||
| results_path = job.output_path | ||
| file_path = storage.load_file(results_path) | ||
| with open(file_path, "r") as f: | ||
| results = json.load(f) | ||
| storage.load_file(job.output_path) | ||
| except FileNotFoundError as err: | ||
| raise HTTPException(status_code=404, detail="Results file not found") from err | ||
| except json.JSONDecodeError as err: | ||
| raise HTTPException(status_code=500, detail="Invalid results file") from err | ||
|
|
||
| # Return result_url and summary for all completed jobs | ||
| result_url = storage.get_signed_url(job.output_path) | ||
| summary = derive_video_summary(results) | ||
| # v0.16.8: Use pre-computed summary from job.summary (set by worker) | ||
| summary = json.loads(job.summary) if job.summary else None | ||
|
Comment on lines
+243
to
+244
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Handle malformed This 🛡️ Small hardening patch- summary = json.loads(job.summary) if job.summary else None
+ try:
+ summary = json.loads(job.summary) if job.summary else None
+ except json.JSONDecodeError:
+ summary = None🤖 Prompt for AI Agents |
||
| return JobResultsResponse( | ||
| job_id=job.job_id, | ||
| status=job.status.value, | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -676,11 +676,15 @@ def _finalize_job(self, job_id: str, meta: dict, results: dict) -> None: | |||||||||||||||||||||||||
| if job.job_type in ("video", "video_multi"): | ||||||||||||||||||||||||||
| job.progress = 100 | ||||||||||||||||||||||||||
| # Discussion #354: Pre-compute summary for /v1/jobs hot path | ||||||||||||||||||||||||||
| summary_dict = derive_video_summary(output_data) | ||||||||||||||||||||||||||
| # v0.16.8: Use plugin-provided summary if available (decoupled from server) | ||||||||||||||||||||||||||
| summary_dict = output_data.get("summary") | ||||||||||||||||||||||||||
| if not summary_dict: | ||||||||||||||||||||||||||
| # Fallback for plugins that don't provide summary | ||||||||||||||||||||||||||
| summary_dict = derive_video_summary(output_data) | ||||||||||||||||||||||||||
| job.summary = json.dumps(summary_dict) | ||||||||||||||||||||||||||
|
Comment on lines
+679
to
684
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only derive a fallback summary for video jobs.
🔧 Minimal fix- summary_dict = output_data.get("summary")
- if not summary_dict:
- # Fallback for plugins that don't provide summary
- summary_dict = derive_video_summary(output_data)
- job.summary = json.dumps(summary_dict)
+ summary_dict = output_data.get("summary")
+ if summary_dict is None and job.job_type in ("video", "video_multi"):
+ # Fallback for legacy video plugins only
+ summary_dict = derive_video_summary(output_data)
+ job.summary = json.dumps(summary_dict) if summary_dict is not None else None📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||
| db.commit() | ||||||||||||||||||||||||||
| send_job_completed(str(job.job_id)) | ||||||||||||||||||||||||||
| logger.info(f"Job {job.job_id} completed successfully via Ray") | ||||||||||||||||||||||||||
| logger.info(f"Job {job_id} completed successfully via Ray") | ||||||||||||||||||||||||||
| finally: | ||||||||||||||||||||||||||
| db.close() | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
|
|
@@ -987,7 +991,11 @@ def cb(current_frame: int, total: int = total_frames) -> None: | |||||||||||||||||||||||||
| if job.job_type in ("video", "video_multi"): | ||||||||||||||||||||||||||
| job.progress = 100 | ||||||||||||||||||||||||||
| # Discussion #354: Pre-compute summary for /v1/jobs hot path | ||||||||||||||||||||||||||
| summary_dict = derive_video_summary(output_data) | ||||||||||||||||||||||||||
| # v0.16.8: Use plugin-provided summary if available (decoupled from server) | ||||||||||||||||||||||||||
| summary_dict = output_data.get("summary") | ||||||||||||||||||||||||||
| if not summary_dict: | ||||||||||||||||||||||||||
| # Fallback for plugins that don't provide summary | ||||||||||||||||||||||||||
| summary_dict = derive_video_summary(output_data) | ||||||||||||||||||||||||||
| job.summary = json.dumps(summary_dict) | ||||||||||||||||||||||||||
| db.commit() | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid
load_file()just to prove the artefact exists.With the S3 backend,
load_file()downloads the whole object to a temp file. Here that path is discarded, so everyGET /v1/jobs/{job_id}can now trigger a full download and leak a temp file on the polling path. Please use a lightweightexists/HEAD-style storage call instead, or make the signed-URL step the only storage round-trip here.🤖 Prompt for AI Agents