Skip to content

🐛 fix(page-agent): inject active documentId into context on send#15610

Merged
arvinxx merged 2 commits into
canaryfrom
fix/page-agent-document-id
Jun 9, 2026
Merged

🐛 fix(page-agent): inject active documentId into context on send#15610
arvinxx merged 2 commits into
canaryfrom
fix/page-agent-document-id

Conversation

@arvinxx

@arvinxx arvinxx commented Jun 9, 2026

Copy link
Copy Markdown
Member

💻 Change Type

  • 🐛 fix

🔗 Related Issue

🔀 Description of Change

Page-scoped conversations (the Page editor's agent) never carried the currently open document id to the agent runtime. When a message was sent, operationContext only held agentId / scope / topicId, so the gateway's appContext.documentId was undefined. On the server, state.metadata.documentId was therefore empty and the PageAgent server runtime rejected every tool call:

PageAgent server runtime received a tool call without documentId in context. The conversation must be scoped to an open page editor.

Root cause: the whole server chain (TRPC ExecAgentSchemaappContextstate.metadataRuntimeExecutors → tool ctx) already reserved a documentId slot; the gateway whitelist (gateway.ts) already reads context.documentId. The only gap was that nobody filled that field at send time — the client path works because it reads the EditorRuntime singleton directly, but the gateway/server path can only see what travels in the context.

Fix: at send time in sendMessage, when scope === 'page', inject the live document id from the page editor runtime (pageAgentRuntime.getCurrentDocId()) into operationContext. This is the same source the client-side executor uses, so both paths now agree. It flows: operationContextexecuteGatewayAgentexecAgentTask appContext → server state.metadata.documentId → tool execution ctx.

Guards:

  • Only injected for scope === 'page' (no leakage into normal chats).
  • !context.documentId preserves an explicitly-provided value.
  • No open document → getCurrentDocId() returns undefined → nothing added.

🧪 How to Test

  • Tested locally
  • Added/updated tests

Added two unit tests in conversationLifecycle.test.ts:

  • page scope → executeGatewayAgent receives context.documentId from getCurrentDocId().
  • non-page scope → documentId is not injected even when a doc is open.

bun run type-check passes; conversationLifecycle.test.ts 32/32 pass.

Manual: open a page in the editor, send a message to the Page agent in gateway/cloud mode, and confirm the agent's document tool calls (readDocument / modifyNodes) succeed instead of throwing the missing-documentId error.

Page-scoped conversations never carried the open document id to the
agent runtime. At send time `operationContext` only had agentId/scope/
topicId, so the gateway's `appContext.documentId` was undefined and the
server-side PageAgent runtime threw "received a tool call without
documentId in context".

Inject the live document id from the page editor runtime
(`pageAgentRuntime.getCurrentDocId()`) into `operationContext` when
scope is `page`, so it flows through `execAgentTask` → server
`state.metadata.documentId` → tool execution context.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@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 Ready Ready Preview, Comment Jun 9, 2026 6:07pm

Request Review

@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. feature:agent Assistant/Agent configuration and behavior feature:page labels 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.

We've reviewed this pull request using the Sourcery rules engine

@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: adfa47c19e

ℹ️ 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 on lines +329 to +332
const activePageDocumentId =
context.scope === 'page' && !context.documentId
? pageAgentRuntime.getCurrentDocId()
: undefined;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Avoid injecting a stale page document id

When a page-scoped send omits context.documentId, this now falls back to the singleton pageAgentRuntime.getCurrentDocId(). That singleton is updated later by PageEditor/StoreUpdater effects, while sendAsWrite creates a new document, calls navigate('/page/${newDoc.id}'), and immediately calls sendMessage({ context: { agentId: pageAgentId, scope: 'page' } }) without waiting for the new editor to mount. If the runtime is still bound to the previous page, the gateway context is populated with that previous document id, so server-side PageAgent tools can read/modify the wrong document instead of the new one. Prefer passing the known new document id through the context (or only inject when the runtime is known to match the active page).

Useful? React with 👍 / 👎.

@codecov

codecov Bot commented Jun 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 67.18%. Comparing base (af3f0ea) to head (67ab294).
⚠️ Report is 5 commits behind head on canary.

Additional details and impacted files
@@            Coverage Diff             @@
##           canary   #15610      +/-   ##
==========================================
+ Coverage   67.14%   67.18%   +0.04%     
==========================================
  Files        3353     3350       -3     
  Lines      338505   338338     -167     
  Branches    35060    36160    +1100     
==========================================
+ Hits       227278   227318      +40     
+ Misses     111036   110829     -207     
  Partials      191      191              
Flag Coverage Δ
app 60.16% <100.00%> (+0.01%) ⬆️
database 89.90% <ø> (ø)
packages/agent-manager-runtime 49.69% <ø> (ø)
packages/agent-runtime 81.06% <ø> (ø)
packages/app-config 44.58% <ø> (ø)
packages/builtin-tool-lobe-agent 20.07% <ø> (+1.55%) ⬆️
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% <ø> (ø)
packages/file-loaders 87.89% <ø> (ø)
packages/locales 0.87% <ø> (+<0.01%) ⬆️
packages/memory-user-memory 74.99% <ø> (ø)
packages/model-bank 99.99% <ø> (ø)
packages/model-runtime 84.23% <ø> (ø)
packages/prompts 72.51% <ø> (ø)
packages/python-interpreter 92.90% <ø> (ø)
packages/ssrf-safe-fetch 0.00% <ø> (ø)
packages/trpc 40.43% <ø> (ø)
packages/types 35.15% <ø> (ø)
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.37% <100.00%> (+0.13%) ⬆️
Services 54.25% <ø> (ø)
Server 97.03% <ø> (ø)
Libs 54.03% <ø> (-0.17%) ⬇️
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.

…avoid stale injection

The page-scoped documentId fallback reads the page editor runtime
singleton, which is only authoritative once the active page's editor has
mounted. `sendAsWrite` creates a document, navigates, and sends
immediately — before the new editor mounts — so the singleton may still
be bound to the previously open page, scoping server-side PageAgent
tools to the wrong document.

Thread the freshly created `newDoc.id` through the conversation context;
the existing `!context.documentId` guard then skips the singleton
fallback entirely. Document the constraint at the fallback site.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@arvinxx arvinxx merged commit 5b4b50e into canary Jun 9, 2026
35 checks passed
@arvinxx arvinxx deleted the fix/page-agent-document-id branch June 9, 2026 18:30
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:agent Assistant/Agent configuration and behavior feature:page size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant