feat(sharing): opt-in lazy auto-refresh of stale shared copies on read#21
Closed
doctatortot wants to merge 1 commit into
Closed
feat(sharing): opt-in lazy auto-refresh of stale shared copies on read#21doctatortot wants to merge 1 commit into
doctatortot wants to merge 1 commit into
Conversation
Shared copies are snapshots: when the source memory is updated, copies don't auto-update, so readers can see stale content unless they poll ?check_stale=true and manually reshare. Add OMEM_AUTO_REFRESH_SHARES (default false). When enabled, reading a shared copy whose source has a newer version transparently refreshes it (pulls current source content + vector) before returning. Extract the refresh primitive out of reshare_memory into a reusable refresh_shared_copy(store_manager, space_store, copy, tenant, agent) helper, used by both the reshare endpoint and the new read path. The source vector is copied as-is, so refresh does not re-embed. Wired into get_memory; source-deleted copies are left untouched. Search is intentionally not auto-refreshed (it ranks on the copy vector; that wants push-on-update or a worker -- left as a follow-up). Tests: test_refresh_shared_copy_helper; full suite green (389 passed). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Contributor
|
Merge conflict after recent merges (likely |
yhyyz
added a commit
that referenced
this pull request
May 21, 2026
- feat(sharing): opt-in per-user rate limiting (PR #24) Token-bucket limiter on all 8 sharing handlers. OMEM_SHARE_RATE_PER_MIN=0 (default, disabled). - feat(sharing): opt-in lazy auto-refresh stale shares on read (PR #21) Extracts refresh_shared_copy() helper, reused by reshare endpoint and new auto-refresh-on-read path in get_memory. OMEM_AUTO_REFRESH_SHARES=false (default, disabled). Co-authored-by: doctatortot <doctatortot@users.noreply.github.com>
Contributor
|
Applied in |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Shared copies are snapshots. When the source memory is updated, copies don't auto-update — users must detect staleness via
?check_stale=trueand manuallyreshare. Shared copies silently drift from their source.Approach
Opt-in lazy refresh on read. With
OMEM_AUTO_REFRESH_SHARES=true, reading a shared copy whose source has a newerversiontransparently refreshes it (pulls current source content + vector) before returning, so a reader never sees a stale snapshot. Default off → zero behavior change.The refresh primitive already lived inside
reshare_memory(fetch source + vector →make_shared_copy→create→soft_deleteold). This PR extracts it into a reusablerefresh_shared_copy(store_manager, space_store, copy, tenant, agent)helper used by both the existing reshare endpoint and the new read path. The source vector is copied as-is, so no re-embedding — refresh is cheap. Wired intoget_memory; source-deleted copies are left untouched.Why only
get_memory(not search / push / worker)Search ranks on the copy's vector, so refreshing mid-search would mutate data on a read and still rank on the stale vector. Search-result freshness wants push-on-update or a background worker (which needs a source→copies reverse index) — deliberately left as a follow-up. Lazy-on-read is the minimal, correct piece: costs nothing when nothing is stale, and only refreshes copies that are actually read.
Config
OMEM_AUTO_REFRESH_SHARES(bool, defaultfalse).Tests
test_refresh_shared_copy_helper: source → share → bump source → refresh → asserts fresh content, advancedsource_version, no-longer-stale, old copy soft-deleted.reshare_memorybehaviour unchanged (it now delegates to the shared helper; existing reshare/stale tests pass).fmt+clippyclean (no new warnings).Refresh logs a
Resharesharing event for audit.