Skip to content

feat: return interrupted status from /interrupt endpoint when prompt_id is specified#14386

Open
bollerdominik wants to merge 1 commit into
Comfy-Org:masterfrom
bollerdominik:patch-1
Open

feat: return interrupted status from /interrupt endpoint when prompt_id is specified#14386
bollerdominik wants to merge 1 commit into
Comfy-Org:masterfrom
bollerdominik:patch-1

Conversation

@bollerdominik

Copy link
Copy Markdown

Problem

Callers using the /interrupt API with an optional prompt_id received no feedback on whether their request actually triggered an interrupt. Since the endpoint silently skips interruption when the prompt is not currently running, callers had no way to distinguish a successful interrupt from a no-op making it less reliable to build on.

Solution

The endpoint now returns a JSON body with an interrupted boolean:

// prompt_id matched and interrupted
{ "interrupted": true, "prompt_id": "<id>" }

// prompt_id not found, no interrupt fired
{ "interrupted": false, "prompt_id": "<id>" }

// global interrupt (no prompt_id given)
{ "interrupted": true }

Backwards compatibility

HTTP status remains 200 in all cases. Callers that only check the status code are unaffected. The response body was previously empty, so only callers explicitly asserting an empty body would be impacted which is a unlikely pattern

@coderabbitai

coderabbitai Bot commented Jun 10, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The /interrupt POST route handler was refactored to parse incoming JSON requests and return structured JSON responses. The implementation now supports targeted interruption of specific prompts via prompt_id parameter (only interrupting if that prompt exists in the running queue) and global interruption when no prompt_id is provided. Request parsing includes error handling with a fallback to an empty dictionary. All responses return HTTP 200 with JSON bodies containing an interrupted boolean flag and optional prompt_id field, replacing the previous empty response body.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely captures the main change: adding a JSON response with interrupt status to the /interrupt endpoint when prompt_id is specified.
Description check ✅ Passed The description clearly explains the problem, solution, and backwards compatibility implications, with concrete JSON examples showing all three response scenarios.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (3)
server.py (3)

1005-1005: ⚡ Quick win

Consider using get_current_queue_volatile() for consistency.

Other read-only queue inspection endpoints in this file use get_current_queue_volatile() (lines 847, 885, 922). Since this handler only reads queue state to check if a prompt_id is currently running, using the volatile version would align with the established pattern.

♻️ Suggested change
-			currently_running, _ = self.prompt_queue.get_current_queue()
+			currently_running, _ = self.prompt_queue.get_current_queue_volatile()
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@server.py` at line 1005, Replace the read-only call to
self.prompt_queue.get_current_queue() with the volatile read variant
self.prompt_queue.get_current_queue_volatile() so this handler uses the same
non-mutating inspection path as other endpoints; keep the existing tuple
unpacking (currently_running, _) and behavior but call
get_current_queue_volatile() instead of get_current_queue().

1018-1025: ⚡ Quick win

Use web.json_response() instead of manual JSON serialization.

The codebase consistently uses web.json_response() for JSON responses throughout this file (lines 328, 334, 342, 356, 446, 697, 701, 705, etc.). Manually setting content_type="application/json" and using text=json.dumps(...) breaks this pattern and is less idiomatic for aiohttp.

♻️ Suggested change
-			return web.Response(
-				status=200,
-				content_type="application/json",
-				text=json.dumps({
-					"interrupted": should_interrupt,
-					"prompt_id": prompt_id,
-				})
-			)
+			return web.json_response({
+				"interrupted": should_interrupt,
+				"prompt_id": prompt_id,
+			})
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@server.py` around lines 1018 - 1025, Replace the manual JSON response using
web.Response with aiohttp's web.json_response to match project conventions:
return web.json_response({"interrupted": should_interrupt, "prompt_id":
prompt_id}, status=200). Update the code that currently constructs
web.Response(...) so it uses web.json_response and preserves the status and JSON
payload (references: web.Response, web.json_response, should_interrupt,
prompt_id).

1029-1035: ⚡ Quick win

Use web.json_response() for consistency.

