-
Notifications
You must be signed in to change notification settings - Fork 1.2k
fix(identity): name the worker's own model when a sub-agent is spawned #5221
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| import { describe, expect, test } from "bun:test"; | ||
| import { | ||
| identifyRoutedModel, | ||
| NEUTRAL_IDENTITY_LINE, | ||
| repairIdentityInResponsesBody, | ||
| repairRoutedIdentity, | ||
| stripRoutedIdentity, | ||
| } from "../../src/adapters/identity"; | ||
| import { createOpenAIChatAdapter } from "../../src/adapters/openai-chat"; | ||
| import { parseRequest } from "../../src/responses/parser"; | ||
| import type { OcxProviderConfig, OcxTextContent } from "../../src/types"; | ||
|
|
||
| /** The sentence the proxy generated for the PARENT session, which a spawned worker inherits (#5217). */ | ||
| const PARENT_IDENTITY = "You are a coding agent powered by the deepseek-v4.1-flash. If asked which model you are, identify as deepseek-v4.1-flash. Do not claim to be a different model or to have a different creator."; | ||
|
|
||
| const WORKER_MODEL = "gpt-6-astra"; | ||
|
|
||
| function developerItem(text: string) { | ||
| return { type: "message", role: "developer", content: [{ type: "input_text", text }] }; | ||
| } | ||
|
|
||
| describe("sub-agent identity inheritance (#5217)", () => { | ||
| test("a stale routed identity sentence is rewritten to the destination model", () => { | ||
| const out = repairRoutedIdentity(`${PARENT_IDENTITY}\n\nUse tools carefully.`, WORKER_MODEL); | ||
| expect(out).toContain(`identify as ${WORKER_MODEL}`); | ||
| expect(out).not.toContain("deepseek-v4.1-flash"); | ||
| expect(out).toContain("Use tools carefully."); | ||
| }); | ||
|
|
||
| test("identifyRoutedModel also repairs a stale sentence and the neutral catalog line", () => { | ||
| expect(identifyRoutedModel(PARENT_IDENTITY, WORKER_MODEL)).toContain(`identify as ${WORKER_MODEL}`); | ||
| expect(identifyRoutedModel(NEUTRAL_IDENTITY_LINE, WORKER_MODEL)).toContain(`identify as ${WORKER_MODEL}`); | ||
| }); | ||
|
|
||
| test("a native destination drops the routed sentence instead of renaming it", () => { | ||
| const out = stripRoutedIdentity(`${PARENT_IDENTITY}\n\nYou and the user share one workspace.`); | ||
| expect(out).not.toContain("powered by the"); | ||
| expect(out).not.toContain("deepseek-v4.1-flash"); | ||
| expect(out).toBe("You and the user share one workspace."); | ||
| }); | ||
|
|
||
| test("text the proxy did not generate is never rewritten", () => { | ||
| for (const text of [ | ||
| "The user asked: which model are you?", | ||
| "```\nYou are a coding agent powered by the thing I wrote myself.\n```", | ||
| "You are a Claude agent built by Anthropic.", | ||
| ]) { | ||
| expect(repairRoutedIdentity(text, WORKER_MODEL)).toBe(text); | ||
| expect(stripRoutedIdentity(text)).toBe(text.trim()); | ||
| } | ||
| }); | ||
|
|
||
| test("the parser repairs the worker's developer item and leaves user turns alone", () => { | ||
| const parsed = parseRequest({ | ||
| model: WORKER_MODEL, | ||
| input: [ | ||
| developerItem(PARENT_IDENTITY), | ||
| { type: "message", role: "user", content: [{ type: "input_text", text: PARENT_IDENTITY }] }, | ||
| ], | ||
| }); | ||
| const [developer, user] = parsed.context.messages; | ||
| const textOf = (content: unknown): string => (typeof content === "string" | ||
| ? content | ||
| : (content as OcxTextContent[]).map(part => part.text).join("")); | ||
| expect(textOf(developer!.content)).toContain(`identify as ${WORKER_MODEL}`); | ||
| expect(textOf(developer!.content)).not.toContain("deepseek-v4.1-flash"); | ||
| // A user turn is the caller's own content; it stays byte-identical. | ||
| expect(textOf(user!.content)).toBe(PARENT_IDENTITY); | ||
| }); | ||
|
|
||
| test("a routed chat destination sends the worker's own model in the system message", async () => { | ||
| const provider = { | ||
| adapter: "openai-chat", | ||
| baseUrl: "https://api.example.invalid", | ||
| apiKey: "key", | ||
| } as unknown as OcxProviderConfig; | ||
| const parsed = parseRequest({ | ||
| model: "some/routed-worker", | ||
| input: [ | ||
| developerItem(PARENT_IDENTITY), | ||
| { type: "message", role: "user", content: [{ type: "input_text", text: "hi" }] }, | ||
| ], | ||
| }); | ||
| const { body } = await createOpenAIChatAdapter(provider).buildRequest(parsed); | ||
| const system = (JSON.parse(body).messages as { role: string; content: string }[]) | ||
| .find(message => message.role === "system")!; | ||
| expect(system.content).toContain("identify as some/routed-worker"); | ||
| expect(system.content).not.toContain("deepseek-v4.1-flash"); | ||
| }); | ||
|
|
||
| test("the Responses body repair covers instructions and developer items only", () => { | ||
| const body = { | ||
| model: WORKER_MODEL, | ||
| instructions: PARENT_IDENTITY, | ||
| input: [ | ||
| developerItem(PARENT_IDENTITY), | ||
| { type: "message", role: "user", content: [{ type: "input_text", text: PARENT_IDENTITY }] }, | ||
| ], | ||
| }; | ||
| const routed = repairIdentityInResponsesBody(body, text => repairRoutedIdentity(text, WORKER_MODEL)) as typeof body; | ||
| expect(routed.instructions).toContain(`identify as ${WORKER_MODEL}`); | ||
| expect((routed.input[0]!.content as { text: string }[])[0]!.text).toContain(`identify as ${WORKER_MODEL}`); | ||
| expect((routed.input[1]!.content as { text: string }[])[0]!.text).toBe(PARENT_IDENTITY); | ||
|
|
||
| const native = repairIdentityInResponsesBody(body, stripRoutedIdentity) as typeof body; | ||
| expect(native.instructions).toBe(""); | ||
| expect((native.input[0]!.content as { text: string }[])[0]!.text).toBe(""); | ||
| }); | ||
|
|
||
| test("a body with no proxy identity is returned unchanged", () => { | ||
| const body = { model: WORKER_MODEL, input: [developerItem("plain instructions")] }; | ||
| expect(repairIdentityInResponsesBody(body, text => repairRoutedIdentity(text, WORKER_MODEL))).toBe(body); | ||
| }); | ||
| }); |
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift
🔎 Supported by static analysis
🏁 Script executed:
Repository: lidge-jun/opencodex
Length of output: 50378
Do not rewrite identity text inside fenced code.
repairRoutedIdentityandstripRoutedIdentityapplyROUTED_IDENTITY_REto the complete developer or system text. An exact proxy-generated sentence inside a fenced code block therefore gets rewritten or removed. Split fenced and prose regions before matching, and apply identity repair only to prose.Also require the same model identifier in both positions. The current alternatives match each identifier independently, so a non-emitted sentence with different model names can match.
🤖 Prompt for AI Agents