Skip to content

Time only the cancellation in the indexing execution-timeout test - #608

Closed
suguanYang wants to merge 1 commit into
mainfrom
fix/wangbinqi/indexing-timeout-test-timer
Closed

suguanYang wants to merge 1 commit into
mainfrom
fix/wangbinqi/indexing-timeout-test-timer

Conversation

@suguanYang

Copy link
Copy Markdown
Contributor

Summary

test_execution_timeout_stops_native_wait_and_returns_without_replay bounded the whole IndexingWorker.run() at budget + 0.32 s. CI runs on unrelated branches measured 0.55–0.72 s (47285454677, 46694073445, 47292243180). Captured logs show a single ~0.6 s stall before the failure transition, after which refund, webhook event and the "Indexing failed" log take only 10–15 ms.

Most of that region is blocking psycopg2 work before and after the native wait. The cooperative gevent timer cannot interrupt it and is not meant to. The test now times the cancellation itself:

 run(jobId)
   pre-native SQL            # blocking, ~0.05 s locally
   native wait (sleeps 20×budget)
+    record startedAt / endedAt
   failure settlement SQL    # blocking, own 2 s settlement budget
-assert run elapsed < budget + 0.32
+assert native wait ended within 0.1 s of max(deadline, wait start)
+assert run returned within the settlement budget after cancellation
 assert calls == ["native"]           # no replay (unchanged)
 assert attempt/job failed, DEADLINE_EXCEEDED   # unchanged

If the SQL before the native wait already used up the budget, the wait must end as soon as it starts. Assertion messages print each phase (native wait started +…, ended +…, run returned +…), so a future CI failure shows where the time went.

Investigation, in a Linux container (Python 3.12, Postgres 15):

  • The whole run takes 0.13–0.21 s, cold or in-suite. No module imports happen in that window; b4c21ff already handled numpy/pandas.
  • The time goes to ~42 statements plus cold SQLAlchemy compilation. clear_application_modules() re-imports shared.* before every test, so compiled-statement caches start empty each time.
  • In-suite, the native wait is entered at +0.049 s and interrupted at +0.086 s, about 6 ms after the 0.08 s deadline. Settlement then takes about 0.09 s.
  • Ruled out locally: leftover greenlets in the hub (none alive at test start; sync Redis is fakeredis), and gen-2 GC inside the window (none in 36 iterations).
  • In-suite gen-2 collections do cost ~0.2 s each. That stays a candidate for the CI stall but is unproven. I could not attribute the CI stall to one phase from the CI logs.

Evidence

  • Before: CI: assert (155.570 - 154.887) < ((0.08 + 0.32) + 0) and assert (185.249 - 184.531) < 0.40, both on unrelated branches.
    After: 20/20 passes, each in a fresh process (cold), in a fresh container. The whole file passes 17/18. The other failure is test_native_connection_failure_consumes_one_terminal_execution, which is untouched. It fails the same way before this change in that container's drifted venv ('pending' == 'failed') and passes on CI.
  • Cancellation broken (deadline Timeout(None, …), temporary): the test still fails:
    AssertionError: budget 0.080s; native wait started +0.031s, ended +1.633s; run returned +1.701s

Caveat: local runs used Python 3.12 and a venv reused from a worker image with a few locked packages patched in. CI uses 3.11.

Merge Danger

Door: two-way

Test-only change; revert restores the old bound.

Blast Radius: one-test

Only this contract test's assertions change. Slow settlement on CI is now allowed up to the 2 s settlement budget instead of 0.32 s. That is deliberate: settlement speed is not what this test is about.

🤖 Generated with Claude Code

The test bounded the whole IndexingWorker.run() at budget + 0.32 s. Most of
that run is blocking psycopg2 work before and after the native wait, which
the cooperative gevent timer cannot interrupt and is not meant to. Locally the
run takes 0.13-0.21 s; on CI runners it reached 0.55-0.72 s on unrelated
branches, with the whole stall landing before the failure transition, so the
bound failed without saying anything about cancellation.

Record when the blocked native wait starts and ends, and assert that it ends
within 0.1 s of the deadline (or of entering the wait, when the SQL before it
already used the budget). Settlement after cancellation must finish within its
own settlement budget, and the native call must not be replayed. Assertion
messages report each phase so a future failure shows where the time went.

With the deadline's Timeout disabled the test still fails: the native wait
ends at +1.63 s.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@suguanYang

Copy link
Copy Markdown
Contributor Author

Superseded by #610, which fixed the same execution-timeout test on main.

@suguanYang suguanYang closed this Dec 4, 2026
@suguanYang
suguanYang deleted the fix/wangbinqi/indexing-timeout-test-timer branch December 4, 2026 13:45
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