Skip to content

AutoGen memory retains session protection across native callbacks - #889

Merged
zlareb1 merged 2 commits into
mainfrom
feat/autogen-callback-protection
Nov 18, 2026
Merged

zlareb1 merged 2 commits into
mainfrom
feat/autogen-callback-protection

Conversation

@zlareb1

@zlareb1 zlareb1 commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Improvement

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_context awaited 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 query and add join 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

  • Wire: none.
  • Operator steps: none. Applications should bind separate memory instances to unrelated conversation families.
  • Rollback: reverting restores the earlier callback behavior and leaves no stored data or migration behind.

Tests

The exact test-only baseline ran in both native CI legs:

  • AutoGen Core 0.7.5 on Python 3.12: seven causal failures and seventeen passes in 1.53 seconds.
  • AutoGen Core 0.7.0 on Python 3.11: the same seven failures and seventeen passes in 1.11 seconds.

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

  • New-head native CI and type checking pass after the causal baseline failures.
  • make format-check, make lint, make typecheck and make test-unit pass.
  • Operation classes, sender exceptions and literal payloads are unchanged.
  • No generated API, settings, schema, plugin or frontend artifacts require changes.
  • Docs describe conversation ownership and the operator and wire implications.
  • Public text follows the repository's copy rules.
  • Commits are signed off (git commit -s).

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 zlareb1 changed the title Add native AutoGen context protection regression cases AutoGen memory retains session protection across native callbacks Nov 18, 2026
@zlareb1
zlareb1 marked this pull request as ready for review November 18, 2026 16:58
@zlareb1
zlareb1 merged commit 1092926 into main Nov 18, 2026
45 checks passed
@zlareb1 zlareb1 mentioned this pull request Nov 18, 2026
6 tasks done
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