fix: gracefully handle missing mocks for pre-app-start queries in replay mode#92
Conversation
There was a problem hiding this comment.
1 issue found across 4 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="drift/instrumentation/psycopg/instrumentation.py">
<violation number="1" location="drift/instrumentation/psycopg/instrumentation.py:589">
P1: Using `_noop_execute` here does not install mock fetch handlers, so missing pre-app-start mocks may still fail when code fetches rows instead of returning a deterministic empty replay result.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review, or fix all with cubic.
There was a problem hiding this comment.
1 issue found across 1 file (changes from recent commits).
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="drift/instrumentation/psycopg/instrumentation.py">
<violation number="1" location="drift/instrumentation/psycopg/instrumentation.py:566">
P1: `_noop_execute` assigns sync fetch methods even on async cursors, which breaks async replay reads (`await cursor.fetchone()` will fail).</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review, or fix all with cubic.
Generated 41 tests - 41 passedTip New to Tusk Unit Tests? Learn more here. Test Summary
ResultsTusk's tests validate the core behavior change: gracefully handling missing mocks for pre-app-start queries across all database and Redis instrumentations. All 41 tests pass, confirming that pre-app-start queries without mocks now return safe no-op/empty results instead of crashing, while post-app-start queries still raise View check history
Was Tusk helpful? Give feedback by reacting with 👍 or 👎 |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
There are 2 total unresolved issues (including 1 from previous review).
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 89b815b. Configure here.



Summary
During replay mode, pre-app-start queries (e.g. Django's migration checks, table introspection) that weren't captured in the original trace would raise
RuntimeError, crashing the replay. These framework-internal queries only occur with certain server configurations (e.g.runservervsgunicorn) and are safe to return empty results for—Django handles "no tables found" gracefully.This change makes all database and Redis instrumentations return a no-op/empty result for pre-app-start queries when no mock is found, instead of raising an error. Post-app-start queries with missing mocks still raise
RuntimeErrorto catch genuine replay issues.Changes
instrumentation.py):_replay_executeand_replay_executemanynow delegate toself._noop_execute(cursor)for pre-app-start queries with no mock, logging a warning instead of raising.instrumentation.py): Same fix applied to_replay_execute,_replay_executemany,_replay_stream(returns empty generator), and_replay_copy(yields emptyMockCopy).instrumentation.py):before_cursor_executesetsmock_resultto an empty result dict ({"rows": [], "rowcount": 0, "description": None}) for pre-app-start queries, allowing the normalafter_cursor_executeflow to proceed.instrumentation.py):_replay_execute_commandreturnsself._get_default_response(command_name)(existing per-command-type defaults) and_replay_pipeline_executereturns[]for pre-app-start commands.