Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
fix(llm): the health wrapper forwards operation-id completions
luisfnicolau401ae5d4152c
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex c0229db6..28612239 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -12,6 +12,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0provider. (#1026)### Fixed+- The provider-health wrapper now forwards the operation-id completions+ (`complete_with_operation_id`, `complete_structured_raw_with_operation_id`).+ They fell to the trait defaults, which drop the caller's id, so every retry+ of one logical operation got a fresh id and, for OpenCode, a new session+ header on every call.- Fixed interrupted launchers blocking an immediate managed-workstream restartby adding explicit `ai-memory run --force-unlock` recovery. The serveratomically expires and replaces only a lease attributed to the samediff --git a/crates/ai-memory-llm/src/health.rs b/crates/ai-memory-llm/src/health.rsindex ceb53040..aa010044 100644--- a/crates/ai-memory-llm/src/health.rs+++ b/crates/ai-memory-llm/src/health.rs@@ -12,7 +12,7 @@ use serde::{Deserialize, Serialize};use crate::embedding::Embedder;use crate::error::{LlmError, LlmResult};use crate::provider::LlmProvider;-use crate::types::{ChatRequest, ChatResponse};+use crate::types::{ChatRequest, ChatResponse, LlmOperationId};const MAX_ERROR_MESSAGE_CHARS: usize = 1024;@@ -345,6 +345,23 @@ impl LlmProvider for HealthRecordingLlmProvider {result}+ // The operation-id variants must be forwarded, not left to the trait+ // defaults: those call `self.complete*`, which drops the caller's id, so+ // the inner provider would mint a fresh one per call and every retry of+ // one logical operation would look unrelated on the wire.+ async fn complete_with_operation_id(+ &self,+ request: ChatRequest,+ operation_id: LlmOperationId,+ ) -> LlmResult<ChatResponse> {+ let result = self+ .inner+ .complete_with_operation_id(request, operation_id)+ .await;+ self.health.record_result(&result);+ result+ }+async fn complete_structured_raw(&self,request: ChatRequest,@@ -355,6 +372,20 @@ impl LlmProvider for HealthRecordingLlmProvider {result}+ async fn complete_structured_raw_with_operation_id(+ &self,+ request: ChatRequest,+ schema: serde_json::Value,+ operation_id: LlmOperationId,+ ) -> LlmResult<serde_json::Value> {+ let result = self+ .inner+ .complete_structured_raw_with_operation_id(request, schema, operation_id)+ .await;+ self.health.record_result(&result);+ result+ }+fn candidate_health(&self) -> Vec<CandidateHealth> {self.inner.candidate_health()}@@ -502,6 +533,80 @@ mod tests {}}+ /// Records the operation id each operation-aware call receives.+ #[derive(Default)]+ struct OperationIdLlm {+ seen: Mutex<Vec<LlmOperationId>>,+ }++ #[async_trait]+ impl LlmProvider for OperationIdLlm {+ fn name(&self) -> &'static str {+ "fake"+ }++ fn model(&self) -> &str {+ "fake-model"+ }++ async fn complete(&self, _request: ChatRequest) -> LlmResult<ChatResponse> {+ Ok(ChatResponse {+ text: "pong".to_string(),+ usage: None,+ model: "fake-model".to_string(),+ })+ }++ async fn complete_with_operation_id(+ &self,+ request: ChatRequest,+ operation_id: LlmOperationId,+ ) -> LlmResult<ChatResponse> {+ self.seen.lock().unwrap().push(operation_id);+ self.complete(request).await+ }++ async fn complete_structured_raw(+ &self,+ _request: ChatRequest,+ _schema: serde_json::Value,+ ) -> LlmResult<serde_json::Value> {+ Ok(serde_json::json!({ "ok": true }))+ }++ async fn complete_structured_raw_with_operation_id(+ &self,+ request: ChatRequest,+ schema: serde_json::Value,+ operation_id: LlmOperationId,+ ) -> LlmResult<serde_json::Value> {+ self.seen.lock().unwrap().push(operation_id);+ self.complete_structured_raw(request, schema).await+ }+ }++ #[tokio::test]+ async fn llm_wrapper_forwards_the_callers_operation_id() {+ let health = ProviderHealth::default();+ let inner = Arc::new(OperationIdLlm::default());+ let llm = health.wrap_llm_provider(inner.clone(), "openai", "gpt-test", None);+ let id = LlmOperationId::new();++ llm.complete_with_operation_id(ChatRequest::user_prompt("ping"), id)+ .await+ .unwrap();+ llm.complete_structured_raw_with_operation_id(+ ChatRequest::user_prompt("ping"),+ serde_json::json!({}),+ id,+ )+ .await+ .unwrap();++ assert_eq!(*inner.seen.lock().unwrap(), vec![id, id]);+ assert_eq!(health.snapshot().llm.status, ProviderHealthStatus::Ok);+ }+#[tokio::test]async fn llm_wrapper_records_unknown_success_and_error() {let health = ProviderHealth::default();