Repository navigation
Description
Summary
In a Codex integration that performs prompt-time recall after AgentMemory's shipped UserPromptSubmit hook, the hook first persists the current prompt through /agentmemory/observe. A subsequent /agentmemory/search in the same turn can return that just-created observation as a top result.
If the result is injected back into Codex, the user's current input is presented as if it were a previous memory. This consumes recall slots and can displace the older context the user actually asked for.
Observed with AgentMemory 0.9.29 and Codex Desktop.
Minimal reproduction
Use a unique session and prompt:
curl -X POST http://127.0.0.1:3111/agentmemory/observe \
-H 'Content-Type: application/json' \
-d '{
"hookType": "prompt_submit",
"sessionId": "same-turn-recall-repro",
"project": "repro",
"data": {"prompt": "same turn recall sentinel 7f0c9a21"}
}'
curl -X POST http://127.0.0.1:3111/agentmemory/search \
-H 'Content-Type: application/json' \
-d '{
"query": "same turn recall sentinel 7f0c9a21",
"limit": 5,
"format": "full"
}'Once the observation is indexed, the result set can contain the observation created by the first request. In a real Codex turn the sequence is:
UserPromptSubmitobserves the current prompt.- A prompt-time recall adapter searches using the current prompt.
- The current prompt observation is returned and injected as "memory".
Expected behavior
Prompt-time recall should search only information that existed before the current prompt capture, while preserving earlier completed turns from the same session.
Actual behavior
The current prompt can recall itself. Excluding the entire current session would hide useful earlier turns, so session-wide filtering is too broad.
Related upstream work
- post-tool-use captures agentmemory MCP calls as observations, polluting recall results #993 reports the same general class of self-capture feedback loop for AgentMemory's own
memory_*tool calls. - feat: add opt-in prompt-time proactive recall #1129 proposed prompt-time proactive recall for Codex/Claude Code, but its flow calls
observePrompt(...)beforerecallContext(...). Its mocked test server returns search fixtures independently from the preceding observe request, so the stateful self-recall case is not covered.
Local workaround tested
We changed the Codex capture order locally:
UserPromptSubmitno longer persists the half-completed turn.- The existing
Stopcapture stores one observation containing both the user prompt and the assistant final response. - Historical recall remains enabled and earlier memories are still returned.
Regression results:
- 28 focused hook/manager tests passed.
- A live synthetic
UserPromptSubmitproduced zero observations for its test session. - A separate historical recall still returned prior memories through the indexed search path.
This workaround also improves memory quality because only completed conversational turns enter the corpus.
Suggested upstream solutions
Any of these would prevent the problem:
- Perform prompt-time recall before calling
observePrompt. - Return the new observation ID from capture and let search accept
excludeObservationIds(preferred over excluding the full session). - Add a search boundary such as
createdBefore, fixed to the start of the current turn. - For Codex, defer conversation capture until
Stopand store the complete user/assistant pair.
A stateful regression test should persist a unique prompt, run prompt-time search, assert that the new observation is absent, and assert that an older observation from the same session remains recallable.
Activity