Skip to content

Device core: reactor-free thread offload, pre-feed, flush barrier, declared-order defaults - #427

Open
mcmartnor wants to merge 5 commits into
inkcut:masterfrom
mcmartnor:fix/device-core
Open

mcmartnor wants to merge 5 commits into
inkcut:masterfrom
mcmartnor:fix/device-core

Conversation

@mcmartnor

@mcmartnor mcmartnor commented Aug 19, 2026 •

Copy link
Copy Markdown

Summary

Core device-layer fixes found while getting a VEVOR KH-870 (CH554 CDC, USB 0483:5750) cutting reliably on macOS — background and full protocol notes in https://github.com/mcmartnor/vevor-cutter-macos and issue #409.

  • defer_to_thread helper (core/utils.py): run blocking work on a daemon thread and fire the Deferred on the GUI thread via enaml's deferred_call. Inkcut installs qreactor but never starts it, so reactor.running is False in the app and twisted's own deferToThread work never executes; this helper is reactor-free. Used by the follow-up USB-transport and PDF-import PRs.
  • Raw fd transport: close the descriptor when connectionLost never fires, so a stale connection can't leak the fd and block reconnects.
  • Job deserialization guards: Job._observe_document and JobInfo._default_request_approval no longer crash when the workbench/plugin doesn't exist yet (state restore, standalone use).
  • Material pre-feed + transport flush barrier + declared-order defaults:
    • Optional pre-feed slowly feeds the material out to the job's length and back before cutting (host-paced; useful for roll media that slips when yanked at full speed). Pause/cancel/connection checks apply between steps.
    • submit() waits for an optional transport flush() (buffered transports) before declaring a job complete, and skips it for cancelled jobs.
    • Transports and protocols offered for a driver now follow the driver's declared order, so transports[0]/protocols[0] (the defaults) are what the driver declares instead of registration order.
    • Explicit cut_velocity takes precedence over the general speed setting, and 0 means "firmware default — send nothing".

Testing

Exercised daily on real hardware (VEVOR KH-870 over the native USB transport from the follow-up PR), verified end-to-end on vinyl. Tests for the pre-feed step builder and the origin handling are included in tests/test_prefeed.py (12 tests, no hardware needed). Upstream defaults are preserved (feed_to_end stays off).

🤖 Generated with Claude Code

Inkcut installs qreactor but never starts it, so the twisted thread
pool never runs and deferToThread'd work never executes. This helper
runs the callable in a daemon thread and fires the returned Deferred
on the main thread via enaml's deferred_call (a thread-safe QEvent
post). Without an enaml Application (cli/tests) it runs inline.
… fires

With a FIFO whose reader died, loseConnection() never triggers
connectionLost: the write fd stayed open forever (holding the FIFO's
writer side hostage) and 'connected' was never reset, so the next
connect() was skipped as already-connected. Close the captured fd
after a grace period (guarded against descriptor reuse) and reset the
flag on disconnect.
_default_request_approval is evaluated by __getstate__ (clone/state
save) and _observe_document can fire during state restore before the
job plugin exists; both now resolve the plugin lazily and fall back to
parser defaults instead of raising AttributeError.
…aults

- Pre-feed: optionally feed the media out to the job's full length and
  back before cutting, paced host-side in small steps (some firmwares
  ignore protocol velocity commands); pause/cancel aware and relative
  to the current origin so feed-past jobs never rewind over prior cuts
- Flush barrier: a transport may buffer writes on a worker thread; wait
  for its flush() (duck-typed) before declaring a job complete or
  disconnecting, so queued data is never dropped mid-job. Cancelled
  jobs skip the flush and drop their queue
- Honor the driver-declared connection and protocol order when building
  a device so transports[0]/protocols[0] (the defaults) match what the
  driver declares instead of plugin registration order
- An explicit cut velocity takes precedence over the general speed
  setting; a job cancelled during the final drain is no longer marked
  complete
Twelve tests over the pre-feed step builder and the device origin
handling: host-paced step construction and its delays, the velocity
commands emitted around a pre-feed, feeding from the device origin
rather than absolute zero, and the cancelled/dead-connection paths.

No hardware is required; the tests drive the protocol through a fake
transport. The Qt application is created from a session fixture rather
than at import, so collecting this module does not stop test_app from
constructing the application inkcut.app.main() needs.
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.

1 participant