🐛 fix(heterogeneous-agents): emit per-turn usage for batch-mode Claude Code#15577
Merged
Conversation
…e Code Device + sandbox runs spawn Claude Code via the `lh hetero exec` CLI in BATCH mode (no `--include-partial-messages`), unlike the desktop driver which always streams partial messages. In batch mode CC emits no `message_delta`, and the adapter deliberately skipped usage on `assistant` events (assuming the stale `message_start` echo that only exists in partial mode). The grand-total `result_usage` is intentionally ignored to avoid double-counting, so batch runs ended up persisting NO usage at all — the model tag showed no token count. Track whether any `stream_event` was seen (partial mode); when none has been (batch mode), emit per-turn usage from the `assistant` event as turn_metadata. The assistant event's usage is authoritative in batch mode, not a stale echo. This also fixes the model tag showing `claude-opus-4-8[1m]`: the `[1m]` 1M-context beta marker only appears in the `system init` model field, while `assistant` events report the canonical `claude-opus-4-8`. The new turn_metadata carries the clean id, which supersedes the init-captured one (and matches the id ModelIcon / pricing lookups expect). Partial mode (desktop/local) is unchanged — `message_delta` still owns usage. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f268d21c0e
ℹ️ 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".
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## canary #15577 +/- ##
==========================================
- Coverage 70.50% 70.49% -0.01%
==========================================
Files 3312 3312
Lines 327060 327060
Branches 34721 29894 -4827
==========================================
- Hits 230582 230574 -8
- Misses 96296 96304 +8
Partials 182 182
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
The multi-step E2E fixture has no `stream_event` records (batch mode) and 5 assistant events with `message.usage`, so the new batch-mode path now emits 5 turn_metadata events. Update the expectation from 0 — this validates the fix on a realistic device/sandbox session: per-turn usage lands with the canonical model id. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…pawned CLI The local CLI spawn forwarded the entire `process.env` to `claude`, so a developer with `ANTHROPIC_API_KEY` / `ANTHROPIC_AUTH_TOKEN` / `ANTHROPIC_BASE_URL` exported in their shell had it inherited by the CLI — overriding its own subscription login and surfacing as a baffling "Invalid API key" + non-zero exit on every message. Strip those three vars from the inherited env via `buildInheritedSpawnEnv`. `session.env` is still spread last, so an agent that explicitly configures an API key continues to win. Adds regression tests for both the strip and the override. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This was referenced Jun 9, 2026
Closed
Closed
Closed
Merged
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
💻 Change Type
🔀 Description of Change
Follow-up to the CC remote-spawn model/provider fix. Two symptoms on remotely-spawned (device / sandbox) Claude Code runs:
claude-opus-4-8[1m]instead of the canonicalclaude-opus-4-8.Root cause: device + sandbox runs spawn CC through the
lh hetero execCLI, which defaults to batch mode (includePartialMessages: false, no--include-partial-messages) — unlike the desktop driver, which always streams partial messages. In batch mode:stream_event/message_delta, so the partial-modeturn_metadata(which carries authoritative per-turn usage) never fires.handleAssistantdeliberately skips usage onassistantevents, assuming the stalemessage_startecho that only exists in partial mode.result_usageis intentionally ignored (avoids double-counting).Net result for batch runs: no usage persisted at all → no token count. And the only model source was
system init, whosemodelfield carries CC's[1m]1M-context beta marker (assistant/message_deltaevents report the cleanclaude-opus-4-8).Fix: the adapter now tracks whether any
stream_eventwas seen (= partial mode). When none has (batch mode), it emits per-turn usage from theassistantevent asturn_metadata— the assistant usage is authoritative there, not a stale echo. This:claude-opus-4-8model id, which supersedes the[1m]init-captured value (and matches whatModelIcon/ pricing lookups expect).Partial mode (desktop / local) is unchanged —
message_deltastill owns usage, and theassistant-event path stays skipped via thesawStreamEventguard, so no double-counting.🧪 How to Test
Updated
claudeCode.test.ts: the existing "no turn_metadata on assistant" case now primes partial mode with astream_eventfirst; a new case asserts batch mode (nostream_event) emitsturn_metadatawith the clean model + authoritative usage. Full adapter suite (91 tests) passes; type-check clean on touched files.Manual: run a Claude Code agent on a remote device, send a short prompt — the model tag should show
claude-opus-4-8with the token count, notclaude-opus-4-8[1m]with no tokens.📝 Additional Information
Shared-package change (
@lobechat/heterogeneous-agents); affects all batch-mode CC runs (device, sandbox, CLI). No server or UI changes needed — the existingturn_metadatapersistence path handles it.