Repository navigation
fix: enforce SQLite execution deadlines from the safety context - #332
Open
seyoung4503 wants to merge 1 commit into
Open
seyoung4503 wants to merge 1 commit into
seyoung4503 wants to merge 1 commit into
Conversation
This was referenced Nov 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.