Skip to content

fix(host): wait for the resent line's ok, not the resend-request ack - #16

Merged
CameronBrooks11 merged 1 commit into
mainfrom
fix/resend-request-ack-desync
Jun 26, 2026
Merged

CameronBrooks11 merged 1 commit into
mainfrom
fix/resend-request-ack-desync

Conversation

@CameronBrooks11

Copy link
Copy Markdown
Member

What

Fixes the reliable-mode resend desync surfaced by the dialect/mock investigation
(#5 track). Marlin's flush_and_request_resend emits Resend: N+1 then a trailing
ok (queue.cpp:275-276) that acks the resend request — before the controller
processes the resent line. _await_terminal returned that ok as the command's
terminal ack, so on every checksum/line-number recovery the host returned one
ack early and desynced reliable streaming by one command (the resent line's real
ok was then misread as the next command's ack).

Fix

One flag: awaiting_resend_ack is set when the host resends on Resend:, the next
ok (the request ack) is swallowed, and the host keeps waiting for the resent
line's real ok.

Test

Adds _ResendSim — a stateful FakeTransport responder that validates N +
checksum and emits Marlin's real Error/Resend/ok double-terminal. This is the
one content-dependent path from_trace (indexed by write count) structurally
cannot cover. Two regression tests: single recovery (off-by-one discriminator is
assert t.read_line() is None) and back-to-back recoveries. The existing retransmit
test was corrected to include the trailing ok it previously omitted.

Verified the regression test fails without the host.py change (leaks a stale
ok) and passes with it.

Review

Adversarial review (APPROVE, no blockers/majors) confirmed against vendored source:
STR_RESEND is emitted only by flush_and_request_resend, which always follows
with STR_OK (so the swallow can never eat a real ack); multi-resend stays bounded
by max_resends; no busy/echo interleaves between Resend: and its ok; the
request ack is always bare ok (ADVANCED_OK form only in ok_to_send); no
non-reliable/streaming regression.

just check && just test green (90 tests, 3.11–3.13). Closes #11.

In reliable mode Marlin's flush_and_request_resend emits `Resend: N+1`
then a trailing `ok` (queue.cpp:275-276) that acks the resend *request*,
before the controller processes the resent line. _await_terminal returned
that `ok` as the command's terminal ack, returning one ack early on every
recovery and desyncing reliable streaming by one command.

Swallow the single request-ack `ok` after resending (awaiting_resend_ack)
and keep waiting for the resent line's real `ok`.

Add a stateful _ResendSim FakeTransport responder (validates N + checksum,
emits the real Error/Resend/ok double-terminal) as the regression test —
the one content-dependent path from_trace cannot cover. Update the existing
retransmit test to include the trailing `ok`.

Closes #11.
@CameronBrooks11
CameronBrooks11 merged commit 3515daf into main Jun 26, 2026
5 checks passed
@CameronBrooks11
CameronBrooks11 deleted the fix/resend-request-ack-desync branch June 26, 2026 17:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(host): resend recovery returns the request-ack early; wait for the resent line's real ok

1 participant