Distinguish retryable thread-store errors from unknown write outcomes (#54664)

## What changed

Add `ThreadStoreError::Retryable` for transient failures known to be safe to retry and `ThreadStoreError::OutcomeUnknown` for writes that may already have committed. Recovery remains the operation owner's responsibility; neither category automatically triggers retries.

Preserve existing app-server error mappings and fatal session startup behavior, and report the new categories in shutdown diagnostics without exposing raw error payloads.

## Testing

Add coverage for conservative SQLx error classification, mutation error mappings, session initialization categories, and shutdown diagnostics that omit raw error payloads.

GitOrigin-RevId: 259a9bfaa6ff3cbfa2ee61a01a1f1e744c90f118
This commit is contained in:
Tom
2026-10-16 17:31:47 +00:00
committed by copyberry
parent 0df4aa6778
commit 96eb400d12
9 changed files with 190 additions and 11 deletions
@@ -284,7 +284,10 @@ fn thread_attachment_store_error(
ThreadStoreError::ThreadNotFound { thread_id } => {
invalid_params(format!("thread not found: {thread_id}"))
}
error @ (ThreadStoreError::Conflict { .. } | ThreadStoreError::Internal { .. }) => {
error @ (ThreadStoreError::Conflict { .. }
| ThreadStoreError::Retryable { .. }
| ThreadStoreError::OutcomeUnknown { .. }
| ThreadStoreError::Internal { .. }) => {
internal_error(format!("failed to process {operation}: {error}"))
}
}
@@ -1,3 +1,44 @@
use codex_app_server_protocol::JSONRPCErrorError;
use codex_thread_store::ThreadStoreError;
use pretty_assertions::assert_eq;
#[test]
fn storage_failure_classification_does_not_change_mutation_error_policy() {
for error in [
ThreadStoreError::Internal {
message: "retryable conflict; outcome unknown".to_owned(),
},
ThreadStoreError::Retryable {
message: "store temporarily unavailable".to_owned(),
},
ThreadStoreError::OutcomeUnknown {
message: "connection lost after write".to_owned(),
},
] {
let mapped = super::thread_store_mutation_error("archive", error.clone());
let expected = JSONRPCErrorError {
code: -32603,
message: format!("failed to archive session: {error}"),
data: None,
};
assert_eq!(mapped, expected);
}
assert_eq!(
super::thread_store_mutation_error(
"archive",
ThreadStoreError::Conflict {
message: "writer already active".to_owned(),
},
),
JSONRPCErrorError {
code: -32600,
message: "writer already active".to_owned(),
data: None,
},
);
}
mod thread_list_cwd_filter_tests {
use super::super::normalize_thread_list_cwd_filters;
use codex_app_server_protocol::ThreadListCwdFilter;
@@ -224,6 +224,8 @@ fn thread_section_store_error(
ThreadStoreError::InvalidRequest { message } => invalid_params(message),
error @ (ThreadStoreError::ThreadNotFound { .. }
| ThreadStoreError::Conflict { .. }
| ThreadStoreError::Retryable { .. }
| ThreadStoreError::OutcomeUnknown { .. }
| ThreadStoreError::Internal { .. }) => {
let action = operation
.strip_prefix("threadSection/")