Skip to content

fix: enforce SQLite execution deadlines from the safety context - #332

Open
seyoung4503 wants to merge 1 commit into
fix/sql-result-completenessfrom
fix/sqlite-query-deadline
Open

seyoung4503 wants to merge 1 commit into
fix/sql-result-completenessfrom
fix/sqlite-query-deadline

Conversation

@seyoung4503

Copy link
Copy Markdown
Collaborator

RunSQL passed a temporary SafetyContext to the safety pipeline and discarded it, so TimeoutLayer's timeout_seconds never reached DB execution. A long SQLite query completed despite a configured 10ms deadline.

Retain the evaluated context and use an optional native-timeout explorer capability. SQLAlchemy's SQLite implementation applies a monotonic SQLite VM progress deadline around both execute and fetch, converts deadline interruption into TimeoutError, and removes the callback before returning the connection to the pool. Both timed and legacy calls use the existing _execute_sync worker. Legacy/non-SQLite explorers retain their existing API and explicitly log/report query_timeout_enforced=false and scope=unsupported.

Scope: sqlite_vm only. This is not an end-to-end wall-clock guarantee: connection acquisition, lock waits, and blocking user-defined functions are outside the SQLite VM callback. Oracle/other adapters do not gain native timeout support in this PR. This limitation is explicit, not silently claimed as enforced.

Validation: real SQLite red-before test previously failed with DID NOT RAISE TimeoutError. Root suite now 270 passed, 1 skipped; Ruff offline and diff checks pass. Tests cover safety-to-executor propagation, execution and fetch interruption, pooled connection cleanup after timeout/syntax error, unmodified syntax-error classification and legacy adapter reporting. Actual MCP stdio runs the default 30-second deadline: TimeoutError at 30.0079 seconds, followed by successful SELECT 42 in the same server. Evidence is committed under bench/accuracy/mcp-review-results/deterministic-query-deadline. No model calls or prompt changes; no benchmark-accuracy claim.

Based on #331. No merge. Reuse: existing SafetyContext/TimeoutLayer, RunSQL error/audit path, SQLAlchemy _execute_sync, asyncio.to_thread and stdio fixture. New native-deadline context manager plus thin capability entry point; one DB execution implementation. No environment variables or deployment settings added; existing timeout configuration is now consumed. The named VM callback interval controls deadline-check granularity.

Principle Result Evidence
Reuse O Existing safety context, execution worker, error path and MCP fixture
Cause O Preserve discarded context and enforce its timeout in native VM
Logging O Scoped failures; unsupported capability warning; response scope metadata
Error levels O TimeoutError propagates through existing audited error path; no swallowed error
Environment N/A No new env access
Comments O Runtime limits explained, no issue references
Verification O Red-before/green-after; 270 passed, 1 skipped; Ruff/diff clean; no CODE MAP generator exists
Authorization O Branch and PR only
Call path O SafetyContext -> optional capability -> same DB worker -> VM callback -> MCP error
Sync/async O Single sync worker under existing to_thread; timeout cancels VM execution rather than abandoning the await
Configuration O Existing configured seconds used; no new deployment values

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant