Bound SQLite integrity checks for diagnostic attachments (#40688)

## Why

Diagnostic uploads skip the doctor attachment if report generation exceeds its
overall timeout. SQLite integrity scans can be delayed by large databases or
lock contention.

## What changed

- Give each database integrity scan a one-second deadline when collecting a
  diagnostic attachment.
- Interrupt scans and lock waits at the deadline, preserve any corruption rows
  already returned, and report an incomplete clean scan as a warning.
- Keep direct `codex doctor` integrity checks unbounded.

## Testing

- Cover interrupted scans, lock waits, retries without a deadline, and
  corruption results returned before interruption.

GitOrigin-RevId: 4817fb459ac53953669a9ba5f03397a6fc82c72e
This commit is contained in:
chess authored and copyberry committed 2026-08-25 20:09:55 +00:00
1 parent 94967e03e5
commit 32ce703a80
7 files changed
+194 -53

No files matched your search

@@ -2,10 +2,10 @@
//!
//! Feedback upload should never depend on doctor succeeding. This module runs
//! the configured Codex executable as a subprocess, accepts only valid JSON from
//! `codex doctor --json`, derives a small set of Sentry tags, and otherwise
//! `codex doctor --json --feedback`, derives a small set of Sentry tags, and otherwise
//! skips the attachment with a warning. Keeping the report generation out of the
//! app-server process avoids sharing doctor internals across crates while still
//! attaching exactly the same JSON a user could copy from the CLI.
//! using the CLI's JSON report format with bounded database scans.
use std::collections::BTreeMap;
use std::path::Path;
@@ -31,7 +31,7 @@ pub(crate) struct DoctorFeedbackReport {
pub(crate) tags: BTreeMap<String, String>,
}
/// Runs `codex --cd <workspace> doctor --json` and returns a best-effort
/// Runs `codex --cd <workspace> doctor --json --feedback` and returns a best-effort
/// feedback attachment.
///
/// Failure to spawn Codex, finish before the timeout, or parse JSON means the
@@ -110,6 +110,7 @@ fn doctor_command(executable: &Path, cwd: &Path, codex_home: &Path) -> Command {
.arg(cwd)
.arg("doctor")
.arg("--json")
.arg("--feedback")
.current_dir(codex_home)
.env("CODEX_HOME", codex_home);
command
@@ -211,7 +212,8 @@ mod tests {
"--cd".as_ref(),
workspace.as_os_str(),
"doctor".as_ref(),
"--json".as_ref()
"--json".as_ref(),
"--feedback".as_ref()
]
);
assert_eq!(