anthropics / anthropics/claude-agent-sdk-python

ClaudeSDKClient.interrupt() is ignored silently when called immediately after query()

Offen
#1,153 2 Kommentare 1 Reaktion 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
Python
Sterne
8.1k
Forks
1.3k
PR-Merge-Kennzahlen
PR-Kennzahlen ausstehend

Beschreibung

**Bug description:**
Calling `interrupt()` immediately (less than roughly 2 seconds) after `query()` has no observable effect. Claude continues generating a full response as if `interrupt()` was never called. The issue disappears if there is a slight delay between the two calls, suggesting a race condition.

**Steps to reproduce:**
```
import time
from claude_agent_sdk import ClaudeAgentOptions, ClaudeSDKClient
from claude_agent_sdk.types import ResultMessage, StreamEvent

options = ClaudeAgentOptions(
cli_path="/path/to/claude",
include_partial_messages=True,
)

ts = lambda: time.strftime("%H:%M:%S")

async with ClaudeSDKClient(options=options) as client:
await client.query("Write a 300 word essay on machine learning")
print(f"[{ts()}] query sent")
await client.interrupt()
print(f"[{ts()}] interrupt acknowledged")
t0 = time.monotonic()

chars_after = 0
async for msg in client.receive_response():
if isinstance(msg, StreamEvent):
d = msg.event.get("delta", {})
chars_after += len(d.get("text", "") + d.get("thinking", ""))
elif isinstance(msg, ResultMessage):
dt = time.monotonic() - t0
verdict = "BUG" if chars_after else "OK"
print(
f"{verdict}: {chars_after} chars in {dt:.1f}s after interrupt (stop_reason={msg.stop_reason})"
)
break
```

The output shows:
```
[15:20:49] query sent
[15:20:49] interrupt acknowledged
BUG: 2464 chars in 23.6s after interrupt (stop_reason=end_turn)
```

Even after `interrupt()` resolves without errors, Claude continues to generate the full response. The `stop_reason` is `end_turn`, not a signal indicating early termination. Adding a `time.sleep()` of a few seconds before the `interrupt()` call causes the interrupt to work correctly.

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.