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.
Delegated coding + GR/IR verification (spec slice 5)
Spec: .ai/specs/implemented/2026-09-23-spend-management-push-only-mode.md §4, §6
Research: .ai/research/spend-management-one-way-push.md
Depends on: slices 2, 3, 4
GATED. Task 1 is a live sandbox verification, not code. Tasks 2–9 must not be started until Task 1 reports, because two of its five questions decide whether the coding half of this slice can exist at all. If Task 1 answers "Ramp silently drops an unrecognised option" or "a non-provider app cannot read
/accounting/field-options", STOP and re-plan — do not build a best-effort version.
What this slice adds
Everything slice 4 deliberately left out: bills coded with the accounting provider's
identifiers, vendors linked through accounting_vendor_remote_id, remote_id dropped
in favour of Ramp's own dedupe, and GR/IR verified against BILL_SYNCED.
Progress
- Task 1: GATE — run the five sandbox verifications
- Task 2: Build the external-identity resolver
- Task 3: Declare
externalAddressingper accounting provider - Task 4: Read and persist the active provider's coding surface
- Task 5: Code draft-bill lines with delegated identifiers
- Task 6: Link the spend vendor to the accounting vendor
- Task 7: Drop
remote_id; dedupe on vendor + invoice number - Task 8: Verify GR/IR against
BILL_SYNCED - Task 9: Verification
Dependencies
- Everything needs Task 1.
- Task 5 needs Tasks 2, 3, 4. Task 6 needs Task 2.
- Tasks 5, 6, 7 and 8 are independent of each other once their prerequisites land.
Task 1: GATE — run the five sandbox verifications
Depends on: none Files:
- Create:
.ai/runs/{today}-ramp-delegated-coding-gates.md
Setup prerequisite: a Ramp demo business where a non-Carbon provider holds the active accounting connection. If Rillet's sandbox cannot be connected to Ramp demo, a manual CSV connection is an acceptable stand-in for gates 1–3 but not for gate 4, which needs a real accounting vendor created by another app. If neither can be arranged, STOP and report — the whole slice is unverifiable and needs a different strategy (ship behind a flag with instrumentation, or accept uncoded permanently).
Steps: answer each, recording the exact request, response status and body.
- Does Ramp validate
field_external_id/field_option_external_idon a bill draft against the ACTIVE connection's options? Send a draft bill with a valid option id, then one with a fabricated id. Record whether the second is rejected, silently dropped, or accepted. A silent drop produces uncoded bills in the GL with no error anywhere — if that is the behaviour, Task 5 must validate every option against the live read before sending, and never send an unknown one. - Can a non-provider app read the active provider's coding surface?
GET /accounting/fields,/accounting/field-options,/accounting/accountswith onlyaccounting:read. Record the status and whether the returnedexternal_ids are ERP-sourced. Task 4 collapses without this. - Is
sync_status/BILL_SYNCEDreadable withbills:readby a non-provider app? Task 8's trigger depends on it. - Can a caller with only
vendors:writesetaccounting_vendor_remote_idon a spend vendor, pointing at an accounting vendor another app created? And what happens when that accounting vendor is already linked to a different Ramp vendor — Ramp documents the constraint "must not already be linked to another Ramp vendor" but not the failure mode. Task 6 needs both answers. - Does omitting
remote_idon a draft bill change anything downstream? Carbon's current behaviour is live-verified only for the Carbon-as-provider case. Task 7.
Verify:
cat .ai/runs/*-ramp-delegated-coding-gates.md
# Expected: all five questions answered with request/response evidence, each marked
# CONFIRMED or BLOCKED. No inference, no "probably".
Out of scope: writing any application code.
Task 2: Build the external-identity resolver
Depends on: Task 1 (gate 2 CONFIRMED) Files:
- Create:
packages/ee/src/sync/identity.ts - Create:
packages/ee/src/sync/identity.test.ts - Copy from (precedent):
packages/ee/src/accounting/core/account-mapping.ts:291-319(loadAccountCodesById— the existing "mapping row → the identifier this provider addresses by" loader this generalizes)
Steps:
- Implement the interface from spec §4:
export interface ExternalIdentityResolver { resolve(kind: ExternalIdentityKind, carbonId: string): Promise<string | null>; resolveMany(kind: ExternalIdentityKind, carbonIds: string[]): Promise<Map<string, string>>; } CarbonIdentityResolverreturns the Carbon id unchanged.DelegatedIdentityResolver(delegateIntegrationId)readsexternalIntegrationMappingunder the delegate'sintegration, returningmetadata.externalCodeor theexternalIdcolumn according to that provider's declaredexternalAddressingfor the kind (Task 3).- Selection is
topology.identityScope(targetIntegrationId)— coding authority, not ledger ownership. They coincide for Ramp but answer different questions, and a partner role that pushes coding while the GL posts AP externally breaks under the conflated rule. Add a test pinning that a fixture withownsLedgerFamilies: ["ap"]andownsRemoteCodingSurface: trueresolves toCarbonIdentityResolver. - Collapse the three sibling loaders —
loadAccountCodesById,loadRilletAccountCodesById,loadQboAccountRefsById— ontoresolveMany. They differ only in which field of the same row they read.
Verify:
pnpm --filter @carbon/ee test -- identity
# Expected: all pass, including the independence test in step 4
pnpm --filter @carbon/ee test -- rillet quickbooks xero
# Expected: unchanged — the collapsed loaders return identical maps
pnpm exec turbo run typecheck --filter=@carbon/ee
# Expected: exit 0
Out of scope: using it in the Ramp push.
Task 3: Declare externalAddressing per accounting provider
Depends on: Task 1 Files:
- Modify:
packages/ee/src/accounting/providers/rillet/provider.ts—{ account: "code", vendor: "id" } - Modify:
packages/ee/src/accounting/providers/xero/provider.ts—{ account: "code", vendor: "id" } - Modify:
packages/ee/src/accounting/providers/quickbooks-online/provider.ts—{ account: "id", vendor: "id" }
Steps:
- Add the declarations. These are read only by the resolver; they change nothing else.
- Xero declares no
capabilitiesobject today — slice 2 Task 4 added one while keeping every currently-absent field absent. AddexternalAddressingto it without adding any other field. - The documented default in
resolveCapabilitiesstays{ account: "code" }, which is correct for a provider that declares nothing.
Verify:
pnpm --filter @carbon/ee test -- capabilities
# Expected: a test asserting each provider's declared addressing matches the field its
# existing bill mapper actually sends (rillet account_code, xero AccountCode,
# qbo AccountRef.value)
pnpm exec turbo run typecheck --filter=@carbon/ee
# Expected: exit 0
Out of scope: behaviour change.
Task 4: Read and persist the active provider's coding surface
Depends on: Task 1 (gate 2 CONFIRMED) Files:
- Create:
packages/ee/src/ramp/lib/coding-surface.ts - Modify:
packages/ee/src/ramp/lib/client.ts— add the threeaccounting:readGETs if absent - Copy from (precedent):
packages/ee/src/ramp/lib/cost-centers.ts(the existingGET /accounting/fields+field-optionsdiff-and-persist shape)
Steps:
loadDelegatedCodingSurface(ctx)drainsGET /accounting/fields,/accounting/field-optionsand/accounting/accounts, returning the active provider's options with theirexternal_idandprovider_name.- Persist as
externalIntegrationMappingrows withentityType: "accountingFieldOption"under the spend integration, recording the Carbon account/cost-center/project id against the option external id. - Re-read on every sync run, not only at install. Customers keep editing the chart of accounts, and Codat is the only unified-API vendor that names this and says to re-validate continuously. Surface a drift state rather than pushing a stale option.
- Resolution is two hops and both are needed: translate (Carbon id → the delegate's identifier, from the accounting provider's mapping rows — Task 2) then validate (that identifier exists as an option here — this task). A miss on hop 1 is an unmapped account; a miss on hop 2 is drift. Both degrade the line to uncoded, with different reason codes, because the fixes differ.
Verify:
pnpm --filter @carbon/ee test -- coding-surface
# Expected: tests for a clean read, a deleted option producing drift, and a re-run
# updating a changed external_id without duplicating mapping rows
pnpm exec turbo run typecheck --filter=@carbon/ee
# Expected: exit 0
Out of scope: applying it to a bill.
Task 5: Code draft-bill lines with delegated identifiers
Depends on: Tasks 2, 3, 4 Files:
- Modify:
packages/ee/src/ramp/lib/coding.ts—buildLineCodingSelectionstakes resolved option ids instead of pushed-id sets - Modify:
packages/ee/src/ramp/entities/bill.ts
Steps:
- Change the signature from
(line, pushed: {pushedAccountIds, …})to(line, resolved: {accountOptionId, costCenterOptionId, projectOptionId}). In provider mode the resolver returns the Carbon ids, so the emitted payload is byte-identical to today — pin that with a test. - Emit a selection only when the id passed both hops. An unresolved account degrades
the line to uncoded with
CODING_OPTION_MISSING(drift) orACCOUNT_NOT_MAPPED(no translation), recorded on the Sync Activity ledger and cleared on resolution. - Never park a bill on an account. An uncoded bill still carries vendor, amount
and invoice number and a human reviews it in Ramp. The Warning copy must say the
degrade is permanent for that bill: coding is a creation-time affordance —
POST /accounting/codingsrequiresaccounting:writeand itsobject_typeenum contains onlyTRANSACTION, so it cannot code a bill at all. - If gate 1 reported a silent drop, additionally refuse to send any option id absent from the live read.
Verify:
pnpm --filter @carbon/ee test -- coding
# Expected: the existing round-trip test still passes in provider mode byte-for-byte;
# new tests cover delegated ids, drift degrade, and unmapped degrade
pnpm exec turbo run typecheck --filter=@carbon/ee
# Expected: exit 0
Out of scope: vendors.
Task 6: Link the spend vendor to the accounting vendor
Depends on: Tasks 1 (gate 4), 2 Files:
- Modify:
packages/ee/src/ramp/lib/spend.ts— addlinkAccountingVendor; leaveresolveOrCreateRampSpendVendor'sexternal_vendor_idbehaviour unchanged - Modify:
packages/ee/src/ramp/entities/bill.tsandpurchase-order.ts— these are the WIRE adapters since slice 3; anything that is a statement about Carbon's data rather than Ramp's payload belongs inpackages/ee/src/spend/*-source.tsinstead
Steps:
external_vendor_idstays as Carbon's own handle. Ramp documents it as "independent of accounting system remote IDs", and Carbon uses it correctly today as its spend-vendor match key. Do not repurpose it.- Add
linkAccountingVendor(client, rampVendorId, accountingVendorRemoteId)callingPATCH /vendors/{id}withaccounting_vendor_remote_id. That is the field that lands a bill on the right GL vendor. - The accounting vendor's remote id comes from the resolver
(
resolve("vendor", supplierId)). When it is absent, defer per slice 4 Task 8 — bills wait, POs push unlinked. - Handle the documented uniqueness constraint per gate 4's answer: if the accounting vendor is already linked to a different Ramp vendor, adopt that link rather than failing, and write the mapping to it.
- Ramp's guide calls confusing Merchant / Vendor / Accounting Vendor "the most common integration error" — put a comment naming all three and their id spaces at the top of the new function.
Verify:
pnpm --filter @carbon/ee test -- spend
# Expected: tests for link-on-first-push, adopt-existing-link, and defer-when-unmapped
pnpm exec turbo run typecheck --filter=@carbon/ee
# Expected: exit 0
Out of scope: remote_id.
Task 7: Drop remote_id; dedupe on vendor + invoice number
Depends on: Task 1 (gate 5) Files:
- Modify:
packages/ee/src/ramp/entities/bill.ts— omitremote_idin push-only - Modify:
packages/jobs/src/inngest/functions/integrations/ramp-sync-bill.ts— the inbound dedupe
Steps:
- In push-only mode, omit
remote_id— Ramp documents it as the id identifying the bill on the accounting-connection owner's side, which is no longer Carbon. Keep sending it in provider mode. - Do not send
enable_accounting_sync: false; its default oftrueis what makes the draft flow onward, and Ramp 422s the combination withremote_id. - Replace the dedupe with Ramp's own documented key — vendor +
invoice_number— plus the Carbon-side mapping row on the returned Ramp bill id. Ramp widenedinvoice_numberto 84 characters specifically to accommodate accounting-provider numbers, which is why following their key is the least surprising choice. - The inbound
ramp-billsstep currently dedupes onremote_id; it must fall back to the mapping row and the vendor + invoice-number match in push-only mode.
Verify:
pnpm --filter @carbon/ee test -- bill
pnpm --filter @carbon/jobs test -- ramp-sync-bill
# Expected: provider mode still sends remote_id and dedupes on it; push-only sends
# none and dedupes on vendor + invoice_number
pnpm exec turbo run typecheck --filter=@carbon/ee --filter=@carbon/jobs
# Expected: exit 0
Out of scope: GR/IR.
Task 8: Verify GR/IR against BILL_SYNCED
Depends on: Task 1 (gate 3) Files:
- Create:
packages/jobs/src/inngest/functions/integrations/ramp-sync-bill-settled.ts - Modify:
packages/jobs/src/inngest/functions/integrations/ramp-sync.ts— add the step - Modify:
packages/ee/src/ramp/lib/models.ts— addcursors.billSyncStatusCheckedAt
Steps:
- Carbon keeps posting the purchase invoice locally, unchanged. That is
load-bearing twice: it clears Carbon's own GR/IR, and it is where the outbound bill
coding comes from (
loadBillCostingLinesreplays the posted journal, becausepurchaseInvoiceLine.accountIdis null for item lines). Do not suppress it. - Poll
GET /bills?sync_status=BILL_SYNCEDon the cursor, and for each bill mapped to a Carbon invoice, compare the coding that came back against what Carbon pushed. - On divergence, raise
BILL_RECODED_EXTERNALLYnaming the line and both accounts. This is the real exposure: the GL's GR/IR clears only because Carbon coded the bill to the GR-IR account, and a reviewer in Ramp can move it. - This is detection, not correction — Carbon cannot recode a Ramp bill (see Task 5 step 3).
Verify:
pnpm --filter @carbon/jobs test -- bill-settled
# Expected: a matching coding raises nothing; a moved line raises
# BILL_RECODED_EXTERNALLY; an unmapped bill is ignored
pnpm exec turbo run typecheck --filter=@carbon/jobs
# Expected: exit 0
Out of scope: any automated correction.
Task 9: Verification
Depends on: Tasks 1–8 Files: none
Steps:
- Run the gates below.
- Against the sandbox from Task 1: post a purchase invoice for a supplier mapped in
the accounting provider, confirm the draft bill's lines carry the provider's
option ids (not Carbon
account.id), the vendor resolves throughaccounting_vendor_remote_id, and noremote_idis sent. - Delete the coded account in the accounting provider, re-push, and confirm the line
is uncoded with
CODING_OPTION_MISSING— and that the bill still reaches Ramp. - Approve and sync the bill in Ramp, confirm
BILL_SYNCEDis observed and no recode Warning is raised; then move a line in Ramp and confirm the Warning appears. - Confirm provider mode is byte-identical to before this slice.
- Write results to
.ai/runs/{today}-ramp-delegated-coding-verification.md.
Verify:
pnpm exec turbo run typecheck --filter=@carbon/ee --filter=@carbon/jobs --filter=erp
pnpm run lint && pnpm run test
# Expected: all pass
Out of scope: nothing — this is the last slice.