Skip to content

perf(agent): deduplicate step metadata, tool contracts, external descriptors, and return payloads - #7290

Open
M4n5ter wants to merge 1 commit into
perf/7272-compress-contentsfrom
perf/7272-structural-dedup
Open

M4n5ter wants to merge 1 commit into
perf/7272-compress-contentsfrom
perf/7272-structural-dedup

Conversation

@M4n5ter

@M4n5ter M4n5ter commented Nov 25, 2026 •

Copy link
Copy Markdown
Member
English

PR 6/8 in the #7272 storage optimization stack (stacked on #7289; rebased onto main after 0057_pinned_memory.sql).

Stack (#7272)

  1. perf(agent-state): drop redundant duplicate and prefix indexes on recall, runs, and interactions #7285 — Drop 6 redundant duplicate/prefix B-tree indexes (m0058)
  2. perf(agent-state): drop stored folded column from agent_recall_messages #7286 — Drop agent_recall_messages.folded (m0059)
  3. perf(agent-state): deduplicate Recall indexing at source and coalesce external deltas #7287 — Deduplicate Recall bodies & FTS5 postings at source + 2-tier immutable external delta sealing (m0060)
  4. perf(agent-state): replace repeated (owner, session) strings with integer namespace_id #7288 — Replace repeated (owner, session) strings with namespace_id (m0061)
  5. perf(event-log): add tiered/dictionary zstd compression and background recompression for contents #7289 — Tiered/dictionary zstd compression & background recompression for contents (m0062–m0063)
  6. perf(agent): deduplicate step metadata, tool contracts, external descriptors, and return payloads #7290 — Structural dedup for step metadata, tool contracts, external descriptors & returns
  7. perf(storage): compress application tables, agent_cells bodies, and intern usage JSON blobs #7318 — Compress application_* & agent_cells, intern agent_usage_calls JSON blobs (m0064–m0065)
  8. perf(agent): externalize and deduplicate media in frozen prompts (Layout v3) #7341 — Externalize & CAS-deduplicate media in frozen prompts (Layout v3, zero SQL migration)

Summary

Eliminates structural duplication in newly written durable fact payloads while keeping full read compatibility with historical payloads:

  • Reference-shares repeated tool contracts, external effect tool definitions (StoredToolDefinition::{Inline, Ref}), and external instructions (instructions_ref) via content-addressed ContentRef blobs.
  • Deduplicates redundant projection text on both ('text', 'text') and ('cell', 'text') tool returns via StoredToolResult::FromOutput, and strips redundant inline CellReply.observation on CellReplyState::Completed outputs (preserving inline observation on CellReplyState::Interrupted so cross-run external wait reads and snapshots stay intact).
  • Switches accept_cell_with_tool (plugins/agent/engine/src/driver/cells.rs) to ToolReturn<StoredToolResult> so compact CellCompleted returns round-trip cleanly across live runs and upgrade_compat capsules, and preserves empty tool_contracts provenance in access/model.rs and compacted.rs.

Offline Real-DB Stack Outcome (24.34 GiB CoW Clone)

This PR targets newly written durable facts (on top of the historical migrations in #7285–#7289 and #7318). Across the full 7-PR stack on a 24.34 GiB offline CoW clone, existing historical data alone drops to 10.34 GiB pre-VACUUM (-57.5% / 2.35×) and 9.30 GiB post-VACUUM (-61.8% / 2.62×), with #7290 further shrinking steady-state new writes.

Tests

  • cargo fmt --check — PASS
  • cargo clippy --no-deps -p maka-event-log -p maka-agent-facts -p maka-agent-state --all-targets -- -D warnings — PASS
  • cargo nextest run -p maka-event-log -p maka-agent-facts -p maka-agent-state -p maka-agent-engine — PASS
  • cargo nextest run -p maka-agent-native -E 'test(tool_history) | test(step_projection) | test(external_return) | test(tool_contracts) | test(external_effect)' — 26/26 PASS
  • cargo nextest run -p maka-cli --test upgrade_compat -E 'test(upgrade_compat_capsule_roundtrip)' — PASS

Refs #7272

中文

#7272 存储优化系列第 6/8 个 PR(基于 #7289,已同步 rebase 到 main 0056 之后)。

系列栈(#7272)

  1. perf(agent-state): drop redundant duplicate and prefix indexes on recall, runs, and interactions #7285 — 删除 6 个重复/前缀冗余 B-tree 索引(m0058)
  2. perf(agent-state): drop stored folded column from agent_recall_messages #7286 — 删除 agent_recall_messages.folded 冗余列(m0059)
  3. perf(agent-state): deduplicate Recall indexing at source and coalesce external deltas #7287 — 从源头对 Recall 正文与 FTS5 postings 联合去重 + 两段不可变外部 delta 封口(m0060)
  4. perf(agent-state): replace repeated (owner, session) strings with integer namespace_id #7288 — 用整数 namespace_id 替换重复 (owner, session) 字符串(m0061)
  5. perf(event-log): add tiered/dictionary zstd compression and background recompression for contents #7289 — contents 分档/静态字典 zstd 压缩与后台存量重压(m0062–m0063)
  6. perf(agent): deduplicate step metadata, tool contracts, external descriptors, and return payloads #7290 — 新写 durable facts 结构去重(tool contracts、external descriptors/instructions、returns)
  7. perf(storage): compress application tables, agent_cells bodies, and intern usage JSON blobs #7318 — 压缩 application_* 与 agent_cells 并对 agent_usage_calls JSON 字典驻留(m0064–m0065)
  8. perf(agent): externalize and deduplicate media in frozen prompts (Layout v3) #7341 — Frozen prompt 媒体外置与 CAS 去重(Layout v3,零 SQL 迁移)

改动内容

消除新写 durable facts 中的结构性重复,同时完整兼容历史载荷读取:

  • 通过内容寻址 ContentRef 引用共享重复的 tool contracts、外部工具定义(StoredToolDefinition::{Inline, Ref})及外部指令文本(instructions_ref)。
  • 通过 StoredToolResult::FromOutput 消除 ('text', 'text') 与 ('cell', 'text') 工具返回中的重复 projection 文本,并仅在 CellReplyState::Completed 输出上剥离冗余内联 CellReply.observation(保留 Interrupted 场景的内联观测,保证跨 run 等待与快照完整)。
  • 将 accept_cell_with_tool 切换为 ToolReturn<StoredToolResult>,并修复 access/model.rs 与 compacted.rs 中空 tool_contracts 的 provenance 还原。

整栈离线实测结果(24.34 GiB CoW 克隆)

本 PR 优化后续新写 durable facts;整条 7-PR 栈(#7285–#7318)仅在存量历史数据上即已从 24.34 GiB -> 10.34 GiB(VACUUM 前活跃页,-57.5% / 2.35×)压至 9.30 GiB(VACUUM 后,-61.8% / 2.62×),叠加本 PR 后新写稳态占用进一步下降。

Refs #7272

@Astro-Han Astro-Han 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.

English

Great work on StoredToolDefinition, out-of-line RequestSpec.toolContracts, removing notifications/recoveredCells duplication from projection/provenance, and keeping CellReplyState::Interrupted observations inline for cross-run wait and snapshot portability.

Issues to address

  1. NativeExternalEffects::settle and read_return return CellReply { observation: Value::Null } to callers (plugins/agent/native/src/owner/driver_external_effects.rs:1381-1460, 836-877, 1716-1740):
    • In settle, reply.observation is mutated to serde_json::Value::Null in place before serializing ExternalReturn::Output, and then that same mutated output is returned directly in Ok(ReturnedToolResult { output, ... }) to HostEffects::invoke callers.
    • Similarly, read_return deserializes the persisted ExternalReturn and passes output straight through render_return without hydrating reply.observation from CellReplyState::Completed { result }.
    • Fix: strip observation only on the persisted payload (keep/restore the original observation for the return value in settle), and hydrate reply.observation from self.state.content(run, result.clone()).await in read_return when reply.observation.is_null() on a Completed cell.
  2. Asymmetry on explicit "observation": null in ToolResultFields::value() (plugins/agent/state/src/session_history/tool_result_source.rs:349-355): external_effects/sql.rs:289 and session_history/sql.rs:967 check reply.observation.is_null(), whereas tool_result_source.rs:353 checks if observation.is_some(). If a blob ever carries an explicit "observation": null instead of omitting the key, lazy reconstruction will be skipped. Changing the check to observation.as_ref().is_some_and(|v| v.kind != JsonKind::Null) makes both sides consistent.
  3. Minor cleanups:
    • driver_model.rs:960-964, 1027: in non-Code-Mode runs, tool_contracts is empty {} yet still writes a tool_contracts_blob and pins it per run; setting tool_contracts: None when empty avoids unnecessary pins.
    • ExternalEffectEvent::Prepared's definition_ref is currently pinned in both sql.rs:1076-1085 and external_effects/sql.rs:215-225, whereas Returned's CellReplyState::Completed { result } is pinned only in external_effects/sql.rs:283-295; consolidating pin ownership in one layer will avoid ordering fragility later.

Further improvements to push steady-state down into 3–5×

Because intra-blob duplication is already ~90% compressed by #7289's zstd, #7290's 1.61 GiB raw reduction nets ~343 MiB post-zstd. Looking at my local 1.71 GiB DB (and post-Nov-22 steady-state writes), the biggest remaining wins that zstd alone cannot solve are:

  1. Extend from_output beyond JSON to Text and Cell projections (plugins/agent/facts/src/tool_output/acceptance.rs:73-82): On my local DB, 97.8% (54.0 of 55.2 MiB) of tool_return(output + projection) blobs are ('cell', 'text'), where projection.text alone accounts for 26.1 MiB of duplicated text alongside the cell output—and ToolOutput::Text ↔ DurableToolProjection::Text isn't covered either. Extending StoredProjection::FromOutput to exact-match Text outputs and deterministically rendered Completed cell projections eliminates the largest remaining text duplication in contents.
  2. Address large uncompressed JSON tables outside contents (223 MiB / 27% of post-stack steady-state on my DB; ~2.1 GiB / 22% on yours):
    • agent_cells.body (22.8 MiB locally, uncompressed TEXT, plus O(n²) full CellView re-serialization on every cell event in cells/sql.rs): normalizing children into a child table or storing snapshots compressed cuts both disk size and WAL write amplification.
    • application_operation_contracts (10.7 MiB locally for only 31 rows of uncompressed JSON), application_intents.recovery_json (13.0 MiB), and application_operations.request_json (12.1 MiB): storing these via contents (or compressing them) immediately captures both deduplication and #7289's zstd savings.
  3. Out-of-line static system / instructions on external-agent prompts: Similar to RequestSpec.toolContracts, external-agent prompt records still embed full static system + instructions per step (49 MiB in my historical corpus); referencing them via ContentRef avoids repeating them across rows.
中文

StoredToolDefinition 互斥枚举、RequestSpec.toolContracts 外置、从 projection/provenance 去掉重复的 notifications/recoveredCells,以及在 CellReplyState::Interrupted 上保留内联 observation 以兼容跨 run wait 和快照迁移,这几处设计都很细致。

需要处理的问题

  1. NativeExternalEffects::settle 与 read_return 向调用方返回了 CellReply { observation: Value::Null }(plugins/agent/native/src/owner/driver_external_effects.rs:1381-1460、836-877、1716-1740):
    • settle 在序列化 ExternalReturn::Output 之前原地把 reply.observation 置成了 serde_json::Value::Null,随后直接把这同一个被改过的 output 放进 Ok(ReturnedToolResult { output, ... }) 返回给了 HostEffects::invoke 调用方。
    • 同样,read_return 反序列化落盘的 ExternalReturn 后直接透传给 render_return,没有按 CellReplyState::Completed { result } 还原 reply.observation。
    • 修复方式:settle 仅对持久化副本剥离 observation(返回时保留/恢复原始 observation),read_return 在检测到 Completed cell 且 reply.observation.is_null() 时从 self.state.content(run, result.clone()).await 还原。
  2. ToolResultFields::value() 对显式 "observation": null 判定不对称(plugins/agent/state/src/session_history/tool_result_source.rs:349-355):external_effects/sql.rs:289 与 session_history/sql.rs:967 判的是 reply.observation.is_null(),而 tool_result_source.rs:353 判的是 if observation.is_some()。若记录里出现显式 "observation": null 而非省略键,会跳过懒重建。改成 observation.as_ref().is_some_and(|v| v.kind != JsonKind::Null) 即可对齐。
  3. 两处小清理:
    • driver_model.rs:960-964, 1027:非 Code Mode 下 tool_contracts 是空 {},目前仍写入 tool_contracts_blob 并按 run pin 一次,空时直接置 tool_contracts: None 更干净。
    • ExternalEffectEvent::Prepared 的 definition_ref 在 sql.rs:1076-1085 和 external_effects/sql.rs:215-225 各 pin 了一次,而 Returned 的 CellReplyState::Completed { result } 只在 external_effects/sql.rs:283-295 pin;统一收口到同一层能避免后续调整调用顺序踩坑。

进一步改进方向(把稳态压进 3–5×)

因为同 blob 内的重复已经被 #7289 的 zstd 提前压掉了约 90%,#7290 的 1.61 GiB 原始减量叠加 zstd 后净省约 343 MiB。结合我本地 1.71 GiB 库(以及 11-22 后的稳态写入),仅靠 zstd 解决不了的最大剩余收益在三处:

  1. 把 from_output 从 JSON 扩展到 Text 和 Cell 投影(plugins/agent/facts/src/tool_output/acceptance.rs:73-82):我本地库里 55.2 MiB 的 tool_return(output + projection) 中 97.8%(54.0 MiB)是 ('cell', 'text'),光重复的 projection.text 就占 26.1 MiB,而 ToolOutput::Text ↔ DurableToolProjection::Text 目前也没覆盖。把 StoredProjection::FromOutput 扩展到完全相等的 Text 输出和确定性渲染的 Completed cell 投影,能砍掉 contents 里剩余最大的文本双份拷贝。
  2. 收口 contents 之外未压缩的大 JSON 表(我本地 223 MiB,占完栈后稳态的 27%;你那边约 2.1 GiB,占 22%):
    • agent_cells.body(本地 22.8 MiB 明文 TEXT,且 cells/sql.rs 每次 cell event 都会把整棵 CellView O(n²) 重写):把 children 拆成子表或压缩存储,能同时压低磁盘体积和 WAL 写放大。
    • application_operation_contracts(本地仅 31 行明文 JSON 就占 10.7 MiB)、application_intents.recovery_json(13.0 MiB)和 application_operations.request_json(12.1 MiB):外置进 contents 或压缩存储,能立刻同时吃到去重和 #7289 zstd 红利。
  3. 外置外部 agent prompt 里的静态 system / instructions:和 RequestSpec.toolContracts 类似,外部 agent prompt 每步仍重复内联完整的 system 和 instructions(我历史语料占 49 MiB),改成 ContentRef 外置即可跨行共享。

@M4n5ter

M4n5ter commented Nov 26, 2026

Copy link
Copy Markdown
Member Author

@Astro-Han Addressed all 3 correctness/cleanup items and landed all 3 further improvements directly in the stack (rebased onto #7289):

  • Fixed settle / read_return observation: Value::Null: settle now strips observation only on the persisted copy while returning the intact ReturnedToolResult, and read_return hydrates Completed observations from self.state.content(run, result).
  • Fixed JsonKind::Null symmetry in tool_result_source.rs: Updated ToolResultFields::value() to treat explicit JSON null the same as absent observation.
  • Cleanup: Omitted empty tool_contracts blob writes when no tools are bound (restoring empty BTreeMap on read in access/model.rs & compacted.rs) and consolidated definition_ref pinning.
  • Extended StoredProjection::FromOutput to ('text', 'text') and ('cell', 'text') tool returns (and switched accept_cell_with_tool to ToolReturn<StoredToolResult>).
  • Out-of-line external instructions_ref: Shared static external instructions via ContentRef.
  • Non-contents large JSON tables: Landed directly as stacked PR perf(storage): compress application tables, agent_cells bodies, and intern usage JSON blobs #7318 (m0063–m0064), compressing application_operation_contracts, application_operations.request_json, application_intents.{reference_json, recovery_json}, and agent_cells.body, and interning agent_usage_calls.{binding_json, quote_json} into agent_usage_json_blobs.

Across the full 7-PR stack (#7285–#7290 + #7318) on a 24.34 GiB offline CoW clone, existing historical storage drops from 24.34 GiB -> 10.34 GiB pre-VACUUM (-57.5% / 2.35×) and 9.30 GiB post-VACUUM (-61.8% / 2.62×), before #7290's new-write structural dedup even applies.

@Astro-Han Astro-Han 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.

English

Confirmed all 3 previous findings are fixed on 76ad3524cc (settle / read_return preserve CellReply.observation, ToolResultFields::value() handles explicit JsonKind::Null, empty tool_contracts blobs are omitted), and the ('text', 'text') / ('cell', 'text') FromOutput extensions plus instructions_ref pin/snapshot/import wiring are cleanly closed end-to-end.

Three smaller items to clean up before merging:

  1. Unbounded RAM read of CellObservation.result in completed_cell_projection_json (plugins/agent/state/src/session_history/tool_result_source.rs:464-470, 999-1015): read_source_bytes accumulates the entire result JSON into a Vec<u8> (the budget only caps per-read 32 KiB chunks) and parses it into a full serde_json::Value DOM, bypassing SourceBudget on large JSON cell results. Streaming JSON escaping or enforcing SourceBudget on the accumulated size closes this.
  2. Assertion misses dictionary tier encoding = 3 (products/maka/cli/tests/upgrade_compat.rs:2086): The post-upgrade continuation check asserts c.encoding IN (1, 2), which will miss rows encoded with #7289's dict_v1 tier (3); changing to IN (1, 2, 3) aligns with #7289.
  3. Silent skip on malformed instructionsRef (plugins/agent/state/src/sql.rs:1081-1091, plugins/agent/state/src/session_history/sql.rs:958-967): if let Ok(reference) = ... silently skips a corrupted instructionsRef object instead of failing closed like the neighboring ExternalEffectEvent::Prepared check.
中文

已核实 76ad3524cc 修完了上次全部 3 条发现(settle / read_return 保持完整 CellReply.observation、ToolResultFields::value() 对齐显式 JsonKind::Null、空 tool_contracts 不再写多余 blob),新增的 ('text', 'text') / ('cell', 'text') FromOutput 扩展与 instructions_ref 的 pin / snapshot / 导入链路也已全链路闭环。

合并前还有三处小问题可以顺手清理:

  1. completed_cell_projection_json 无界缓存 CellObservation.result 绕过 SourceBudget(plugins/agent/state/src/session_history/tool_result_source.rs:464-470, 999-1015):read_source_bytes 会把整份 result JSON 无界读进 Vec<u8>(budget 只限制单次 32 KiB 读块)再解析成完整 serde_json::Value DOM。对大 JSON cell 结果建议改为流式转义输出或把累计字节纳入 SourceBudget 上限。
  2. products/maka/cli/tests/upgrade_compat.rs:2086 漏掉了字典编码档 3:升级后续跑校验写的是 c.encoding IN (1, 2),会漏掉 #7289 走 dict_v1 压缩的行,改成 IN (1, 2, 3) 即可。
  3. instructionsRef 格式损坏时静默跳过(plugins/agent/state/src/sql.rs:1081-1091、plugins/agent/state/src/session_history/sql.rs:958-967):if let Ok(reference) = ... 遇到损坏的 instructionsRef 字段会静默跳过,建议和旁边的 ExternalEffectEvent::Prepared 一样改成 fail-closed。

@M4n5ter

M4n5ter commented Nov 26, 2026

Copy link
Copy Markdown
Member Author
English

@Astro-Han Thanks for the review! Rebased onto the updated stack and fixed all three items in ef0d958a3e:

  1. Bounded streaming in completed_cell_projection_json: Replaced unbounded read_source_bytes + serde_json::Value DOM in plugins/agent/state/src/session_history/tool_result_source.rs with read_bounded_source_bytes(..., 128) for cell_id and a streaming JsonStringEscapedBytes (ByteSource / ByteCursor adapter over 32 KiB SourceBudget chunks with whitespace compaction). Added completed_cell_projection_json_streams_byte_identical_output_and_slices verifying byte-identical output and arbitrary slice offsets.
  2. Fail-closed instructionsRef extraction: Extracted shared crate::sql::external_task_instructions_ref in plugins/agent/state/src/sql.rs (used by both sql.rs and session_history/sql.rs) so missing instructionsRef returns Ok(None), while read errors or malformed references fail closed with Err. Added negative test external_task_instructions_ref_fails_closed_on_malformed_reference.
  3. upgrade_compat.rs encoding assertion: Updated c.encoding IN (1, 2) to c.encoding IN (1, 2, 3) so dictionary-compressed continuation writes are counted properly.
中文

@Astro-Han 感谢 review!已同步 rebase 并在 ef0d958a3e 全部修复:

  1. completed_cell_projection_json 有界流式改造:移除 plugins/agent/state/src/session_history/tool_result_source.rs 中无界 read_source_bytes 与 serde_json::Value DOM,cell_id 走 read_bounded_source_bytes(..., 128),结果正文改为基于 32 KiB SourceBudget 分块的流式 JsonStringEscapedBytes(含空白折叠与 JSON 字符串转义),并补 completed_cell_projection_json_streams_byte_identical_output_and_slices 锁定字节一致与任意切片偏移。
  2. instructionsRef fail-closed 校验:在 plugins/agent/state/src/sql.rs 抽共用函数 external_task_instructions_ref(sql.rs 与 session_history/sql.rs 共享),字段缺失返回 Ok(None),读取失败或引用非法直接返回 Err,并补了负面测试 external_task_instructions_ref_fails_closed_on_malformed_reference。
  3. upgrade_compat.rs 编码断言:将 c.encoding IN (1, 2) 修正为 c.encoding IN (1, 2, 3),覆盖字典压缩写入。

@M4n5ter
M4n5ter force-pushed the perf/7272-structural-dedup branch from ef0d958 to 4f4f92f Compare November 27, 2026 02:56
@github-actions github-actions Bot added effort/XXL Over 2500 readable lines and removed effort/XL Under 2500 readable lines labels Nov 27, 2026

@Astro-Han Astro-Han 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.

English

Confirmed all three previous items are cleanly fixed on 4f4f92f9a4:

  • completed_cell_projection_json now streams via JsonStringEscapedBytes with bounded memory, correct JSON escaping and UTF-8 chunk-boundary handling, and byte-identical slicing.
  • external_task_instructions_ref is shared and fail-closed on malformed or missing referenced content.
  • upgrade_compat.rs checks c.encoding IN (1, 2, 3).

Two optional minor follow-ups (non-blocking):

  • plugins/agent/state/src/sql.rs:1124-1135: ExternalEffectEvent::Returned still ignores read/parse errors fail-open when pinning, unlike session_history/sql.rs:966-979 which fails closed.
  • plugins/agent/state/src/session_history/tool_result_source.rs:1235: JsonStringEscapedCursor::read_chunk allocates a fixed 32 KiB scratch buffer while holding the caller's buffer; clamping to cap.clamp(64, 32 * 1024) or reusing a cursor buffer is slightly tighter under small budgets.

Ready to merge once the earlier PRs in the stack land.

中文

已确认 4f4f92f9a4 上三项问题均已干净修复:

  • completed_cell_projection_json 已改为 JsonStringEscapedBytes 有界流式实现,JSON 转义、UTF-8 跨块边界与任意切片均正确。
  • external_task_instructions_ref 已抽成共用实现并在非法/缺失引用时 fail-closed。
  • upgrade_compat.rs 已更新为 c.encoding IN (1, 2, 3)。

两处不阻塞合并的小点:sql.rs:1124-1135 的 ExternalEffectEvent::Returned pin 仍是 fail-open(与 session_history/sql.rs:966-979 不一致);tool_result_source.rs:1235 可按 cap.clamp(64, 32 * 1024) 申请或复用缓冲。前置 PR 就绪后即可合并。

@M4n5ter
M4n5ter force-pushed the perf/7272-structural-dedup branch from 4f4f92f to aa191fc Compare November 27, 2026 06:29
@M4n5ter

M4n5ter commented Nov 27, 2026

Copy link
Copy Markdown
Member Author

@Astro-Han Quick heads-up on the rebase push aa191fc4c1 (onto updated #7289): beyond the rebase, we also folded in two write/read-path cleanups from our internal audit — deduplicating StoredExternalEffectDescriptor / StoredExternalReturn decoding inside the Root write transaction via PersistedExternalEffect (and moving read_external_return JSON deserialization off the Tokio executor into a single SQLite read snapshot), plus trimming compact_external_effect_shares_definition_and_preserves_cross_run_cell_reads to go directly through production effects.prepare_descriptor.

…riptors, and return payloads

Eliminate structural duplication in newly written durable fact payloads while
preserving full read compatibility with historical payloads:
- Reference-share repeated tool contracts, external effect definitions
  (StoredToolDefinition::{Inline, Ref}), and external instructions
  (instructions_ref) via content-addressed ContentRef blobs.
- Deduplicate redundant projection text on ('text', 'text') and ('cell', 'text')
  tool returns via StoredToolResult::FromOutput and strip redundant inline
  CellReply.observation on Completed outputs (keeping observation on Interrupted
  for cross-run external wait reads).
- Switch accept_cell_with_tool to StoredToolResult so compact CellCompleted
  returns round-trip cleanly across live runs and upgrade_compat capsules.

Refs #7272

Generated-by: Antigravity
@M4n5ter
M4n5ter force-pushed the perf/7272-structural-dedup branch from aa191fc to e714c93 Compare November 27, 2026 09:30

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

effort/XXL Over 2500 readable lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants