Repository navigation
AutoGen memory retains session protection across native callbacks - #889
Merged
Merged
Conversation
Exercise session contributors across native message awaits, context exit and client rebinding before changing the adapter. Preserve explicit memory calls and verify the mock transport excludes inherited proxies. Signed-off-by: zlareb1 <[email protected]>
Bind native context assembly before awaiting messages so rebinding cannot remove its session contributors. Preserve direct query and add ownership while retaining their response observers. Signed-off-by: zlareb1 <[email protected]>
zlareb1
marked this pull request as ready for review
November 18, 2026 16:58
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.
Changelog category (leave one):
Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes):
AutoGen memory callbacks retain session contributors across context exit and client rebinding. Native context assembly stops when a retained family is protected, while direct query and add operations preserve their caller's ownership.
Why
LoomMemory.update_contextawaited native messages before retaining its callback contributors, then searched outside automatic invocation ownership. Constructor and earlier callback contributors were also lost. A client rebound during the native await or after a contributing context ended could therefore dispatch automatic work without a known protected family.The memory reuses the shared callback protection helper. It retains constructor and callback contributors, and enters automatic scope before awaiting native messages. Direct
queryandaddjoin automatic scope only when their caller already owns automatic work; otherwise they retain response observers without becoming automatic operations. A marked response is durably observed before its content reaches the native system message.Scope and risk
The change covers the memory callback boundary, its existing native tests and conversation-ownership documentation. Query selection, search arguments, content-derived keys, serialization, tags, user scope, abstention, ranking filters, cancellation signatures and deletion refusal are unchanged.
Use one memory instance per conversation's application-owned session family. Native user and session ids do not select protection. The adapter creates no session capsule, backend, dependency or capability declaration. Existing literal send sites remain visible to the sender census; no operation class, exception or manifest hash changes are needed.
Tests use the real SDK and
BufferedChatCompletionContext, including its genuine message methods around controlled await/rebinding and durable-observation assertions. HTTP mock transport replaces external I/O, with inherited proxies excluded before client construction through client closure. No model or provider call is required.Compatibility, rollout and rollback
Tests
The exact test-only baseline ran in both native CI legs:
All failures were the predicted missing automatic refusal or failed-observation refusal. There were no import, setup or proxy failures. The native await/rebinding, constructor/ambient/earlier callback, marked recall and explicit query/add cases executed through the actual native methods and SDK.
The production fix follows that baseline. The entire test module remains byte-identical to the baseline, with twenty-four cases. On the corrected head, all 24 native cases pass on both supported CI legs: 0.77 seconds with AutoGen Core 0.7.5/Python 3.12 and 0.65 seconds with AutoGen Core 0.7.0/Python 3.11. Strict mypy passes four source files in both jobs. All 45 CI checks are terminal: 43 pass and two publication checks are expected skips. All four applicable workflows pass, including the sender census and required integration gates. Local tests, framework imports and installation were not attempted while disk admission remained blocked.
Scoped Ruff formatting, Ruff lint, whitespace and public prose checks pass. The source audit found no AutoGen manifest entry to renew and preserved the literal send expressions; it is not a claim that the census test ran locally.
AI assistance in the code (leave one; writing this description with AI is fine):
AI-generated: An agent wrote the change and checked the native callback methods, retained contributors, explicit-operation behavior and unchanged search/write payloads.
I can explain every line of this diff and how it interacts with the rest of Loom.
Checklist
make format-check,make lint,make typecheckandmake test-unitpass.git commit -s).