fix: preserve routed sub-agent task payloads by sanitizing before parse - #94
Closed
Wibias wants to merge 2 commits into
Closed
fix: preserve routed sub-agent task payloads by sanitizing before parse#94Wibias wants to merge 2 commits into
Wibias wants to merge 2 commits into
Conversation
…ted sub-agents receive spawn payloads sanitizeEncryptedContentInPlace now runs on the raw body BEFORE parseRequest, for every path. Previously it ran only for native-bound models (no provider prefix) and only after parsing, so routed models (anthropic/*, opencode-go/*) built their parsed messages from the unsanitized input: the agent_message branch dropped the encrypted_content part carrying the actual task text, and spawned sub-agents received an empty NEW_TASK envelope. _rawBody shares the same object reference, so the native passthrough keeps the rewritten parts too; genuine Fernet ciphertext stays byte-identical (looksLikeBackendCiphertext). Adds a regression test mirroring the exact handleResponses order (sanitize, then parse).
Wibias
marked this pull request as draft
July 11, 2026 06:31
Wibias
marked this pull request as ready for review
July 11, 2026 06:33
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This fixes a routed multi-agent regression where spawned sub-agents woke up with the environment/context but without the actual task payload.
On the wire, the task body can arrive parked as plaintext inside an
encrypted_contentslot inside an internalagent_message. Two transformations are required before provider translation:input_textagent_messageto a standard usermessagethatparseRequestunderstandsPreviously the sanitizer ran only on the native-bound path and only after parsing. Moving it before
parseRequestexposed a second gap: the routed parser intentionally ignores unknown input item types, so merely making the content readable still left the entireagent_messageundispatched. The sanitizer now performs both operations when the payload is entirely plaintext.What changed
src/server/responses.tssanitizeEncryptedContentInPlaceonbody.inputimmediately afterexpandPreviousResponseInput(body)and beforeparseRequest(body)agent_messageto{ type: "message", role: "user" }only when no genuine encrypted content remainstests/multi-agent-compat.test.tsNEW_TASKpayload in parsed user messagesRoot cause
parseRequesttolerates unknown input items at the schema boundary but only emits context messages for recognized item types. After the first version of this patch, the encrypted slot became readableinput_text, yet its parent still hadtype: "agent_message". The parser therefore skipped it, producing one user message instead of two and dropping the spawned task.This is why the regression test failed in CI with:
21The follow-up commit fixes that actual boundary rather than weakening the assertion.
Safety properties
Scope
This PR intentionally contains only:
src/server/responses.tstests/multi-agent-compat.test.tsVerification
bun test tests/multi-agent-compat.test.ts --test-name-pattern "sanitize-then-parse delivers"- passbun test tests/multi-agent-compat.test.ts- 27 pass, 0 failbun run typecheck- passgit diff --check- passbun test- the spawn regression passes; the local run remains red on five unrelated pre-existing environment/integration tests (Cursor MCP live stdio x3, server pool-health, Windows service task)The upstream cross-platform CI rerun was triggered by the follow-up push.