Files
llm-multiverse/implementation-plans/issue-120.md
Pi Agent 960e5527e8 fix: resolve tech debt from issue #31 review
- Add [UNTRUSTED CONTENT] markers for external-provenance memories in
  extraction prompts (provenance == 2)
- Parallelize extract_batch using futures::future::join_all instead of
  sequential processing
- Consolidate duplicate FullMockGateway/TestGateway into shared
  test_helpers::MockGateway with configurable inference support

Closes #120

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 09:38:27 +01:00

2.1 KiB

Issue #120: Tech debt: minor findings from issue #31 review

Summary

Address three tech debt items from the extraction step review:

  1. Add [UNTRUSTED CONTENT] marker for external-provenance memories - Wrap corpus text in [UNTRUSTED CONTENT]...[END UNTRUSTED CONTENT] markers when the memory has external provenance (provenance == 2), providing prompt injection mitigation.

  2. Parallel extraction for batch candidates - Change extract_batch from sequential to parallel processing using futures::future::join_all, reducing latency for multiple candidates.

  3. Consolidate duplicate mock gateway test helpers - Merge FullMockGateway (service.rs) and TestGateway (service.rs query_memory test) into a shared test_helpers module.

Item 1: [UNTRUSTED CONTENT] markers

Approach

Add a provenance parameter to build_extraction_prompt. When provenance == 2 (external), wrap the corpus block in [UNTRUSTED CONTENT]...[END UNTRUSTED CONTENT] markers. Update extract and extract_batch to pass the candidate's provenance field through.

Files changed

  • services/memory/src/extraction/prompt.rs - Add provenance param to build_extraction_prompt
  • services/memory/src/extraction/mod.rs - Pass provenance through extract and extract_batch

Item 2: Parallel extraction

Approach

Replace the sequential for loop in extract_batch with futures::future::join_all to process all candidates concurrently. The ExtractionClient wraps a ModelGatewayServiceClient which supports concurrent calls via clone().

Files changed

  • services/memory/Cargo.toml - Add futures dependency
  • services/memory/src/extraction/mod.rs - Rewrite extract_batch with join_all

Item 3: Consolidate mock gateway helpers

Approach

Create a test_helpers module at the top of the #[cfg(test)] section in service.rs containing a single configurable MockGateway struct that handles both embedding and inference RPCs. Replace FullMockGateway and the inline TestGateway with this unified type.

Files changed

  • services/memory/src/service.rs - Consolidate into shared test_helpers module, update test functions