Repository navigation
Conversation
63dd010 to
b4c1de0
Compare
b4c1de0 to
b7cf74d
Compare
b7cf74d to
d3452d1
Compare
Astro-Han
left a comment
There was a problem hiding this comment.
English
This delivers the single cleanest structural win in the stack (agent_session_history down 70.8%, -2.34 GiB on your DB), and the SQL coverage plus removal.rs guarded cleanup of agent_namespaces look thorough.
Issues to address
- Multi-hop behavior change in the
0055migration hook (recall/index.rs:1295-1360): Becauserebuild_sessionmoved tonamespace_id,migrate_external_effect_observationswas rewritten to incrementally insert missing rows instead of rebuilding the affected session's Recall index. Unlike the original v55 hook, this no longer clearsagent_recall_gapsfor affected sessions, so upgrading<v55 -> v59behaves differently from<v55 -> v55..v58. Either keep clearingagent_recall_gapsfor those sessions inside the v55 hook or verify that gap state stays consistent across the multi-hop path in tests. - Stacked triple rebuild inside one
SAVEPOINT: On top of #7286 (DROP COLUMN folded) and #7287 (fullagent_recall_messagesrebuild), #7288 rebuildsagent_recall_messagesa third time plusagent_session_historyand 8 child tables inside a single uncommittedSAVEPOINT. Combining thefoldedremoval (and any Recall schema change) into oneagent_recall_messagesrebuild will save tens of seconds of startup lock and gigabytes of peak WAL. - Minor query-plan note (
session_catalog/query.rs:112-117):STALE_CATALOG_SQLusesCROSS JOINto drive fromagent_session_history_historicalbefore filteringagent_namespacesby(owner, session prefix). Whenhistorical=1rows are sparse (0 rows on my local DB) this is fast, but on multi-owner DBs with many imported historical snapshots, driving fromagent_namespaces(UNIQUE(owner, session)) and probingagent_session_history_historical(namespace_id, sequence DESC)scales better.
Further improvements to push toward 3–5×
- Two remaining near-redundant indexes on
agent_session_history(namespace.rs:388-398):agent_session_history_result(namespace_id, fact_id) WHERE result_source=1:fact_idalready has a table-wideUNIQUEindex and nothing usesINDEXED BY agent_session_history_result.agent_memory_run_termination(run) WHERE kind='run_terminated':agent_session_history_run(run, step, kind)already covers(run, NULL, 'run_terminated')sincerun_terminatedalways hasstep IS NULL.
- Next table for
namespace_id—agent_usage_calls: On my 1.71 GiB DB,agent_usage_calls+agent_usage_resultstake 38.6 MiB (24.4 MiB in indexes alone; ~392 MiB on your 23.4 GiB DB), largely because(owner, session)repeats across the table and multiple secondary indexes. A follow-up migration givingagent_usage_callsa nullablenamespace_id(to preserve standalone cells whereowner IS NULL) will reclaim a large chunk of the remaining "everything else" bucket.
中文
这个 PR 是整套 stack 里收益最扎实的结构性改进(agent_session_history 降幅 70.8%,你那边直省 -2.34 GiB),全仓 SQL 切换和 removal.rs 带守卫的 agent_namespaces 清理都很完整。
需要处理的问题
- 已发布
0055迁移 hook 的跨级行为分歧(recall/index.rs:1295-1360):因为rebuild_session改成了namespace_id版,migrate_external_effect_observations被改写为增量插入缺失行而不再重建受影响 session 的 Recall 索引。和原版 v55 hook 不同,这不再清理受影响 session 的agent_recall_gaps,导致<v55 -> v59与<v55 -> v55..v58的升级结果不一致。建议在 v55 hook 里保留对受影响 session 的agent_recall_gaps清理,并在跨级升级测试中覆盖断言。 - 同一外层
SAVEPOINT下连续三次重建大表:叠在 #7286(DROP COLUMN folded)和 #7287(整表重建agent_recall_messages)之上,#7288 在同一个未提交SAVEPOINT里第三次重建agent_recall_messages,外加重建agent_session_history和 8 张子表。把删folded(以及 Recall 结构改动)合并进同一次agent_recall_messages重建,能省下几十秒启动阻塞和数 GiB 的 WAL 峰值。 - 查询计划小提示(
session_catalog/query.rs:112-117):STALE_CATALOG_SQL用CROSS JOIN强制先扫agent_session_history_historical再按(owner, session prefix)过滤agent_namespaces。historical=1稀疏时(我本地为 0 行)很快,但在多 owner 导入大量历史快照的库上,先走agent_namespaces的UNIQUE(owner, session)范围扫描再去探测agent_session_history_historical(namespace_id, sequence DESC)扩展性更好。
进一步改进方向(继续压向 3–5×)
agent_session_history上还有 2 个近冗余索引可以精简(namespace.rs:388-398):agent_session_history_result(namespace_id, fact_id) WHERE result_source=1:fact_id已有全表UNIQUE索引,且全仓没有INDEXED BY agent_session_history_result。agent_memory_run_termination(run) WHERE kind='run_terminated':agent_session_history_run(run, step, kind)已经能覆盖(run, NULL, 'run_terminated')(run_terminated恒有step IS NULL)。
- 下一张最值得转
namespace_id的表是agent_usage_calls:我本地 1.71 GiB 库里agent_usage_calls+agent_usage_results占 38.6 MiB(光索引就占 24.4 MiB;你 23.4 GiB 库上约 392 MiB),大头就是主表和多个二级索引重复存(owner, session)。后续给agent_usage_calls加一个可空的namespace_id(兼容owner IS NULL的 standalone cell),能从“其余表”里再抠出一大块空间。
d3452d1 to
a42de78
Compare
|
@Astro-Han Addressed every item from your review and rebased onto latest
|
Astro-Han
left a comment
There was a problem hiding this comment.
English
Confirmed all previous review items are cleanly resolved on a42de7813c (0055 multi-hop rebuild_session parity, STALE_CATALOG_SQL join order, dropping the 2 redundant indexes, and migrating agent_usage_calls / agent_usage_results to namespace_id). On my 1.71 GiB DB clone, m0060 completed in 3.11 s and brought agent_session_history* down -71.9% (183.93 -> 51.62 MiB).
Two small items left after the rebase from v59 to v60:
- Off-by-one version check in
products/maka/cli/tests/upgrade_compat.rs:745, 850: Both guards still checkversions.contains(&59)(and some assertion messages innamespace.rs:510, 526, 549andlib.rs:509, 521still say59) even though the migration is now registered at version60. Updating the check to&60prevents false failures on a database stopped at v59. - Minor query-plan polish (
plugins/agent/state/src/session_catalog/query.rs:604-611):STALE_CATALOG_SQLnow scansagent_namespacesviaUNIQUE(owner, session)in(owner, session)order, butGROUP BY ns.idstill triggersUSE TEMP B-TREE FOR GROUP BY. Changing it toGROUP BY ns.session(1:1 withns.idunderns.owner = ?1) eliminates the temp sort.
中文
已核实 a42de7813c 干净解决了上次全部评审项(0055 跨级 rebuild_session 一致性、STALE_CATALOG_SQL 连接顺序、删除 2 个近冗余索引,以及将 agent_usage_calls / agent_usage_results 纳入 namespace_id)。在我本地 1.71 GiB 库克隆上,m0060 耗时仅 3.11 s,agent_session_history* 降幅达 -71.9%(183.93 -> 51.62 MiB)。
rebase 到 v60 后还有两处小问题:
products/maka/cli/tests/upgrade_compat.rs:745, 850版本号错位:两处仍用versions.contains(&59)(namespace.rs:510, 526, 549和lib.rs:509, 521的断言文案也还写着59),但迁移已升至60。停在 v59 的库会在此误报,改成&60即可。- 查询计划微调(
plugins/agent/state/src/session_catalog/query.rs:604-611):STALE_CATALOG_SQL已改为按UNIQUE(owner, session)扫描agent_namespaces,但GROUP BY ns.id仍会触发USE TEMP B-TREE FOR GROUP BY;在ns.owner = ?1条件下ns.session与ns.id一一对应,改成GROUP BY ns.session即可省掉临时排序。
a42de78 to
65d9c6e
Compare
English@Astro-Han Thanks for catching both! Rebased onto latest
中文@Astro-Han 感谢指正!已 rebase 到最新
|
65d9c6e to
578a073
Compare
Astro-Han
left a comment
There was a problem hiding this comment.
English
Confirmed upgrade_compat.rs guards (&61), STALE_CATALOG_SQL (GROUP BY ns.session), and the 0057_pinned_memory.sql / #7315 / #7317 port onto namespace_id all check out on 578a0733a6.
Two blocking cold-upgrade issues in the newly added non-Current branch of index_sources_with_layout (plugins/agent/state/src/recall/index.rs:2597-2622):
-
Cold migration crash on pre-
#7115RequestSpecrows (recall/index.rs:2615-2616):- I ran the full upgrade on an offline CoW clone of my 1.71 GiB database (
max_ver=55), and migration0060aborted immediately with:
Json(Error("unknown fieldsystemPrompt, expected one ofsurface,dynamicContext,toolCatalogDigest,providerOptions,maxOutputTokens")) - My DB has 1,049
agent_request_specsrows from before#7115(Nov 21) wherecompositionstill hassystemPrompt/toolsinstead ofsurface, andRequestCompositioncarries#[serde(deny_unknown_fields)]. Because this branch only checksrequest_spec.steering.get(position) == Some(&frozen.source), deserializing the entireRequestSpecfails closed on historical DBs unnecessarily. - Fix: deserialize only a lightweight local struct (e.g.
#[derive(Deserialize)] struct RequestSteeringOnly { #[serde(default)] steering: Vec<ContentRef> }withoutdeny_unknown_fields) to verifysteering.get(position) == Some(&frozen.source).
- I ran the full upgrade on an offline CoW clone of my 1.71 GiB database (
-
frozen.spec != *specbreaks cold upgrades of v57+ (0057_pinned_memory) DBs with queued runs (recall/index.rs:2598):#7184populatesRunSpec.memory_projection/ updatesmemory_admissionon admission after enqueueing, which is whyplugins/agent/state/src/session_history/sql.rs:1087checks!frozen.matches_run_input(spec)instead of strict equality. Any v57+ DB containing such a queued run will abort during migration0060with"original Run input differs from consumed request".- Fix: change
if frozen.spec != *spectoif !frozen.matches_run_input(spec.clone()).
Minor cleanup: namespace.rs still has leftover "v59"/"v60" strings in temp table names, error text, and test assertions (actual migration is 61), and recall.rs:46-47 has a duplicate #[cfg(test)].
中文
已核验 578a0733a6 上 upgrade_compat.rs 版本守卫(&61)、STALE_CATALOG_SQL(GROUP BY ns.session)以及 0057_pinned_memory.sql / #7315 / #7317 向 namespace_id 的移植均无问题。
三轮在 index_sources_with_layout 非 Current 分支(plugins/agent/state/src/recall/index.rs:2597-2622)新增的校验引入了两个会阻断冷升级的问题:
-
遇到
#7115前的历史RequestSpec直接导致冷迁移崩溃(recall/index.rs:2615-2616):- 在我本地 1.71 GiB 真实库副本(
max_ver=55)上跑完整升级时,m0060直接报错中止:Json(Error("unknown fieldsystemPrompt, expected one ofsurface,dynamicContext,toolCatalogDigest,providerOptions,maxOutputTokens"))。 - 库里有 1,049 条
#7115(11-21)之前的agent_request_specs记录,其composition仍是旧字段systemPrompt/tools,而RequestComposition带有#[serde(deny_unknown_fields)]。这里实际只需要核对steering.get(position) == Some(&frozen.source)。 - 修复:改为轻量结构体(如不带
deny_unknown_fields的struct RequestSteeringOnly { #[serde(default)] steering: Vec<ContentRef> })局部反序列化。
- 在我本地 1.71 GiB 真实库副本(
-
frozen.spec != *spec会阻断含 pinned-memory 排队 Run 的 v57+ 数据库冷升级(recall/index.rs:2598):#7184在 follow-up 入队后、接纳 Run 时才补写memory_projection/memory_admission,因此session_history/sql.rs:1087专门用!frozen.matches_run_input(spec)而非直接判等。v57+ 库含此类 Run 时会在m0060报错"original Run input differs from consumed request"中止迁移。- 修复:将
if frozen.spec != *spec改为if !frozen.matches_run_input(spec.clone())。
小清理:namespace.rs 里仍有若干残留的 v59/v60 临时表名和报错/测试文案(当前迁移号为 61);recall.rs:46-47 有重复的 #[cfg(test)]。
578a073 to
1a60f8d
Compare
|
@Astro-Han Addressed both cold-upgrade blockers and the minor cleanup in
Verified locally with |
Astro-Han
left a comment
There was a problem hiding this comment.
English
Confirmed both cold-upgrade blockers are fixed on 1a60f8d291 (RequestSteeringOnly for pre-#7115 RequestSpec rows and !frozen.matches_run_input(spec.clone()) for #7184 v57+ queued runs), and the new agent_recall_external_segments table is cleanly migrated to namespace_id across namespace.rs, store/removal.rs, and all recall queries.
I re-ran the full v55 -> v65 upgrade + background recompression end-to-end on a fresh CoW clone of my real 1.71 GiB database:
- Migrations
v55 -> v65completed cleanly in75.68 s(debug), recompression in13.45 s(179,691rows,-345.89 MiBraw payload),incremental_vacuum->740.38 MiB,VACUUM->667 MiB, withPRAGMA quick_check = ok,foreign_key_check = 0, andFTS5 integrity-check = OK.
One remaining blocker inherited from #7287:
plugins/agent/state/src/session_history.rs:153-159:ExecutorTranscript::mask_piecesstill queriesAND m.fact_id = s.factonagent_recall_messages(which has nofact_idcolumn). Once fixed in#7287, please port theJOIN agent_session_history h ON h.namespace_id = m.namespace_id AND h.sequence = m.sequence AND h.fact_id = s.factupdate here as well.
中文
已确认 1a60f8d291 修好了两个冷升级阻塞问题(RequestSteeringOnly 兼容 #7115 前历史 RequestSpec,!frozen.matches_run_input(spec.clone()) 兼容 #7184 v57+ 排队 Run),新增的 agent_recall_external_segments 也完整迁移到了 namespace_id(namespace.rs、store/removal.rs 及全部 Recall 查询无遗漏)。
也在我本地 1.71 GiB 真实库新副本上重跑通了完整 v55 → v65 迁移与重压:
- 迁移
75.68 s(debug)、后台重压13.45 s(179,691 行,省345.89 MiB原始载荷)、incremental_vacuum后740.38 MiB、VACUUM后667 MiB,quick_check = ok、foreign_key_check = 0、FTS5 integrity-check = OK。
仅剩一处从 #7287 承接的阻塞项:
plugins/agent/state/src/session_history.rs:153-159:ExecutorTranscript::mask_pieces同样查询了agent_recall_messages不存在的m.fact_id列,随#7287修复后请同步改为JOIN agent_session_history h ON h.namespace_id = m.namespace_id AND h.sequence = m.sequence AND h.fact_id = s.fact。
…eger namespace_id Introduce an interned agent_namespaces(id, owner, session) dictionary in migration 0061 and replace repeated owner/session text columns on agent_recall_messages, agent_session_history, agent_usage_calls, and agent_usage_results with integer namespace_id foreign keys: - Preserve all hot-path query plans across Recall, SessionHistory (including LivePositions, CompletedWorkAt, TOOL_IMAGE_BINDINGS / ImageSourcesAt, and metrics), and Usage queries. - Eliminate ~150+ byte repeated owner/session strings from primary tables and secondary B-tree indexes. - Verify migration 0061 invariants and query equivalence in migration_tests and upgrade_compat.rs. Refs #7272 Generated-by: Antigravity
1a60f8d to
5e3ca94
Compare
|
@Astro-Han Rebased onto
|
English
PR 4/8 in the #7272 storage optimization stack (stacked on #7287; rebased onto
mainafter0057_pinned_memory.sql).Stack (#7272)
m0058)agent_recall_messages.folded(m0059)m0060)(owner, session)strings withnamespace_id(m0061)contents(m0062–m0063)application_*&agent_cells, internagent_usage_callsJSON blobs (m0064–m0065)Layout v3, zero SQL migration)Summary
Introduces an interned
agent_namespaces(id, owner, session)dictionary in migration0061_namespace_surrogate_keys.sqland replaces repeated(owner, session)strings onagent_recall_messages,agent_session_history,agent_usage_calls, andagent_usage_resultswith compact integernamespace_idforeign keys:usage/index.rs,session_history/metrics.rs(u.namespace_id = h.namespace_id), andsession_history/source_tree/queries.rs(TOOL_IMAGE_BINDINGS,CompletedWorkAt,ImageSourcesAt).0060invariants inmigration_testsandupgrade_compat.rs.Offline Real-DB Verification (24.34 GiB CoW Clone)
m0061:51.22 s, live size19,441.60 MiB -> 16,846.02 MiB(-2,595.58 MiB/-2.53 GiB)agent_session_history*(post-stack):2,308.06 MiB -> 663.75 MiB(-1,644.31 MiB/-71.2%)Refs #7272
中文
#7272 存储优化系列第 4/8 个 PR(基于 #7287,已同步 rebase 到
main0056之后)。系列栈(#7272)
m0058)agent_recall_messages.folded冗余列(m0059)m0060)namespace_id替换重复(owner, session)字符串(m0061)contents分档/静态字典 zstd 压缩与后台存量重压(m0062–m0063)application_*与agent_cells并对agent_usage_callsJSON 字典驻留(m0064–m0065)Layout v3,零 SQL 迁移)改动内容
在迁移
0061_namespace_surrogate_keys.sql中引入agent_namespaces(id, owner, session)字典表,用整数namespace_id替换agent_recall_messages、agent_session_history、agent_usage_calls与agent_usage_results及所有二级索引中的重复(owner, session)字符串,并合入评审与 rebase 修复(含usage/index.rs、session_history/metrics.rs及source_tree/queries.rs中的TOOL_IMAGE_BINDINGS/ImageSourcesAt)。真实库离线实测(24.34 GiB CoW 克隆)
m0061:51.22 s,活跃数据19,441.60 MiB -> 16,846.02 MiB(-2,595.58 MiB/-2.53 GiB)agent_session_history*:2,308.06 MiB -> 663.75 MiB(-1,644.31 MiB/-71.2%)Refs #7272