Skip to content

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

Closed

Description

@CameronBrooks11

Bug (found by the dialect/mock investigation)

On a reliable-mode checksum / line-number recovery, Marlin's
flush_and_request_resend() emits Resend: N+1 then a trailing ok
(gcode/queue.cpp:275-276). That ok acks the resend request — it is emitted
before the controller processes the resent line; the resent line's real ok
arrives afterward.

In MarlinHost._await_terminal (marlin_host/host.py:299-306), on needs_resend
the host reframes + resends and continues, then reads that trailing ok and
returns it as the command's terminal ack (host.py:292-293). So in reliable mode
the host returns one ack early on every recovery, desyncing the stream by one
command (the resent line's real ok is then misread as the next command's ack).

Current resend tests only prove the host reacts to a canned Resend:; the
synthetic corpus drops the trailing ok, hiding this. FakeTransport.from_trace
is indexed by write count, not content (transport.py:75), so it structurally
cannot reproduce a real checksum-driven recovery.

Fix

After resending, swallow exactly the one trailing ok that accompanies the
Resend: request, and keep waiting for the resent line's real ok (e.g. a
awaiting_resend_ack flag set when we resend, cleared by the next ok).

Regression test — a stateful resend responder (where a behavioral mock earns its keep)

Add a small stateful responder callable passed to the existing
FakeTransport(responder=...) — no new Transport, no printer emulator. It:

  1. parses N + *checksum from the written line, recomputes XOR via
    framing.checksum, compares N to an expected counter;
  2. on mismatch emits Error:<err><last_N> + Resend: <last_N+1> + ok (the real
    double-terminal, queue.cpp:320-327,275-276); on match emits ok and increments;
  3. handles framed M110 Nn resync.

Acceptance criteria

  • A reliable-mode round-trip with a deliberately corrupted checksum drives the host
    through Error: → Resend: → <resend> → ok, and send() returns only the
    resent line's
    ok — stream stays in sync, no off-by-one.
  • The responder lives in tests / a tiny test helper; banner/M115/M105/M114/busy/halt
    stay on existing traces + synthetic corpus (not re-implemented).
  • just check && just test green.

Evidence

marlin_host/host.py:292-306, marlin_host/transport.py:50-83,91-92,
_reference/Marlin/Marlin/src/gcode/queue.cpp:269-277,320-327.
Design: working/dialect-and-mock-investigation.md (Now).

Part of #5.

Activity

  1. added
    bug
    on Jun 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions