Skip to content

fix(memory): make Memoria session finalization durable and owner-aware #996

Closed

Description

@loveRhythm1990

Existing issue search

Checked existing issues for Memoria, working/episodic memory, governance, and owner binding. This is a follow-up to #994 / #995, which fixed failed snapshot reads and recall admission ordering. Those fixed defects are excluded here. #597 describes a different, unbound in-process chat bridge; the CLI owner-namespace mismatch below occurs with a successfully bound server authority.

Version and environment

Reviewed upstream main at 9611cfb04af8c3de05c9118b5feae14565822d50, after #995 merged. The findings cover authenticated CLI + Server and Server session finalization. Validation used isolated Rust source-module probes and synthetic identities; no live memory writes or user data were required.

Actual behavior

1. CLI finalization can purge working memory without writing an episode (high)

CliSessionMemoryMemoriaPort implements store and purge_working, but does not override store_episode, store_scene, or reflect_session. The default MemoriaPort::store_episode returns Ok(String::new()) without persisting anything.

CLI finalization calls canonical session-end governance. When an episode is needed, governance accepts the empty-ID success and keeps safe_to_purge_working = true. If strict snapshot retrieval succeeds and a working ID is tracked, CLI finalization can delete that working snapshot without creating its episodic replacement. A successful CLI exit therefore does not prove successful long-term consolidation.

Sources: CLI port implementation, default episode/scene methods, CLI finalization, episode receipt and purge decision.

2. CLI strict recall compares two different owner namespaces (medium)

CLI constructs its memory port using /auth/me.user_id, which is the canonical Astra user ID. It then requires every returned memory's user_id to equal that ID.

The server resolves the actual Memoria owner separately. In UC built-in memory this is uc_ plus base64url(SHA256(issuer + NUL + subject)); it differs from the canonical Astra external user ID. Connected personal Memoria accounts may also have a different owner ID. The server validates retrieval against the resolved Memoria owner and returns those owner fields unchanged. CLI then rejects valid rows as memory_scope_violation: ... invalid user_id.

This is an availability/finalization defect, not evidence of a cross-user disclosure. The fail-closed validation itself must remain intact.

Sources: CLI port construction, CLI strict owner validation, UC Memoria owner namespace, server validation using resolved authority.

3. Explicit server close does not coordinate with pending extraction (high)

close_session_handler marks the session closed and immediately spawns governance. It does not drain or fence the owner/session's pending extraction, nor verify that the durable snapshot covers the final turn. Governance starts with default session facts and reads whichever working snapshot is currently available.

Normal turn completion explicitly detaches final extraction/drain from the user-visible response. The extraction worker does not reject writes solely because the session was subsequently closed. This permits the following interleavings:

  • Governance reads turn N; extraction writes turn N+1; governance stores the older episode and purges all session working rows, including turn N+1.
  • Governance purges working rows; the pending extraction later recreates working memory in a closed session, with no corresponding final episode.

These interleavings are confirmed by source inspection; a full concurrent close/extraction integration test has not yet been run. The existing process-local governance debouncer coordinates duplicate governance calls, not extraction versus governance or separate server processes.

Sources: explicit close and governance scheduling, detached post-turn cleanup, extraction worker, existing pending-turn drain operation.

4. Partial governance failures are marked complete and suppress retries (medium)

Episode-write failure and working-purge failure set flags in SessionEndReport, but governance returns Ok(report). Scene-write failures are also counted without failing the operation. The close scheduler treats every Ok(report) as completion and calls governance_permit.complete() without inspecting those flags.

This starts the 15-minute cooldown even when required work failed. There is no automatic durable retry queued by this path. A repeated close during cooldown is skipped; cooldown expiry only makes a later invocation eligible and does not itself retry the work. The retained snapshot prevents immediate loss on episode failure, but successful session closure does not guarantee eventual consolidation.

Sources: partial-failure reporting, unconditional completion for Ok(report), 15-minute completion cooldown.

5. HTTP success is accepted without a valid write receipt (high for purge safety)

HttpMemoriaPort::store_episode and store_scene return an empty ID for a successful JSON response with a missing or incorrectly typed memory_id. Empty strings are also accepted. Governance allows working purge after the empty episode receipt and counts empty-ID scene writes as stored.

Separately, the explicit memory-tool gateway fabricates status: completed / memory stored when a remember request returns an empty successful HTTP response. This can make the assistant claim persistence without a confirmed write receipt. The normal store path rejects a missing ID, but still does not reject an empty string.

The current Memoria API normally returns a write object with an ID; this finding concerns Astra's handling of incompatible or malformed successful responses, in addition to the unconditional CLI no-op in finding 1.

Sources: episode response parsing, scene response parsing, empty episode ID permits purge, empty HTTP-success handling, fabricated remember acknowledgment.

Current timeout and failure behavior

These are distinct budgets, not one global Memoria timeout:

Path Current budget Boundary / failure behavior
Automatic prompt recall 750 ms absolute deadline Includes authority resolution and retrieval; first-turn profile/episode lanes run concurrently. Failure omits optional memory context and the model turn continues.
HttpMemoriaPort transport 10 s connect; 60 s total HTTP request Callers may impose a shorter outer budget.
Explicit memory tools 10 s per HTTP request by default Authority resolution precedes this HTTP budget. Update/forget may add a 5 s pre-operation snapshot; strict session recall may add a separate working-list request. This is not a 10 s end-to-end guarantee.
Server memory HTTP proxy 30 s per forwarded HTTP request Authority resolution precedes forwarding; strict recall additionally reconciles a working-list request.
Background extraction 20 s overall attempt Snapshot read: 3 s; selector stage: at most 12 s, reduced to reserve 7 s for persistence; working store: at most two 3 s attempts, followed by up to 1 s stale cleanup. These inner budgets share the outer deadline.
Server explicit-close governance 60 s overall Detached from the close response.
CLI exit maintenance 5 s overall Timed-out child tasks are aborted and drained.

Working-store retries are immediate and bounded. Failed persistence does not advance extraction freshness; a later eligible turn can retry. Selector failure falls back to deterministic extraction. Explicit tools open their availability circuit after two transient failures with a 30 s cooldown; background extraction has a separate owner-scoped threshold of three failures and exponential cooldown starting at 60 s, capped at 16 minutes. Consent denials remain fail-closed and must not be reinterpreted as successful empty writes/reads.

Timeout sources: interactive deadline, HTTP client budgets, tool HTTP budget, proxy HTTP budget, extraction budgets, working-store retry budgets, background availability cooldown.

Ownership and lifecycle context

  • Memoria stores ownership in user_id; session_id is an additional session boundary. Optional author_id / subject_id are not substitutes for the authenticated owner.
  • UC built-in memory uses a server-only deployment credential with the owner-scoped Memoria-Owner scheme and a distinct owner per issuer/subject. Sharing a service credential does not mean sharing one personal memory namespace.
  • Connected Memoria credentials retain their verified Memoria owner and consent. Current authority is resolved on each operation; none disables memory, read_only allows reads, and read_write allows writes/maintenance.
  • Intended lifecycle: per-turn working snapshots -> confirmed final episodic write -> working purge -> best-effort semantic scene reflection. Ordinary turn completion preserves working continuity.
  • Astra does not impose one fixed TTL on all long-term memories. Backend retention/governance governs aging. Disconnect revokes the connection rather than erasing remote memories; deleting an Astra session does not currently invoke remote Memoria cleanup. Any user-facing erasure/derived-memory contract needs to describe that distinction explicitly.

Steps to reproduce / validation

Three deterministic source-module probes reproduced:

  1. Use an admitted port with an empty successful snapshot read, implement ordinary store and purge_working, and inherit the default store_episode. Call governance with nontrivial SessionFacts (e.g. turn 3). Observe no ordinary store call, no episode ID, and one working-purge call.
  2. Return a memory with the correct session but a resolved Memoria owner different from /auth/me.user_id. Run the CLI's strict validator with the canonical Astra ID. Observe a legitimate row rejected for invalid user_id.
  3. Make episode persistence return an error. Governance returns Ok(report) with working_retained_due_to_episode_failure = true. Apply the close handler's current completion action; a second debounce permit cannot be acquired during cooldown.

Review coverage of the #995 patch: total_files=3, reviewed_files=3, skipped_files=0, coverage_rate=100% for the three Rust files; the accompanying design-document change was also read. This review additionally traced the relevant CLI, server lifecycle, authority, transport, and backend response contracts; it is not a claim of whole-repository coverage.

The probes plus the existing debouncer unit tests passed: 13 tests, 0 failures. They assert the current problematic behavior and are not a full CLI/server integration suite. The close/extraction race and malformed HTTP receipt paths were inspected statically.

Expected behavior and acceptance criteria

  • CLI uses the canonical server-owned lifecycle/authority boundary and actually persists a required episode before any working purge. Unsupported episode/scene operations must fail explicitly instead of returning empty success.
  • Strict owner validation compares against the authenticated Memoria owner, while session ownership is authorized using the canonical Astra identity. Cover UC, connected personal Memoria, and explicitly enabled local self-hosted accounts without weakening isolation.
  • Closing a session coordinates the final extraction generation and durable turn freshness before consolidation/purge. An unsettled or failed final extraction retains working memory; late workers cannot recreate or lose final state through a close race. Account for multiple server instances rather than relying solely on process-local state.
  • Successful required writes return a validated, nonempty receipt. Missing, empty, wrong-type, or malformed receipts never authorize working purge or a user-visible claim of storage.
  • Governance distinguishes complete, incomplete, and failed outcomes. Required failures are retryable and do not start the successful-completion cooldown. Retry partial stages without creating duplicate episodes/scenes, and expose the failure flags in diagnostics.
  • Add deterministic tests at public CLI/server entrypoints for the above cases and preserve the existing authority, consent, and bounded-latency contracts. Clarify close/disconnect/delete semantics in the memory documentation.

The confirmed defects above are in Astra. They do not by themselves establish that a Memoria server code change is required; any backend protocol or atomicity extension should be scoped separately with evidence.

Activity

  1. added
    kind/bug
    on Oct 13, 2026
  2. XuPeng-SH commented on Oct 20, 2026

    @XuPeng-SH
    Collaborator

    Cleanup: PR #997 fixed CLI archive receipts and safe working-memory cleanup. PR #1005 completed durable, owner-aware session finalization and strict recall, with Memoria PR #310 providing the required idempotent-write protocol. All three changes are merged, so the coordinated Astra and Memoria path is available. Closing this issue.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions