Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.
Bugfix run: purchase receipt void leaves cost layers; revenue recognition cron runs for companies with accounting off
- Date: 2026-10-08
- Mode: fully-autonomous
- Request: "great. make sure to fix the new bugs we found" — the 2 bugs recorded in
.ai/specs/implemented/2026-10-08-accounting-cutover.md(Risks; section 1):- A purchase receipt void reverses
itemLedgerand journal lines but never updatescostLedger. The voided layer keeps itsremainingQuantity. - The
revenue-recognition-proposalcron proposes Draft runs for companies with accounting off.
- A purchase receipt void reverses
- Phase plan: root-cause [run] · instrument [resolved after root-cause] · fix [run] · test [skip — pure logic, the regression tests prove it] · commit [skip — no explicit ask]
Decisions
- instrument: skip — both causes are HIGH confidence and visible in code — 2026-10-08
- regression test (bug 1): a pure planner
planReceiptVoidCostLedgerwith a unit test. The live-database fixtures skip without a localSUPABASE_DB_URL, and none is running in this worktree — 2026-10-08 - consumed receipt layers: refuse the void, as the sales-return void already does (now
post-receipt/index.ts:436) and as Business Central's Undo Receipt does — 2026-10-08
Phase log
root-cause: HIGH ×2. The
post-receiptline numbers in this entry are from before the fix. Bug 1: the PO void path (post-receipt/index.ts:581-1057) never touchescostLedger; posting writesPurchase Receiptlayers bydocumentId(:1738-1777) and negative lines relieve layers FIFO (:2114-2151). Bug 2: the cron enumerates everycompany(revenue-recognition-proposal.ts:42); nothing readsaccountingEnabled.fix bug 1: new pure planner
packages/server-functions/src/post-receipt/void-cost-ledger.ts. The PO void transaction inpost-receipt/index.tsreads the receipt'sPurchase ReceiptlayersFOR UPDATE. It refuses when a later movement used part of one layer. Then it closes the layers and inserts a restoring layer for each negative row. Testvoid-cost-ledger.test.ts: 3 of 4 failed against the stub that copied today's behavior, 4 of 4 pass after.fix bug 2:
companiesToProposeinrevenue-recognition-proposal.tskeeps only companies whosecompanySettings.accountingEnabledis true. The first step reads those ids withfetchAllFromTable. Test: 2 new cases failed against the pass-through stub, 6 of 6 pass after.packages/jobs/AGENTS.mdrow updated. The cron no longer readsaccountingEnabled(see Later changes).gates: biome PASS · typecheck(@carbon/server-functions, @carbon/jobs) PASS · test(@carbon/jobs) 935 passed, 31 skipped · test(@carbon/server-functions) 308 passed, 150 skipped with
SUPABASE_DB_URLunset. With the worktree.envvalue, the same 150 database tests fail onECONNREFUSED 127.0.0.1:54322: no local database runs here. This change does not cause those failures.test (browser): skipped — pure logic, the regression tests prove it.
Later changes
- 2026-10-08 — bug 2: commit 3b9d4372e9 replaced the
accountingEnabledfilter with a filter oncompanySettings.accountingCutoverDate. The cutover spec retires the flag. - 2026-10-09 — bug 2: commit 188a710e24 makes
companiesToProposeone Kysely query (packages/jobs/src/inngest/functions/scheduled/revenue-recognition-proposal.ts). The query joinscompanytocompanySettingsand keeps the rows whereaccountingCutoverDateis not null. The 2fetchAllFromTablereads are gone. The test compiles the query and checks the join and the filter (revenue-recognition-proposal.test.ts). - 2026-10-09 — bug 1, current locations: the planner
planReceiptVoidCostLedgeris atpackages/server-functions/src/post-receipt/void-cost-ledger.ts:39. The PO void transaction inpackages/server-functions/src/post-receipt/index.tsimports it at:63and calls it at:941. The sales return void refuses a consumed layer at:436.
Outcome
- READY. Not committed: no explicit ask.