Skip to content

A desktop coding agent with free access to frontier models.

TypeScript

fix: name the parent on helper requests

ogsamratbeb67f70916d
diff --git a/apps/server/src/omnirush-gateway-broker.test.ts b/apps/server/src/omnirush-gateway-broker.test.ts
index 91a67305..0326798a 100644
--- a/apps/server/src/omnirush-gateway-broker.test.ts
+++ b/apps/server/src/omnirush-gateway-broker.test.ts
@@ -1243,6 +1243,7 @@ describe("OmniRush gateway broker: sub-agent model fallback", () => {
"x-omnirush-subagent-root": "ses_main",
"x-omnirush-session-id": "ses_child",
"x-omnirush-task-id": "msg_1",
+ "x-parent-session-id": "ses_main",
};
const refuse = (status: number, code: string) => Response.json({ detail: code }, { status });
@@ -1264,6 +1265,8 @@ describe("OmniRush gateway broker: sub-agent model fallback", () => {
for (const call of calls) {
expect([...call.headers.keys()].filter((name) => name.startsWith("x-omnirush-subagent"))).toEqual([]);
expect(call.headers.get("x-omnirush-session-id")).toBe("ses_child");
+ // The main session goes upstream: the gateway files the request under it.
+ expect(call.headers.get("x-parent-session-id")).toBe("ses_main");
}
expect(events).toEqual([expect.objectContaining({
sessionId: "ses_child",
diff --git a/apps/server/src/omnirush-gateway-broker.ts b/apps/server/src/omnirush-gateway-broker.ts
index 3fa32100..e7ddedc9 100644
--- a/apps/server/src/omnirush-gateway-broker.ts
+++ b/apps/server/src/omnirush-gateway-broker.ts
@@ -9,6 +9,7 @@ import {
SUBAGENT_FALLBACK_EFFORT_HEADER,
SUBAGENT_FALLBACK_MODEL_HEADER,
SUBAGENT_ROOT_SESSION_HEADER,
+ PARENT_SESSION_HEADER,
} from "./omnirush-swarm.js";
import { builtinOmniRushModelCatalog, omnirushModelWantsReasoningSummary } from "./omnirush-model-catalog.js";
import { RejectedAttachments, isRejectedAttachmentError, type Attachment } from "./rejected-attachments.js";
@@ -1574,7 +1575,7 @@ export class OmniRushGatewayBroker {
headers.set("Authorization", `Bearer ${accessToken ?? this.state.accessToken}`);
headers.set("Content-Type", request.headers.get("content-type") || "application/json");
headers.set("Accept", request.headers.get("accept") || "application/json");
- for (const name of ["x-omnirush-session-id", "x-omnirush-task-id"]) {
+ for (const name of ["x-omnirush-session-id", "x-omnirush-task-id", PARENT_SESSION_HEADER]) {
const value = request.headers.get(name);
if (value) headers.set(name, value);
}
diff --git a/apps/server/src/omnirush-swarm.ts b/apps/server/src/omnirush-swarm.ts
index eca6af0e..40fa3fa1 100644
--- a/apps/server/src/omnirush-swarm.ts
+++ b/apps/server/src/omnirush-swarm.ts
@@ -41,6 +41,8 @@ export const OMNIRUSH_SWARM_MAX_PER_TURN = Number.POSITIVE_INFINITY;
export const SUBAGENT_FALLBACK_MODEL_HEADER = "x-omnirush-subagent-fallback-model";
export const SUBAGENT_FALLBACK_EFFORT_HEADER = "x-omnirush-subagent-fallback-effort";
export const SUBAGENT_ROOT_SESSION_HEADER = "x-omnirush-subagent-root";
+/** The main session above a sub-agent's model request; the gateway files the request under it (forwarded upstream). */
+export const PARENT_SESSION_HEADER = "x-parent-session-id";
/** The session upload trace event recording that a sub-agent ran on the main model instead of the picked one. */
export const SUBAGENT_MODEL_FALLBACK_TRACE = "subagent.model_fallback";
diff --git a/apps/server/src/opencode-plugins/omnirush-swarm.test.ts b/apps/server/src/opencode-plugins/omnirush-swarm.test.ts
index 2c119e31..4ca162e4 100644
--- a/apps/server/src/opencode-plugins/omnirush-swarm.test.ts
+++ b/apps/server/src/opencode-plugins/omnirush-swarm.test.ts
@@ -539,12 +539,18 @@ describe("omnirush swarm plugin: sub-agent model and effort", () => {
return output.headers;
};
expect(await headers("ses_grand", "gpt-6-sol")).toEqual({
+ "x-parent-session-id": "ses_main",
"x-omnirush-subagent-fallback-model": "gpt-6-astra",
"x-omnirush-subagent-fallback-effort": "max",
"x-omnirush-subagent-root": "ses_main",
});
expect(await headers("ses_main", "gpt-6-astra")).toEqual({});
- expect(await headers("ses_grand", "gpt-6-astra")).toEqual({});
+ // Every sub-agent request names its main session, on any model.
+ expect(await headers("ses_grand", "gpt-6-astra")).toEqual({ "x-parent-session-id": "ses_main" });
+ expect(await headers("ses_child", "gpt-6-astra")).toEqual({ "x-parent-session-id": "ses_main" });
+ const other = { headers: {} as Record<string, string> };
+ await hooks["chat.headers"]({ sessionID: "ses_child", model: { id: "claude", providerID: "anthropic" } }, other);
+ expect(other.headers).toEqual({});
// The finished task names the sub-agent's own model.
const output = { output: "<task>done</task>", metadata: { sessionId: "ses_child", model: { providerID: "omnirush", modelID: "gpt-6-astra" } } as Record<string, unknown> };
diff --git a/apps/server/src/opencode-plugins/omnirush-swarm.ts b/apps/server/src/opencode-plugins/omnirush-swarm.ts
index 0abba71e..9a9dea86 100644
--- a/apps/server/src/opencode-plugins/omnirush-swarm.ts
+++ b/apps/server/src/opencode-plugins/omnirush-swarm.ts
@@ -71,6 +71,7 @@ import {
SUBAGENT_FALLBACK_EFFORT_HEADER,
SUBAGENT_FALLBACK_MODEL_HEADER,
SUBAGENT_ROOT_SESSION_HEADER,
+ PARENT_SESSION_HEADER,
OMNIRUSH_SWARM_ARCHIVE_DIR,
OMNIRUSH_SWARM_FILE,
OMNIRUSH_SWARM_MAX_PER_TURN,
@@ -655,13 +656,19 @@ export const OmniRushSwarm = async (input?: { client?: SwarmClient; directory?:
if (main) remember(mainModels, message.sessionID, main, MAX_TRACKED_TREES);
},
- // A sub-agent on a picked model names the main model for the gateway
- // broker's fallback (the broker consumes these headers).
+ // Every sub-agent model request names its main session, so the gateway
+ // files it under that session from the first request on. A sub-agent on
+ // a picked model also names the main model for the gateway broker's
+ // fallback (the broker consumes those headers).
"chat.headers": async (
request: { sessionID?: string; model?: { id?: string; providerID?: string } },
output: { headers: Record<string, string> },
) => {
if (typeof request?.sessionID !== "string" || !output?.headers) return;
+ if (request.model?.providerID === "omnirush") {
+ const { root } = await locate(request.sessionID);
+ if (root !== request.sessionID) output.headers[PARENT_SESSION_HEADER] = root;
+ }
const override = overrides.get(request.sessionID);
if (!override?.fallbackModel || request.model?.providerID !== "omnirush" || request.model.id !== override.model) return;
output.headers[SUBAGENT_FALLBACK_MODEL_HEADER] = override.fallbackModel;