Skip to content

fix(agent): run on_response_received when resumed history holds SDK models - #40

Merged
alexb-openrouter merged 2 commits into
mainfrom
devin/1795956501-hitl-hook-model-history
Nov 30, 2026
Merged

alexb-openrouter merged 2 commits into
mainfrom
devin/1795956501-hitl-hook-model-history

Conversation

@alexb-openrouter

@alexb-openrouter alexb-openrouter commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Risk: an app that uses a HITL tool's on_response_received hook to strip private fields from a human/backend result, and keeps ConversationState in memory between call_model() calls, sent the raw unfiltered function_call_output to the model. The hook and the tool's output_schema validation were both skipped.

Cause: a live turn stores the generated SDK's pydantic OutputFunctionCallItem in state. apply_on_response_received_hooks built its callId -> tool name map only from Mapping items, so on resume the historical call was not found and the output passed through unchanged. A serialize/deserialize round trip turns the history into dicts, which is why persisted state was not affected.

Fix: apply_on_response_received_hooks matches function_call and function_call_output items through dump(item) when they are not mappings. Items it doesn't rewrite are returned as they came in (pydantic models stay pydantic; _send still normalizes at the transport boundary).

- for item in items:
-     if isinstance(item, Mapping) and item.get("type") == "function_call":
+ as_mappings = [item if isinstance(item, Mapping) else dump(item) for item in items]
+ for entry in as_mappings:
+     if isinstance(entry, Mapping) and entry.get("type") == "function_call":

The TypeScript agent is not affected: its history items are plain objects and isFunctionCallItem checks item.type directly.

Tests: tests/unit/test_hitl_model_history.py adds a unit test for the hook dispatcher with a pydantic history item and an end-to-end test that uses the real OpenRouter client and SSE decoder over httpx.MockTransport with an in-memory state accessor. Both fail on main and pass with this change. ruff check, ruff format --check, mypy src tests and pytest tests/unit pass locally.

…odels

A live turn stores the SDK's pydantic function_call item in conversation
state. The resume path only matched dict-like history items, so with an
in-memory state accessor the caller's function_call_output skipped the
tool's on_response_received hook and output validation and was sent to the
model unchanged. Read history and output items through their dumped form so
both representations match.
@devin-ai-integration

devin-ai-integration Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

I'll fix CI failures and address comments from users with write access that start with 'Devin'.

  • Disable automatic comment, CI, and merge conflict monitoring

@devin-ai-integration
devin-ai-integration Bot marked this pull request as ready for review November 29, 2026 12:50
@OpenRouterTeam OpenRouterTeam deleted a comment from devin-ai-integration Bot Nov 30, 2026
@alexb-openrouter
alexb-openrouter merged commit 33705d8 into main Nov 30, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant