Commit Graph

3 Commits (piker_pin)

Author SHA1 Message Date
Gud Boi b3e07bd569 Fix swallowed `TransportClosed` on ctx scope exit
EOF-driven cancellation can be absorbed by the ctx nursery before
teardown sees a disconnected channel and skips its recorded error.
Route an unfinished transport fault through `wait_for_result()` so
it raises the original error without waiting on broken IPC or
manufacturing a cancellation requester.

Share `ContextStatus._outcome_is_unfinished()` between EOF
notification and ctx teardown. Both buffered `Return` msgs and
decoded falsey results remain completed outcomes; notification
requires no existing error while teardown raises the recorded one.

Deats,
- Reconcile the close example and advanced-fault matrix with prompt
  fault propagation, preserving break order and pre-`Stop` cases.
- Check exception leaves, socket causes, cancellation provenance,
  and post-close send/receive error precedence and identity. Keep
  synthetic Ctrl-C for the healthy no-break cases.
- Cover buffered/consumed `None`, `False`, `0`, and empty-string
  results across EOF, including final value and type preservation.
- Add `assert_child_reaped()` for retained process handles. Check
  both backend completion and PID disappearance without cleanup.

(this patch was generated in some part by `opencode` using
`gpt-6-astra` (`openai`))
2026-10-30 13:13:37 -04:00
Gud Boi e100d06732 Move ctx state into `ContextStatus`
Make `Context._status` the single store for outcome, cancellation
and handshake state. Migrate internal callers and existing test
assertions directly, without descriptors or duplicate fields.
Keep policy and live resources on `Context`.

Deats,
- Add shallow-frozen fault metadata in `ContextCancelReason`,
  delivered via Trio's public cancellation reason API. Preserve
  the first cancelling fault when the recorded error changes.
- Distinguish local transport/protocol faults from boxed remote
  failures; type-check self-cancel acknowledgements before reading
  remote-error metadata.
- Move `._final_result_is_set()` onto `ContextStatus` and migrate
  its five production callers plus the existing stream assertion.
- Retain the human's `._scope_tn` rename and add status-only reprs.

Keep public APIs, including the deprecated `.result()` wrapper.
New status regression tests follow in their own commit.

Prompt-IO: ai/prompt-io/opencode/20260919_context_fault_status.md

(this patch was generated in some part by `opencode`
using `gpt-6-astra` (`openai`))
2026-10-30 13:13:37 -04:00
Gud Boi db8dc0e27c Notify unfinished `Context` owners on IPC EOF
Save the proposed transport-fault handling for discovered peers.
`process_messages()` reports EOF then exits, leaving parent ctx
owners blocked until another send detects the loss. Wake unfinished
owners on that exact channel with `TransportClosed`, including
owners paused at application checkpoints unrelated to IPC.

This scope-cancellation policy remains provisional pending the
transport contract discussion. Saving the impl and regression cases
on this branch does not settle that policy or imply acceptance.

Deats,
- Match `Context.chan` by identity and notify all unfinished parent
  ctxs on the failed connection, leaving other channels alone.
- Preserve received outcomes and record buffered `Return` receipt
  using the `Unresolved` sentinel before EOF can replace success.
- Keep local transport loss distinct from a remote cancellation
  request: do not invent `Context._canceller` provenance.
- Preserve the original disconnect cause through owner cancellation
  and unwinding in `Context._maybe_raise_remote_err()`.

Also,
- Exercise two owners sharing a discovered sibling channel, blocked
  in stream receive or an application `Event`, plus a healthy peer
  that continues to echo after fault handling.
- Synchronize EOF injection after startup and task quiescence.
  Cover drained and buffered final results without timing sleeps.
- Regress cause preservation directly with a connection-reset cause
  and a distinct owner-unwinding exception.
- Carry the staged structured session provenance unchanged. Its
  broader cancellation observations do not expand this boundary;
  the root-owned `cancel_soon()` fix remains outside this save.

Exact-tree project tests remain pending in the commit plan. Earlier
session results in the provenance log are not passes for this tree.

Prompt-IO: ai/prompt-io/opencode/20260916_ib_disconnect_cleanup.md

(this patch was generated in some part by `opencode`
using `gpt-6-astra` (`openai`))
2026-10-30 13:13:37 -04:00