fix(subagents): cover persistence and naming edge cases

This commit is contained in:
Mohamed Boudra
2026-07-15 00:10:30 +02:00
parent f62359fae0
commit 8529eda8a7
4 changed files with 31 additions and 1 deletions
@@ -94,6 +94,7 @@ function createManagedAgent(overrides: ManagedAgentOverrides = {}): ManagedAgent
historyPrimed: true,
lastUserMessageAt: now,
attention: { requiresAttention: false },
dismissedProviderSubagentIds: new Set(),
};
return {
@@ -134,6 +135,7 @@ describe("toStoredAgentRecord", () => {
it("captures lifecycle metadata, config, and persistence", () => {
const agent = createManagedAgent({
currentModeId: "focus",
dismissedProviderSubagentIds: new Set(["native-child"]),
persistence: {
provider: "claude",
sessionId: "persist-2",
@@ -155,6 +157,7 @@ describe("toStoredAgentRecord", () => {
expect(record.updatedAt).toBe(agent.updatedAt.toISOString());
expect(record.lastActivityAt).toBe(agent.updatedAt.toISOString());
expect(record.lastUserMessageAt).toBe(agent.lastUserMessageAt?.toISOString());
expect(record.dismissedProviderSubagentIds).toEqual(["native-child"]);
expect(record.persistence).toEqual({
provider: "claude",
sessionId: "persist-2",
@@ -126,6 +126,7 @@ function createManagedAgent(overrides: ManagedAgentOverrides = {}): ManagedAgent
lastUserMessageAt: overrides.lastUserMessageAt ?? core.now,
lastUsage: overrides.lastUsage,
lastError: overrides.lastError,
dismissedProviderSubagentIds: overrides.dismissedProviderSubagentIds ?? new Set(),
};
}
@@ -267,6 +267,24 @@ describe("codex tool-call mapper", () => {
});
});
it("uses only the final segment of a subAgentActivity path outside the root namespace", () => {
const item = mapCodexToolCallFromThreadItem({
type: "subAgentActivity",
id: "activity-external-path",
kind: "started",
agentThreadId: "child-thread-external-path",
agentPath: "/tmp/native/investigator",
});
expect(item).toMatchObject({
detail: {
type: "sub_agent",
subAgentType: "investigator",
description: "/tmp/native/investigator",
},
});
});
it("does not fail a collabAgentToolCall from child error state alone", () => {
const item = mapCodexToolCallFromThreadItem({
type: "collabAgentToolCall",
@@ -993,7 +993,15 @@ function mapCollabAgentToolCallItem(
function mapSubAgentActivityItem(
item: z.infer<typeof CodexSubAgentActivityItemSchema>,
): ToolCallTimelineItem {
const nativeName = item.agentPath.replace(/^\/root(?:\/|$)/, "") || "Sub-agent";
let nativeName = item.agentPath;
if (nativeName === "/root") {
nativeName = "";
} else if (nativeName.startsWith("/root/")) {
nativeName = nativeName.slice("/root/".length);
} else if (nativeName.includes("/")) {
nativeName = nativeName.slice(nativeName.lastIndexOf("/") + 1);
}
nativeName ||= "Sub-agent";
return {
type: "tool_call",
callId: item.id,