Same issue as the targeted interrupt branch: manually constructing the JSON response instead of using the web.json_response() helper breaks the established pattern in this codebase.

♻️ Suggested change
-			return web.Response(
-				status=200,
-				content_type="application/json",
-				text=json.dumps({
-					"interrupted": True,
-				})
-			)
+			return web.json_response({
+				"interrupted": True,
+			})
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@server.py` around lines 1029 - 1035, Replace the manual JSON construction
using web.Response(... text=json.dumps(...)) with aiohttp's helper: return
web.json_response({"interrupted": True}, status=200) so it matches the codebase
pattern; locate the return that currently creates web.Response with json.dumps
and swap it to web.json_response (remove explicit content_type and text usage).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@server.py`:
- Around line 998-1001: The current try/except around request.json() only
catches json.JSONDecodeError and silently sets json_data = {}, which masks other
aiohttp errors; update the handler so that either you remove the try/except to
let exceptions from request.json() propagate (matching the other POST handlers)
or catch aiohttp.web.HTTPException (and other relevant aiohttp errors) and
return an explicit HTTP error response; specifically modify the request.json()
call and the json_data assignment (replace the json.JSONDecodeError except) to
either let errors bubble up or catch aiohttp.web.HTTPException / Exception and
respond with a clear HTTPBadRequest (including an error message) instead of
defaulting to {}.

---

Nitpick comments:
In `@server.py`:
- Line 1005: Replace the read-only call to self.prompt_queue.get_current_queue()
with the volatile read variant self.prompt_queue.get_current_queue_volatile() so
this handler uses the same non-mutating inspection path as other endpoints; keep
the existing tuple unpacking (currently_running, _) and behavior but call
get_current_queue_volatile() instead of get_current_queue().
- Around line 1018-1025: Replace the manual JSON response using web.Response
with aiohttp's web.json_response to match project conventions: return
web.json_response({"interrupted": should_interrupt, "prompt_id": prompt_id},
status=200). Update the code that currently constructs web.Response(...) so it
uses web.json_response and preserves the status and JSON payload (references:
web.Response, web.json_response, should_interrupt, prompt_id).
- Around line 1029-1035: Replace the manual JSON construction using
web.Response(... text=json.dumps(...)) with aiohttp's helper: return
web.json_response({"interrupted": True}, status=200) so it matches the codebase
pattern; locate the return that currently creates web.Response with json.dumps
and swap it to web.json_response (remove explicit content_type and text usage).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 067cefda-d4b6-43ab-87fc-8f29347b6aaa

📥 Commits

Reviewing files that changed from the base of the PR and between 039ed38 and 41234d6.

📒 Files selected for processing (1)
  • server.py

Comment thread server.py
Comment on lines +998 to +1001
try:
json_data = await request.json()
except json.JSONDecodeError:
json_data = {}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Consider catching broader exceptions from request.json().

The try/except block only catches json.JSONDecodeError, but request.json() can raise other exceptions (e.g., aiohttp.web.HTTPBadRequest for invalid content-type, or other aiohttp client errors). Other POST handlers in this file (lines 930, 984, 1039, 1050) don't use try/except and let these exceptions propagate naturally, which may return proper HTTP error responses.

The current implementation silently treats any JSON parse failure as a global interrupt request (empty dict → no prompt_id). Consider whether this is the intended behavior or if you should:

  1. Let exceptions propagate like other handlers, or
  2. Catch a broader exception type and return an explicit error response
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@server.py` around lines 998 - 1001, The current try/except around
request.json() only catches json.JSONDecodeError and silently sets json_data =
{}, which masks other aiohttp errors; update the handler so that either you
remove the try/except to let exceptions from request.json() propagate (matching
the other POST handlers) or catch aiohttp.web.HTTPException (and other relevant
aiohttp errors) and return an explicit HTTP error response; specifically modify
the request.json() call and the json_data assignment (replace the
json.JSONDecodeError except) to either let errors bubble up or catch
aiohttp.web.HTTPException / Exception and respond with a clear HTTPBadRequest
(including an error message) instead of defaulting to {}.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant