Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
test: verify serialized Codex auth recovery
Gabriel Scharb9667844cc588
diff --git a/crates/ai-memory-llm/src/codex.rs b/crates/ai-memory-llm/src/codex.rsindex 1761e334..a608e0d7 100644--- a/crates/ai-memory-llm/src/codex.rs+++ b/crates/ai-memory-llm/src/codex.rs@@ -517,6 +517,23 @@ mod tests {second_status: u16,}+ #[derive(Clone)]+ struct UnauthorizedUntilRotated;++ impl Respond for UnauthorizedUntilRotated {+ fn respond(&self, request: &Request) -> ResponseTemplate {+ let authorization = request+ .headers+ .get("authorization")+ .and_then(|value| value.to_str().ok());+ if authorization == Some("Bearer new-token") {+ ResponseTemplate::new(200).set_body_string(completed_sse("ok"))+ } else {+ ResponseTemplate::new(401).set_body_string("expired")+ }+ }+ }+impl Respond for RotateThenRespond {fn respond(&self, request: &Request) -> ResponseTemplate {let call = self.calls.fetch_add(1, Ordering::SeqCst);@@ -817,4 +834,43 @@ mod tests {.to_string();assert!(error.contains("timed out"));}++ #[tokio::test]+ async fn concurrent_unauthorized_calls_share_one_recovery() {+ let server = MockServer::start().await;+ let dir = tempfile::tempdir().unwrap();+ let auth_path = dir.path().join("auth.json");+ write_auth(&auth_path, "old-token", "account-secret");+ fs::write(dir.path().join("fake-mode"), "success").unwrap();+ Mock::given(method("POST"))+ .and(request_path("/responses"))+ .respond_with(UnauthorizedUntilRotated)+ .mount(&server)+ .await;+ let provider = Arc::new(+ CodexProvider::new(+ CodexAuth {+ auth_file: auth_path,+ executable: compile_fake_codex(dir.path()),+ },+ "gpt-5.6-luna",+ )+ .unwrap()+ .with_responses_url(format!("{}/responses", server.uri())),+ );++ let first = provider.complete(ChatRequest::user_prompt("first"));+ let second = provider.complete(ChatRequest::user_prompt("second"));+ let (first, second) = tokio::join!(first, second);++ assert_eq!(first.unwrap().text, "ok");+ assert_eq!(second.unwrap().text, "ok");+ assert_eq!(+ fs::read_to_string(dir.path().join("fake-invocations"))+ .unwrap()+ .lines()+ .count(),+ 1+ );+ }}diff --git a/crates/ai-memory-llm/tests/support/fake_codex.rs b/crates/ai-memory-llm/tests/support/fake_codex.rsindex 33a72e02..49ed6878 100644--- a/crates/ai-memory-llm/tests/support/fake_codex.rs+++ b/crates/ai-memory-llm/tests/support/fake_codex.rs@@ -1,4 +1,4 @@-use std::fs;+use std::fs::{self, OpenOptions};use std::io::{self, BufRead, Write};use std::path::PathBuf;use std::thread;@@ -6,6 +6,15 @@ use std::time::Duration;fn main() {let codex_home = PathBuf::from(std::env::var_os("CODEX_HOME").expect("CODEX_HOME"));+ writeln!(+ OpenOptions::new()+ .create(true)+ .append(true)+ .open(codex_home.join("fake-invocations"))+ .unwrap(),+ "started"+ )+ .unwrap();let mode = fs::read_to_string(codex_home.join("fake-mode")).unwrap_or_else(|_| "success".into());if mode.trim() == "sleep" {diff --git a/docs/testing/codex-provider.tdd.md b/docs/testing/codex-provider.tdd.mdindex b2d10e9d..04f0225c 100644--- a/docs/testing/codex-provider.tdd.md+++ b/docs/testing/codex-provider.tdd.md@@ -30,7 +30,7 @@ cargo test -p ai-memory-cli codex --no-default-featuresObserved results:-- Codex unit/recovery suite: 8 passed.+- Codex unit/recovery suite: 9 passed.- Existing openai-oauth regression suite: 18 passed.- Codex-related CLI/config tests: 17 passed.@@ -41,5 +41,25 @@ limits, premature process exit, timeout, process cleanup, and auth-filerotation. HTTP mocks cover account headers, model, reasoning, SSE, structuredoutput, reload-before-retry, and the one-retry ceiling.-Full workspace gates and live text/structured smoke results are appended only-after they run successfully.+## Local gates and smoke++- `cargo fmt --all -- --check`: passed.+- `git diff --check`: passed.+- `TAILWIND_SKIP=1 cargo clippy --workspace --all-targets -- -D warnings`:+ passed.+- `cargo deny check`: passed (`advisories`, `bans`, `licenses`, `sources`).+- `TAILWIND_SKIP=1 cargo test --workspace`: provider and downstream suites+ passed until two unrelated `ai-memory-core::routing_skills` assertions hit+ CRLF bytes in the existing Windows checkout. Neither the embedded skill+ assets nor their tests are changed by this branch.+- `cargo llvm-cov` was unavailable locally, so the 80% target was not measured;+ the new parser, HTTP/retry path, structured output, protocol limits, native+ process recovery, failure cleanup, and concurrent recovery are directly+ exercised.+- Live text smoke (`gpt-5.6-luna`, effort `medium`): returned+ `AI_MEMORY_CODEX_TEXT_OK`.+- Live structured smoke (`gpt-5.6-luna`, effort `medium`): returned+ `{"answer":"AI_MEMORY_CODEX_STRUCTURED_OK"}`.+- The Codex auth-file SHA-256 was identical before and after both smokes, and+ `codex login status` remained authenticated. The digest itself is omitted+ from this repository artifact.