Skip to content

fix(spawner): unify @-mention expansion on foundation XML helper, fix resume + REPL paths - #191

Merged
Brian Krabach (bkrabach) merged 1 commit into
mainfrom
fix/mentions-unify-xml-helper
May 21, 2026
Merged

fix(spawner): unify @-mention expansion on foundation XML helper, fix resume + REPL paths#191
Brian Krabach (bkrabach) merged 1 commit into
mainfrom
fix/mentions-unify-xml-helper

Conversation

@bkrabach

Copy link
Copy Markdown
Collaborator

Problem Statement

At-mention expansion logic had accumulated duplication across 5 call sites in two repos, with:

  • 2 different output formats (developer messages vs. XML)
  • 2 different loader implementations (async foundation, sync CLI)
  • 2 different call sites per repo missing expansion entirely

Yesterday's commit aa94be5 added expansion to spawn_sub_session but accidentally introduced a third copy of the inline expansion block — deepening the maintenance problem.

Peer Review Catch

Credit: Anonymous Reviewer (@Reviewer) caught the critical gapresume_sub_session was still sending raw @file.md strings directly to the child session's execute() call with zero resolution. This is the user-visible bug that motivated the broader consolidation.

Dependency

This PR depends on microsoft/amplifier-foundation#224 (expansion helper + foundation call site conversions). Must merge first.

Changes in This PR

REPL path (main.py):

  • Convert _process_runtime_mentions() to use expand_mentions_in_instruction()
  • Now returns the expanded prompt string instead of injecting developer messages
  • Updated all 5 call sites in the REPL loop

Spawn paths (session_spawner.py):

  • Convert spawn_sub_session system_instruction block → foundation helper + XML
  • Convert spawn_sub_session delegation instruction block → foundation helper + XML
  • ADD expansion to resume_sub_session (previously missing entirely)
    • New block before session.execute(instruction)
    • Same structure as spawn, consistent semantics

Consolidation:

  • Delete amplifier_app_cli/lib/mention_loading/loader.py (MentionLoader class)
    • Zero remaining callers after conversion
    • Eliminates duplicate sync loader vs async foundation helper
  • Delete tests/lib/mention_loading/test_loader.py
  • Update TestSpawnMentionExpansion to assert XML format (not developer messages)
  • Add TestResumeMentionExpansion to cover previously untested resume path

Behaviour Change Call-Out

spawn_sub_session now injects mention content as inline <context_file> XML blocks (prepended to instructions) instead of separate developer-role messages. This aligns with:

  • The system-prompt path's existing XML approach (not developer messages)
  • Foundation's expand_mentions_in_instruction() design
  • Your prior direction that XML is the better LLM-input format

The instruction string itself is unchanged; only the surrounding context format changed.

Test Results

  • 955 passed
  • 1 pre-existing failure (unrelated to @mention expansion)
    • test_subprocess_routing.py::TestSubprocessRouting::test_subprocess_param_routes_to_subprocess
    • Concerns subprocess config dict shape, not @mentions
  • New tests: TestResumeMentionExpansion validates the previously untested resume path

Call Sites Covered

Site File Status
System-prompt factory (agent body) amplifier-foundation/.../bundle/_prepared.py Foundation PR #224
PreparedBundle.spawn() runtime instruction amplifier-foundation/.../bundle/_prepared.py Foundation PR #224
REPL _process_runtime_mentions This PR — converted ✅
spawn_sub_session system_instruction This PR — converted ✅
spawn_sub_session delegation instruction This PR — converted ✅
resume_sub_session instruction This PR — FIXED (was broken) ✅
subprocess_runner._run_child_session Foundation PR #224

Design Rationale

See docs/designs/at-mention-unify-xml-helper.md in the parent workspace for full design rationale:

  • Why developer-message-injection was wrong for these paths
  • Why XML (inline <context_file> blocks) is the right format choice
  • Why the foundation helper is the single source of truth for expansion logic

Upstream Dependency

Foundation PR: microsoft/amplifier-foundation#224


Generated with Amplifier

… resume + REPL paths

This completes the unified @-mention expansion effort. Part 1 (foundation PR #224)
introduced expand_mentions_in_instruction() helper and converted foundation's call
sites. This PR (CLI) converts the remaining call sites and fixes two gaps where
expansion was missing entirely.

User-visible fix: resume_sub_session now expands @-mentions before passing the
instruction to child_session.execute(). Previously, raw @file.md strings were sent
directly to the LLM with no resolution — the gap peer reviewers caught.

Changes:
- Convert _process_runtime_mentions() in main.py to use the foundation helper
  - Now returns expanded prompt string instead of injecting developer messages
  - Updated all 5 call sites in the REPL loop to use the returned string
- Convert spawn_sub_session (both system_instruction and delegation instruction)
  to use the foundation helper
  - Replaces previous MentionLoader → developer-message-injection format
  - Now uses inline <context_file> XML blocks (consistent with system-prompt path)
- ADD expansion to resume_sub_session (previously had no expansion at all)
  - New block before session.execute(instruction), same structure as spawn path
  - Consistent with spawn and REPL semantics
- Delete amplifier_app_cli/lib/mention_loading/loader.py (MentionLoader class)
  - Zero remaining callers after conversion to foundation helper
  - Eliminates duplicate loader implementation (sync MentionLoader vs async expand_)
- Delete tests/lib/mention_loading/test_loader.py
  - Covered the deleted MentionLoader class
- Update TestSpawnMentionExpansion tests to assert new XML format
- Add TestResumeMentionExpansion to cover previously untested resume path

Net: 230 insertions, 428 deletions (-198 lines — more consolidation than new code)

Test results: 955 passed (1 pre-existing failure unrelated to @mention expansion).

Depends on: microsoft/amplifier-foundation#224 (must merge first)

Generated with Amplifier
Co-Authored-By: Amplifier <240397093+microsoft-amplifier@users.noreply.github.com>
@bkrabach
Brian Krabach (bkrabach) merged commit 2257609 into main May 21, 2026
1 check passed
@bkrabach
Brian Krabach (bkrabach) deleted the fix/mentions-unify-xml-helper branch May 21, 2026 15:47
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