Skip to content

Fix filament consumption across retraction and E-only moves - #501

Open
remcoder wants to merge 2 commits into
developfrom
codex/499-filament-consumption
Open

Fix filament consumption across retraction and E-only moves#501
remcoder wants to merge 2 commits into
developfrom
codex/499-filament-consumption

Conversation

@remcoder

Copy link
Copy Markdown
Member

Problem

Fixes #499. M83; G1 E10 reported zero filament, while retracting and restoring filament during movement counted that filament twice.

Cause and fix

Linear and arc handlers counted only positive E deltas attached to XYZ moves. Both now send every signed delta to shared statistics accounting, including E-only moves. Outstanding retraction is tracked per stats object without expanding its public shape.

For a delta d and outstanding retraction r, newly consumed filament is max(0, d - r) and the remaining retraction is max(0, r - d). Negative deltas therefore increase retraction without subtracting prior consumption; positive deltas repay it before adding consumption. G92 only changes coordinates and leaves this accounting intact.

Behavior changes

extrusionDistance now means newly advanced filament, including stationary purges/primes and excluding recovery. The original signed delta still classifies paths, so recovery moves retain their rendering behavior. Existing command counters are unchanged.

Checks

  • 995 tests pass with 100% statement, branch, function and line coverage.
  • Typecheck, lint and production build pass.
  • Pipeline tests cover both issue examples, M82/M83, equal/partial/excess recovery, G92, linear and arc retractions/recovery, independent jobs, and every command chunk size in a representative sequence.
  • Independent of the inch-unit fix in Fix inch-unit conversion for coordinates and extrusion #500; both PRs target develop.

Assisted by OpenAI Codex (GPT-6).

@remcoder remcoder added bug Something isn't working 3.0 Targeted for the 3.0 release interpreter Related to the G-code interpreter / state machine labels Sep 10, 2026
@github-actions

github-actions Bot commented Sep 10, 2026

Copy link
Copy Markdown

Visit the preview URL for this PR (updated for commit c2d8b03):

https://gcode-preview--pr501-codex-499-filament-c-1w4gfvnw.web.app

(expires Sat, 10 Oct 2026 21:07:00 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: 59bd114ae4847b32c2bba0b68620b9069a3e3531

Comment thread src/interpreter/commands/arc-move.ts Outdated
Comment thread src/interpreter/commands/linear-move.ts Outdated
Comment thread src/__tests__/filament-consumption.ts Outdated
- recordExtrusion moves from a free function + WeakMap onto JobStats as a
  method with a private #outstandingRetraction field
- linear-move splits applyExtrusion and recordExtrusion into two steps
- filament-consumption.ts is split into src/__tests__/job-stats.ts (unit)
  and describe blocks in the linear-move/arc-move command tests
- CONTRIBUTING spells out one-test-file-per-module so feature-named test
  files stop appearing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3.0 Targeted for the 3.0 release bug Something isn't working interpreter Related to the G-code interpreter / state machine

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix extrusionDistance: include E-only extrusion and exclude retraction recovery

2 participants