Fix: /memory/ingest hardcodes source_mode=chat, partially defeats #877 partition#4
Draft
mimeding wants to merge 2 commits into
Draft
Fix: /memory/ingest hardcodes source_mode=chat, partially defeats #877 partition#4mimeding wants to merge 2 commits into
mimeding wants to merge 2 commits into
Conversation
PR osaurus-ai#877 partitioned the memory store by execution mode (chat, chat_sandbox, work_host, work_sandbox) and made pure-chat recall filter out tool-using contributions to prevent phantom-tool priming. The HTTP ingest endpoint, however, was hardcoded to tag every turn as .chat, regardless of where the source turns actually came from. That means anyone seeding memory from existing logs, migrating from another system, or running offline batch ingestion (LoCoMo benchmark runs are exactly this) ends up writing tool-flavoured turns under the chat partition. When the agent later runs in pure-chat mode, the chatOnly filter happily surfaces those rows -- the very leak the partition was designed to prevent. Fix by accepting an optional source_mode at both the request level (batch default) and per-turn (override). Both fields default to .chat so existing callers keep working byte-for-byte. MemorySourceMode is already Codable with the right string raw values, so callers send 'chat' / 'chat_sandbox' / 'work_host' / 'work_sandbox' as JSON strings. Docs/MEMORY.md updated with the new fields and a short note on why tagging matters. Co-authored-by: Michael Meding <mimeding@users.noreply.github.com>
ModelManager.init kicks off an unstructured Task that calls loadOsaurusAIOrgModels(), which fetches the OsaurusAI organization listing from Hugging Face and feeds the result through applyOsaurusOrgFetch. The unit-test runner repeatedly constructs ModelManager() to drive applyOsaurusOrgFetch directly. The background launch-time fetch races with those test calls — whichever finishes last wins, and the merge result is non-deterministic. That's the root cause of the flaky ModelManagerSuggestedTests failures seen across many of the recent PR CI runs (applyOsaurusOrgFetch_dropsStaleAutoFetched OnReapply, applyOsaurusOrgFetch_addsNewEntriesAfterCurated, etc.). Gate the launch-time fetch on a small isRunningInTestEnvironment helper that checks for any of XCTestConfigurationFilePath, XCTestBundlePath, or XCTestSessionIdentifier in the process environment. Those variables are only present inside an xctest host process; production app launches still get the HF fetch exactly as before. This is a network call, so removing it under tests also has the side benefit of making the test suite work offline / on hermetic CI runners. Co-authored-by: Michael Meding <mimeding@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Why this matters (business)
PR osaurus-ai#877 introduced one of the more important UX guarantees in the memory subsystem: facts learned while an agent had tools available (Work mode, sandbox, etc.) should not seep back into pure-chat sessions and make the model believe it has tools it doesn't. Without that partition, agents in chat-only mode confidently reference file paths, sandbox commands, and other agentic affordances that won't actually work for the user.
The HTTP ingest endpoint — which is the path users hit for:
was tagging every ingested turn as pure
.chat, regardless of what mode produced the source data. Tool-flavoured turns therefore landed in the partition that chat-only recall reads from, and the recent partition guarantee silently degraded the moment a real batch was loaded.This is the kind of regression that doesn't surface in unit tests but shows up as "the agent keeps offering to run shell commands when I never enabled tools" in user reports.
What's wrong (technical)
Both the chunk insert and the
recordConversationTurncall hardcoded.chat.MemorySourceModeis alreadyCodable(seeWork/WorkExecutionMode.swift:38), and both downstream APIs already accept an optionalMemorySourceModeparameter — only the HTTP request decoder was missing the field.Fix
Add two optional fields to
MemoryIngestRequest:source_mode— batch-level default applied to every turn that does not override it.source_modeonMemoryIngestTurn— per-turn override for migrated logs that mix modes.Both default to
.chat, so existing callers (and the example indocs/MEMORY.md) are byte-identical. Tagging now flows correctly throughdb.insertChunkandMemoryService.recordConversationTurn.Also:
docs/MEMORY.mdparameter table with the new fields and a one-line note on why tagging matters.Changes
/memory/ingest; downstreaminsertChunk(sourceMode:)already has coverage inMemoryDatabaseTests)docs/MEMORY.mdupdated)Test Plan
Default behavior unchanged:
Inspect the resulting
conversation_chunksrow —source_mode = 'chat'as before.Per-batch override:
source_mode = 'work_host'on every chunk. Open the agent in pure-chat mode and confirm via Insights that those rows are filtered out ofchatOnlyrecall.Per-turn override:
First chunk pair tagged
chat, second taggedchat_sandbox.Checklist
CONTRIBUTING.md