sdk-python icon indicating copy to clipboard operation
sdk-python copied to clipboard

[BUG] Resuming an interrupt with response=None is silently ignored, and the caller gets the same interrupt back

Open roshangardi opened this issue 2 months ago • 0 comments

Checks

  • [x] I have updated to the lastest minor and patch version of Strands
  • [x] I have checked the documentation and this is not expected behavior
  • [x] I have searched ./issues and there are no duplicates of my issue

Strands Version

main @ 7b2e0503e

Python Version

3.12

Operating System

macOS 15

Installation Method

git clone

Steps to Reproduce

"""Resuming an interrupt with response=None is silently ignored."""

from typing import Any, AsyncGenerator

from strands import Agent
from strands.models import Model
from strands.vended_tools.handoff_to_user import handoff_to_user


class HandoffOnceModel(Model):
    """Requests handoff_to_user once, then finishes."""

    def __init__(self) -> None:
        self.call_count = 0

    def get_config(self) -> Any:
        return {}

    def update_config(self, **model_config: Any) -> None:
        pass

    async def structured_output(self, *args: Any, **kwargs: Any) -> AsyncGenerator[Any, None]:
        yield {}

    async def stream(self, *args: Any, **kwargs: Any) -> AsyncGenerator[Any, None]:
        self.call_count += 1
        yield {"messageStart": {"role": "assistant"}}
        if self.call_count == 1:
            yield {"contentBlockStart": {"start": {"toolUse": {"name": "handoff_to_user", "toolUseId": "t1"}}}}
            yield {"contentBlockDelta": {"delta": {"toolUse": {"input": '{"message": "What is your address?"}'}}}}
            yield {"contentBlockStop": {}}
            yield {"messageStop": {"stopReason": "tool_use"}}
        else:
            yield {"contentBlockStart": {"start": {}}}
            yield {"contentBlockDelta": {"delta": {"text": "done"}}}
            yield {"contentBlockStop": {}}
            yield {"messageStop": {"stopReason": "end_turn"}}


agent = Agent(model=HandoffOnceModel(), tools=[handoff_to_user], callback_handler=None)

result = agent("Process my order")
assert result.stop_reason == "interrupt"
interrupt_id = result.interrupts[0].id
print(f"paused: {result.interrupts[0].reason!r}")

resumed = agent([{"interruptResponse": {"interruptId": interrupt_id, "response": None}}])

print(f"stop_reason after resume: {resumed.stop_reason}")
print(f"same interrupt returned again: {resumed.interrupts[0].id == interrupt_id}")

Output on main (7b2e0503e):

paused: 'What is your address?'
stop_reason after resume: interrupt
same interrupt returned again: True

Answering with "" or False resumes normally — only None is swallowed.

Expected Behavior

Either the response resolves the interrupt (TypeScript behavior), or the resume call fails loudly telling me None is not an accepted response. Silently returning the same interrupt again is the one behavior that can't be right: resume() already raises TypeError for malformed prompts and KeyError for unknown interrupt ids, so it validates everything except this.

Actual Behavior

resume() stores the None response, every consumer of interrupt state still treats the interrupt as unanswered, and the agent returns the same interrupt again (stop_reason == "interrupt", same id) without re-calling the model. Background tasks answered with None stay input_required with that answer never advancing them.

Additional Context

_InterruptState.resume() accepts an interruptResponse whose response is None without complaint (strands-py/src/strands/interrupt.py, the assignment in the resume() loop). But everywhere else in the SDK, response is None is the sentinel for "this interrupt was never answered":

  • _Interruptible.interrupt() re-raises InterruptException unless interrupt_.response is not None (strands-py/src/strands/types/interrupt.py:108), so the resumed tool or hook pauses again with the same interrupt.
  • The agent collects response is None interrupts as the unanswered set returned to the caller (strands-py/src/strands/agent/agent.py:1544).
  • Background tasks gate readiness on all(interrupt.response is not None ...) (strands-py/src/strands/background_tasks/in_process/_manager.py:235), so a background task answered with None stays input_required — the None answer never advances it (a later non-None answer still resolves it).

The result: a caller who answers an interrupt with response=None gets stop_reason == "interrupt" again with the same interrupt id, with no error and no indication the response was dropped. Each retry loops the same way. From the caller's side the agent re-asks a question that was just answered.

This bites in human-in-the-loop clients because JSON null is a natural encoding for "the user dismissed / gave no answer", and because the TypeScript SDK accepts exactly this payload: its resolve check is response !== undefined (strands-ts/src/interrupt.ts:417), so response: null resolves the interrupt and hands null to the tool. The same wire payload resumes one SDK and silently livelocks the other. The new handoff_to_user vended tool (added in #4348, ported to TypeScript in #4382) makes this easy to hit: its contract is "the human's reply is returned as the tool result", and a null reply is a realistic reply. The interrupts guide's only stated constraint on a response is that it "must be JSON-serializable" — which null is.

Possible Solution

Smallest fix, and what the attached PR does: reject response=None in _InterruptState.resume() with a ValueError, consistent with the method's existing validation strictness. None is the SDK's own "unanswered" sentinel (the Interrupt dataclass default), so accepting it can never mean "answered". resume() is the shared resume entry point for single-agent, Swarm, Graph, and background tasks, so the one check covers every path.

Two adjacent issues support rejecting loudly rather than assigning None a meaning: #4202 establishes that dismissing an interrupt is a different intent from answering it and should get its own API rather than ride on a response value, and #4171 is the sibling case of a bad interrupt response being silently accepted where the expected behavior was a loud rejection.

The alternative — treating None as a real answer for full TypeScript parity — means replacing the None sentinel across every consumer of interrupt state (agent result assembly, tool-cycle retention, background-task readiness, serialized session state), which changes persisted-state semantics and feels like a maintainer decision. Raising now doesn't foreclose it: going from raise to accept later is non-breaking.

Session-restore note: a session persisted before this change that already stored a None response was already stuck re-interrupting; after this change, replaying it raises instead of silently re-interrupting — it surfaces an already-broken state rather than creating a new failure. The fixed resume() raises before persisting anything, and the SDK itself never re-propagates a None response (agent/_agent_as_tool.py:357 filters them).

One asymmetry note for completeness: the TypeScript twin of this gap is response: undefined, which its resume() also stores and its resolve check also treats as unanswered — but reaching that requires violating the declared JSONValue type from plain JS, whereas Python's None arrives from a spec-legal JSON payload, so this issue and PR scope to Python.

roshangardi avatar Sep 21 '26 20:09 roshangardi