Implement Codex-style memory system - #35
Conversation
Co-authored-by: multica-agent <github@multica.ai>
There was a problem hiding this comment.
Sorry @trotsky1997, you have reached your weekly rate limit of 500000 diff characters.
Please try again later or upgrade to continue using Sourcery
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 34adf1c6a5
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| r"(?i)(api[_ -]?key|access[_ -]?token|auth[_ -]?token|token|secret|password)\s*[:=]\s*([^\s,;]+)", | ||
| "$1=<redacted>", |
There was a problem hiding this comment.
Redact natural-language secrets before persisting memories
When a user says a secret in prose such as password is hunter2 or token abc123, the extractor selects that line because it contains password/token, but this regex only redacts :/= assignments (plus a couple of provider-shaped tokens). With memory enabled, those lines are then written to the local memory JSON in plaintext, which defeats the secret-redaction guarantee for common user wording.
Useful? React with 👍 / 👎.
| if let Some(GenerationDecision::Pending { remaining_idle, .. }) = outcome { | ||
| let system = system.clone(); | ||
| let session = session.clone(); | ||
| tokio::spawn(async move { | ||
| tokio::time::sleep(remaining_idle).await; |
There was a problem hiding this comment.
Keep delayed memory generation alive for one-shot commands
With the default min_idle_before_generation_secs of 600, generate_for_session reaches this branch, spawns a delayed task, and returns immediately. In the ra one-shot run_print/resume paths that call it just before returning from main, the Tokio runtime shuts down before the sleep completes, so enabled memories are never generated unless users override the idle delay to zero.
Useful? React with 👍 / 👎.
| { | ||
| *self.active.lock().await = true; | ||
| *self.last_activity_at.lock().await = Instant::now(); |
There was a problem hiding this comment.
Clear memory activity state on prompt errors
If run_loop() later returns an error (for example a model stream or tool failure), res? exits prompt_unlocked before the cleanup block clears this newly-added active flag and refreshes last_activity_at. Any subsequent save/generation pass for that session will continue to see is_active = true and skip memory generation as SessionActive, even though the prompt has already ended with an error.
Useful? React with 👍 / 👎.
| UseDecision::Active => rendered.push(render_artifact(artifact)), | ||
| UseDecision::Suppressed { .. } => {} | ||
| } | ||
| if rendered.len() >= self.max_entries { |
There was a problem hiding this comment.
Honor a zero prompt-memory limit
When max_prompt_memories = 0, this loop still pushes the first active artifact before checking the limit, so setting the documented maximum to zero renders one memory instead of suppressing memory context. This makes the config unable to fully disable prompt injection via the prompt limit alone.
Useful? React with 👍 / 👎.
| if let Some(prompt) = crate::memory::load_prompt_for_cwd(Some(&self.memory), &cwd).await { | ||
| s.set_memory_prompt(Some(prompt)).await; |
There was a problem hiding this comment.
Preserve memory controls when forking ACP sessions
When an ACP user disables memory_use or memory_generate on a session and then forks it, create_session builds the child with default memory controls and immediately loads the memory prompt; the fork handler only copies the transcript. The fork can therefore start using or generating memories that the parent explicitly opted out of, even though ACP fork is supposed to carry the same conversation context forward.
Useful? React with 👍 / 👎.
Co-authored-by: multica-agent <github@multica.ai>
Summary
Validation