{"data":{"slug":"github-lobehub-lobehub-agents-skills-heterogeneous-agent-14b45087b2c0","title":"Debug and Fix Heterogeneous Agent Pipeline Issues","summary":"Use this skill to debug and resolve issues in the heterogeneous agent pipeline, including CLI agents, adapters, and transport events. The deliverable is a fixed pipeline with verified event mapping, tool persistence, and subagent routing.","url":"https:\/\/skillshunter.net\/skills\/github-lobehub-lobehub-agents-skills-heterogeneous-agent-14b45087b2c0","json_url":"https:\/\/skillshunter.net\/api\/public\/v1\/skills\/github-lobehub-lobehub-agents-skills-heterogeneous-agent-14b45087b2c0","markdown_url":"https:\/\/skillshunter.net\/skills\/github-lobehub-lobehub-agents-skills-heterogeneous-agent-14b45087b2c0.md","download_url":"https:\/\/skillshunter.net\/skills\/github-lobehub-lobehub-agents-skills-heterogeneous-agent-14b45087b2c0\/download","category":{"slug":"software-development","name":"Software & Development"},"editor_note":"Before debugging, ensure the raw CLI output is correct by reviewing the most recent session trace via `cat .heterogeneous-tracing\/.last-live-trace`. Verify that the raw output matches the adapter output, and inspect `persistToolBatch`, `persistToolResult`, step transitions, and subagent routing only after confirming the transport\/adapter\/executor path is sound.","instructions":"---\nname: heterogeneous-agent\ndescription: 'Use for external-agent launchers and execution identity, Claude Code\/Codex adapters, IPC, event mapping, sessions, persistence and tool-call chains.'\n---\n\n# Heterogeneous Agent Development\n\nUse this skill when the bug or feature lives in the external CLI agent pipeline, not the normal server-side agent runtime.\n\n## Use This Skill For\n\n- Adding or changing a driver under `apps\/desktop\/src\/main\/modules\/heterogeneousAgent\/drivers\/`\n- Editing an adapter under `packages\/heterogeneous-agents\/src\/adapters\/`\n- Changing CLI\/Desktop dispatch launchers, including OpenClaw\/Hermes, or debugging task-comment authorship\n- Debugging `heteroAgentRawLine` transport, `window.__HETERO_AGENT_TRACE`, or `executeHeterogeneousAgent`\n- Fixing Claude Code stream-json bugs such as duplicate partial\/full chunks, broken `message.id` boundaries, missing `tool_result`, TodoWrite state drift, or subagent thread routing\n- Fixing Codex JSONL bugs such as mixed multi-tool messages, broken turn boundaries, or missing tool-result mapping\n- Fixing step-boundary, tool persistence, subagent thread, or resume bugs in Claude Code \/ Codex flows\n- Reproducing multi-tool mixing, orphan tool messages, or stuck tool-result loading\n\n## Pipeline Map\n\n1. CLI raw stdout \/ JSONL\n2. Electron main spawns the CLI and broadcasts `heteroAgentRawLine`\n3. Adapter maps raw provider events into `HeterogeneousAgentEvent`\n4. `executeHeterogeneousAgent` persists assistant\/tool messages and forwards stream events\n5. `createGatewayEventHandler` hydrates the UI\n6. Only after this path looks correct should you move on to `agent-tracing` or context-engine debugging\n\n## Read These Files First\n\n- `apps\/desktop\/src\/main\/controllers\/HeterogeneousAgentCtr.ts`\n- `apps\/desktop\/src\/main\/modules\/heterogeneousAgent\/drivers\/claudeCode.ts`\n- `apps\/desktop\/src\/main\/modules\/heterogeneousAgent\/drivers\/codex.ts`\n- `packages\/heterogeneous-agents\/src\/adapters\/claudeCode.ts`\n- `packages\/heterogeneous-agents\/src\/adapters\/codex.ts`\n- `src\/store\/chat\/slices\/agentRun\/actions\/transports\/hetero\/heterogeneousAgentExecutor.ts`\n- `src\/store\/chat\/slices\/agentRun\/actions\/__tests__\/heterogeneousAgentExecutor.test.ts`\n\n## Default Debug Order\n\n1. Prove whether the raw CLI output is correct before touching UI code. The app records every real session \u2014 read the most recent one via `cat .heerogeneous-tracing\/.last-live-trace` rather than hand-rolling a `claude -p` repro (see references\/debug-workflow\\.md \u00a72).\n2. If raw output is correct, compare it with adapter output. In dev, `executeHeterogeneousAgent` exposes `window.__HETERO_AGENT_TRACE`.\n3. If adapted events look correct, inspect `persistToolBatch`, `persistToolResult`, step transitions, and subagent routing.\n4. Turn the repro into a focused test before fixing.\n5. Only after the transport\/adapter\/executor path looks sound should you debug later-stage message processing.\n\n## Critical Invariants\n\n- One raw tool item must map to one stable `ToolCallPayload.id`.\n- A new main-agent step must emit a boundary signal before events are forwarded to the new assistant.\n- In Claude Code, multiple assistant events with the same `message.id` are one turn, not multiple turns.\n- In Claude Code, `tool_result` lives in `type: 'user'` events, not assistant events.\n- In Claude Code partial mode, `message_delta.usage` is authoritative; do not trust echoed usage on every assistant block.\n- `persistToolBatch` must pre-register assistant `tools[]` before creating tool messages.\n- Every tool message must keep `parentId` equal to the owning assistant and `tool_call_id` equal to the tool id.\n- `tool_result` must resolve an existing `toolMsgIdByCallId`.\n- Subagent chunks must stay in thread scope and must not be forwarded into the main assistant stream.\n- Never clear the global `toolMsgIdByCallId` map at main step boundaries.\n\n## Dispatched Run Identity\n\nA connector or desktop process can itself run inside another Agent's conversation. Its inherited environment identifies the launcher, not the dispatched Agent.\n\n- Build child identity from the current dispatch. Clear inherited `LOBEHUB_AGENT_ID`, `LOBEHUB_ASSISTANT_MESSAGE_ID`, `LOBEHUB_TASK_ID`, and `LOBEHUB_WORKSPACE_ID`; replace `LOBEHUB_TOPIC_ID` and `LOBEHUB_OPERATION_ID` with the dispatched values. Inject optional context only when supplied by the current dispatch; absent values must not retain ancestor identity.\n- Keep authorship independent of authentication. Clearing `LOBEHUB_JWT` or falling back to user credentials must not change the executing Agent. Never infer the author from the topic owner or task assignee.\n- In `apps\/cli\/src\/commands\/task\/lifecycle.ts`, `lh task comment` must refuse to post when topic or operation context exists but the Agent ID is missing or blank. Ordinary terminal comments without execution identity remain user-authored. Misattributed Agent progress can otherwise become human `<user_feedback>` in later task runs.\n\nCheck all four launch surfaces when changing this contract or adding a launcher:\n\n| Surface                 | Entry point                                                                                                          |\n| ----------------------- | -------------------------------------------------------------------------------------------------------------------- |\n| CLI Agent dispatch      | `apps\/cli\/src\/device\/agentRun.ts` \u2014 `spawnHeteroAgentRun` (Agent ID forwarded by `apps\/cli\/src\/commands\/connect.ts`) |\n| CLI OpenClaw\/Hermes     | `apps\/cli\/src\/tools\/heteroTask.ts` \u2014 `runHeteroTask`                                                                 |\n| Desktop Agent dispatch  | `apps\/desktop\/src\/main\/controllers\/HeterogeneousAgentImpl.ts` \u2014 `spawnLhHeteroExec`                                  |\n| Desktop OpenClaw\/Hermes | `apps\/desktop\/src\/main\/controllers\/GatewayConnectionCtr.ts` \u2014 `runHeteroTask`                                        |\n\nRegression coverage must include a clean environment, conflicting ancestor identity, and missing current Agent\/optional context. Check both OpenClaw and Hermes on CLI and Desktop, plus task comments after JWT fallback. Mocked spawn assertions verify environment construction, not end-to-end propagation through an external runtime.\n\n## Common Bug Patterns\n\n- Claude Code duplicates text or thinking:\n  check whether partial deltas and the later full assistant block are both being emitted.\n- Claude Code opens too many assistant messages:\n  check whether the adapter is cutting steps on every assistant event instead of only on `message.id` changes.\n- Claude Code tool results never land:\n  check whether `type: 'user'` `tool_result` blocks are being ignored because the code only inspects assistant events.\n- Claude Code TodoWrite cards look stale:\n  check whether synthesized `pluginState.todos` is being attached at tool-result time.\n- Claude Code subagent transcript leaks into the main bubble:\n  check `parent_tool_use_id` handling and whether subagent chunks are being forwarded to the main gateway handler.\n- Multiple Codex tools collapse into one assistant message:\n  first check whether the adapter emits a usable step boundary such as `newStep` or an equivalent turn-change signal.\n- Orphan tool messages:\n  first check step-transition ordering and whether `persistToolBatch` Phase 1 ran before tool message creation.\n- Tool bubble stays loading:\n  look for `tool_result for unknown toolCallId` and missing `result_msg_id` backfill.\n- Subagent tools show up in the main bubble:\n  check for subagent chunks reaching the main gateway handler.\n- Wrong terminal-error guide (e.g. \"usage limit reached\" shown for a network drop):\n  a classifier is branching on a structured field whose mere presence isn't its meaning.\n  Grep the field across all event states in a real trace before trusting it \u2014 see\n  references\/debug-workflow\\.md \u00a78 (CC `rate_limit_info` rides on `status: \"allowed\"` too).\n\n## References\n\n- For commands, trace capture, invariants, and focused test commands, read [references\/debug-workflow.md](.\/references\/debug-workflow.md).\n- Live official-model compatibility checks are available only through explicit\n  user invocation of `\/testing-heterogeneous-agents` in Claude Code or\n  `$testing-heterogeneous-agents` in Codex. Do not automatically load or run that\n  skill during diagnosis. Its failed-cell evidence can be used here for diagnosis\n  or a code fix.\n","use_cases":["Fixing Claude Code stream-json bugs like duplicate chunks or missing tool_result","Debugging Codex JSONL issues such as mixed multi-tool messages or broken turn boundaries","Resolving subagent thread routing or step-boundary bugs in agent flows"],"limitations":[],"compatibility":[],"setup_tip":null,"sample_input":null,"sample_output":null,"source_url":"https:\/\/github.com\/lobehub\/lobehub\/blob\/54382b5c8e81544da454fa6d7b50f461a562c1ee\/.agents\/skills\/heterogeneous-agent\/SKILL.md","source_commit":"54382b5c8e81544da454fa6d7b50f461a562c1ee","license":null,"version":null,"listing_approved_at":"2026-11-22","created_at":"2026-11-21T11:15:35.000000Z","updated_at":"2026-11-22T11:17:05.000000Z","seo_title":"Debug Heterogeneous Agent Pipeline Issues","seo_description":"Fix bugs in heterogeneous agent pipelines, including CLI agents, adapters, and transport events. Debug Claude Code and Codex JSONL issues.","seo_keywords":["debug heterogeneous agent pipeline","fix Claude Code JSONL issues","resolve Codex multi-tool messages","debug agent subagent routing","heterogeneous agent transport events"]}}