Repository navigation
fix(memory): preserve working state on failed reads and admit valid recall - #995
Conversation
641c2e3 to
bbaac30
Compare
XuPeng-SH
left a comment
There was a problem hiding this comment.
结论:Approve。未发现需要修改的明确问题。
审查范围:base a41e48a4c6fe7b4e2c6bd0d734eef358860fb0e6 → head bbaac30a236ca4499473fd3d6ceaa4179cb0ae6c。完整阅读了四个文件的修改,追踪了 snapshot loader 的所有生产调用方、session 关闭调度与 debounce、MemoriaPort 读取及 session-start recall 准入。提交前再次确认 head 未变。
- 关闭 session 的修复正确。 canonical snapshot loader 保留 Disabled / AuthorityUnavailable / Failed;governance 在 episode 写入、purge 和 reflection 之前返回错误。成功空读取仍保持原有清理行为,读取失败不再被解释成缺少记忆而授权清理。
- 失败不会被记成治理成功。 Server 的错误分支不调用 governance permit.complete(),原有 Drop 释放 in-flight ownership,允许后续关闭请求重试;这没有新增自动后台重试机制。可选上下文调用方显式把错误投影为缺少远端上下文,本地快照选择及交互超时保持原有行为。
- Recall 修复保持原有约束。 仍按后端分数排序、按 memory_id 去重,复用 canonical typed prompt admission。只有通过身份、类型、状态和有限评分校验的记录才计入每类三条上限。请求候选数仍为 5+6,两次并行读取共用原有 750ms 绝对截止时间,没有额外后端请求、授权预检或数据库查询。
- 回归测试覆盖实际行为。 governance 测试通过公共入口覆盖三类读取错误 × 空/非空 session facts,并断言只有 retrieve、没有任何后续写入/清理/反思;成功空读取保留正向路径。mixed-candidate 测试覆盖非结构化、归档、namespace/type 不匹配和无评分记录,检查低排名有效记录仍被采用、结果排名及每类上限。原有 episode 写入失败保留 working state、可选读取降级和共享 deadline 测试也保持覆盖。
复杂度与资源成本:四个文件 +216/-19,净增 197 行;按现有 cfg(test) 模块边界统计,实现及注释 +38/-17(净增 21),测试 +172/-2(净增 170),文档 +6。新增测试复用现有 fixture;没有新增平行状态机、缓存、表或配置。额外工作是对已返回候选做少量本地验证,范围与修复收益匹配。
验证:当前 head 的 Static Checks / Test Suite 已通过。实际读取 astra-runtime CI 日志,确认 5,914 passed、173 skipped,包含新增 governance 与 first-turn mixed-candidate 回归,以及原有降级、deadline、本地 snapshot 和 debounce 测试。Skipped 不计为通过。本地 git diff --check 通过;本轮未本地重跑 Rust、数据库或 live-provider 测试,也未使用 subagent。
该 PR 修复两个明确的数据保留/召回问题,沿用现有职责边界,范围清晰,可以独立合并。
Merge Queue Status
This pull request spent 20 minutes 59 seconds in the queue, including 20 minutes 42 seconds running CI. Required conditions to merge
|
bbaac30 to
6a10ca9
Compare
Summary
Session closure could purge working memories after its final snapshot read failed. Preserve typed read errors in the canonical snapshot loader and stop session-end governance before any subsequent write, purge or reflection when that read fails. Optional prompt/local-context consumers continue to treat failed reads as absent context.
Session-start profile/episode recall capped candidates before validating prompt eligibility. Apply the existing three-entry cap to admitted evidence instead, preserving ranking, type checks, deduplication and the shared interactive deadline.
Related issue
Closes #994
Change type
User and compatibility impact
Working memories survive transient snapshot read failures, unavailable authorization and a memory-disable race during session closure. Successful empty reads retain existing cleanup behavior. Valid recall candidates remain usable when higher-scoring rows are malformed, inactive or inconsistent with their declared type. No public HTTP API, configuration, database schema, credentials or deployment changes.
Architecture and complexity delta
Verification
make format-check: passed.git diff --check: passed.Independently compiled source-module memory-prefetch tests: 15 passed, including the new mixed-candidate regression.
CI on memory-fix commit
431c30ef:Test: astra-runtime,Test: MOI fresh-Astra compatibility, clippy and formatting passed. The previous local whole-runtime compilation was stopped after these CI checks completed.Rebased onto current
main(a41e48a4), which includes the dependency security fix from feat(tui): add explicit next-turn follow-up submission #992.git range-diffconfirms the Memoria patch is unchanged; this PR contains noCargo.lockchanges and no duplicate dependency commit.Security audit after rebasing (cargo-audit 0.22.2, current advisory database): passed with zero reported vulnerabilities; audit policy is unchanged.
cargo check --locked -p astra-core: passed with the same lockfile now supplied by feat(tui): add explicit next-turn follow-up submission #992.make format-checkandgit diff --checkpassed after rebasing. CI is rerunning on the rebased Memoria-only branch; final results are pending.Public entrypoint exercised:
run_session_end_governance, used by authenticated session closure, andprefetch_session_start_memories_with_client, used by first-turn context assembly.Unhappy paths exercised: failed snapshot transport, unavailable authority and disabled reads with both empty and nonempty session facts; mixed malformed/archived/type-mismatched/unranked recall candidates. Positive paths cover successful empty reads and existing snapshot consolidation, write failure retention, ranking and per-bucket bounds.
Database verification: not applicable; no schema, query, transaction or database-routing changes. The regressions use deterministic MemoriaPort fixtures without live credentials or cluster mutation.
Final checklist