Repository navigation
fix: retain Anthropic requests through cancellation cleanup - #143377
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed September 9, 2026, 4:46 PM ET / 20:46 UTC (Revision 2). ClawSweeper reviewWhat this changesThe PR keeps aborted Anthropic requests’ runtime resources alive until response-body cancellation finishes, while preserving prompt abort reporting and adding regression coverage. Merge readiness✅ Ready for maintainer review The fix remains necessary on inspected main, and no blocking defect was found. The verified test merge and reported refreshed validation resolve the previous review’s conflict concern. Priority: P2 Review scores
Verification
How this fits togetherOpenClaw’s Anthropic transport converts provider response streams into assistant output. Its pending cleanup must remain attached to the request’s runtime owner so resources are released only after that cleanup finishes. flowchart TD
A[Prepared model request] --> B[Anthropic response stream]
B --> C[Response parser]
D[Caller abort] --> C
C --> E[Prompt abort result]
C --> F[Tracked body cancellation]
F --> G[Runtime owner drains]
G --> H[Release request resources]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +5, Tests +139. Total +144 across 3 files. View PR surface stats
Review metricsNone. Technical reviewBest possible solution: Keep response cancellation in its original request context and retain the existing runtime owner until the actual cleanup promise settles. Do we have a high-confidence way to reproduce the issue? Yes, from source: abort a stalled Anthropic response from another async context while body cancellation remains pending; main discards the first cleanup promise. This review did not execute the reproduction. Is this the best way to solve the issue? Yes. Moving cancellation to the parser and using the existing work observer repairs the lifecycle owner directly without introducing a parallel API or changing normal cleanup. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against b1aa4805a6c4. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
0e3774c to
fd9a80b
Compare
|
Merged via squash.
|
Related: #140674.
What Problem This Solves
Resolves a problem where an aborted Anthropic request can release its prepared runtime while the response body is still cancelling. Cancellation can also run in the aborting caller's context instead of the request's original context.
Why This Change Was Made
Start body cancellation once, in the parser's original continuation, and give that actual promise to the existing host work observer before reporting the abort. Previously the abort listener started cancellation and discarded its promise; the parser's second cancellation was already resolved even though the first cleanup was still running.
The production repair is seven added and two removed lines. Normal non-abort cleanup remains awaited, and aborts preserve their original reason without waiting for cancellation to finish. No public API, dependency, or database policy changes.
User Impact
Aborted Anthropic calls still return promptly, while their runtime remains alive until accepted cancellation work finishes. Cleanup failures do not replace the original abort reason.
Evidence
Original code fails three transport regressions and the actual core ownership case: the parent drains early, cancellation runs in a foreign context, and a new ModelRegistry is built during held cleanup. The candidate passes all 148 transport and core cases. Affected checks, fresh isolated Codex review through P2, and the ordinary build (317.9 seconds) pass.
Compiled proof uses the actual exec reviewer and managed Anthropic transport against a local synthetic HTTP server. Abort reporting took 4.357 and 0.534 milliseconds for resolving and rejecting cancellation. The original owner stayed alive, overlapping preparation reused its generation, and final drainage followed the held cancellation's settlement. Non-abort cleanup and successful completion also passed.
All child processes exited; 12,119 build artifact hashes stayed unchanged and 2,872 resolved files used no application source fallback. No reviewed command was executed, and no real vendor credentials or production Gateway were used. These are individual correctness timings, not a comparative benchmark. The proof establishes ModelRegistry retention; general RUN SQLite physical disposal remains a separate prerequisite chain.
The final rebase combines the newly landed SDK cases with this cancellation regression. Both transport source files remain byte-identical to the reviewed build; all 157 transport/core composition cases and formatting checks pass on the refreshed head.