fix(memory): team-scoped memories were never stored — null agent_id threw a swallowed TypeError - #139
Merged
Merged
Conversation
…hrew a swallowed TypeError `StoreMemoryAction::execute()` advertises `?string $agentId`, but storeChunk() and every write-gate helper below it declared a non-nullable `string`. Any team-scoped write — DistillTeamEventsAction passes `agentId: null` explicitly — threw: StoreMemoryAction::storeChunk(): Argument #2 ($agentId) must be of type string, null given, called in .../StoreMemoryAction.php on line 88 execute() wraps the loop in try/catch and logs that at WARNING, so the failure never surfaced: the job "succeeded", the distillation watermark advanced past the events, and nothing was stored. Reproduced on production — `memories` holds 0 rows, and a live distil run returned 61 events in / 0 stored while the model had produced a valid 625-char digest. Widen $agentId to ?string through storeChunk, evaluateWriteGate, handleUpdate, handleAdd and mergeContent. The `where('agent_id', $agentId)` lookups need no change: Laravel's where() maps a null value to `whereNull`. Found by validating the failed_jobs backlog instead of assuming the recent silence meant the failures were fixed.
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.
The bug
StoreMemoryAction::execute()advertises?string $agentId, butstoreChunk()and every write-gate helper below it declared a non-nullablestring. Any team-scoped write throws:execute()wraps the chunk loop intry/catchand logs that at WARNING, so it never surfaced anywhere: the job reports success, the distillation watermark advances past the events, and nothing is stored. Silent, permanent data loss for every team-level memory.DistillTeamEventsActionpassesagentId: nullexplicitly, so the nightly digest has never worked.Reproduced on production
A live distil run for a real team:
…while the model had produced a perfectly good 625-character digest, and the gateway, embeddings and config were all healthy. Calling
StoreMemoryAction::execute(agentId: null)directly reproduced the exact TypeError above in the swallowed warning.Fix
Widen
$agentIdto?stringthroughstoreChunk,evaluateWriteGate,handleUpdate,handleAdd,mergeContent.The
where('agent_id', $agentId)lookups need no change — Laravel'swhere()maps a null value towhereNull.How it was found
By validating the
failed_jobsbacklog rather than accepting that the recent silence meant the failures were fixed. The nightlyDistillTeamEventsJobfailures stopped on 2026-07-29 — two days before the fix that supposedly addressed them (#131, 2026-08-01), so that fix could not be the reason. Chasing the real reason led here.Worth noting: #131 made the symptom quiet by catching
AiAccessUnavailableExceptionand advancing the watermark. This PR fixes the case where there is no exception to catch at all.Verification
Unit/Domain/Memory+Feature/Domain/Memory$agentId