Skip to content

✨ feat(sandbox): sync user-uploaded files into the cloud sandbox#15550

Merged
ONLY-yours merged 2 commits into
canaryfrom
feat/sandbox-init-files
Jun 9, 2026
Merged

✨ feat(sandbox): sync user-uploaded files into the cloud sandbox#15550
ONLY-yours merged 2 commits into
canaryfrom
feat/sandbox-init-files

Conversation

@ONLY-yours

Copy link
Copy Markdown
Member

πŸ’» Change Type

  • ✨ feat

πŸ”€ Description of Change

When a cloud sandbox session is first used in a conversation, this pre-loads the files the user attached in that conversation into the sandbox at /mnt/data, and tells the agent they are available β€” so the agent can read/process them directly instead of asking the user to re-upload.

1. File source β€” FileModel.findFilesToInitInSandbox(topicId)
Merges the two associations a topic can have, de-duped by file id:

  • messages_files (files attached to messages in the topic)
  • files_to_sessions (files attached to the session that owns the topic)

2. Bootstrap into the sandbox β€” SandboxMiddlewareService.ensureFilesInitialized()
Runs once at the start of the first tool call:

  • presigns a download URL per file and runs an idempotent curl … -o /mnt/data/<name> command (mirrors the existing skill-bootstrap pattern)
  • idempotency is guaranteed by an in-sandbox marker file (re-syncs automatically if the sandbox is recycled); a short-lived Redis hint lets steady-state calls skip the work
  • best-effort: any failure is swallowed and never blocks the actual tool call
  • caps: 50 files / 100 MB each / 120s timeout; filenames are sanitized to a flat basename (no path traversal)
  • works for both onlyboxes and market providers (both support runCommand)

3. Agent awareness
Adds a <uploaded_files> section to the cloud-sandbox systemRole: a static "files are synced into /mnt/data, run listFiles to see them" hint plus a dynamic {{sandbox_uploaded_files}} list. The placeholder generator is registered on both the server (RuntimeExecutors) and client (contextEngineering) paths, so it never leaks an unresolved placeholder.

πŸ§ͺ How to Test

  • Tested locally
  • Added/updated tests

Tests added:

  • packages/database/src/models/__tests__/file.test.ts β€” DB integration tests for findFilesToInitInSandbox (topic + session merge, de-dupe, user isolation, empty)
  • src/server/services/sandbox/__tests__/bootstrap.test.ts β€” idempotent command builder (marker guard, path de-dupe, shell escaping)
  • src/server/services/sandbox/__tests__/serviceInit.test.ts β€” sync runs once, skips without DB / files, never blocks on failure
  • src/server/services/sandbox/__tests__/uploadedFiles.test.ts β€” name sanitization & prompt formatting

type-check reports no errors in the changed files; all changed files pass eslint.

πŸ“ Notes / Trade-offs

  • Client-side awareness lists only the loaded topic message files; the server includes session files too. The static listFiles /mnt/data hint covers any gap so the agent always has an accurate fallback.
  • Filename collisions resolve to the same /mnt/data/<name> path (last write wins); rare in practice.

πŸ€– Generated with Claude Code

Pre-load the files a user attached in a conversation (topic message files +
session files) into the cloud sandbox the first time it is used, and tell the
agent they are available.

