Skip to content

Commit 50a7328

Browse files
anp-oaicopyberry
authored andcommitted
Enforce centralized SQLite connection creation (openai#35828)
## Why Direct SQLx constructors can bypass the shared SQLite configuration in `codex-state`. ## What changed - Deny SQLx pool, connection, and database creation methods through the workspace Clippy configuration for both Cargo and Bazel builds. - Exempt `codex-rs/state/src/sqlite.rs`, the centralized connection shim, from the lint. - Document that the deny list must be audited when upgrading SQLx. GitOrigin-RevId: e20d7e83095727ac446347157782175062a100fc
1 parent 155c3e2 commit 50a7328

4 files changed

Lines changed: 22 additions & 0 deletions

File tree

.bazelrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ build:clippy --@rules_rust//rust/settings:clippy.toml=//codex-rs:clippy.toml
117117
build:clippy --@rules_rust//rust/settings:clippy_flag=-Dwarnings
118118
build:clippy --@rules_rust//rust/settings:clippy_flag=--deny=clippy::await_holding_invalid_type
119119
build:clippy --@rules_rust//rust/settings:clippy_flag=--deny=clippy::await_holding_lock
120+
build:clippy --@rules_rust//rust/settings:clippy_flag=--deny=clippy::disallowed_methods
120121
build:clippy --@rules_rust//rust/settings:clippy_flag=--deny=clippy::expect_used
121122
build:clippy --@rules_rust//rust/settings:clippy_flag=--deny=clippy::identity_op
122123
build:clippy --@rules_rust//rust/settings:clippy_flag=--deny=clippy::manual_clamp

codex-rs/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,7 @@ symphonia = { version = "0.6.0", default-features = false, features = [
409409
"wav",
410410
] }
411411
socket2 = "0.6.1"
412+
# When bumping sqlx, audit the SQLite constructor deny list in clippy.toml.
412413
sqlx = { version = "0.9.0", default-features = false, features = [
413414
"chrono",
414415
"json",
@@ -482,6 +483,7 @@ rust = {}
482483
[workspace.lints.clippy]
483484
await_holding_invalid_type = "deny"
484485
await_holding_lock = "deny"
486+
disallowed_methods = "deny"
485487
expect_used = "deny"
486488
identity_op = "deny"
487489
manual_clamp = "deny"

codex-rs/clippy.toml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,20 @@ disallowed-methods = [
1111
{ path = "ratatui::style::Stylize::white", reason = "Avoid hardcoding white; prefer default fg or dim/bold. Exception: Disable this rule if rendering over a hardcoded ANSI background." },
1212
{ path = "ratatui::style::Stylize::black", reason = "Avoid hardcoding black; prefer default fg or dim/bold. Exception: Disable this rule if rendering over a hardcoded ANSI background." },
1313
{ path = "ratatui::style::Stylize::yellow", reason = "Avoid yellow; prefer other colors in `tui/styles.md`." },
14+
# Audited against workspace sqlx 0.9.0. Revisit this SQLite escape-hatch list when bumping sqlx.
15+
{ path = "sqlx::Pool::connect", reason = "Create SQLite pools through codex-state's sqlite shim." },
16+
{ path = "sqlx::Pool::connect_with", reason = "Create SQLite pools through codex-state's sqlite shim." },
17+
{ path = "sqlx::Pool::connect_lazy", reason = "Create SQLite pools through codex-state's sqlite shim." },
18+
{ path = "sqlx::Pool::connect_lazy_with", reason = "Create SQLite pools through codex-state's sqlite shim." },
19+
{ path = "sqlx::Pool::set_connect_options", reason = "Do not replace options on SQLite pools created by codex-state's sqlite shim." },
20+
{ path = "sqlx::pool::PoolOptions::connect", reason = "Create SQLite pools through codex-state's sqlite shim." },
21+
{ path = "sqlx::pool::PoolOptions::connect_with", reason = "Create SQLite pools through codex-state's sqlite shim." },
22+
{ path = "sqlx::pool::PoolOptions::connect_lazy", reason = "Create SQLite pools through codex-state's sqlite shim." },
23+
{ path = "sqlx::pool::PoolOptions::connect_lazy_with", reason = "Create SQLite pools through codex-state's sqlite shim." },
24+
{ path = "sqlx::Connection::connect", reason = "Create SQLite connections through codex-state's sqlite shim." },
25+
{ path = "sqlx::Connection::connect_with", reason = "Create SQLite connections through codex-state's sqlite shim." },
26+
{ path = "sqlx::ConnectOptions::connect", reason = "Create SQLite connections through codex-state's sqlite shim." },
27+
{ path = "sqlx::migrate::MigrateDatabase::create_database", reason = "Create SQLite databases through codex-state's sqlite shim." },
1428
]
1529

1630
# Increase the size threshold for result_large_err to accommodate

codex-rs/state/src/sqlite.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
//! Shared SQLite connection configuration.
22
3+
#![expect(
4+
clippy::disallowed_methods,
5+
reason = "this is the centralized SQLite connection shim"
6+
)]
7+
38
use crate::DbTelemetry;
49
use crate::migrations::repair_legacy_recency_migration_version;
510
use crate::runtime::RuntimeDbInitError;

0 commit comments

Comments
 (0)