feat: add ids filter to GET /api/jobs for batch polling#14700
feat: add ids filter to GET /api/jobs for batch polling#14700mattmillerai wants to merge 2 commits into
ids filter to GET /api/jobs for batch polling#14700Conversation
Add an optional comma-separated `ids` query parameter to GET /api/jobs so a caller can poll a known set of jobs in a single request instead of one call per job. The filter narrows the result to the requested job ids and composes with the existing status / workflow_id filters; an absent or empty `ids` means no filter. The handler caps the request at 100 ids (checked before validation) and validates each id with the existing validate_job_id helper, returning HTTP 400 on overflow or a malformed id. get_all_jobs gains an optional ids argument that narrows the normalized job list by id. Adds unit coverage for the filter logic and the endpoint's validation contract.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughThis PR adds an Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant GetJobsHandler
participant parse_ids_filter
participant get_all_jobs
Client->>GetJobsHandler: GET /api/jobs?ids=...
GetJobsHandler->>parse_ids_filter: ids_param
alt invalid ids
parse_ids_filter-->>GetJobsHandler: JobIdsFilterError(payload)
GetJobsHandler-->>Client: 400 payload
else valid ids
parse_ids_filter-->>GetJobsHandler: ids_filter
GetJobsHandler->>get_all_jobs: ids=ids_filter
get_all_jobs-->>GetJobsHandler: jobs, total
GetJobsHandler-->>Client: 200 jobs
end
Estimated code review effort: Medium Suggested labels: enhancement, api, backend Suggested reviewers: (none specified) A rabbit hopped through queries deep, 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Comment |
There was a problem hiding this comment.
🔍 Cursor Review — Consolidated panel
Triggered by @mattmillerai.
Found 5 finding(s).
| Severity | Count |
|---|---|
| 🟢 Low | 3 |
| ⚪ Nit | 2 |
Panel: 8/8 reviewers contributed findings.
- parse_ids_filter: one shared parser/validator for the ids query param, used
by the /api/jobs handler AND its tests (no more hand-copied wiring that can
drift from — and silently outlive a regression in — the shipped handler)
- present-but-empty ids (?ids=, ?ids=,,) is now a zero-match filter, not a
silent 'return the entire job history'
- bounded history lookup when an ids filter is present: a batch poll costs
O(requested ids), not O(total history)
- dedupe ids so the max-count cap bounds distinct values, not repeats
- .get('id') instead of j['id'] so a job missing its id degrades to no-match
rather than a 500
|
Addressed all review-panel findings in
16 tests pass (added 6). Resolving these threads. |
ELI-5
GET /api/jobslists jobs and already supports filtering bystatusandworkflow_id. If you've just queued a batch of prompts and want the status ofonly that set, today you have to either fetch everything and filter client-side,
or call
GET /api/jobs/{id}once per job. This PR adds anidsfilter so youcan ask for exactly the jobs you care about in a single request:
What changed
server.py(GET /api/jobs) — parse an optional comma-separatedidsquery parameter. The request is capped at 100 ids (count checked before
validating the list, so an oversized request fails fast), and each id is
validated with the existing
validate_job_idhelper. Overflow or a malformedid returns HTTP 400 with a client-safe message. The parsed list is passed down
to
get_all_jobs.comfy_execution/jobs.py(get_all_jobs) — new optionalids: Optional[list[str]] = Noneargument that narrows the normalized joblist to the requested ids when provided.
Semantics
idsmeans no filter — the full list is returned, exactlylike the existing
status/workflow_idparams.idscomposes with the other filters; it only ever narrows the result.Judgment call for reviewers
validate_job_idaccepts only canonical lowercase hyphenated UUIDs and rejectsany other spelling. This PR keeps the new filter consistent with the endpoint's
existing job-id validation (e.g. the cancel path) rather than normalizing
non-canonical forms (such as uppercase) before matching. Job ids are stored and
compared verbatim everywhere downstream, so accepting a non-canonical spelling
would silently miss every exact-match lookup. Flagging in case reviewers prefer
normalization instead.
Tests
tests-unit/jobs_list_test/adds coverage for both layers:get_all_jobs(ids=...)returns only the requested ids, composes with thestatus filter, treats an unknown id as silently absent, and treats absent /
empty
idsas no filter.oversized set (>100) returns 400, and a malformed id returns 400.
As in
tests-unit/jobs_cancel_test/, the HTTP layer is exercised against asmall aiohttp app whose handler mirrors the endpoint wiring, keeping the test
free of the heavy ComfyUI runtime.
Out of scope
The
output_typeandafter(cursor) parameters are not implemented here —that's separate, larger work to make
/api/jobshonor its full contract.