Repository navigation
Allow trace thread retrieval to retry after a transient failure - #1148
Gareth.Y (linjiaye929) wants to merge 1 commit into
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b7fd563b9b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "Codex (@codex) review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "Codex (@codex) address that feedback".
| return await self._thread_cache[cache_key] | ||
| task = self._thread_cache.get(cache_key) | ||
| # Share in-flight work and successful results, not a previous failed attempt. | ||
| if task is None or (task.done() and (task.cancelled() or task.exception() is not None)): |
There was a problem hiding this comment.
Reset the cancelled flush before retrying the thread
When a get_thread() caller is cancelled while _ensure_spans_ready() is awaiting the production flush callback, that cancellation also cancels _spans_flush_promise. flush_and_mark() clears the promise only under except Exception, but asyncio.CancelledError is a BaseException; consequently this new task.cancelled() branch creates a replacement that immediately awaits the permanently cancelled flush task, and every later explicit retry is cancelled instead of rerunning the flush. Clear the flush promise on cancellation (and cover this path) before treating cancelled thread tasks as retryable.
Useful? React with 👍 / 👎.
LocalTrace.get_thread()caches the task for each preprocessor. If a span flush or preprocessor invocation fails once, a later call on the same trace awaits the already-failed task and gets the original exception without attempting the operation again. In the flush case this also prevents the retry that_ensure_spans_ready()already supports.Keep sharing in-flight work and successful results. On the caller’s next explicit request, replace a completed task that failed or was cancelled. The initial error still propagates. This adds no automatic retries and does not change how cancellation propagates between active waiters.
The regression covers a one-time flush failure and a one-time invoke failure. In each case, two concurrent retries share a successful fetch and a later call uses the cached messages.
Verification on Linux, Python 3.14.7, against
4df5c78d:test_trace.py: 43 passed, using VCR replay.make fixup: all seven configured hooks passed.make -C py test-core: 1,227 passed, 112 skipped, 12 expected failures; two pytest-asyncio deprecation warnings.Prepared with AI assistance. Live provider integrations and the full OS/Python CI matrix were not run locally.