Repository navigation
Conversation
5fb113b to
4b1c84c
Compare
4b1c84c to
f87a8ad
Compare
Astro-Han
left a comment
There was a problem hiding this comment.
English
Really clean design on f87a8adfcd—moving media out of the 32 KiB prompt chunks removes both the 2.33× per-image arena bloat and chunk-shift re-storage with zero SQL migration. I verified:
- Full 32-byte SHA-256 + byte-length fail-closed binding across capture, index record (
r[6..10]), andrestore_prompt_from(bothLiveandSnapshotsources), with streaming file-backed restoration and clean arena cleanup on error/cancellation. description.commitmentandprefix_digestremain byte-identical between Layout v2 and v3, preserving prompt caching andcovered_prefixacross upgrades.- All
snapshot_promptsites (driver_model.rs,compacted.rs,summary_repair.rs) wireprompt_mediaintoFrozenInput::content_refs()->RequestSpec.request_contentsfor live and fork-snapshot pinning.
One item worth adding before merging:
products/maka/cli/tests/upgrade_compat.rs:2311-2320: per the persisted payload compatibility rule, when checkingcontinuation_run_id'sRequestSpecs after upgrading legacy capsules, please also decoderequest(FrozenInput) and assert that post-upgrade writes emitlayout.version == 3(confirming v2 -> v3 live continuation end-to-end).
Two minor nits:
plugins/agent/engine/src/history/canonical_prompt.rs:95-99:CaptureArena::new(self.io.clone(), None)already starts file-backed, so the immediately followingcreated.promote_to_file().awaitis redundant and briefly reserves a second local I/O lease.plugins/agent/engine/src/preparation/snapshot.rs:91-115: optionally includemedia.len() * size_of::<RestoredMediaEntry>()instagingmetadata accounting for consistency.
中文
f87a8adfcd 的设计很干净,零 SQL 迁移就把单图 2.33× 膨胀和 32 KiB 切片位移重存一起解决了。已核验:
- 捕获、索引记录(
r[6..10])和restore_prompt_from(Live/Snapshot双路径)全程做了完整 32 字节 SHA-256 + 长度 fail-closed 绑定,流式文件恢复且异常/取消路径无 arena 泄漏。 description.commitment与prefix_digest在 Layout v2 与 v3 之间逐比特一致,升级不断 prompt cache 与covered_prefix。driver_model.rs、compacted.rs、summary_repair.rs全链路将prompt_media写入FrozenInput::content_refs()->RequestSpec.request_contents,live 与 fork 快照 pin 闭合。
合并前建议补一项:
products/maka/cli/tests/upgrade_compat.rs:2311-2320:按持久化 JSON payload 变更规范,建议在continuation_run_id校验RequestSpec时顺带解码FrozenInput,断言升级后新写入的是layout.version == 3,端到端验证 v2 胶囊续跑切到 v3。
两处小细节:canonical_prompt.rs:95-99 的 CaptureArena::new(..., None) 本身已是文件型,紧接着的 promote_to_file() 是多余的;snapshot.rs:91-115 的 staging 可选顺带计入 RestoredMediaEntry 向量元数据字节。
3de9958 to
fae2955
Compare
|
@Astro-Han Thanks for the review — all items plus a few capture/restore hardening fixes are in
Verified locally with |
Astro-Han
left a comment
There was a problem hiding this comment.
English
Confirmed all items and the extra capture/restore hardening are cleanly in place on fae2955ba6:
upgrade_compat.rs:2322-2364decodes post-upgrade continuationFrozenInputpayloads and assertslayout.version == 3.- Removed the redundant
promote_to_file()call inMediaCapture::ensure_arena. - Single-pass streaming with
truncate_unsealed, directory budget accounting in both capture and restore, and upfrontvalidate_external_media_directoryverification all check out.
Ready to merge once the base stack lands.
中文
已确认 fae2955ba6 全部项及新增的捕获/恢复加固都干净落地:
upgrade_compat.rs:2322-2364已解码升级续跑写入的FrozenInput并断言layout.version == 3。MediaCapture::ensure_arena已移除多余的promote_to_file()。- 单遍流式写入配合
truncate_unsealed、捕获与恢复双侧 directory 预算记账以及前置validate_external_media_directory校验均核查通过。
前置栈合入后即可合并。
…out v3) Prevent frozen prompt snapshots from duplicating media payloads inside 32 KiB prompt chunks: - Previously, exact_message_async base64-encoded media (1.33x) into the CaptureArena and canonical_prompt::project::decode_media immediately decoded a raw binary copy (+1.0x) into the same arena (2.33x per image per prompt), and any earlier byte shift re-hashed and re-stored every image chunk. - Add Layout v3 in canonical_prompt + preparation/snapshot: all new frozen prompt snapshots emit Layout v3 uniformly (with prompt_media omitted when empty); media parts write only a compact content-addressed ref placeholder into the prompt arena, capture raw bytes once into a lazy MediaCapture arena deduplicated by (digest, bytes), and pin the media ContentRefs in FrozenInput.prompt_media / RequestSpec.request_contents (hitting CAS against existing attachment/artifact rows in contents with zero extra disk storage). - Bind every externalized media record's 32-byte SHA-256 digest and byte length inside the prompt arena record and verify them fail-closed on restore_prompt_from. Layout v2 is kept strictly as a read-only legacy path for existing hash-chained prompts (zero SQL migration required). Refs #7272 Generated-by: Antigravity
fae2955 to
c9361ea
Compare
English
PR 8/8 in the #7272 storage optimization stack (stacked on #7318; zero SQL migration required).
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)Problem
As highlighted by the screenshot-heavy desktop workload report on #7318,
snapshot_promptpreviously inflated and duplicated media payloads inside frozen prompt chunks:serialize_source::exact_message_asyncbase64-encoded each image/audio/file part (1.33×) intoCaptureArena, andcanonical_prompt::project::decode_mediaimmediately decoded a raw binary copy (+1.0×) back into the same arena. Both copies are incompressible entropy and sit on top of the original attachment/artifact blob already stored incontents.snapshot_promptslices the monolithic arena into fixed 32 KiB chunks, any earlier 1-byte change (e.g. skillrevisionhash, system prompt update, new run) shifts byte alignment and re-hashes/re-stores another2.33×copy of every historical image in the prompt (amplifying screenshot-heavy and CUA sessions dramatically).Summary
canonical_prompt.rs,project.rs,serialize_source.rs,preparation/snapshot.rs):snapshot_promptserializes aContentRecipe::Mediapart (bothUsermessages andToolOutputRecipe::Content), it captures the raw bytes into a lazyMediaCapturearena deduplicated by(sha256, bytes)and writes only a compact content-addressed placeholder ({"type":"ref","digest":"sha256:...","bytes":...}) into the main prompt arena — eliminating base64 encoding/decoding roundtrips and keeping prompt chunks small and zstd-compressible.Layout { version: 3 }uniformly (prompt_mediaomitted when empty);Layout { version: 2 }is kept strictly as a read-only legacy path for existing immutable prompts.r[6..10]) inside the cryptographically hashed prompt arena. Onrestore_prompt_from, media blobs are streamed fromContentSource::{Live, Snapshot}into the temporary restore arena afterlayout.byte_len, with strict fail-closed verification of version, length, and digest (preventing equal-length blob swaps or missing refs).driver_model.rs,compacted.rs,summary_repair.rs,materialize.rs,auxiliary.rs):#[serde(default, skip_serializing_if = "Vec::is_empty")] prompt_media: Vec<ContentRef>toFrozenInputand includes it inFrozenInput::content_refs()->RequestSpec.request_contents, so liveagent_content_pinsand forkagent_history_snapshot_pinsretain every media blob automatically.contentsrows via CAS (0 extra bytes stored on disk across steps, prefix shifts, and forks); resized images fromMediaViewstore once per unique digest instead of2.33×per shifted step.Tests
frozen_prompt_externalizes_and_deduplicates_media_with_tamper_guards(tool_history.rs) covering repeatedUser+ToolOutput::Contentmedia deduplication,< 8 KiBchunk size proof, prefix-shift stability, bit-for-bitPreparedPromptlogical identity parity with v2, live SQLite restore, and fail-closed checks (equal-length swap, empty media on v3, non-empty media on v2).prompt_media_round_trips_and_pins_in_content_refs(driver_model.rs).maka-agent-engine(41/41 PASS),maka-agent-nativeimage/media/attachment/fork/snapshot tests (19/19 PASS),maka-cli::upgrade_compat upgrade_compat_capsule_roundtrip(PASS),cargo fmt --check,asf-license-headers,migrations(74 locked, 0 pending), zero clippy warnings on touched files.Refs #7272
中文
#7272 存储优化系列第 8/8 个 PR(基于 #7318,无需新增 SQL 迁移)。
系列栈(#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 迁移)问题背景
结合 #7318 评论中多截图桌面库的实测反馈,排查确认此前
snapshot_prompt存在两层媒体放大:serialize_source::exact_message_async先将媒体 base64 编码(1.33×)写入CaptureArena,紧接着canonical_prompt::project::decode_media又把原始二进制解码(+1.0×)追加进同一个 arena;两份都是 zstd 压不动的随机熵,且叠加在contents原附件之上。snapshot_prompt按固定 32 KiB 切片,只要前面 system prompt / Skillrevision/ 上下文变化哪怕 1 字节,历史中所有图片的 2.33× 都会重新分块落库(多截图对话与 CUA 场景尤为严重)。改动内容
canonical_prompt.rs/project.rs/serialize_source.rs/preparation/snapshot.rs):snapshot_prompt遇到ContentRecipe::Media(覆盖User消息与ToolOutputRecipe::Content)时,将原始字节按(sha256, bytes)去重写入延迟创建的MediaCapture临时 arena,主 prompt arena 内只写一条 ~100 B 的内容寻址占位({"type":"ref","digest":"sha256:...","bytes":...}),免去每步 base64 编解码并保持 prompt chunk 高度可压。Layout v3(无媒体时省略prompt_media),Layout v2仅作为已封存历史 prompt 的只读兼容路径。r[6..10]),restore_prompt_from从ContentSource::{Live, Snapshot}装回时严格 fail-closed 校验版本、长度与摘要(防止等长媒体替换或缺失)。driver_model.rs/compacted.rs/summary_repair.rs/materialize.rs/auxiliary.rs):FrozenInput新增可选字段prompt_media: Vec<ContentRef>(为空时省略),合入FrozenInput::content_refs()->RequestSpec.request_contents,自动受活库agent_content_pins与 forkagent_history_snapshot_pins保护;未缩放原图直接 CAS 命中contents现有行(磁盘零新增),缩放后图片也仅按唯一摘要存一份。验证
frozen_prompt_externalizes_and_deduplicates_media_with_tamper_guards(tool_history.rs)与prompt_media_round_trips_and_pins_in_content_refs(driver_model.rs)。maka-agent-engine41/41 PASS、maka-agent-native图片/媒体/附件/fork/snapshot 定向测试 19/19 PASS、upgrade_compat_capsule_roundtripPASS、cargo fmt --check/asf-license-headers/migrations(74 locked, 0 pending)全绿,改动文件零 clippy 警告。Refs #7272