Skip to content

🐛 fix(cli): handle agent_run_request in lh connect so device dispatch doesn't time out#15634

Merged
ONLY-yours merged 4 commits into
canaryfrom
fix/cli-connect-agent-run-ack
Jun 10, 2026
Merged

🐛 fix(cli): handle agent_run_request in lh connect so device dispatch doesn't time out#15634
ONLY-yours merged 4 commits into
canaryfrom
fix/cli-connect-agent-run-ack

Conversation

@ONLY-yours

Copy link
Copy Markdown
Member

💻 Change Type

  • 🐛 fix

🔀 Description of Change

Symptom: Running a heterogeneous agent (e.g. Claude Code) against a device connected via lh connect fails with:

{ "error": "{\"error\":\"TIMEOUT\",\"success\":false}", "message": "Hetero agent device dispatch failed", "status": "error" }

Root cause: The dispatch path is:

aiAgent.execAgent → device-gateway POST /api/device/agent/run
  → WS `agent_run_request` to the selected device
  → gateway waits for `agent_run_ack` (default 10s) → else TIMEOUT

lh connect auto-registers the CLI as a device (#15300/#15377), so with deviceId: null the gateway can pick the CLI socket (sockets[0]) as the dispatch target. But connect.ts only listened for system_info_request and tool_call_request — it never handled agent_run_request, so it never called sendAgentRunAck. The gateway waited out its ack window → {error:'TIMEOUT',success:false} (504) → surfaced server-side as "Hetero agent device dispatch failed".

The error is a clean TIMEOUT (not DEVICE_OFFLINE), which confirms the socket was online and the request was delivered — the device just never acked. The desktop app (gatewayConnectionSrv.ts) already handles agent_run_request; the CLI connect path was the missing half of the feature.

agent_run_request has never appeared in connect.ts git history — this is a missing-wiring gap, not a regression.

Fix: Add an agent_run_request handler that mirrors the desktop's executeAgentRun:

  • Spawn lh hetero exec fire-and-forget and sendAgentRunAck({ status: 'accepted' }) immediately, so the gateway doesn't time out. The spawned process owns the full execute → adapt → BatchIngester → server-ingest pipeline.
  • Re-invoke the current CLI entry (process.execPath + process.argv[1]) instead of relying on lh being on PATH — matches the daemon self-spawn convention and works inside the detached lh connect --daemon child.
  • Same stdin contract as desktop: plain prompt → JSON string; with systemContext → content-block array.

🧪 How to Test

  • Added/updated tests — apps/cli/src/device/agentRun.test.ts locks the lh hetero exec arg contract (--type/--operation-id/--topic/--render none/--input-json -/--cwd), --resume, and the stdin payload shapes.
  • Tested locally — bunx vitest run apps/cli/src/device/agentRun.test.ts passes; type-check clean for the changed files.

Manual: lh connect a device, dispatch a Claude Code run to it from the app — it now starts instead of returning Hetero agent device dispatch failed.

🤖 Generated with Claude Code

…ch doesn't time out

`lh connect` auto-registers the CLI as a device, so the gateway can pick it
as the dispatch target for a heterogeneous agent run (`agent_run_request`).
But the connect daemon only listened for `system_info_request` and
`tool_call_request` — it never handled `agent_run_request`, so it never sent
`agent_run_ack`. The gateway waited out its ack window and returned
`{error:'TIMEOUT',success:false}`, surfaced server-side as "Hetero agent
device dispatch failed".

Add an `agent_run_request` handler mirroring the desktop app: spawn
`lh hetero exec` fire-and-forget and ack `accepted` immediately. The spawned
process owns the full execution + server-ingest pipeline. It re-invokes the
current CLI entry (process.execPath + argv[1]) rather than relying on `lh`
being on PATH, so it works inside the detached daemon.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @ONLY-yours, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jun 10, 2026
@vercel

vercel Bot commented Jun 10, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
lobehub Ready Ready Preview, Comment Jun 10, 2026 7:55am

Request Review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 48143a97e5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread apps/cli/src/device/agentRun.ts Outdated
ONLY-yours and others added 2 commits June 10, 2026 14:47
…error

`child_process.spawn` reports a missing/inaccessible cwd asynchronously via
the child's `error` event, after the handler had already sent an `accepted`
ack. The gateway/server then recorded dispatch success while no `lh hetero
exec` process existed to emit `heteroFinish`, leaving the assistant message
stuck instead of surfacing a failure.

`spawnHeteroAgentRun` now resolves on the child's outcome: `accepted` on the
`spawn` event (stdin is written only then), `rejected` on an early `error`. A
rejected ack returns the gateway 422 → execAgent writes a ServerAgentRuntimeError
onto the assistant message, so a failed dispatch is visible. Still resolves in
milliseconds, well within the gateway's 10s ack window.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@codecov

codecov Bot commented Jun 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 67.60%. Comparing base (5b02563) to head (54f22c3).
⚠️ Report is 2 commits behind head on canary.

Additional details and impacted files
@@            Coverage Diff             @@
##           canary   #15634      +/-   ##
==========================================
- Coverage   67.60%   67.60%   -0.01%     
==========================================
  Files        3354     3354              
  Lines      338490   338490              
  Branches    29467    35256    +5789     
==========================================
- Hits       228846   228844       -2     
- Misses     109453   109455       +2     
  Partials      191      191              
Flag Coverage Δ
app 60.13% <ø> (-0.01%) ⬇️
database 98.12% <ø> (ø)
packages/agent-manager-runtime 49.69% <ø> (ø)
packages/agent-runtime 81.06% <ø> (ø)
packages/app-config 44.58% <ø> (ø)
packages/builtin-tool-lobe-agent 20.07% <ø> (ø)
packages/context-engine 84.12% <ø> (ø)
packages/conversation-flow 91.29% <ø> (ø)
packages/device-gateway-client 90.18% <ø> (ø)
packages/env 11.42% <ø> (ø)
packages/eval-dataset-parser 95.15% <ø> (ø)
packages/eval-rubric 76.11% <ø> (ø)
packages/file-loaders 87.89% <ø> (ø)
packages/locales 0.87% <ø> (ø)
packages/memory-user-memory 74.99% <ø> (ø)
packages/model-bank 99.99% <ø> (ø)
packages/model-runtime 84.27% <ø> (ø)
packages/prompts 72.51% <ø> (ø)
packages/python-interpreter 92.90% <ø> (ø)
packages/ssrf-safe-fetch 0.00% <ø> (ø)
packages/trpc 40.43% <ø> (ø)
packages/types 35.18% <ø> (ø)
packages/utils 85.03% <ø> (ø)
packages/web-crawler 88.08% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
Store 68.41% <ø> (ø)
Services 54.25% <ø> (ø)
Server 97.03% <ø> (ø)
Libs 54.03% <ø> (ø)
Utils 82.08% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ONLY-yours ONLY-yours merged commit 723c4d6 into canary Jun 10, 2026
31 of 33 checks passed
@ONLY-yours ONLY-yours deleted the fix/cli-connect-agent-run-ack branch June 10, 2026 07:19
arvinxx added a commit that referenced this pull request Jun 10, 2026
# 🚀 LobeHub Release (20260610)

**Release Date:** June 10, 2026  
**Since v2.2.2:** 131 merged PRs · 13 contributors

> This weekly release strengthens agent collaboration across cloud,
desktop, CLI, and workspace flows, with steadier runtime behavior and a
broader foundation for workspace-scoped data.

---

## ✨ Highlights

- **Agent execution across devices** — Unifies per-device working
directories, project skill discovery, and sub-agent suspend/resume
behavior across server, QStash, and device RPC flows. (#15543, #15566,
#15481, #15620, #15591)
- **Connector and sandbox platform** — Expands connector permissions,
custom OAuth MCP connector onboarding, sandbox provider support, and
user-uploaded file sync into cloud sandbox runs. (#15463, #15546,
#15184, #15550)
- **Desktop and CLI reliability** — Fixes desktop cold-start,
auto-update, Windows build, CLI skill discovery, and `lh connect` agent
dispatch paths. (#15547, #15525, #15527, #15562, #15632, #15634)
- **Pages and sharing** — Refreshes topic sharing, improves Page Editor
layout behavior, and routes Page Agent tool execution through the
server-side editor path. (#15581, #15556, #15588, #15023, #15610)
- **Model availability and provider updates** — Adds user-scoped LobeHub
model availability, Claude Fable 5, Qwen thinking preservation, and
MiniMax M3 updates. (#15590, #15639, #13494, #15376)

---

## 🏗️ Core Product & Architecture

### Agent Runtime & Heterogeneous Agents

- Improves sub-agent lifecycle handling, including async suspend/resume,
queue-mode QStash resume delivery, and blocking nested sub-agent calls.
(#15481, #15620, #15575)
- Stabilizes heterogeneous agent ingestion and streaming with raw stream
dumps, per-turn usage, image forwarding on regenerate, and
duplicate-text fixes. (#15602, #15577, #15592, #15585)
- Adds execution-device and working-directory controls across device
RPC, legacy defaults, and remote-spawned Claude Code sessions. (#15543,
#15566, #15591, #15572)
- Improves runtime diagnostics and compatibility, including Gemini
multimodal output capture, abort stream semantics, and trace quality
analysis. (#15535, #13677, #15508)

---

## 📱 Platforms, Integrations & UX

### Connectors, Sandbox & Tools

- Ships API-level connector tool permissions, custom OAuth MCP connector
onboarding, and connector-first runtime execution. (#15463, #15546)
- Adds sandbox provider support, cloud sandbox file sync, and safer
external URL file input handling with SSRF validation. (#15184, #15550,
#12657)
- Improves tool visibility and execution with pinned app-fixed tools,
ANSI output rendering, gateway-tunneled MCP calls, and automatic
headless tool runs. (#15509, #15516, #15469, #15492)

### Desktop, CLI & Web UX

- Restores desktop startup and reload behavior, preserves IPC error
causes, and keeps the tab bar new-tab action visible across routes.
(#15547, #15597, #15638)
- Fixes desktop update and build stability for browser quit guards,
macOS update signing, and Windows Visual Studio detection. (#15525,
#15527, #15562)
- Shows the plan-limit upgrade UI on desktop builds. (#15628)
- Adds the Agent Run delivery checker and fixes CLI device dispatch plus
skill list/search output. (#15489, #15634, #15632)
- Refreshes onboarding, auth source preservation, topic UI states,
referral/Fable campaign copy, and chat-input control bar behavior.
(#15629, #15544, #15573, #15614, #15616, #15617, #15622, #15643)

---

## 🔒 Security, Reliability & Rollout Notes

- External URL file input now includes SSRF validation for safer Google
file handling. (#12657)
- Database workspace-scope migrations are part of this release;
self-hosted operators should run the normal migration path before
serving the updated app. (#15446, #15465, #15468, #15472)
- The release branch was re-cut from `canary` and includes the latest
`main` release-version commit so `v2.2.2` is the verified compare base.

---

## 👥 Contributors

@ONLY-yours, @sxjeru, @hardy-one, @xujingli, @hezhijie0327, @Coooolfan,
@arvinxx, @tjx666, @Innei, @rivertwilight, @rdmclin2, @cy948,
@AmAzing129

**Full Changelog**:
v2.2.2...release/weekly-20260610-recut-3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant