Skip to content

🤯 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.

🐛 fix(hetero): don't end a resumed Claude Code run on its empty task-notification result (#19979)

Arvin Xu2186544d6e3b
diff --git a/packages/heterogeneous-agents/src/adapters/claudeCode.test.ts b/packages/heterogeneous-agents/src/adapters/claudeCode.test.ts
index f4963eaea0d..2c23d4e3d3e 100644
--- a/packages/heterogeneous-agents/src/adapters/claudeCode.test.ts
+++ b/packages/heterogeneous-agents/src/adapters/claudeCode.test.ts
@@ -55,6 +55,58 @@ describe('ClaudeCodeAdapter', () => {
]);
});
+ // Resuming a session with orphaned background tasks: CC reports them, then
+ // closes that pass with an empty zero-turn result before the user's turn.
+ // Ending the run there left the reply as an empty `...` shell.
+ it('does not end the run on the empty task-notification result a resume opens with', () => {
+ const adapter = new ClaudeCodeAdapter();
+ const events = [
+ { status: 'stopped', subtype: 'task_notification', task_id: 'bg_1', type: 'system' },
+ { session_id: 'sess_1', subtype: 'init', type: 'system' },
+ {
+ is_error: false,
+ num_turns: 0,
+ origin: { kind: 'task-notification' },
+ result: '',
+ subtype: 'success',
+ type: 'result',
+ usage: { input_tokens: 0, output_tokens: 0 },
+ },
+ { session_id: 'sess_1', subtype: 'init', type: 'system' },
+ {
+ message: { content: [{ text: 'PR opened', type: 'text' }], id: 'msg_1' },
+ type: 'assistant',
+ },
+ ].flatMap((raw) => adapter.adapt(raw));
+
+ const types = events.map((e) => e.type);
+ expect(types).not.toContain('stream_end');
+ expect(types).not.toContain('visible_output_end');
+ expect(types).not.toContain('agent_runtime_end');
+ expect(events.find((e) => e.type === 'stream_chunk')?.data.content).toBe('PR opened');
+
+ const final = adapter.adapt({
+ is_error: false,
+ num_turns: 1,
+ result: 'PR opened',
+ type: 'result',
+ });
+ expect(final.map((e) => e.type)).toContain('agent_runtime_end');
+ });
+
+ it('keeps a task-notification result that ran a turn terminal', () => {
+ const adapter = new ClaudeCodeAdapter();
+ adapter.adapt({ subtype: 'init', type: 'system' });
+ const events = adapter.adapt({
+ is_error: false,
+ num_turns: 1,
+ origin: { kind: 'task-notification' },
+ result: 'background check finished',
+ type: 'result',
+ });
+ expect(events.map((e) => e.type)).toContain('agent_runtime_end');
+ });
+
it('emits error on failed result', () => {
const adapter = new ClaudeCodeAdapter();
adapter.adapt({ subtype: 'init', type: 'system' });
diff --git a/packages/heterogeneous-agents/src/adapters/claudeCode.ts b/packages/heterogeneous-agents/src/adapters/claudeCode.ts
index 43ab27db3bb..1e59ff31703 100644
--- a/packages/heterogeneous-agents/src/adapters/claudeCode.ts
+++ b/packages/heterogeneous-agents/src/adapters/claudeCode.ts
@@ -700,6 +700,17 @@ const isAbortedResult = (raw: any): boolean =>
!getCliResultMessage(raw?.result) &&
!getCliResultErrors(raw);
+/**
+ * A `result` that closes CC's own task-notification pass without running a
+ * single turn. A notification pass that DID run a turn (`num_turns > 0`) carries
+ * real output and stays a normal result.
+ */
+const isEmptyTaskNotificationResult = (raw: any): boolean =>
+ raw?.origin?.kind === 'task-notification' &&
+ raw.num_turns === 0 &&
+ !raw.is_error &&
+ !getCliResultMessage(raw.result);
+
const buildAbortedRuntimeEndData = (raw: any): Record<string, unknown> => ({
kind: 'aborted' satisfies HeteroErrorKind,
reason: 'interrupted',
@@ -2050,6 +2061,13 @@ export class ClaudeCompatibleStreamAdapter implements AgentEventAdapter {
}
private handleResult(raw: any): HeterogeneousAgentEvent[] {
+ // Resuming a session whose previous run left background tasks behind makes
+ // CC first report them as orphaned (`task_notification` ×N), then close that
+ // bookkeeping pass with an empty zero-turn `result` BEFORE the user's turn
+ // even starts. Treating it as terminal ends the operation with no content
+ // and drops the real turn that follows — the reply stays a `...` shell.
+ if (isEmptyTaskNotificationResult(raw)) return [];
+
// Emit authoritative grand-total usage from CC's result event. The
// executor currently ignores this phase (it persists per-turn via
// turn_metadata), but we still emit it so other consumers — cost