Repository navigation
Description
Problem
Astra should support the same logical Session through CLI + Edge + Server and Server-only, including many users on different machines and multiple Server instances. The current combination of local and remote journals, execution state, projections, and background observers makes that goal too expensive and difficult to reason about. Long histories add further work even when a client needs only the recent working set.
The goal is a simpler, robust, high-performance design: fewer independently maintained states, less MatrixOne traffic and data, and a clear execution and recovery story. Local CLI/Edge storage should carry as much of the local work as appropriate; Server-only must still persist the context and execution facts needed to resume and display a Session. This is about general capabilities, not special cases for a particular prompt or test.
Evidence on current main
Baseline: bebb535cef44c9b2a226b9cc57df75e9e778e0a8. The following are code observations and isolated experiments, not a production capacity measurement:
- Each connected Edge has a two-second pending-dispatch database poll, while a separate batched observer also checks for cross-Server wakeups. Assuming 1,000 continuously connected Edges and normal scheduling, the per-connection poll alone implies roughly 500 SELECTs/s, plus roughly 33 registration heartbeat updates/s. These are source-derived estimates, not measured throughput.
- In an isolated MatrixOne v4.2.6 test using the actual dispatch schema and a prepared wake query, 1,000 owners had 100,000 completed dispatches and no pending dispatches. A 128-Edge empty wake query scanned 12,800 rows. That is one synthetic distribution, not a claim about every production plan.
- A bound, quiet TUI refreshes its Run tree every 15 seconds; its handler reads the Session and its Runs. If 1,000 such TUIs are idle, that implies roughly 67 requests/s and at least 133 related SELECTs/s, before additional reads. This estimate applies to bound TUIs, not all CLI processes.
- In an isolated MatrixOne v4.2.6 experiment with the actual Run schema and full prepared production query, one user's 10,000 Runs were distributed across 100 Sessions; the target Session had 100 Runs.
EXPLAIN ANALYZEshowed 10,000 table-scan input rows to select that Session's 100 Runs.LIMITand an index declaration alone therefore do not establish bounded physical work. This resembles matrixone#31856, but the same root cause has not been established. - Local conversation-log reads can read the entire journal to find a snapshot or suffix. The one-shot commit path also rereads the journal around its CAS. These are specific paths, not a claim that every TUI turn reads the whole file. Repeated full reads make long Sessions increasingly expensive.
The prior 1,000-connection exercise for #1236 used simulated clients from one load host for 10 seconds and did not establish SQL cost, sustained capacity, distributed real CLI behavior, or 1,000 concurrently active tasks.
Design direction
- One Session fact model and one execution backbone. Inventory the owners and consumers of local conversation records, Server transcript/context, Run events, and Edge invocation records. Preserve one logical identity, ordering, and execution ownership for the same Session across modes. Keep full user-visible history distinct from the compact model working context. Allow multiple observers and concurrent independent Sessions; serialize only execution that actually shares a Session's existing owner, not an entire workspace.
- Use local storage where it exists, and persist what sharing requires. Reuse the existing local Session and Edge invocation journals instead of adding another authoritative state machine. Synchronize only facts needed for shared history, recovery, billing, and required audit, with bounded idempotent asynchronous batches where semantics allow. In Server-only mode, persist the same logical facts in shared storage. Remove redundant projections or outbox state only after identifying their consumers and preserving their actual behavior.
- Make consistency visible. A local fact awaiting sync must not be presented as durably available on another device. If the original machine is offline, another device can only see facts already persisted to a shared location. Preserve ordering, explicit unknown tool outcomes, and correct recovery; do not blindly repeat a side effect when its result is unknown.
- Use live delivery rather than continuous per-connection database discovery. Reuse existing event and authenticated relay capabilities where possible, including correct routing when the caller and Edge are attached to different Servers. Eliminate duplicate idle polling paths and replace periodic TUI full-tree refresh with event-driven updates plus bounded replay or on-demand recovery. Handle missed events, disconnects, Server failure, slow consumers, and reconnect without requiring a new mandatory broker or parallel coordination service.
- Bound long-history work. Append and read recent local facts without reloading the full journal; use snapshots, cursors, or rebuildable offsets only where useful. Page user history and assemble a bounded model working set. For Server reads, verify the actual MatrixOne physical plan and rows scanned on realistic cardinalities, not just SQL
LIMITor index names. Do not replace one unbounded scan with another.
Favor deletion and convergence of existing state, SQL, and paths over adding caches, tables, queues, or compatibility layers. Retain the existing authentication/revocation and local execution boundaries, necessary usage/audit facts, and the frozen MOI Gate contract. A fresh design needs no legacy migration or compatibility layer; this is not authorization to delete existing user data. The local Codex rollout/journal and bounded-tail scanning implementation is a useful reference, while Astra's multi-Server and cross-device semantics still require their own solution.
Acceptance
- Map the facts, owners, readers, and retained/removed projections across CLI, Edge, and Server-only. Show what state, SQL paths, and code are removed, separately accounting for implementation, tests, and documentation.
- Measure before and after against a real MatrixOne instance. Report foreground and background SQL and transactions, rows scanned, pool/lock wait, storage/network bytes, Server CPU/RSS, connection resources, and p50/p95/p99 latency. Include real query plans and data distributions.
- Validate at least 1,000 real CLI/Edge clients distributed across multiple machines, connected to at least two Servers for a sustained period (target at least one hour). Measure idle separately from 100 and 1,000 active tasks, including simple conversation, actual tool calls, multiple Sessions per user, and multiple observers of one Session. Report offered, completed, failed, and queued work; do not present online connections as active throughput.
- Steady-state idle clients do not each cause scheduled Session, Run-tree, or dispatch SQL. Any node-level recovery work is bounded and its rate is reported. Verify reconnect and token-refresh bursts do not create a request storm.
- Exercise Sessions with 100, 10,000, and 100,000 historical facts/Runs. Recent-window reads and appends must not require reading all local or Server history; paged history must remain complete and ordered. Measure actual scan and resource growth.
- Test cross-Server routing, Server/CLI restart, network loss and lost acknowledgements, backlog, unknown tool results, multiple clients, Session deletion, credential revocation, user isolation, and MOI Gate behavior. A failure must not be reported as success or cause duplicate side effects.
- Verify user-visible behavior and real recovery paths, including Server-only durable resume and honest visibility of unsynchronized local facts. Do not claim scale from mocks, a short idle test, or a single load host.
Related work and boundary
- fix(runtime): preserve execution and context continuity #1236 addresses shell/task execution and context continuity. Reuse its final owners and contracts; do not reimplement its interactive-shell, capture, or plan coordination work. Its distributed multi-Server and active-load acceptance is still outstanding.
- perf(storage): simplify hot-path persistence and retire redundant product state #1186 covers broad storage/schema and hot-path retirement; coordinate ownership and reuse that work rather than implementing the same cleanup twice. This issue specifically owns the cross-mode same-Session model, distributed idle connection cost, local/remote synchronization, and long-history access.
- [Bug]: Short Server turns incur excessive database round trips with a remote MatrixOne database #980 tracks an individual short Server-only turn's remote-database latency. Reuse its measurements where applicable rather than treating the older baseline as the present system.
Activity
XuPeng-SH commentedon Nov 17, 2026
补充 2026-11-17 确认的产品方向与实施顺序。当前核对基线为 main
f000f7ec4(#1315 已合并)。CLI/Edge 优先本地持久化,不自动向云端保存完整对话和工具输出;基础 introspect、trace、reflect 证据必须保留并可扩展。 这是本 issue “本地承载本地工作”方向的进一步明确。云端共享摘要不等于完整内容已经备份,也不代表另一台设备具备恢复条件。
数据归属
“必要计量”由已有计量 owner 负责;本地 trace 用量不能冒充完整账单。未知副作用和未确认回执不能因为减量、过期或重试而丢失。
关键现状与设计约束
当前 CLI 的模型循环、模型轮次准备和 canonical Context 仍由 Server 管理;本地 journal 不是这一 Server 恢复权威的直接替代品。仅关闭 journal 上传仍不能实现完整内容只存本地;直接停止 Server 的 canonical 写入会破坏续聊与故障恢复。
因此需要先盘点真实 producer、reader 和恢复 owner,再调整执行/存储归属。目标是让同一个 backbone 支持 CLI/Edge 执行宿主,沿用现有 execution binding、journal、checkpoint、权限和副作用语义;不是恢复另一套 CLI agent loop,也不是让 Server 隐式访问用户文件。具体宿主接入与 owner 切换协议仍需落实和验证,尚未实现。
实施顺序
先删除已经确认的冗余。
再完成执行 owner 与存储 owner 的统一。
控制长期增长并验证容量。
验证与当前进度
本地已有一个尚未提交/发布的窄修复:移除同步重放的三条冗余 SQL 路径。真实隔离 MatrixOne 上,新增 SQL 观察断言先在基线上复现了全历史 COUNT、最后事件查询和摘要 UPDATE;修改后,按 nextest 独立测试进程执行的 5 项
sync_outbox_数据库测试通过,覆盖批量重放/混合记录、投影身份、惰性 session 创建、删除 fence 和同 session ID 的跨 owner 隔离。这不是整体优化完成、生产部署或千用户容量结论。继续沿用本 issue 原验收,不降低门槛:
职责分工:本 issue 继续拥有 CLI/Edge/Server 的同 Session 语义、执行与存储归属、同步和长历史规模化;#1186 继续拥有通用 schema/SQL/冗余产品状态清理;#1302 第 5 节保留同拓扑非模型延迟与持久化性能验收。复用已有优化,不把已合并工作重复计入收益。