- FileModel.findFilesToInitInSandbox: merge messages_files (by topic) and
  files_to_sessions (by the topic's session), de-duped by file id
- SandboxMiddlewareService.ensureFilesInitialized: on first tool call, presign
  download URLs and run an idempotent curl bootstrap into /mnt/data; guarded by
  an in-sandbox marker and a short-lived Redis hint, best-effort so it never
  blocks the actual tool call (caps: 50 files / 100MB / 120s)
- Agent awareness via {{sandbox_uploaded_files}} in the cloud-sandbox systemRole,
  populated by both the server (RuntimeExecutors) and client (contextEngineering)
  placeholder generators

Co-Authored-By: Claude Opus 4.8 <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 8, 2026
@vercel

vercel Bot commented Jun 8, 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 8, 2026 10:25am

Request Review

@dosubot dosubot Bot added feature:files File upload and knowledge base feature:tool Tool calling and function execution labels Jun 8, 2026

@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: 1af1da6a62

ℹ️ 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 src/server/services/sandbox/service.ts
Comment thread src/server/services/sandbox/service.ts Outdated
Comment thread src/server/modules/AgentRuntime/RuntimeExecutors.ts
@codecov

codecov Bot commented Jun 8, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.55462% with 16 lines in your changes missing coverage. Please review.
βœ… Project coverage is 70.57%. Comparing base (0ac53b4) to head (b047305).
⚠️ Report is 2 commits behind head on canary.

Additional details and impacted files
@@            Coverage Diff             @@
##           canary   #15550      +/-   ##
==========================================
+ Coverage   63.50%   70.57%   +7.07%     
==========================================
  Files        2482     3304     +822     
  Lines      234144   326326   +92182     
  Branches    21106    29796    +8690     
==========================================
+ Hits       148692   230319   +81627     
- Misses      85452    95824   +10372     
- Partials        0      183     +183     
Flag Coverage Ξ”
app 61.32% <82.41%> (+0.01%) ⬆️
database 92.24% <100.00%> (+0.01%) ⬆️
packages/agent-manager-runtime 49.69% <ΓΈ> (?)
packages/agent-runtime 81.06% <ΓΈ> (?)
packages/builtin-tool-lobe-agent 18.52% <ΓΈ> (?)
packages/context-engine 84.25% <ΓΈ> (?)
packages/conversation-flow 91.29% <ΓΈ> (?)
packages/device-gateway-client 90.18% <ΓΈ> (?)
packages/eval-dataset-parser 95.15% <ΓΈ> (?)
packages/eval-rubric 76.11% <ΓΈ> (?)
packages/fetch-sse 85.57% <ΓΈ> (?)
packages/file-loaders 87.89% <ΓΈ> (?)
packages/memory-user-memory 74.99% <ΓΈ> (?)
packages/model-bank 99.99% <ΓΈ> (?)
packages/model-runtime 84.22% <ΓΈ> (?)
packages/prompts 72.51% <ΓΈ> (?)
packages/python-interpreter 92.90% <ΓΈ> (?)
packages/ssrf-safe-fetch 0.00% <ΓΈ> (?)
packages/types 35.23% <ΓΈ> (?)
packages/utils 84.98% <ΓΈ> (?)
packages/web-crawler 88.08% <ΓΈ> (?)

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

Components Coverage Ξ”
Store 68.37% <ΓΈ> (ΓΈ)
Services 54.88% <50.00%> (-0.02%) ⬇️
Server 71.47% <84.70%> (+0.01%) ⬆️
Libs 54.45% <ΓΈ> (ΓΈ)
Utils 81.93% <ΓΈ> (+0.20%) ⬆️
πŸš€ 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.

…mpt consistent

Address review feedback on the uploaded-files sync:

1. (high) The sync was a no-op on the cloudSandbox server runtime and the skills
   runtime because createSandboxService() was called without serverDB, so
   ensureFilesInitialized() returned early. Thread serverDB through both.
   (heterogeneous sandboxRunner is intentionally left out: it runs a coding agent
   in /workspace and does not use the cloud-sandbox systemRole.)

2. (medium) Drop the Redis "already initialized" hint. The in-sandbox marker is
   now the single source of truth for idempotency, so a recycled sandbox always
   re-syncs instead of being skipped by a stale 5-min Redis key.

3. (medium) Apply the 50-file / 100MB caps inside formatUploadedFilesPrompt (via
   the shared selectSandboxInitFiles), so the files the prompt advertises match
   exactly what the bootstrap downloads.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@ONLY-yours ONLY-yours merged commit 251e2ed into canary Jun 9, 2026
35 checks passed
@ONLY-yours ONLY-yours deleted the feat/sandbox-init-files branch June 9, 2026 02:40
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

feature:files File upload and knowledge base feature:tool Tool calling and function execution 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