π€― LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
π fix(hetero): record real claude-code/codex provider+model on op rows, structured op id (#16302)
Arvin Xu5487b492bc09
diff --git a/apps/server/src/services/aiAgent/index.ts b/apps/server/src/services/aiAgent/index.tsindex f111a4bdd74..3fd532c11b5 100644--- a/apps/server/src/services/aiAgent/index.ts+++ b/apps/server/src/services/aiAgent/index.ts@@ -1362,7 +1362,9 @@ export class AiAgentService {if (isHeteroAgent) {const isRemoteHetero = isRemoteHeterogeneousType(heteroType);- const operationId = nanoid();+ // Same structured shape as the built-in path (`op_{ts}_{agentId}_{topicId}_{rand}`)+ // so hetero ops aren't visually distinct bare nanoids in the trace/op tables.+ const operationId = `op_${Date.now()}_${resolvedAgentId}_${topicId}_${nanoid(8)}`;// Persist a first-class agent_operations row for the hetero run. The id is// generated here (authoritative) and flows through to heteroIngest /@@ -1377,9 +1379,14 @@ export class AiAgentService {agentId: persistAgentId,chatGroupId: appContext?.groupId ?? null,maxSteps,- model,+ // Seed the heterogeneous provider (claude-code / codex / β¦), NOT the+ // agent's configured chat provider β the run executes on the CLI, so+ // `provider` (e.g. `lobehub`) and `model` (e.g. `deepseek-v4-pro`) are+ // irrelevant. `model` is intentionally left unset: the real executed+ // model arrives mid-stream and is backfilled by heteroFinish. Mirrors the+ // assistant-message seeding above (provider: heteroType, model: undefined).operationId,- provider,+ provider: heteroType,taskId: operationTaskId ?? null,threadId: appContext?.threadId ?? null,topicId,diff --git a/apps/server/src/services/heterogeneousAgent/HeteroTraceRecorder.ts b/apps/server/src/services/heterogeneousAgent/HeteroTraceRecorder.tsindex db9f6f38491..08402d1e4a0 100644--- a/apps/server/src/services/heterogeneousAgent/HeteroTraceRecorder.ts+++ b/apps/server/src/services/heterogeneousAgent/HeteroTraceRecorder.ts@@ -18,6 +18,13 @@ export interface HeteroFinalizeParams {* operation row's aggregate columns by `heteroFinish`. */export interface HeteroTraceTotals {llmCalls: number;+ /** Real executed model, resolved from the CLI's stream_start / turn_metadata+ * (e.g. `claude-opus-4-8`). Null until an event carries it. Lets `heteroFinish`+ * backfill the op row, which `recordStart` can only seed as null at dispatch. */+ model: string | null;+ /** Heterogeneous provider the run executed on (e.g. `claude-code`). Mirrors the+ * provider `recordStart` already seeds, returned so the backfill stays consistent. */+ provider: string | null;stepCount: number;toolCalls: number;totalCost: number;@@ -131,6 +138,8 @@ export class HeteroTraceRecorder {return {llmCalls: steps.filter((s) => s.stepType === 'call_llm').length,+ model: partial.model ?? null,+ provider: partial.provider ?? null,stepCount: steps.length,toolCalls: steps.filter((s) => s.stepType === 'call_tool').length,totalCost,diff --git a/apps/server/src/services/heterogeneousAgent/__tests__/HeteroTraceRecorder.test.ts b/apps/server/src/services/heterogeneousAgent/__tests__/HeteroTraceRecorder.test.tsindex 28e69ff9e0e..806037714f7 100644--- a/apps/server/src/services/heterogeneousAgent/__tests__/HeteroTraceRecorder.test.ts+++ b/apps/server/src/services/heterogeneousAgent/__tests__/HeteroTraceRecorder.test.ts@@ -109,6 +109,9 @@ describe('HeteroTraceRecorder', () => {expect(totals).toMatchObject({llmCalls: 1,+ // resolved from stream_start, so heteroFinish can backfill the op row+ model: 'sonnet',+ provider: 'anthropic',stepCount: 2,toolCalls: 1,totalInputTokens: 12,diff --git a/apps/server/src/services/heterogeneousAgent/index.ts b/apps/server/src/services/heterogeneousAgent/index.tsindex 9728657c6f4..229e7981851 100644--- a/apps/server/src/services/heterogeneousAgent/index.ts+++ b/apps/server/src/services/heterogeneousAgent/index.ts@@ -271,6 +271,12 @@ export class HeterogeneousAgentService {completionReason,error: error ?? null,llmCalls: totals?.llmCalls ?? null,+ // Backfill the real executed model/provider resolved from the CLI stream+ // (recordStart could only seed provider=heteroType + model=null at+ // dispatch). Spread conditionally so a run without a model event keeps the+ // seeded values instead of getting clobbered back to null.+ ...(totals?.model ? { model: totals.model } : {}),+ ...(totals?.provider ? { provider: totals.provider } : {}),status: completionReason,stepCount: totals?.stepCount ?? null,toolCalls: totals?.toolCalls ?? null,diff --git a/packages/database/src/models/agentOperation.ts b/packages/database/src/models/agentOperation.tsindex 97715bd30e8..c57d6a7374e 100644--- a/packages/database/src/models/agentOperation.ts+++ b/packages/database/src/models/agentOperation.ts@@ -59,7 +59,13 @@ export interface RecordOperationCompletionParams {error?: AgentOperationError | null;interruption?: AgentOperationInterruption | null;llmCalls?: number | null;+ /** Backfill the executed model when it's only known at completion (e.g. a+ * heterogeneous run learns its real model from the CLI mid-stream). Omit to+ * keep the value seeded at `recordStart`. */+ model?: string | null;processingTimeMs?: number | null;+ /** Backfill the executed provider β see {@link RecordOperationCompletionParams.model}. */+ provider?: string | null;status:| 'running'| 'waiting_for_human'@@ -148,6 +154,8 @@ export class AgentOperationModel {updates.totalOutputTokens = params.totalOutputTokens;if (params.llmCalls !== undefined) updates.llmCalls = params.llmCalls;if (params.toolCalls !== undefined) updates.toolCalls = params.toolCalls;+ if (params.model !== undefined) updates.model = params.model;+ if (params.provider !== undefined) updates.provider = params.provider;if (params.cost !== undefined) updates.cost = params.cost;if (params.usage !== undefined) updates.usage = params.usage;if (params.error !== undefined) updates.error = params.error;diff --git a/src/hooks/useCreateHeteroAgent.ts b/src/hooks/useCreateHeteroAgent.tsindex ec456219ab2..63aa81c247f 100644--- a/src/hooks/useCreateHeteroAgent.ts+++ b/src/hooks/useCreateHeteroAgent.ts@@ -31,6 +31,12 @@ export const useCreateHeteroAgent = () => {},},avatar: definition.avatar,+ // Stamp the heterogeneous type as the agent's provider so every reader+ // (op rows, agent list, message tags) attributes the run to claude-code /+ // codex rather than the inherited default chat provider (e.g. lobehub).+ // The real chat model is reported by the CLI at runtime, so `model` stays+ // unset here and is backfilled per-run.+ provider: definition.type,systemRole: '',title: definition.title,},diff --git a/src/routes/(main)/home/_layout/hooks/useCreateMenuItems.test.tsx b/src/routes/(main)/home/_layout/hooks/useCreateMenuItems.test.tsxindex 920fa219649..aa4c54df521 100644--- a/src/routes/(main)/home/_layout/hooks/useCreateMenuItems.test.tsx+++ b/src/routes/(main)/home/_layout/hooks/useCreateMenuItems.test.tsx@@ -171,6 +171,7 @@ describe('useCreateMenuItems', () => {},},avatar: 'claude-avatar',+ provider: 'claude-code',systemRole: '',title: 'Claude Code',},@@ -204,6 +205,7 @@ describe('useCreateMenuItems', () => {},},avatar: 'avatar',+ provider: 'codex',systemRole: '',title: 'Codex',},