Skip to content

AG2 recall policies retain session protection across callbacks - #882

Merged
zlareb1 merged 2 commits into
mainfrom
feat/ag2-recall-session-protection
Nov 18, 2026
Merged

zlareb1 merged 2 commits into
mainfrom
feat/ag2-recall-session-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):

AG2 recall policies retain session protection across callbacks and client rebinding. Protected conversations stop automatic recall before dispatch, while model-selected Loom tools remain explicit operations.

Why

The recall policy sends the latest user message to memory.search before each model call. It retained neither its constructor's session contributors nor earlier callbacks' contributors, and the search lacked automatic invocation ownership. A protected contributor could therefore send another automatic recall after a client was rebound or an ambient context ended.

The policy reuses the shared callback protection helper to retain the application-owned contributors and classify its native apply callback as automatic. The transport observes a marked response durably before its content reaches the prompt; later automatic callbacks refuse.

Scope and risk

The change covers the recall policy, its existing adapter tests and its conversation-ownership documentation. The search arguments, query selection, abstention, ranking filters and prompt format are unchanged. loom_tools and its execution helpers are byte-identical to the base.

Use one policy per conversation and bind its Loom client to the application's session family. Native user and session ids do not select protection. This adds no session capsule, operation, field or capability declaration. The existing sender census already classifies memory.search; its call remains visible and no exception or classification changes.

The test helper disables inherited proxies before constructing the real SDK client and restores the environment after closing it. HTTPX can select proxy mounts before an assigned mock transport, so replacing only the default transport does not isolate requests. A direct transport-selection check under inherited proxies fails before any network attempt if that isolation breaks; the real SDK request and response hooks remain installed.

Compatibility, rollout and rollback

  • Wire: none.
  • Operator steps: none. An application reusing a policy across unrelated conversations should create one policy per conversation.
  • Rollback: reverting restores the earlier callback behavior and leaves no stored data or migration behind.

Tests

Before the fix, seven focused native cases produced six expected missing-refusal failures and one explicit-tool control pass in 1.25 seconds. The cases use the real SDK, native assembly callbacks and an HTTP mock transport. They cover retained constructor and callback contributors, rebinding during authentication, durable marked recall, failed observation and explicit tools.

After the fix, the planned eleven-case check was blocked before launch because available disk space was below the runner's 16 GiB admission floor. No supervisor or local test started, and no local passing result is claimed. Before the test-helper correction, GitHub CI passed all 20 native adapter tests on both supported dependency legs: AG2 1.3.0 with Python 3.11 and AG2 1.3.2 with Python 3.12. Strict adapter mypy also passed in both jobs. The production adapter is byte-identical in the current head; its test helper now isolates inherited proxies and adds one control. On the current head, GitHub CI passes all 21 native cases on both supported legs: 1.09 seconds with AG2 1.3.0/Python 3.11 and 1.07 seconds with AG2 1.3.2/Python 3.12. Strict mypy passes four source files in both jobs. Full required CI passes on this head: all 45 checks are terminal, with 43 successes and two expected publication skips across four successful workflows.

Scoped checks passed:

  • Strict mypy on the adapter and shared callback helper.
  • Ruff formatting and lint on the adapter and existing test module.
  • Public prose and whitespace checks.
  • Byte comparison of the explicit-tool implementation against the base.

AI assistance in the code (leave one; writing this description with AI is fine):

  • AI-generated: An agent wrote the change and checked the callback ownership, unchanged search arguments and explicit-tool implementation.

  • I can explain every line of this diff and how it interacts with the rest of Loom.

Checklist

  • Required full GitHub CI passes on the current head, including formatting, lint, types, unit tests, coverage, benchmarks, native adapters and integration gates.
  • No generated API, settings, schema or plugin artifacts require changes.
  • No migration, plugin behavior or frontend code changed.
  • Docs under docs/ describe the behavior, and this description names the operator and wire implications.
  • Public text follows the repository's copy rules.
  • Commits are signed off (git commit -s).

Bind automatic recall to its constructor and callback contributors so client
rebinding cannot remove a protected family's authority. Keep model-selected
tools explicit and preserve the search payload and prompt behavior.

Signed-off-by: zlareb1 <[email protected]>
Exclude proxies before constructing the SDK client so inherited proxy mounts
cannot bypass the mock transport. Keep that environment until client closure
and check transport selection before any request.

Signed-off-by: zlareb1 <[email protected]>
@zlareb1
zlareb1 merged commit 84c62b9 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