Skip to content

fix(agent): apply toModelOutput to deferred results delivered by resumeToolResults - #176

Open
alexb-openrouter wants to merge 1 commit into
mainfrom
devin/1796055615-resume-to-model-output
Open

alexb-openrouter wants to merge 1 commit into
mainfrom
devin/1796055615-resume-to-model-output

Conversation

@alexb-openrouter

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

Copy link
Copy Markdown
Contributor

Summary

resumeToolResults (and a deferred tool's .resolve(), which calls it) put the raw validated output into the tool_task_result envelope. It never called the tool's toModelOutput, so a mapper that hides fields was bypassed and the raw result reached the model.

Now buildResumeEnvelope maps a successful output through the new shared helper mapTaskResultForModel (src/lib/task-result-for-model.ts):

  • The mapper gets the original call's input, parsed with the tool's inputSchema. The input comes from the matching function_call item in persisted history ({} if that item is gone). If schema parsing fails, the mapper gets the raw arguments, the same as computeToolOutputForModel.
  • content and json mapper values both go into result.
  • If the mapper throws or returns any other type, the envelope and the persisted task status become failed with the error message. The raw result is never sent.
  • Tools without a mapper are unchanged. If tools is omitted, there is no mapper to apply (the call is already documented as unvalidated).

The helper works the same way as lateTaskForModel in #174 (late background results), so #174 can call it too. #173 widens ToModelOutputResult with json. The helper reads mapped.type as a string, so it works with or without #173. This PR does not touch model-result.ts, so it does not conflict with #171–#175.

Tests

tests/unit/to-model-output-resume.test.ts covers:

  • a content mapper with parsed input (.resolve() with run, checking the next model request)
  • a json mapper
  • a mapper that throws, which delivers failed
  • an unknown mapper type, which delivers failed
  • raw arguments passed to the mapper on a schema parse failure
  • no mapper, which keeps the raw result

Five of these failed on main. All unit tests, typecheck and biome pass.

@devin-ai-integration

devin-ai-integration Bot commented Nov 30, 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

@alexb-openrouter
alexb-openrouter marked this pull request as ready for review November 30, 2026 16:28
@devin-ai-integration

Copy link
Copy Markdown
Contributor

@strix-security

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant