Skip to content

fix(store-runtime): guard retained memory by served store identity - #1192

Merged
ScriptedAlchemy merged 6 commits into
codex/tracedecay-total-redesign-plan-reopenedfrom
fix/retained-memory-identity-guards
Sep 10, 2026
Merged

fix(store-runtime): guard retained memory by served store identity#1192
ScriptedAlchemy merged 6 commits into
codex/tracedecay-total-redesign-plan-reopenedfrom
fix/retained-memory-identity-guards

Conversation

@ScriptedAlchemy

Copy link
Copy Markdown
Owner

Fixes defects introduced by #1179 (extract retained owners from the root crate), found in independent review.

  • test + fix(store-runtime): guard retained memory by served store identity — the move turned two live guards into self-comparisons: authority.project_root was compared against itself and FactOwnerV1 was fabricated from the request scope instead of read from the store. The open guard now compares the served instance's project_root and store_layout.identity.project_id against the admitted request scope (plus the restored mounted-scope vs request-scope check), denying with NotFoundOrNotAuthorized; the owner stamped on facts is store-derived. RED→GREEN: ..._denies_when_store_layout_identity_disagrees, ..._served_root_disagrees, ..._mounted_scope_disagrees.
  • fix(store-runtime): honor read access with read-only leasesRead (get/list/contradict/status and probe/related/reason, which never recorded retrieval) takes issue_database_read_only_lease(); RecordRetrieval (search) takes a write lease on a writable graph so track_explicit_search/project_memory_update_retrieval_projection_tx keep updating retrieval_count/last_retrieved_at (per docs/TRUST-DECAY-SEMANTICS.md, doc corrected to name the function), and degrades to a read-only lease with truthful ReadOnly telemetry when the graph or owner is not writable instead of failing Unavailable; Write on a read-only graph is a typed refusal. Tests: memory_recall_updates_retrieval_count (bump + funnel), ..._read_open_issues_a_read_only_lease, ..._degrades_when_owner_is_not_writable.
  • refactor(daemon): drop retained owner facade — the pub(crate) use façade over session-runtime is gone; six call sites import the owner crate directly. AssembledRetainedAutomation stays: it must cg.read().await per call, which a mount-time value cannot express.
  • fix(daemon): resolve retained memory identity per call — the port no longer snapshots identity at mount (which would go stale across branch reopen) nor try_reads the lock at mount (which fails under a queued writer and would leave memory permanently "not mounted"); each call takes a real read lock (no nested guard — the mount site no longer locks) and builds authority from the current Arc<TraceDecay>. assembled_memory_authority_tracks_swapped_graph_identity proves it. project_memory_read_only is byte-identical to the base — a review caught an intermediate version publishing a read-only owner into the registry, which would have let a cross-project read of X make X's own memory non-writable; read_only_open_does_not_publish_a_project_memory_owner guards that, and the degrade test uses a #[cfg(test)] seam.

Verification: retained_memory 10; session_registry 97; root daemon::retained_owner 8; session_suite (test-transport) 462; MCP lcm_test/session_search_test/memory_facts_test/status_without_retained 48; clippy -D warnings --tests on store-runtime/session-runtime/root after merging #707; fmt; commitlint. Four independent Opus review rounds.

@changeset-bot

changeset-bot Bot commented Sep 10, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 8b5c535

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 10, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-10T02:19:18.865910Z 8b5c535 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8b5c535d11

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +1715 to +1716
#[cfg(test)]
pub async fn publish_read_only_memory_owner_for_test(

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Remove the test-only registry publication port

This adds a #[cfg(test)] method directly to the production registry that fabricates a detached, read-only memory-owner state which no production lifecycle publishes. Consequently, same_project_record_retrieval_degrades_when_owner_is_not_writable can pass without proving that the fallback works through a real user journey; exercise a reachable production owner transition instead, or remove the unreachable fallback and this synthetic publication seam.

AGENTS.md reference: AGENTS.md:L121-L123

Useful? React with 👍 / 👎.

@github-actions

Copy link
Copy Markdown
Contributor

Performance Comparison codex/tracedecay-total-redesign-plan-reopenedfix/retained-memory-identity-guards

Total Elapsed Time: 4.09s → 4.04s (-1.2%)
CPU Baseline: 86.51µs → 79.75µs (-7.8%)
Benchmark ID: index-bench-timing

timing - Execution duration of functions.

+------------------------------------------+----------------------------+--------------------------------+--------------------------------+--------------------------------+------------------------------+
| Function                                 | Calls                      | Avg                            | P95                            | Total                          | % Total                      |
+------------------------------------------+----------------------------+--------------------------------+--------------------------------+--------------------------------+------------------------------+
| tracedecay-index-bench                   | 1 → 1 (+0.0%)              | 4.09s → 4.04s (-1.2%)          | 4.09s → 4.04s (-1.2%)          | 4.09s → 4.04s (-1.2%)          | 100.00% → 100.00% (+0.0%)    |
+------------------------------------------+----------------------------+--------------------------------+--------------------------------+--------------------------------+------------------------------+
| query.artifact.append_pages              | 13 → 13 (+0.0%)            | 126.29ms → 125.63ms (-0.5%)    | 173.41ms → 171.84ms (-0.9%)    | 1.64s → 1.63s (-0.6%)          | 40.13% → 40.42% (+0.7%)      |
+------------------------------------------+----------------------------+--------------------------------+--------------------------------+--------------------------------+------------------------------+
| code_index.workers.install               | 83 → 83 (+0.0%)            | 14.02ms → 13.77ms (-1.8%)      | 48.23ms → 48.01ms (-0.5%)      | 1.16s → 1.14s (-1.7%)          | 28.44% → 28.28% (-0.6%)      |
+------------------------------------------+----------------------------+--------------------------------+--------------------------------+--------------------------------+------------------------------+
| domain.canonical.sha256                  | 110414 → 110414 (+0.0%)    | 9.32µs → 9.23µs (-1.0%)        | 12.52µs → 12.33µs (-1.5%)      | 1.03s → 1.02s (-1.0%)          | 25.16% → 25.22% (+0.2%)      |
+------------------------------------------+----------------------------+--------------------------------+--------------------------------+--------------------------------+------------------------------+
| query.artifact.batch.sqlite              | 13 → 13 (+0.0%)            | 72.81ms → 72.34ms (-0.6%)      | 100.14ms → 94.96ms (-5.2%)     | 946.52ms → 940.42ms (-0.6%)    | 23.14% → 23.27% (+0.6%)      |
+------------------------------------------+----------------------------+--------------------------------+--------------------------------+--------------------------------+------------------------------+
| code_index.build.and_publish             | 2 → 2 (+0.0%)              | 463.33ms → 455.21ms (-1.8%)    | 543.69ms → 533.46ms (-1.9%)    | 926.67ms → 910.41ms (-1.8%)    | 22.65% → 22.53% (-0.5%)      |
+------------------------------------------+----------------------------+--------------------------------+--------------------------------+--------------------------------+------------------------------+
| query.artifact.batch.postings            | 13 → 13 (+0.0%)            | 63.59ms → 63.47ms (-0.2%)      | 89.72ms → 84.54ms (-5.8%)      | 826.61ms → 825.11ms (-0.2%)    | 20.21% → 20.42% (+1.0%)      |
+------------------------------------------+----------------------------+--------------------------------+--------------------------------+--------------------------------+------------------------------+
| query.artifact.finalization.advance_wake | 14 → 14 (+0.0%)            | 46.61ms → 45.51ms (-2.4%)      | 282.85ms → 283.38ms (+0.2%)    | 652.55ms → 637.15ms (-2.4%)    | 15.95% → 15.77% (-1.1%)      |
+------------------------------------------+----------------------------+--------------------------------+--------------------------------+--------------------------------+------------------------------+
| code_index.chunk.index_file              | 276 → 276 (+0.0%)          | 2.32ms → 2.19ms (-5.6%)        | 3.25ms → 3.20ms (-1.5%)        | 639.12ms → 603.28ms (-5.6%)    | 15.62% → 14.93% (-4.4%)      |
+------------------------------------------+----------------------------+--------------------------------+--------------------------------+--------------------------------+------------------------------+
| code_index.extract.parser_artifact       | 276 → 276 (+0.0%)          | 2.08ms → 2.11ms (+1.4%)        | 3.12ms → 3.25ms (+4.2%)        | 573.70ms → 582.83ms (+1.6%)    | 14.02% → 14.42% (+2.9%)      |
+------------------------------------------+----------------------------+--------------------------------+--------------------------------+--------------------------------+------------------------------+
| query.artifact.prepare_pages             | 13 → 13 (+0.0%)            | 43.64ms → 43.60ms (-0.1%)      | 61.93ms → 64.45ms (+4.1%)      | 567.26ms → 566.84ms (-0.1%)    | 13.87% → 14.03% (+1.2%)      |
+------------------------------------------+----------------------------+--------------------------------+--------------------------------+--------------------------------+------------------------------+
| query.artifact.batch.postings.ngram_rows | 13 → 13 (+0.0%)            | 35.02ms → 35.31ms (+0.8%)      | 48.43ms → 47.19ms (-2.6%)      | 455.21ms → 459.03ms (+0.8%)    | 11.13% → 11.36% (+2.1%)      |
+------------------------------------------+----------------------------+--------------------------------+--------------------------------+--------------------------------+------------------------------+
| query.artifact.batch.parallel_prepare    | 13 → 13 (+0.0%)            | 34.72ms → 34.51ms (-0.6%)      | 49.41ms → 50.89ms (+3.0%)      | 451.34ms → 448.64ms (-0.6%)    | 11.03% → 11.10% (+0.6%)      |
+------------------------------------------+----------------------------+--------------------------------+--------------------------------+--------------------------------+------------------------------+
| code_index.build.assemble                | 2 → 2 (+0.0%)              | 205.89ms → 204.01ms (-0.9%)    | 212.86ms → 210.63ms (-1.0%)    | 411.77ms → 408.02ms (-0.9%)    | 10.07% → 10.10% (+0.3%)      |
+------------------------------------------+----------------------------+--------------------------------+--------------------------------+--------------------------------+------------------------------+
| code_index.chunk.build                   | 276 → 276 (+0.0%)          | 1.36ms → 1.37ms (+0.7%)        | 1.99ms → 1.98ms (-0.5%)        | 374.91ms → 377.35ms (+0.7%)    | 9.17% → 9.34% (+1.9%)        |
+------------------------------------------+----------------------------+--------------------------------+--------------------------------+--------------------------------+------------------------------+

Generated with hotpath-rs

@ScriptedAlchemy
ScriptedAlchemy merged commit 4e1d27b into codex/tracedecay-total-redesign-plan-reopened Sep 10, 2026
27 of 37 checks passed
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.

1 participant