Repository navigation
Conversation
…ed turns With a Memory set, the coding agents' model endpoint now does two things around each call. Recall: the latest user message is the query. Results come from a two-minute per-gateway cache or a search bounded by the recall timeout (2s when unset). Up to five memories are added as a note to the first message when it is a system message, or as a new system message at the front. A failed or slow search is logged as memory.recall_failed without the query, and the call goes on without a note. Learning: after the answer has streamed to the agent, a turn the person typed is learned in the background. "remember that ..." is stored word for word with Remember. Anything else is sent to Add with the answer text, up to 4,000 runes. At most four learn calls run at once, and further turns are skipped as busy. Loop steps, failed answers, agent disconnects, pi's summarization calls and pastes over 8,000 runes are never learned. Refusals, failures and successes are logged by user and count only. With Memory nil the upstream body and the stream are byte for byte as before. copyEvents now also returns the error writing to the agent.
wiring.AgentModel takes the memory service, a recall cache and memory.recallTimeout. The gateway builds the cache only when memory is on and passes a nil interface when it is off, so a nil service never looks like one. The cache stays in a variable for the memories API. The apitest fixture gains Options.Memory. A gateway test checks that alice's and bob's agent apps each recall with their own identity name and get only their own note.
Learning runs in its own goroutine, outside the HTTP handler's recover, so a panic in the memory service would have ended the gateway. The goroutine now recovers it and logs memory.learn_panicked with the user and the stack. It never logs the panic value, which may carry typed or memory text. The learn slot is still released, so later turns keep learning.
GET /api/memories lists what Tapas remembers about the signed-in
person, newest first. DELETE /api/memories/{id} removes one of theirs
and drops their recall cache entries, so a deleted memory is not
recalled again. Another person's id, or one that does not exist, is a
404.
Both routes refuse an app's or a job's own token. With memory off they
answer 404 "Memory is off on this platform.". When mem0 fails they
answer 502 "Memory could not be reached; try again later." and log
memory.list_failed or memory.delete_failed with the user.
ui/openapi.json and the generated UI client are regenerated.
Settings gains Memories, next to Secrets. It lists each memory with the day it was saved and lets the person delete one after confirming. With nothing saved it says so and hints at "remember that ...". With memory off, or mem0 unreachable, it shows the server's message instead of a list.
The admin memory page now describes what memory does: recall into the admin's agent model calls, learning, "remember that ...", the SSN refusal, the Memories page and API, memory.recallTimeout, every memory.* log line, and the limits. It also fixes the start check description, which now retries. The members' Ask AI page gains a Memories section, and the Helm values example shows recallTimeout.
…orget recall results after a learn A typed message over 8,000 characters was skipped from learning without a log line; it now logs memory.learn_skipped reason=too_long, as the spec says. pi's own summarization calls are still skipped silently. After mem0 stores at least one memory, the person's cached recall results are dropped, so asking the same thing again within two minutes recalls what was just stored.
Memory off is an admin's choice, so the Memories page shows its banner in the info tone. Other errors stay red.
DELETE /api/memories/{id} now refuses every API token with 403, including
a coding agent's own token when its owner lets it act without asking, and
personal tokens. An agent can then never erase what is remembered about
its owner, even if a prompt talks it into trying. The route joins the
session-only routes in the token middleware, and the handler checks again.
Listing memories is unchanged.
Say that only an SSN written with dashes is refused, that deleting a memory works only from the browser, that recall of a deleted memory can last a couple of minutes, and that long typed messages log too_long.
| } | ||
| audit(person, model, in, outTok, result) | ||
| if ans != nil && resp.StatusCode/100 == 2 && werr == nil { | ||
| p.startLearning(r.Context(), person, text, ans.String()) |
There was a problem hiding this comment.
A real agent disconnect still gets learned here, with a cut-off answer. The disconnect cancels r.Context(), the upstream read fails, and copyEvents returns a nil error (line 343 ignores sc.Err()), so werr stays nil. The brokenWriter test in learn_test.go:262 fails the write instead, so it doesn't cover this path. Returning sc.Err() from copyEvents and also requiring r.Context().Err() == nil before startLearning would close it.
There was a problem hiding this comment.
Fixed in 5882449, with both changes. The non-streamed path had the same hole: it ignored the io.ReadAll error, so a disconnect there learned the typed turn alone. It now carries the read error too.
I added five subtests to TestLearnSkipsFailedAnswers covering a cancelled context mid-stream, during a non-streamed answer, and at the end of a complete stream, plus an upstream connection drop in each path. I also checked that each part of the fix is needed: dropping sc.Err(), the read error, or the context check each makes its own test fail.
When an agent disconnected mid-answer, the cancelled request context ended the upstream read, but copyEvents ignored sc.Err() and returned nil, so the cut-off answer was learned. The non-streamed path ignored the io.ReadAll error the same way, learning the typed turn alone. copyEvents now returns the error that ended reading, the non-streamed path carries its read error, and learning also requires the request context to be live, which catches an agent that went away as the last bytes of a complete answer were written.
Memories: list and delete under Settings
Slice 2: Recall and learning in the agent model proxy
Every coding-agent model call through the gateway now carries the person's memories, and what they type is learned in the background. A slow or down mem0 never breaks the agent or holds it past the recall limit. With memory off, the request to the provider and the stream back are byte for byte what they were.
Stacked on #20. Base this on
feat/memory-mvp-1-coreuntil #20 merges.How it works (
internal/ai/agentproxy):memory.recallTimeout(2s). Up to five memories go into a note in the first message when it is a system message, or into a new system message at the front. The note goes at the front because some models (Qwen chat templates under vLLM, Anthropic, Bedrock) refuse a system message anywhere else.memory.recall_failed,memory.learn_panicked,memory.learned,memory.learn_failed,memory.learn_skipped(reason=busy|too_long) andmemory.write_refused reason=ssn. They carry the user and counts, never the query, the typed text, the answer or memory text.Contracts touched:
agentproxy.Proxygains the optionalMemory,RecallandRecallTimeoutfields. Keyed literals are unaffected.wiring.AgentModeltakes the memory service, cache and recall timeout. Its only caller isservercmd/gateway.go.copyEventsalso returns the error writing to the agent, so a disconnect is never learned.Notes for review:
context.WithoutCancel. It is bounded by mem0's add client timeout (memory.addTimeout, 120s by default).memory.learn_panicked(user and stack, never the panic value). The learn slot is still released.apitest.Options.Memorysets memory on the fixture's agent model proxy, including one a test passes in.Depends on: #20
Validation
go test ./internal/ai/... ./internal/cli/... ./internal/gateway/... -race -count=1go test ./internal/ai/agentproxy -run 'Remember|Recall|Learn|SSN|RecallFails|MemoryOff' -vTestMemoryOffForwardsTheSameBytes,TestRecallFailsOpenWhenMemIsDownOrSlow,TestLearnRefusesSSNWithoutLoggingItandTestLearnRunsAtMostFourAtOncemake test-localmake testinternal/filesandinternal/storage/hosthomefail on main too, andtest/devenvandtest/imagetagfail on my machine's commit signing and missingshasum.