- 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>
2.1 KiB
Issue #120: Tech debt: minor findings from issue #31 review
Summary
Address three tech debt items from the extraction step review:
-
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. -
Parallel extraction for batch candidates - Change
extract_batchfrom sequential to parallel processing usingfutures::future::join_all, reducing latency for multiple candidates. -
Consolidate duplicate mock gateway test helpers - Merge
FullMockGateway(service.rs) andTestGateway(service.rs query_memory test) into a sharedtest_helpersmodule.
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 tobuild_extraction_promptservices/memory/src/extraction/mod.rs- Pass provenance throughextractandextract_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- Addfuturesdependencyservices/memory/src/extraction/mod.rs- Rewriteextract_batchwithjoin_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 sharedtest_helpersmodule, update test functions