Skip to content

fix(memory): preserve working state on failed reads and admit valid recall - #995

Merged
mergify[bot] merged 1 commit into
matrixorigin:mainfrom
loveRhythm1990:fix/memoria-governance-recall
Oct 13, 2026
Merged

mergify[bot] merged 1 commit into
matrixorigin:mainfrom
loveRhythm1990:fix/memoria-governance-recall

Conversation

@loveRhythm1990

@loveRhythm1990 loveRhythm1990 commented Oct 13, 2026 •

Copy link
Copy Markdown
Collaborator

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

  • Bug fix
  • Documentation
  • Test

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

  • Canonical owner changed or extended: existing session-memory snapshot loader and session-end governance; existing typed prompt admission.
  • Existing implementations and callers searched: optional remote/local snapshot consumers, session-close scheduling and debounce completion, scoped MemoriaPort reads, profile/episode recall and contract tests.
  • Superseded code, states, tables, shims, or self-only tests removed: error-to-empty projection is removed from the shared snapshot boundary; optional consumers make that projection explicitly. Candidate truncation moves after canonical prompt validation.
  • If parallel implementations remain, their boundary and retirement condition: none added.

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-diff confirms the Memoria patch is unchanged; this PR contains no Cargo.lock changes 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-check and git diff --check passed 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, and prefetch_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

  • I added or updated tests at the layer that owns the behavior.
  • I updated the memory design contract.
  • I checked the diff for credentials, private URLs, customer data, generated files, and other sensitive information.
  • The PR title follows the repository's Conventional Commit format.

@loveRhythm1990
loveRhythm1990 force-pushed the fix/memoria-governance-recall branch from 641c2e3 to bbaac30 Compare October 13, 2026 10:16
@loveRhythm1990
loveRhythm1990 marked this pull request as ready for review October 13, 2026 10:22

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

结论: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 修复两个明确的数据保留/召回问题,沿用现有职责边界,范围清晰,可以独立合并。

@mergify mergify Bot added the queued label Oct 13, 2026
@mergify

mergify Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-10-13 10:57 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • ✅ Checks passed · in-place
  • ✅ Merged — 2026-10-13 11:18 UTC · at 9611cfb04af8c3de05c9118b5feae14565822d50 · squash

This pull request spent 20 minutes 59 seconds in the queue, including 20 minutes 42 seconds running CI.

Required conditions to merge
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • github-review-approved [🛡 GitHub branch protection]
  • any of [🛡 GitHub branch protection]:
    • check-success = Check PR title
    • check-neutral = Check PR title
    • check-skipped = Check PR title
  • any of [🛡 GitHub branch protection]:
    • check-success = check
    • check-neutral = check
    • check-skipped = check
  • any of [🛡 GitHub branch protection]:
    • check-success = Test: core crates + bridge hooks
    • check-neutral = Test: core crates + bridge hooks
    • check-skipped = Test: core crates + bridge hooks
  • any of [🛡 GitHub branch protection]:
    • check-success = Test: astra-runtime
    • check-neutral = Test: astra-runtime
    • check-skipped = Test: astra-runtime
  • any of [🛡 GitHub branch protection]:
    • check-success = Test: astra-cli (edge-fs-tools)
    • check-neutral = Test: astra-cli (edge-fs-tools)
    • check-skipped = Test: astra-cli (edge-fs-tools)
  • any of [🛡 GitHub branch protection]:
    • check-success = Test: astra-cli (edge-git-gix)
    • check-neutral = Test: astra-cli (edge-git-gix)
    • check-skipped = Test: astra-cli (edge-git-gix)
  • any of [🛡 GitHub branch protection]:
    • check-success = Test: astra-cli (edge-rest)
    • check-neutral = Test: astra-cli (edge-rest)
    • check-skipped = Test: astra-cli (edge-rest)
  • any of [🛡 GitHub branch protection]:
    • check-success = Test: astra-cli (edge-shell)
    • check-neutral = Test: astra-cli (edge-shell)
    • check-skipped = Test: astra-cli (edge-shell)
  • any of [🛡 GitHub branch protection]:
    • check-success = Test: astra-cli (non-edge)
    • check-neutral = Test: astra-cli (non-edge)
    • check-skipped = Test: astra-cli (non-edge)
  • any of [🛡 GitHub branch protection]:
    • check-success = Test: online (core)
    • check-neutral = Test: online (core)
    • check-skipped = Test: online (core)
  • any of [🛡 GitHub branch protection]:
    • check-success = Test: online (integration)
    • check-neutral = Test: online (integration)
    • check-skipped = Test: online (integration)
  • any of [🛡 GitHub branch protection]:
    • check-skipped = Test: turn-core + services + plan
    • check-neutral = Test: turn-core + services + plan
    • check-success = Test: turn-core + services + plan
  • any of [🛡 GitHub branch protection]:
    • check-skipped = web (typecheck, test, build)
    • check-neutral = web (typecheck, test, build)
    • check-success = web (typecheck, test, build)
  • any of [🛡 GitHub branch protection]:
    • check-skipped = Astra SDK (typecheck, test+coverage, build)
    • check-neutral = Astra SDK (typecheck, test+coverage, build)
    • check-success = Astra SDK (typecheck, test+coverage, build)
  • any of [🛡 GitHub branch protection]:
    • check-success = Test: macOS workspace coordination
    • check-neutral = Test: macOS workspace coordination
    • check-skipped = Test: macOS workspace coordination

@mergify
mergify Bot force-pushed the fix/memoria-governance-recall branch from bbaac30 to 6a10ca9 Compare October 13, 2026 10:57
@mergify
mergify Bot merged commit 9611cfb into matrixorigin:main Oct 13, 2026
@mergify mergify Bot removed the queued label Oct 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(memory): retain working state after read failures and admit valid recall candidates

2 participants