Commit Graph
2 Commits
Author SHA1 Message Date
deepseek-v4-pro f25d0a6920 fix: Unit 5 — ledger decrement on all teardown paths + channel-id adoption (C-06, C-08, C-12, C-13, C-18, C-25 #4 #5)
- C-06: add ChannelLifecyclePolicy to ChannelsAdapter; demux loop decrements
  per-identity counts on connection drop (clear_all path). Handler-exit
  teardown: wrap handler tasks in run_open_wrapper to call teardown_channel
  + on_close on natural completion. Fix check_open leak: on_close on
  allocation failure in run_open_wrapper.
- C-08: odd/even ID split (connect=1, accept=2, step=2) via ChannelSide
  enum. Add adopt_channel to ChannelManager for non-allocating side
  routing. Add ChannelClient::open_channel (call open op + adopt).
- C-12: reject channel_id:0 in channel/close handler.
- C-13: drain-before-close — await handler task (5s timeout) instead of
  abort, then decrement policy.
- C-18: re-check max_channels on re-acquire after mux.register in
  open_channel (TOCTOU-safe).

Tests added: policy_decremented_on_connection_drop,
concurrent_opens_respect_max_channels, channel_close_rejects_channel_zero,
channel_adoption_end_to_end_round_trip, odd_even_split_no_collision,
adopt_channel_installs_routing, adopt_channel_duplicate_id_returns_channel_exists,
open_channel_too_many_channels_rejected, connect_side_starts_at_1_accept_side_starts_at_2.

Verification: 450 tests pass (was 441; +9), clippy clean, fmt clean.
2026-08-13 08:14:55 +00:00
deepseek-v4-pro 1f06253959 fix: Unit 4 — backpressure fixes (C-04, C-05, C-07, C-16, C-17, C-25 #2 #3 #6)
C-04 [critical]: route_payload is now async — uses send().await instead
of try_send, so the demux stalls on a full buffer instead of dropping
chunks. Lossless bounded-buffer backpressure per ADR-040 REQ-CH-05.

C-05 [critical]: DEFAULT_BUFFER_CAP changed from 1,048,576 (messages)
to 64 (messages). The old value counted messages, not bytes, giving a
~16 TiB per-channel bound instead of the intended 1 MiB. The new value
is a reasonable message-count bound; the actual memory bound is
enforced by the 16 MiB MAX_CHUNK_LEN per message.

C-07 [critical]: demux loop now skips the payload bytes on
ChunkError::TooLarge before continuing. The parsed length is in the
error variant; the demux reads and discards that many bytes, then
resyncs on the next 8-byte header. Previously it continued without
skipping, causing permanent stream desync.

C-16 [major]: MpscSendStream switched from tokio::sync::mpsc to
futures::channel::mpsc, which exposes poll_ready for proper async
backpressure in poll_write. The ~50 lines of abandoned deliberation
comments are removed. The mux pump now uses futures::StreamExt::next
instead of tokio recv.

C-17 [major]: mux pump writes an EOF chunk when the receiver ends
without a sentinel (handler dropped without shutdown). Previously
the pump exited silently on recv→None, leaving the remote handler
hanging until full transport close.

Tests added:
- C-25 #2: demux_resyncs_after_oversized_chunk
- C-25 #3: backpressure_slow_reader_no_data_loss_other_channel_unaffected
- C-25 #6: mux_pump_writes_eof_on_implicit_close

Verification: 441 tests pass (was 439; +3), clippy clean, fmt clean,
doc warnings unchanged (2 pre-existing, Unit 6 long-tail).
2026-08-13 07:03:49 +00:00