Repository navigation
fix(bridge): enforce one receive deadline per frame - #121
Conversation
|
I'll take a look shortly. I have no way to test Windows end-to-end, but I think we can do better than what's there now. |
The handler waited a fixed 30 s for each client's request frame, so the single-deadline receive behavior (PR #121 / issue #120) could not be exercised end to end through the real server in any reasonable time. Add FREECAD_MCP_RECV_TIMEOUT: seconds to wait for one complete request frame per connection (header and body share one deadline). Unset, empty or whitespace-only keeps the 30 s default. Otherwise it must be a plain ASCII decimal greater than 0 and at most 3600. Zero (which socket code treats as non-blocking, not "no timeout"), negatives, NaN/inf, exponents, underscores and non-ASCII digits are rejected. A bad value never silently becomes the default: the module still imports (so a typo cannot take the whole addon down), and start_server() reports the error on every platform and refuses to start. The value is passed to the handler's only receive_message() call site. Documented in AGENT-INSTALL.md. Tests pin both sides of the 0 and 3600 boundaries, the ambiguous number forms, import safety, that the default matches receive_message()'s own default, that the configured value actually reaches receive_message, and that a bad value refuses to start with Windows both on and off. Verified against a real FreeCAD handler: with PR #121's change applied and the timeout at 1.0, a request trickled over ~10 s is dropped at ~1.0 s and the next request is served; without it the same request completes. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ws workflow The handler has a distinct Windows code path (loopback TCP listener, per-launch auth token with an icacls ACL, SO_EXCLUSIVEADDRUSE, pid liveness, instance stop) that had never run on a real Windows host in CI. Add: - tests/windows/: a harness that launches the real headless_server.py under a real FreeCADCmd, fully isolated, and drives it over TCP with the project's own framing. Each server gets its OWN temp tree (and so its own token file); stdout/stderr go to files, not pipes (a Windows pipe holds 4096 bytes); an autouse session gate aborts the run before any test if FreeCAD ignored the profile redirect (it would otherwise use the real profile, or a cwd-relative dir inside the checkout). - Tests: token file, ACL signature (real Windows), a 9-way auth matrix incl. non-ASCII and lone-surrogate tokens, sync/async/poll round trip, exclusive bind (real Windows), token rotation, pid liveness boundaries (real Windows; W-7 and W-9b as strict xfails), framing at MAX-1/MAX/MAX+1 plus zero-length, truncated and short frames, the FREECAD_MCP_RECV_TIMEOUT receive deadline, and a stop/orphan check. - Fake mode (FREECAD_MCP_WINDOWS_TESTS_FAKE=1): tests/windows/fakewin_headless.py forces the handler's Windows branch on Linux/macOS so the harness and the platform-independent tests can be developed locally. It proves logic only; Windows-only tests are skipped and fake results never count as Windows coverage. - .github/workflows/windows-tests.yml: advisory (not in all-tests-pass). tier1 runs `-m windows_safe`; tier2 downloads the pinned FreeCAD, verifies the release-API digest (weekly builds publish no -SHA256.txt), and always runs bin\FreeCADCmd.exe, never the 1.1.x root-level launcher shim. assert_tests_ran.py fails an all-skipped run. Known-failing-by-design: test_slow_trickle_is_dropped_at_the_single_deadline is a strict xfail until PR #121 lands (verified: applying #121 flips it to XPASS(strict)). Mutation check: replacing the token check with `return True` fails all 9 bad-token tests. Local fake-mode run: 23 passed, 13 Windows-only skipped, 1 xfailed. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Thanks for this, and for the report in #120. The single-deadline approach looks right to me. Could you retarget the PR to Two things have changed on
Happy to help if anything is unclear once you've retargeted. |
|
Thanks for the detailed review, and for trial-merging this onto dev and adding the configurable receive timeout and the Windows headless suite. That makes the slow-trickle case much easier to exercise end to end. I've noted the three requested changes: retarget the PR to In a local check, the commit applies cleanly onto current dev ( |
Replace the elapsed-time bound in test_receive_timeout_bounds_entire_frame with an assertion that the receive gives up before the peer has delivered the full frame, and drive the shared header/body deadline test with a fake monotonic clock. Remove the strict xfail on the Windows slow-trickle test, which this change makes pass.
2b952f5 to
09e1fb0
Compare
…kle oracle Add test_receive_deadline_boundary (fake clock; just-below/exactly-at/ just-above the deadline, both framing implementations). Exactly-at must give up and must never hand the socket a non-positive timeout. Mutating 'remaining_time <= 0' to '< 0' in either file now fails it. test_receive_timeout_bounds_entire_frame now also asserts the receiver held on for ~the whole budget (lower bound only, so it cannot flake under load), so a None caused by a disconnect/decode error no longer passes vacuously. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Thanks for the quick turnaround, the single-deadline fix and the follow-up look good. I reviewed the diff and pushed one small test-only commit to your branch (4768032, `maintainerCanModify` was on). It does not touch the fix itself. What I added
What I checked
Optional, not blocking: the `receive_message` docstrings in both files still describe `timeout` as a socket timeout. It now bounds the whole frame from the call onward, so it may be worth a line saying so. Once the Windows job is green I'm happy to take it out of draft and merge. |
The handler waited a fixed 30 s for each client's request frame, so the single-deadline receive behavior (PR #121 / issue #120) could not be exercised end to end through the real server in any reasonable time. Add FREECAD_MCP_RECV_TIMEOUT: seconds to wait for one complete request frame per connection (header and body share one deadline). Unset, empty or whitespace-only keeps the 30 s default. Otherwise it must be a plain ASCII decimal greater than 0 and at most 3600. Zero (which socket code treats as non-blocking, not "no timeout"), negatives, NaN/inf, exponents, underscores and non-ASCII digits are rejected. A bad value never silently becomes the default: the module still imports (so a typo cannot take the whole addon down), and start_server() reports the error on every platform and refuses to start. The value is passed to the handler's only receive_message() call site. Documented in AGENT-INSTALL.md. Tests pin both sides of the 0 and 3600 boundaries, the ambiguous number forms, import safety, that the default matches receive_message()'s own default, that the configured value actually reaches receive_message, and that a bad value refuses to start with Windows both on and off. Verified against a real FreeCAD handler: with PR #121's change applied and the timeout at 1.0, a request trickled over ~10 s is dropped at ~1.0 s and the next request is served; without it the same request completes. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ws workflow The handler has a distinct Windows code path (loopback TCP listener, per-launch auth token with an icacls ACL, SO_EXCLUSIVEADDRUSE, pid liveness, instance stop) that had never run on a real Windows host in CI. Add: - tests/windows/: a harness that launches the real headless_server.py under a real FreeCADCmd, fully isolated, and drives it over TCP with the project's own framing. Each server gets its OWN temp tree (and so its own token file); stdout/stderr go to files, not pipes (a Windows pipe holds 4096 bytes); an autouse session gate aborts the run before any test if FreeCAD ignored the profile redirect (it would otherwise use the real profile, or a cwd-relative dir inside the checkout). - Tests: token file, ACL signature (real Windows), a 9-way auth matrix incl. non-ASCII and lone-surrogate tokens, sync/async/poll round trip, exclusive bind (real Windows), token rotation, pid liveness boundaries (real Windows; W-7 and W-9b as strict xfails), framing at MAX-1/MAX/MAX+1 plus zero-length, truncated and short frames, the FREECAD_MCP_RECV_TIMEOUT receive deadline, and a stop/orphan check. - Fake mode (FREECAD_MCP_WINDOWS_TESTS_FAKE=1): tests/windows/fakewin_headless.py forces the handler's Windows branch on Linux/macOS so the harness and the platform-independent tests can be developed locally. It proves logic only; Windows-only tests are skipped and fake results never count as Windows coverage. - .github/workflows/windows-tests.yml: advisory (not in all-tests-pass). tier1 runs `-m windows_safe`; tier2 downloads the pinned FreeCAD, verifies the release-API digest (weekly builds publish no -SHA256.txt), and always runs bin\FreeCADCmd.exe, never the 1.1.x root-level launcher shim. assert_tests_ran.py fails an all-skipped run. Known-failing-by-design: test_slow_trickle_is_dropped_at_the_single_deadline is a strict xfail until PR #121 lands (verified: applying #121 flips it to XPASS(strict)). Mutation check: replacing the token check with `return True` fails all 9 bad-token tests. Local fake-mode run: 23 passed, 13 Windows-only skipped, 1 xfailed. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The handler waited a fixed 30 s for each client's request frame, so the single-deadline receive behavior (PR #121 / issue #120) could not be exercised end to end through the real server in any reasonable time. Add FREECAD_MCP_RECV_TIMEOUT: seconds to wait for one complete request frame per connection (header and body share one deadline). Unset, empty or whitespace-only keeps the 30 s default. Otherwise it must be a plain ASCII decimal greater than 0 and at most 3600. Zero (which socket code treats as non-blocking, not "no timeout"), negatives, NaN/inf, exponents, underscores and non-ASCII digits are rejected. A bad value never silently becomes the default: the module still imports (so a typo cannot take the whole addon down), and start_server() reports the error on every platform and refuses to start. The value is passed to the handler's only receive_message() call site. Documented in AGENT-INSTALL.md. Tests pin both sides of the 0 and 3600 boundaries, the ambiguous number forms, import safety, that the default matches receive_message()'s own default, that the configured value actually reaches receive_message, and that a bad value refuses to start with Windows both on and off. Verified against a real FreeCAD handler: with PR #121's change applied and the timeout at 1.0, a request trickled over ~10 s is dropped at ~1.0 s and the next request is served; without it the same request completes. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ws workflow The handler has a distinct Windows code path (loopback TCP listener, per-launch auth token with an icacls ACL, SO_EXCLUSIVEADDRUSE, pid liveness, instance stop) that had never run on a real Windows host in CI. Add: - tests/windows/: a harness that launches the real headless_server.py under a real FreeCADCmd, fully isolated, and drives it over TCP with the project's own framing. Each server gets its OWN temp tree (and so its own token file); stdout/stderr go to files, not pipes (a Windows pipe holds 4096 bytes); an autouse session gate aborts the run before any test if FreeCAD ignored the profile redirect (it would otherwise use the real profile, or a cwd-relative dir inside the checkout). - Tests: token file, ACL signature (real Windows), a 9-way auth matrix incl. non-ASCII and lone-surrogate tokens, sync/async/poll round trip, exclusive bind (real Windows), token rotation, pid liveness boundaries (real Windows; W-7 and W-9b as strict xfails), framing at MAX-1/MAX/MAX+1 plus zero-length, truncated and short frames, the FREECAD_MCP_RECV_TIMEOUT receive deadline, and a stop/orphan check. - Fake mode (FREECAD_MCP_WINDOWS_TESTS_FAKE=1): tests/windows/fakewin_headless.py forces the handler's Windows branch on Linux/macOS so the harness and the platform-independent tests can be developed locally. It proves logic only; Windows-only tests are skipped and fake results never count as Windows coverage. - .github/workflows/windows-tests.yml: advisory (not in all-tests-pass). tier1 runs `-m windows_safe`; tier2 downloads the pinned FreeCAD, verifies the release-API digest (weekly builds publish no -SHA256.txt), and always runs bin\FreeCADCmd.exe, never the 1.1.x root-level launcher shim. assert_tests_ran.py fails an all-skipped run. Known-failing-by-design: test_slow_trickle_is_dropped_at_the_single_deadline is a strict xfail until PR #121 lands (verified: applying #121 flips it to XPASS(strict)). Mutation check: replacing the token check with `return True` fails all 9 bad-token tests. Local fake-mode run: 23 passed, 13 Windows-only skipped, 1 xfailed. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
What does this PR do?
Fixes #120. A peer that sends one byte every 80 ms currently completes a message after about 640 ms even with
receive_message(timeout=0.2): eachrecv()gets a fresh timeout. This affects both the MCP bridge's response wait and FreeCAD's per-connection request wait (now configurable throughFREECAD_MCP_RECV_TIMEOUT).Use one monotonic deadline for the prefix and body, passing only the remaining budget to each exact read. Keep the wire format, size limits, failure return value, caller-timeout restoration, and
None/zero blocking modes. This is independent of the dependency migration proposed in #118.Follow-up from review: rebased onto
dev; the deadline unit tests no longer assert elapsed wall-clock time (the slow-trickle test checks that the receive gives up before the peer has delivered the full frame, and the shared header/body deadline test uses a fake monotonic clock); the strict xfail ontest_slow_trickle_is_dropped_at_the_single_deadlineintests/windows/test_windows_headless.pyis removed.Validation (Windows, CPython 3.14,
uv sync --frozen --group dev, on dev51e6502)-k 'timeout_bounds_entire_frame or fragmented_frame_finishes or share_receive_deadline or preserves_blocking_modes'): 12 passed with this change; on unpatched dev the same tests give 6 failed, 6 passed (the four slow header/body cases and the two shared-deadline cases fail).python -m pytest tests/unit --ignore=tests/unit/test_headless_server.py -q: 157 failed, 2709 passed, 39 errors, 10 skipped with this change; unpatched dev in the same environment gives 157 failed, 2697 passed, 39 errors, 10 skipped. The failing/error node-ID sets are identical, so this adds no failures; the Windows run is not green and no full-suite pass is claimed.test_headless_server.pyis excluded because one of its tests sends SIGTERM to the pytest process on Windows (exit code 15).ruff checkon the changed test files andgit diff --checkpass.tests/windows(no FreeCAD installed on this machine), and the Linux/macOS matrices. The FreeCAD import stubs used by the unit tests do not stand in for FreeCAD-native validation.Checklist
devbranch (notmain, which is release-only)python3 -m pytest tests/unit/(see the Windows baseline note above)tests/windowsslow-trickle test, not run locally)fix:,feat:,docs:, etc.)Platform tested on
Windows only.