tractor/ai/prompt-io/opencode/20260812T150027Z_c2a6ccef_p...

2.3 KiB
Raw Blame History

The user requested the third iterative refinement for Tractor PR 490: closing one broadcast subscriber must not set another receiver owners shared event and create a runnable hot loop, then stop for a complete commit plan.

git diff HEAD~1..HEAD -- tractor/trionics/_broadcast.py

Added receiver-local wait cancellation and source-read ownership scopes. Closing a non-owner waiting behind another source reader cancels only that receivers private wait and maps it to ClosedResourceError; the shared event remains untouched. Closing the active source owner cancels only its private source-read scope, wakes peers after cleanup, and lets one peer take ownership.

Source outcomes are captured inside the owner scope and classified only after checking close/cancel state. A cancellation-shielding source therefore cannot publish a returned value, ordinary error, or EOC after its owner was closed. The private scopes cancel_called bit is asserted to imply receiver closure; outer task cancellation remains trio.Cancelled and is not translated into ClosedResourceError. Owner-key comments document that only the receiver identified by recv_ready[0] may cancel the shared source-read scope. The same explicit-close invariant is enforced symmetrically for private peer-wait scope cancellation.

git diff HEAD~1..HEAD -- tests/test_task_broadcasting.py

Added deterministic bounded regressions for both close positions. The non-owner test places two peers behind an active source read, closes one and proves only that peer exits while the shared event stays unset. The owner test closes a source owner whose receive shields cancellation and parameterizes a returned value, RuntimeError, and EndOfChannel; each discarded outcome hands the next source receive to the waiting root without terminal-state or EOC publication.

Verification output:

.................                                                        [100%]
17 passed in 5.84s

Python compilation and git diff --check passed. Iterative adversarial review caught a waiting non-owner hang, cancellation-shielded source returns, and shielded source exceptions. All were fixed. Final review found no actionable issues.