Repository navigation
Fix flaky tests, a lost-update race in the redis token manager, and slow supervisor tests - #7938
Conversation
The blocking-detection tests flaked on loaded runners (macOS, Windows): - probe_queued stayed set after its probe ran, so a handler could block before the monitor queued the probe that times it, a polling gap or more late. Totals came out short (0.116 >= 0.12) and a 0.055s block could go unseen. Track a probe that is still pending instead. - The import test sampled while the import machinery found and compiled the new module, which can take past the threshold on a slow file system. Hold the sample until the module body runs. - The event processor tests held the loop for a fixed 0.12s, so a monitor thread descheduled for that long reported nothing. Hold it until the monitor warns, for at most five seconds. Claude-Session: https://claude.ai/code/session_01LwJUCTbMr47R4wgWUN4W91
…eed limit The first cold process of a Windows run compiles the bytecode of every module it imports and timed out at 30 seconds, though a script takes about a second. Claude-Session: https://claude.ai/code/session_01LwJUCTbMr47R4wgWUN4W91
A request the old worker accepted as the reload stopped it was reset with the worker (ConnectionResetError). The app now answers with its worker's pid, and the test sends its request once that worker has exited, while the slow replacement still loads, so it must queue in the supervisor's backlog. Claude-Session: https://claude.ai/code/session_01LwJUCTbMr47R4wgWUN4W91
…t one A real redis delivers keyspace events on their own connection, so after a lease closes the next event may be the state write before the lock release (assert 1 == 2 in test_modify_oplock). Wait until the expected count arrives. Claude-Session: https://claude.ai/code/session_01LwJUCTbMr47R4wgWUN4W91
A 502 from the API failed the changes job, and with it every gate behind the filter, with a JSONDecodeError. Retry the call up to three times. Claude-Session: https://claude.ai/code/session_01LwJUCTbMr47R4wgWUN4W91
[Medium impact] The PR appears safe to merge; no new blocking issues were found. SummaryThis PR fixes a Redis update race and makes CI tests more reliable and faster. The latest change rechecks the subscription deadline after a timed wait ends.
The previous findings are addressed. No new actionable issues were found. Reviews (5) · Last reviewed commit: "fix(token-manager): keep waiting until t..." · Reviewed by Greptile |
There was a problem hiding this comment.
All reported issues were addressed across 6 files
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
Merging this PR will not alter performance1 warning
Comparing Footnotes
|
…cket record on_connect started the lost and found subscriber as a background task and stored the socket record before redis confirmed the subscription. Another instance publishing for the token in that window had its delta dropped by redis, which flaked test_redis_token_manager_lost_and_found. A connect now waits for the confirmation, as the redis state manager does for its lock subscription, and goes ahead with a warning after 5 seconds. Only an instance's first connect waits. Claude-Session: https://claude.ai/code/session_01LwJUCTbMr47R4wgWUN4W91
There was a problem hiding this comment.
All reported issues were addressed across 4 files (changes from recent commits).
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
The supervisor tests spent about 32 seconds of every unit run waiting on the production drain budget (5s), record grace (2s) and a 15ms-per-line consumer. Scripts that only need some limit to end the drain now set it short, as the others already did, and the slow consumer reads at 5ms per line, still far slower than the writer. The file now runs in about 19 seconds. Claude-Session: https://claude.ai/code/session_01LwJUCTbMr47R4wgWUN4W91
…of waiting An earlier commit here put the Windows timeouts down to bytecode compilation, but collection has already imported sqlalchemy, sqlmodel and reflex.app in the parent, so that is not it. A slow interpreter and a hang in the import locks these tests exercise look the same from outside. The script now dumps every thread's stack and exits after 60 seconds, so a failure shows which it was, and the parent waits 90 seconds instead of 180. Claude-Session: https://claude.ai/code/session_01LwJUCTbMr47R4wgWUN4W91
…t each connect While redis could not confirm the lost and found subscription, every connect waited the full five seconds. Connects now wait only until five seconds after the subscriber started. The timeout test moves to module level, and the changed-paths retry says how long it sleeps. Claude-Session: https://claude.ai/code/session_01LwJUCTbMr47R4wgWUN4W91
A subscriber that failed after its first five seconds was retried inside the same task, so connects did not wait for its new subscription and the race came back. Every attempt now sets the deadline connects wait until. The post-handler blocking test now compares both warnings in full. Claude-Session: https://claude.ai/code/session_01LwJUCTbMr47R4wgWUN4W91
On Windows, where the monotonic clock moves in 15.6ms ticks, a subscription wait could time out while the loop clock still read just before the deadline. The next connect then waited again and warned a second time, failing test_redis_token_manager_waits_for_an_unconfirmed_subscription_once on windows-latest. The wait now re-reads the deadline until it has passed, and a connect warns only when it waited and gave up. A Linux run with a simulated 15.6ms clock failed 3 of 5 times before and 0 of 25 after. Claude-Session: https://claude.ai/code/session_01LwJUCTbMr47R4wgWUN4W91
Port upstream's EventNamespace changes to the moved namespace modules, so both transports get them. The X-Forwarded-For validation of reflex-dev#7880 runs in build_static_router_data, with _is_port and _forwarded_client_ip next to _trusted_forwarded_value; _clip moves there too for its debug line, and reflex.app imports it back. The suppress_warnings parameter of reflex-dev#7921 is on BaseEventNamespace.emit_update, and the awaited lost-and-found subscription of reflex-dev#7938 runs in BaseEventNamespace.handle_connect. The X-Forwarded-For tests move to tests/units/test_event_namespace.py. The modify_state test of reflex-dev#7921 builds a WebsocketEventNamespace and reads the warning from reflex.event_namespace, which logs it now.
…inification - reflex-dev#7583's field subscription goes on the state's local, which a resolver can prefix with `$rx_`; the two hook tests expect the field list. - reflex-dev#7938's wait for the lost-and-found subscription runs after the per-SID setup, which has to happen before the connect's first await, and still before link_token_to_sid stores the socket record.
Fixes flaky tests that fail CI on
mainand on unrelated PRs. One of them came from a real race inRedisTokenManager, which is also fixed here. The PR also cuts about 13 seconds from every unit test run.Type of change
Changes
test_token_manager.py::test_redis_token_manager_lost_and_found:Expected 'mock' to have been called once. Called 0 times.on_connectstarted the lost-and-found subscriber in the background and stored the socket record before Redis confirmed the subscription. A delta another instance published in that window was dropped by Redis. Delaying thePSUBSCRIBEby 0.5s reproduces it every time.psubscribeconfirmation, as the Redis state manager already does for its lock subscription. Each subscription attempt, including a retry after a failure, gives connects at most 5s to wait, so a Redis that can't confirm doesn't stall every connect. News fragment included.test_lazy_serializer_regressions.py::test_sqlmodel_relationships_from_cold_state[False-None]:subprocess.TimeoutExpiredafter 30s (Windows)reflex.appin the parent. From outside, a slow interpreter and a hang in the import locks these tests exercise look the same.faulthandler.dump_traceback_later), so the next failure shows where it was. The parent waits 90s as a backstop.test_blocking.py::test_blocking_just_over_threshold_is_detectedandtest_event_processor.py::test_processor_reports_blocking_after_handler_returns: empty caplog (macOS).test_blocking_import_is_logged_with_import_advice: wrong stack (Windows)probe_queuedstayed set after its probe ran, so a handler could block before the probe that times it was queued. Under CPU load I reproduced totals of0.116 >= 0.12. The import test sampled while the import machinery was still finding and compiling the module. The event processor tests held the loop for only a fixed 0.12s.test_exec.py::test_run_granian_backend_holds_requests_across_reload:ConnectionResetErrortest_redis.py::test_modify_oplock:assert 1 == 2changesjob:gh: Server Error (HTTP 502)→JSONDecodeErrorFaster tests
test_supervisor.pyspent about 32s of every unit run waiting out production timeouts: the 5s drain budget, the 2s record grace, and a consumer reading at 15ms per line. Scripts that only need some limit to end the drain now set it short, as others in the file already did. The slow consumer now reads at 5ms per line, still far slower than the writer. The file now runs in about 19s, and 8 of 8 runs under CPU load passed.Testing
ruff,pyrightandpre-commitpass on the changed files.Not addressed
reflex-docs-macosfails on mostmainpushes withPrerender: Request failed for /docs/: The operation was aborted due to timeout. React Router 8.4 uses a fixed 10s per-request prerender timeout with no retries, and its config does not expose either. That needs its own investigation.https://claude.ai/code/session_01LwJUCTbMr47R4wgWUN4W91