Skip to content

fix(agent): bind deferred task identity to tool schema and strip HITL outputs - #180

Open
alexb-openrouter wants to merge 4 commits into
mainfrom
devin/1796091730-tool-output-deferred-identity
Open

alexb-openrouter wants to merge 4 commits into
mainfrom
devin/1796091730-tool-output-deferred-identity

Conversation

@alexb-openrouter

@alexb-openrouter alexb-openrouter commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes two tool-output / deferred-resolution bugs in @openrouter/agent:

  1. Deferred task tool identity & schema binding (resume-tool-results.ts, tool-executor.ts, model-result.ts, tool.ts)

    • Previously resumeToolResults only checked task.name !== request.expectToolName. A separate deferred tool instance with the same public name and a looser outputSchema could settle the original tool's pending task and bypass the owning tool's outputSchema.
    • computeToolFingerprint(tool) now computes a deterministic SHA-256 fingerprint over the client tool's name, inputSchema, and outputSchema (including Zod v4 refinements, transforms, strict/passthrough catchalls, and unrepresentable types) and persists it on PendingAsyncTool.toolFingerprint (additive within state version 1, JSON-serializable across processes).
    • bindDeferredCompletion passes expectTool: toolValue to resumeToolResults, which verifies task.toolFingerprint before persisting for .resolve(), .fail(), .cancel(), and resumeToolResults({ tools }).
  2. HITL outputSchema stripping (tool-executor.ts)

    • invokeOnResponseReceived and computeHitlItemOutput validated against tool.function.outputSchema via z4.safeParse but discarded validation.data and forwarded the unstripped hookResult or raw item.output.
    • Both paths now serialize validation.data via toFunctionCallOutputValue(validation.data) so extra fields stripped by outputSchema are never sent to the model (while computeHitlItemOutput still returns null when the serialized validated payload is already identical to item.output).

Testing

  • Added unit tests in packages/agent/tests/unit/async-tool-deferred.test.ts covering same-name looser-schema rejection for .resolve()/.fail()/.cancel(), dropped .refine() rejection, direct resumeToolResults({ tools }) substitution rejection, and cross-process JSON round-trip resolution with an equivalent tool definition.
  • Added unit tests in packages/agent/tests/unit/hitl-tool.test.ts covering extra-field stripping with onResponseReceived, without a hook, and on content-array outputs.
  • Verified with pnpm test (112 test files, 1299 tests), pnpm typecheck, pnpm lint, pnpm build, and pnpm verify:packages.
@devin-ai-integration

devin-ai-integration Bot commented Dec 1, 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

This branch has not been deployed

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

Labels

None yet

1 participant