fix: prevent plan polling from causing intermittent 500s#86
Open
black-pwq wants to merge 12 commits intoketing:mainfrom
Open
fix: prevent plan polling from causing intermittent 500s#86black-pwq wants to merge 12 commits intoketing:mainfrom
black-pwq wants to merge 12 commits intoketing:mainfrom
Conversation
…om anyio
The test test_ensure_repo_sync_retries_retryable_fetch_failure was
asserting that time.sleep is called exactly once during a retryable
fetch failure, but it was failing with:
AssertionError: Expected 'sleep' to have been called once.
Called 32 times.
Root cause
----------
The test patched 'services.git_service.time.sleep', which replaces the
'sleep' attribute on the shared time module object itself. Because
patch operates on the module-level name binding, this ends up replacing
time.sleep globally for the duration of the test. The anyio library
(used by pytest-anyio, which is loaded as a plugin) runs an internal
thread pool that polls with exponential back-off using time.sleep
directly. Those 31 extra calls (0.001, 0.002, 0.004, ... 0.05 × 25)
belong to anyio's scheduler, not to git_service, yet they were captured
by the same mock, causing the assertion to fail.
Fix
---
Introduce a module-level alias in git_service:
_sleep = time.sleep
and use _sleep(delay) inside _retry_git_operation instead of calling
time.sleep(delay) directly.
The test now patches 'services.git_service._sleep' instead of
'services.git_service.time.sleep'. This replaces only the name binding
inside the git_service module namespace; time.sleep elsewhere in the
process (including inside anyio) is unaffected. The mock therefore
captures exactly the one call made by the retry logic, and
assert_called_once() passes reliably.
Replace the manual venv + pip workflow with uv in both the English and Chinese README: - Remove: python3.12 -m venv .venv && source .venv/bin/activate - Remove: pip install -r requirements-dev.txt - Replace: uvicorn main:app ... → uv run uvicorn main:app ... - Add a note explaining that uv auto-creates the venv from pyproject.toml and that dev deps can be installed with
Owner
|
主线修复(polling_loop 用 run_in_executor 调度 poll_project,worker 内开新 session 不复用 scheduler 的)方向正确,回归测试 合并前请处理一个 Blocker:
另一个非阻塞建议(Minor):
|
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.
Summary
Fix the intermittent 500 error seen after entering the Plan stage.
This change keeps the background polling path from blocking the event loop and exhausting request threads, which could surface as:
GET /api/projects/{id}/plansreturning 500RuntimeError: can't start new threadChanges
run_in_executorGET /api/projects/{id}/plansstaying responsive during background pollingVerification
Closes #51