Repository navigation
fix(edi): reject /document files the KDE gate would refuse before ISA13 - #3820
Conversation
/document answered 201 with accepted: 0 for every 861, 850 and 810, and for 856, 944 and 945 documents missing a required KDE. It also stored a synthesized "EDI <set> Item" for a line with no product id. - Check each set's required KDEs before the ISA13 is reserved. A miss is a logged 422, so the corrected resend is not a 409 replay. - 861 now emits receive_date, immediate_previous_source, reference_document and tlc_source_reference. The TLC source comes from the caller's form field, as on 856. - 850 and 810 always return 422. The PO date, invoice date and buyer and seller parties are not a ship date or shipping locations. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The product check looped over no lines and passed, so these documents reached FSMA validation after the ISA13 was reserved. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. 🗂️ Base branches to auto review: 1
Please check the settings in the CodeRabbit UI or the
|
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
PR Blocker ChecklistHead SHA: Status: Ready
|
…to claude/edi-document-kde-gate Picks up the secrets pragma fix on the flagged curl line. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e-gate Takes #3818's placeholder checks for 856 on /document, so 856 no longer goes through the document preflight table. The other line sets had the same hole. 861, 944 and 945 could still store a blank unit as "units", and an 861 with no quantity element as 1.0. The document preflight now needs a positive quantity and a recognized unit on every line, so these return edi_<set>_missing_required_kdes before the ISA13 is reserved. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…to claude/edi-document-kde-gate # Conflicts: # services/ingestion/app/edi_ingestion/routes.py Co-authored-by: PetrefiedThunder <131207452+PetrefiedThunder@users.noreply.github.com>
PetrefiedThunder
left a comment
There was a problem hiding this comment.
Codex re-review of head cb17b76 (headless codex exec, read-only). Focused on the delta from 5074af6, then a full pass over the PR diff vs merge-base with main.
Delta: the legacy 856 placeholder validation (_legacy_856_placeholder_errors) now runs in the pre-reservation gate in services/ingestion/app/edi_ingestion/routes.py, before the ISA13 is reserved, instead of after. A corrected resend is no longer blocked by a burned ISA13. test_edi_856_real_kde_gate.py now parametrizes that regression over both routes. Full PR: the required-KDE checks and canonical field mappings are sound, with no correctness or tenant-isolation issues found. Test data and storage fakes are explicit. This was a static review and the tests were not run.
Defects: none.
Note: this review does not clear the PR Blocker Checklist or Head SHA Check Guard. Failing checks at review time: Engine Review Pass.
REVIEW: PASS codex cb17b76
cb0ba0c
into
claude/modest-volhard-f77f2b
POST /api/v1/ingest/edi/documentno longer returns 201 withaccepted: 0. Each set now stores through the real gate, or gets a logged 422 before the ISA13 is reserved, so a corrected resend is not a 409 replay.Stacked on #3818. Merge that first.
Before and after
accepted: 0accepted: 0with noN1*SForN1*STname. A line with no product id storedEDI 856 Itemtlc_source_referencereturned 201accepted: 0. Lines with no product id stored a placeholderunits, and an 861 with no quantity element stored1.0accepted: 0944 and 945 were not named in the original task. They are here because 945 hit the same bug when probed, and 944 uses the same check.
Changes
_preflight_document_required_kdeswalksREQUIRED_KDES_BY_CTEfor 861, 944, 945, 850 and 810 and runs before the ISA13 is reserved. It needs a positive quantity and a recognized unit on every line, so bad values returnedi_<set>_missing_required_kdeshere instead ofedi_non_positive_quantityoredi_unmapped_unit_of_measureafter the reservation./documentuses fix(edi): store valid 856s through the required-KDE gate #3818's_legacy_856_placeholder_errorspath, not this table.receive_date(BRA02),immediate_previous_source(N1*SF name, or GLN as on 944),reference_documentandtlc_source_reference.tlc_source_referenceon 861 and 945 follows the fix(edi): store valid 856s through the required-KDE gate #3818 decision: the caller supplies it, and it is never derived from the ship-from party.location_overridestill does not fillship_from_location. Only the location name uses it.messageon both routes now points toerrorsinstead of suggesting overrides, because/documenthas no override for most of these KDEs.850 and 810
Every 850 and 810 returns 422 on
ship_date,ship_from_locationandship_to_location. This is the current behaviour, by maintainer decision. No value was invented: BEG05 is a PO date and BIG01 is an invoice date, and the N1 BY, SE and RI parties are commercial parties, not shipping locations. These sets stored nothing before this PR either.How to handle them longer term is still open. This PR adds no 810 field extraction and keeps both sets as shipping CTEs.
Verification
All on merge commit
cb17b769.services/ingestion/tests -k edi: passed, with 3 skips that needREMEDIATION_EXCHANGE_PG_ADMIN_DSN./document, and 856 (blank unit, no ship-from name) on/: 422, then a corrected resend on the same ISA13 returned 201accepted: 1, then replay returned 409. 850 and 810 returned 422.fsma.traceability_events: each has quantity 200, unitcases, and thetlc_source_referenceand reference document sent. 11 rejections were logged.test_856_blank_sn1_quantity_is_rejectedchanged: its document now has parties and a product, so it still reaches the quantity check.quantity,unit_of_measureandproduct_descriptiontogether.Not changed
/documentstill happen after the reservation. fix(edi): release the ISA13 claim when an interchange is not stored #3782 covers these too.routes.py.🤖 Generated with Claude Code
Note
Medium Risk
Changes FSMA traceability ingestion semantics on a production EDI route (what persists vs 422, interchange dedup timing), but the behavior is fail-closed validation rather than new persistence of inferred KDEs.
Overview
POST /api/v1/ingest/edi/documentno longer succeeds withaccepted: 0when the real required-KDE gate would drop events. Valid 861, 944, and 945 documents now persist; bad ones return 422 withedi_<set>_missing_required_kdes, a logged rejection, and no ISA13 reservation, so a fixed resend is not treated as a 409 replay.A new
_preflight_document_required_kdesruns before interchange dedup for non-856 sets. It enforcesREQUIRED_KDES_BY_CTEper line (product, positive quantity, recognized unit,tlc_source_reference, and set-specific locations/references) instead of letting the route synthesize placeholders likeunits,1.0, or generic item names that the gate cannot catch. 856 on this route still uses_legacy_856_placeholder_errors, unified under_reject_missing_required_kdes.861 events now carry gate-facing KDEs (
receive_date,immediate_previous_source,reference_document,tlc_source_reference). 850 and 810 always 422 onship_date,ship_from_location, andship_to_locationbecause those documents do not record shipments; nothing is stored (same effective outcome as before, but explicit). Docs and integration tests cover pre-reservation rejection, batch failure, and the commercial-document behavior.Reviewed by Cursor Bugbot for commit 5074af6. Bugbot is set up for automated code reviews on this repo. Configure here.