Skip to content

🐛 fix(agent): resolve working directory by target device instead of legacy-only#15591

Merged
arvinxx merged 1 commit into
canaryfrom
fix/agent-working-dir-by-device
Jun 9, 2026
Merged

🐛 fix(agent): resolve working directory by target device instead of legacy-only#15591
arvinxx merged 1 commit into
canaryfrom
fix/agent-working-dir-by-device

Conversation

@arvinxx

@arvinxx arvinxx commented Jun 9, 2026

Copy link
Copy Markdown
Member

💻 Change Type

  • 🐛 fix

🔗 Related Issue

🔀 Description of Change

Problem. When a user picked a working directory in the chat-input directory picker (e.g. agent-gateway) and sent a message, the run executed under a different default directory (the app's own repo) and lost the project binding / --resume.

Root cause. The picker writes the selection to agencyConfig.workingDirByDevice[deviceId], but every consuming path resolved the agent working directory through selectors that only read the legacy localAgentWorkingDirectoryMap:

  • getAgentWorkingDirectoryById → send (conversationLifecycle), regenerate (generation/action), file-mention index, conversation Header
  • currentAgentWorkingDirectory → streaming executor, {{workingDirectory}} placeholder, out-of-scope warning

So a freshly picked directory was silently dropped and execution fell back to a default cwd.

Fix. Make both selectors device-aware. Precedence (the agent-owned slice only — topic overrides are still layered on by callers):

agencyConfig.workingDirByDevice[targetDeviceId] > legacy localStorage > desktop/home

The target device is resolved from a passed-in currentDeviceId (kept out of the selector so hook callers stay reactive), via the existing resolveTargetDeviceId helper — so a device-bound agent reads its bound device's choice rather than the local machine's. All 7 call sites now supply the device id (getElectronStoreState() in actions, useElectronStore(...) in hooks).

The legacy localAgentWorkingDirectoryMap is retained as a lower-precedence fallback for pre-migration desktop users; fully retiring it (with a one-time backfill into workingDirByDevice) is tracked as separate follow-up work.

🧪 How to Test

  • Tested locally

  • Added/updated tests

  • No tests needed

  • New regression tests in agentByIdSelectors.test.ts cover: per-device choice for the current device, bound-device choice when executionTarget === 'device', legacy fallback, and desktop/home fallback.

  • Updated the two affected mocks (parserPlaceholder, gateway) to the curried selector shape.

  • type-check clean on all changed files; eslint clean; affected suites green (agentByIdSelectors 6, agentWorkingDirectory 7, parserPlaceholder 70, gateway 27).

Manual: pick a directory in the chat-input picker for a brand-new topic, send a message, confirm the agent runs in the selected directory (not the app's own repo).

📝 Additional Information

No DB/server contract change — client selectors + call sites only.

…egacy-only

The chat-input directory picker writes the selection to
`agencyConfig.workingDirByDevice[deviceId]`, but the send / regenerate /
streaming / placeholder paths resolved the agent working directory via
selectors that only read the legacy `localAgentWorkingDirectoryMap`. So a
freshly picked directory was silently dropped and execution fell back to a
default cwd (the app's own repo), losing the user's project and `--resume`.

Make both `getAgentWorkingDirectoryById` and `currentAgentWorkingDirectory`
device-aware: per-device choice > legacy > desktop/home, with the target
device resolved from a passed-in `currentDeviceId` (kept out of the selector
so hook callers stay reactive). Update all call sites to supply the device id.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jun 9, 2026

@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 @arvinxx, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@vercel

vercel Bot commented Jun 9, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
lobehub Building Building Preview, Comment Jun 9, 2026 10:54am

Request Review

@codecov

codecov Bot commented Jun 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 74.41860% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 65.76%. Comparing base (b295265) to head (4712477).
⚠️ Report is 5 commits behind head on canary.

❗ There is a different number of reports uploaded between BASE (b295265) and HEAD (4712477). Click for more details.

HEAD has 4 uploads less than BASE
Flag BASE (b295265) HEAD (4712477)
packages/file-loaders 1 0
packages/prompts 1 0
packages/web-crawler 1 0
packages/model-runtime 1 0
Additional details and impacted files
@@             Coverage Diff             @@
##           canary   #15591       +/-   ##
===========================================
- Coverage   79.34%   65.76%   -13.59%     
===========================================
  Files         996     3025     +2029     
  Lines      123342   312076   +188734     
  Branches     9977    30205    +20228     
===========================================
+ Hits        97864   205224   +107360     
- Misses      25287   106784    +81497     
+ Partials      191       68      -123     
Flag Coverage Δ
app 60.11% <74.41%> (?)
database 89.90% <ø> (ø)
packages/agent-manager-runtime 49.69% <ø> (ø)
packages/agent-runtime 81.06% <ø> (ø)
packages/app-config 44.58% <ø> (ø)
packages/builtin-tool-lobe-agent 18.52% <ø> (ø)
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/fetch-sse 87.28% <ø> (+1.71%) ⬆️
packages/file-loaders ?
packages/locales 0.87% <ø> (ø)
packages/memory-user-memory 74.99% <ø> (ø)
packages/model-bank 99.99% <ø> (ø)
packages/model-runtime ?
packages/prompts ?
packages/python-interpreter 92.90% <ø> (ø)
packages/ssrf-safe-fetch 0.00% <ø> (ø)
packages/trpc 40.43% <ø> (ø)
packages/types 35.21% <ø> (ø)
packages/utils 85.06% <ø> (ø)
packages/web-crawler ?

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

Components Coverage Δ
Store 68.24% <84.37%> (∅)
Services 54.25% <ø> (∅)
Server 97.03% <ø> (∅)
Libs 54.23% <ø> (∅)
Utils 81.88% <ø> (-18.12%) ⬇️
🚀 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.

@arvinxx arvinxx merged commit cdbef3f into canary Jun 9, 2026
38 of 39 checks passed
@arvinxx arvinxx deleted the fix/agent-working-dir-by-device branch June 9, 2026 11:45
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