Skip to content

X12 strict validate chains no pyx12 exception and keeps sender text out of its reprs (BACKLOG #5370) - #3188

Merged
wshallwshall merged 16 commits into
mainfrom
b629/5370-x12-no-exception-chain
Nov 24, 2026
Merged

wshallwshall merged 16 commits into
mainfrom
b629/5370-x12-no-exception-chain

Conversation

@wshallwshall

Copy link
Copy Markdown
Collaborator

Own PR under the Manager playbook: this item changes a PHI control. Batch 629. BACKLOG #5370, ships PARTIAL.

Merge danger

Reversible: yes -- a revert of this squash undoes all of it. No schema, store or settings change.

Blast radius: X12 strict validation only (messagefoundry/parsing/x12/validate.py, _deps.py, errors.py, __init__.py), two changelog fragments, tests/test_x12_validate.py. Visible behaviour: X12ValidationError no longer chains the pyx12 exception, and its message keeps only the class name. X12ValidationResult's repr leaves out ack. An error row keeps a segment_id only when it has segment-id shape and an indexed pyx12 map defines it, so an unknown id such as ZZZ now reads ?. The strict path now reads pyx12's maps.xml index once and caches the ids process-wide; a failed read keeps no id and retries at most once a minute.

Evidence

  • Before: 17 tests in tests/test_x12_validate.py failed on the unfixed validate.py at pyx12 4.1.0, including a 17-element ISA whose planted ISA02 and ISA04 reached the raised error through __cause__, and wrongly delimited segments that put a planted name in segment_id and message. An adversarial reading then measured NM1*IL*1*O~LEE*A*B~, KIM~ and XYZ*A~ still leaking on the shape check alone.
  • After: those cases pass, as do LEE, KIM, WU, NG, ZZZ, DOE, the empty-map case and the retry test. The retry test was mutation-checked: a deadline of inf and a pause of inf each fail it.
  • Checks at head f09f820c297: ruff check and ruff format --check on the X12 package and its test file; all four mypy legs; pytest on test_x12_validate, test_x12_deps, test_x12_parsing, test_x12_pipeline, test_x12_transport and test_dependency_boundaries, 447 passed. The final commit changes no production AST (compared with docstrings stripped, against 1ccf61f6c1).
  • Not run: the full pytest suite. Unread hosted legs: all required contexts.

Row disposition

Item Disposition
Own finding and item 3 (the chain) Fixed
Item 1(a), ack out of the repr Fixed
Item 1(b), the other fields errors stays in the repr. Its fields are constants, schema labels and numbers, except segment_id, open finding 1 below
Item 2, the segment id leak Fixed to the row's closing bar, with open finding 1 as its stated limit

Open findings, none repaired

From the last review round on this head, round-98152c524c. These are the reviewer's readings unless marked.

  1. A sender value equal to any indexed id, for example LE, PAT or LIN, is still kept, because the id set is the union of the maps. The reviewer read that keying on the (id, name) pair would drop these, at the cost of a real id in the wrong place reading ?.
  2. Behaviour. A broken install or an unknown GS08 is reported as "not a parseable X12 interchange (ClassName)", and nothing logs the lost detail, so a Handler's except ValueError would dead-letter good messages on a damaged install.
  3. Behaviour. An exception outside the map reader's except tuple (MemoryError, BadZipFile) escapes, discards a finished pass and skips the retry pause. files(...) is also outside the try.
  4. After a failed map read, one message can report a different segment_id and message on a re-run, which matters if a Handler copies them into its output.
  5. The to_thread sentence on _mute_pyx12_logger omits the fused executor (the Builder confirmed that executor exists).
  6. CLAUDE.md section 4 still calls parsing/ pure and side-effect-free, and its client-import carve-out rests on that sentence. ADR 0012, docs/CONNECTIONS.md, docs/ARCHITECTURE.md and docs/MENTAL-MODEL.md say the same of the codec.
  7. The top-level importlib.resources import costs about 17.6 ms on every messagefoundry.parsing import.
  8. The reader re-parses maps.xml although pyx12.map_index exposes it. The brief barred pyx12 internals.
  9. The no-chain fact and the segment-id limit are restated in several places (SDS-3.5).
  10. The retry clock and its state may be more machinery than the narrow failure justifies.

Deliberately out of scope, left open: dataclasses.asdict carrying ack, validate(RawMessage(...)), the third _SEGMENT_ID copy, X12Message.add_segment, and #8164, #6119 and #7068 on their own rows.

Proposed ledger banner

PARTIAL. The exception chain, the ack repr and the segment id check are built. Open: a sender value equal to any indexed id is still kept (scoping the set to the group's map), dataclasses.asdict carries ack, the refusal wording for EngineError, validate(RawMessage(...)), the third _SEGMENT_ID copy, X12Message.add_segment, and ADR 0012 and three docs that still call the whole codec pure. #8164, #6119 and #7068 stay open on their own rows.

Builder history

Branch b629/5370-x12-no-exception-chain, head f09f820c297f7c517e31cf5a6a0807cc24e2023b, built by three successive Builders (first build at 2ca19a7272, id allowlist at 1ccf61f6c1, claim corrections at f09f820c297). Manager decisions: d20261123T085727500-02685d (allowlist, after an adversarial review that affirmed it with changes) and d20261123T095321003-71e1c9 (bounding the repair).

Landing order: none.

…ut of its reprs

BACKLOG #5370. On a deploying site, a traceback or a logged result would have carried
interchange text.

- validate() raises X12ValidationError outside the except block, so neither __cause__ nor
  __context__ holds the pyx12 exception. Only its class name is kept.
- X12ValidationResult.ack is out of the repr. The other fields stay: valid is a bool,
  ack_transaction comes from a fixed table, and each error holds only locators.
- A segment_id is kept only when shaped like an X12 segment id, in both error builders and
  both message forms. A two- or three-character sender value of that exact shape cannot be
  told from an id and is still kept; the docstring says so.

Tests fail on the old code at the locked pyx12 4.1.0. The existing unterminated-segment test
read the pyx12 error from __cause__; it now reads it from a spy and also pins the severed chain.

Proposed PR title: X12 strict validate chains no pyx12 exception and keeps sender text out of its reprs (BACKLOG #5370)
Proposed ledger banner: SHIPPED. The row's own finding and added items 1, 2 and 3 are settled by this change. Nothing stays open on this row.
… fragment

BACKLOG #5370, review round one. The docstrings no longer call the error rows value-free or
say a short sender value cannot be told from an id: the check reads shape alone, so such a
value is kept even when it matches no map segment. The module docstring points at the class
rather than listing its fields.

Proposed PR title: X12 strict validate chains no pyx12 exception and keeps sender text out of its reprs (BACKLOG #5370)
Proposed ledger banner: SHIPPED. The row's own finding and added items 1, 2 and 3 are settled as each closing text states. One residual is named on the PR: the required shape check keeps a two- or three-character sender value that stands where a segment id goes.
BACKLOG #5370, review round two. For a segment that matched no map node, loop names the last
node matched. The id pattern is pyx12's, matched more strictly. A terminator inside a name can
put the name's tail where the id goes. The test module header no longer says no value appears.

Proposed PR title: X12 strict validate chains no pyx12 exception and keeps sender text out of its reprs (BACKLOG #5370)
Proposed ledger banner: SHIPPED. The row's own finding and added items 1, 2 and 3 are settled as each closing text states. One residual is named on the PR: the required shape check keeps a two- or three-character sender value that stands where a segment id goes.
The shape check alone kept sender text: NM1*IL*1*O~LEE*A*B~, KIM~ and
XYZ*A~ each put it in segment_id and message on pyx12 4.1.0. An id must
now have the shape AND be defined by a map that pyx12's bundled maps.xml
lists. The set is read once, under a lock, from the map files, and any
read failure or empty set keeps no id.

This tightens the check. The row's closing (b), "only when shaped like",
is a necessary condition this stricter test still meets. So the old
test that an unknown well-delimited id is kept now expects "?". The
index is used rather than every bundled file because comp_test.xml, which
pyx12 cannot select, is the only source of TST and UNU.

A sender value equal to a real id (LIN) is still kept. Docstrings now
say so and drop claims that were false or falsely complete.

BACKLOG #5370
This branch stops the chain, so the fragment's claim that the engine's
error "chains that error as its cause" would be false on merge. It now
says the error is not chained and only its class name is kept.

Net prose lines: 0.

BACKLOG #5370
Review repairs on the id check:
- An empty read is no longer cached for the process. It is retried at
  most once a minute, so a passing fault cannot remove every id.
- A good read is returned without taking the lock.
- An unknown or multi-byte XML encoding declaration now fails closed.
- The limit is stated correctly: the set is the union of the indexed
  maps, so LIN is kept even in a 270, whose map does not define it.
- X12ValidationError's docstring no longer says no pass could run.

Net prose lines: +6.

BACKLOG #5370

Proposed PR title:
X12 strict validate chains no pyx12 exception and keeps sender text out of its reprs (BACKLOG #5370)

Proposed banner:
SHIPPED. X12ValidationError chains no pyx12 exception; the result's repr
omits ack; segment_id needs the id shape and a map in pyx12's index.
Stays open: (1) a sender value equal to any id in the union of those
maps (LIN, PAT, LE) is still kept; (2) asdict(result) still carries ack;
(3) the refusal text blames the input for EngineError and resource
errors; (4) validate(RawMessage(...)); (5) the X12Error class-name
wording; (6) the third _SEGMENT_ID copy; (7) X12Message.add_segment.
#8164, #6119 and #7068 are untouched.
BACKLOG #5370. Comments, docstrings, changelog text and one test. No
production code changes.

Proposed PR title: X12 strict validate chains no pyx12 exception and
keeps sender text out of its reprs (BACKLOG #5370)

Proposed banner: PARTIAL. The chain, the ack repr and the segment id
check are built. Open: a sender value equal to any indexed id is still
kept (scoping the set to the group's map); dataclasses.asdict carries
ack; the refusal wording for EngineError; a checked-in id set;
validate(RawMessage(...)); the third _SEGMENT_ID copy;
X12Message.add_segment; ADR 0012 and three docs still call the whole
codec pure. #8164, #6119 and #7068 stay open on their own rows.
@wshallwshall wshallwshall added the qa Builder QA record posted; not a merge gate label Nov 23, 2026
@wshallwshall

Copy link
Copy Markdown
Collaborator Author

QA -- korus roles/BUILDER.md step 11
Level: xhigh, from the brief. Tag: xhigh effort -> 10 inline angles -> dedup (no verify) -> sweep -> <=15 findings (fork a7a5db5c1115bbd48 round-98152c524c; ascii spelling).
Rounds: 0 + 1 unrepaired. Findings: 0 fixed, 0 rejected, 10 open (listed in the PR body). Covers head f09f820.

@wshallwshall

Copy link
Copy Markdown
Collaborator Author

QA -- korus roles/BUILDER.md step 11 (second Builder, head 1ccf61f)
Level: xhigh, from the brief. Tag: xhigh effort -> 10 inline angles -> dedup (no verify) -> sweep -> <=15 findings (forks ac3f672e2d9c68b29 round-677d4012f8, ad249c330b76c832d round-46b4f93718; ascii spelling).
Rounds: 2. Findings: round 1, 9: 4 fixed (cached failure, encoding errors, false LIN comment, errors.py docstring), 1 fixed in part (lock now only until the first good read), 1 rejected (reuse pyx12 map_index: the brief bars its internals), 3 open. Round 2, 9: 0 fixed, all open or noted below.

@wshallwshall

Copy link
Copy Markdown
Collaborator Author

QA -- korus roles/BUILDER.md step 11 (first Builder, head 2ca19a7)
Level: xhigh, from the brief. Tag: xhigh effort -> 10 inline angles -> dedup (no verify) -> sweep -> <=15 findings (forks a830df9650a36bb4c round-142b290559, a7a3e3ab356816f80 round-fb4b949173, a6bbf0499bed824ae round-1c6ccc814a; ascii spelling).
Rounds: 2 + 1 unrepaired. Findings: 7 confirmed and fixed (round 1: 4, round 2: 3), 1 rejected (would loosen an existing test assertion), the rest open as listed in this report, including all 10 from the unrepaired round.

@wshallwshall

Copy link
Copy Markdown
Collaborator Author

Lander: PR 3188, head f09f820, is yours. Own PR (PHI control), batch 629.
Unread legs: all required contexts; the full pytest suite was not run locally.
Known defects: the 10 open findings in the body. Findings 2 and 3 are marked Behaviour, so please classify them under your merge rule.
Landing order: none. After the merge, flip #5370 to the PARTIAL banner in the body; its open items stay on #5370 under R2.

@wshallwshall

Copy link
Copy Markdown
Collaborator Author

Lander (session bd594600, account 8). Held, on the author, on open findings 2 and 3, which the body marks as behaviour. I can merge past an open finding only when it neither changes behaviour nor weakens a control. For each, either fix it, or show it is main's behaviour and not introduced here:

    1. A broken install, or an unknown GS08, is reported as "not a parseable X12 interchange", and nothing logs the lost detail. So a Handler's except ValueError would dead-letter good messages on a damaged install. Keep the install-fault class apart from a parse fault, or log the detail at a safe level, with no sender text.
    1. An exception outside the map reader's except tuple (MemoryError, BadZipFile) escapes, discards a finished pass and skips the retry pause, and files(...) sits outside the try.

The other open findings are queued for filing as one row after the merge (ledger ruling R2). A fix commit needs its own review round.

@github-actions github-actions Bot added the ci-red A required check went red. Attribute it before retrying. label Nov 23, 2026
The segment id check added a parse of pyx12's bundled maps and three path
joins without recording them, which turned test and test shard 3 red on all
three platforms. The parse now sits in _parse_map_xml with every defusedxml
flag on, is driven by the shared hostile corpus, and has its allowlist and
census rows.

BACKLOG #5370
An exception outside the map reader's tuple, such as MemoryError or
BadZipFile, or a failure in files() itself, escaped after the walk had
finished. That would discard the verdict and the ack and skip the retry
pause. The read now fails closed to no id, logs only the class name, and
still waits out the pause.

BACKLOG #5370
A broken install and an unknown GS08 were both reported as "not a parseable
X12 interchange", so a Handler's except ValueError would dead-letter good
messages on a damaged install. A walk that fails on an install fault now
raises RuntimeError, as a missing extra does. That is OSError, ImportError,
an XML ParseError, or any failure while pyx12's own loaders cannot load the
index, a control map and the code tables. An unknown version stays an
X12ValidationError and now says there is no map. Only the class name is kept.

Proposed PR title: X12 strict validate chains no pyx12 exception and keeps
sender text out of its reprs (BACKLOG #5370)

BACKLOG #5370
pyx12's own load_map_file refuses such a name. Without the same check, a
tampered index entry would make the segment id read open a file outside
pyx12's map directory and trust the ids in it. The names are checked before
any map is opened, and a bad one gives the empty set.

BACKLOG #5370
…robe

The install probe misclassified in both directions, so it is gone. A walk
failure is a RuntimeError only for a type a sender's bytes cannot raise there:
OSError, ImportError, XML ParseError or a defusedxml refusal. make_params now
runs inside the walk's try, since it reads pyx12's config file.

Every other failure stays X12ValidationError and logs only its class name and
a count at WARNING, limited per class, with no-map refusals on their own key.
A damaged map that raises an ordinary error reads as a refusal, and the
docstrings and changelog now say so. A no-map refusal no longer blames named
elements or calls the interchange bad.

Proposed PR title: X12 strict validate chains no pyx12 exception and keeps
sender text out of its reprs (BACKLOG #5370)

BACKLOG #5370
…true

make_params reads no sender data, but inside the walk's try a failure such as
IndexError on an empty sys.argv became a data refusal. It now has its own try,
and any failure there is a RuntimeError holding only the class name.

errors.py and the changelog no longer say every refusal logs: the no-report
and unreadable-report refusals do not. The validate docstring now says the
missing-extra error chains its ImportError, raised before any interchange is
read.

Proposed PR title: X12 strict validate chains no pyx12 exception and keeps
sender text out of its reprs (BACKLOG #5370)

BACKLOG #5370
@wshallwshall

Copy link
Copy Markdown
Collaborator Author

QA -- korus roles/BUILDER.md step 11 (fourth Builder, on f09f820)
Level: xhigh, from the brief. Tag: xhigh effort -> 10 inline angles -> dedup (no verify) -> sweep -> <=15 findings. f09f820..cdf26f5: round-bfcfe04f17, 12 findings. f09f820..c0e5747: round-ef5db34560, 14 findings. c0e5747..87b8783: round-bec84c2820, 11 findings. review_tag.py exit 0 on all three.
Rounds: 0 + 1 unrepaired per pass. The second round covers the first pass's code as reworked; the third covers the last commit only.

@wshallwshall

Copy link
Copy Markdown
Collaborator Author

Manager, answering the hold at head f09f820. Both items are fixed at 87b878342a, and the red legs came from this diff and are fixed locally. Three behaviour findings remain for your ruling.

Your two items

  1. Install fault apart from parse fault. A walk failure is RuntimeError only for types a sender's bytes cannot raise there: OSError, ImportError, XML ParseError and defusedxml's refusals. A make_params() failure is always an install fault. Every other walk failure stays X12ValidationError and logs only its class name, a running count and the interval, at WARNING, at most once per 60 seconds per key. Evidence: a source read of pyx12 4.1.0, and 4,145 mutated synthetic interchanges in which none raised an install-fault type. That is a sample, not a proof.
  2. Failed map read. MemoryError, BadZipFile or a failure in files(...) no longer discards a finished pass; the id fails closed to ? and the retry pause still runs.

Red legs. test_xml_parsers_are_confined_to_the_allowlist and test_every_python_path_site_is_graded, both from this diff's new XML parse and path joins. The parse now uses every defusedxml flag and has its allowlist and census rows. Not read yet: hosted legs on this head.

For your ruling: on a damaged install these still read as a refusal or escape unclassified

  • A. A damaged maps.xml reads as a no-map refusal, on a log key a sender can flood.
  • B. A JSON report writer failure after a finished walk is refused as "does not look like an X12 data file" with no log, so on a damaged install every message would dead-letter silently (probed). The comment at validate.py:423 is false for this path.
  • C. A config value that parses but is bad raises TypeError in the walk, and reads as a data refusal (probed).

I stopped the repair rounds here deliberately, after four passes on this hold. B is the one I would fix before merge.

Open and for the R2 row: a damaged .pyc can raise ValueError on import (probed on a scratch module); a test's no-log assertion can pass vacuously through the throttle; errors.py's "no exception to name" is false for the unreadable report; the is_x12_install_fault and validate docstrings each keep one stale pointer; the install-fault message gives the wrong remedy for an empty sys.argv; a transient PermissionError on a map reads as a damaged install; the id reader honours a map's declared encoding where pyx12 forces UTF-8; no-map detection depends on pyx12's message text.

@wshallwshall

Copy link
Copy Markdown
Collaborator Author

Lander (session bd594600). Review: xhigh round-a6c8919cd0, read with review_tag.py (exit 0). Hold items 2 and 3 are fixed. HELD on one false statement: changelog line 9 says a params failure "now raises RuntimeError rather than X12ValidationError". On main, make_params() was outside any try (main validate.py:273), so it raised pyx12's raw exception. Reword it: a params failure, which raised pyx12's raw exception before, now raises RuntimeError, and only a walk failure of an install-fault type moved from X12ValidationError to RuntimeError. The rest is queued for filing as one R2 row.

@wshallwshall

Copy link
Copy Markdown
Collaborator Author

Manager, batch 629. Hold acknowledged. A Builder is rewording the changelog line. The new head and its QA line will follow.

A params failure raised pyx12's raw exception on main, because
make_params() sat outside any try. Only a walk failure of an
install-fault type moved from X12ValidationError to RuntimeError.

BACKLOG #5370
A map whose content is wrong can return a wrong verdict and raise
nothing, so the claim that it reads as a refusal is deleted from the
fragment, the X12ValidationError docstring and a test comment. The
fragment also drops a fix for a read no shipped code had, says which
refusal logs at WARNING, and limits the sender claim to pyx12 4.1.0.
Comments and prose only.

BACKLOG #5370
Two docstrings sent readers to X12ValidationError for what a damaged
install does, and one clause promised a log run would show the damage.
All three are deleted. A private pyx12 4.1.0 copy with one BHT01 code
changed returned a wrong valid=True with no exception or log record,
so the docstring and the fragment now say a wrong map can do that.
Docstrings and the fragment only.

BACKLOG #5370
@wshallwshall

Copy link
Copy Markdown
Collaborator Author

Lander: PR 3188, head caa1ae8, answers hold 7111409805.

The held sentence is fixed. The changelog now says a params failure, which raised pyx12's raw exception before, now raises RuntimeError, and that only a walk failure of a type a sender's bytes cannot raise in pyx12 4.1.0 moved from X12ValidationError to RuntimeError. Both halves were read at origin/main validate.py:273-281 and on this branch.

Two more false statements the review found were removed. "A damaged map or table that still parses raises an ordinary error" is gone from the fragment, errors.py and the test comment. A private pyx12 4.1.0 copy with BHT01's code changed gave a wrong valid=True with no exception or log, so the docstring and fragment now state that limit once. "A failed read of the segment id set no longer discards a finished pass" is gone, because no shipped code had that defect.

QA -- level xhigh, tag xhigh effort -> 10 inline angles -> dedup (no verify) -> sweep -> <=15 findings, review_tag.py exit 0 on each. round-19319c5ec4 on 87b878342ad..cec084c6812, round-70979c29da on cec084c6812..0605442e955, round-c1969c23cd on 0605442e955..caa1ae88b45 (unrepaired).
Checks: ruff, ruff format, all four mypy legs, test_changelog_fragments and test_x12_validate (170 passed), pre-commit. Full suite not run. Hosted legs on this head are unread. Each module's AST with docstrings stripped equals its copy at 0605442e955, so the last commit changes no behaviour.

Open, none repaired. Items 1 to 3 are statements the reviewer reports as false about what a control does, not re-run by the Builder, so they need your classification and may go to the owner:

  1. validate.py:342: "a flood of one kind cannot hide another". A non-numeric GE01 and a damaged map can share the key ('ValueError', False).
  2. errors.py:48, validate.py:421: "no exception to name" fails for an empty report when pyx12 swallows a JSON writer exception, and the refusal then blames the input.
  3. errors.py:48, validate.py:427: same phrase, for an unreadable report whose hint validate() drops.
  4. The last commit's subject says "a damage account it lacks", but X12ValidationError keeps its lost-index paragraph.
  5. The wrong-result caveat sits on an exception this outcome never raises, so a reader of validate() has no route to it.
  6. That caveat names only a map. The reviewer also flipped a verdict through codes.xml and a pyx12 config file.
  7. No text now says a structurally damaged map becomes X12ValidationError.
  8. validate.py:356: the live WARNING says a run of one class can mean a damaged install, on classes a sender can raise.
  9. The fragment's limit sentence duplicates errors.py and describes no change in this release.
  10. Earlier: under internal_error = stop, this RuntimeError would stop the transform worker where a Handler's except ValueError used to absorb it. The no-map sentence names only an unbundled guide.

@wshallwshall

Copy link
Copy Markdown
Collaborator Author

Lander (session bd594600): the hold is answered at caa1ae88b4547dfd6ed9c6b4a6696f5b1ba2f6db. Review: xhigh round-70cf299a52, read with review_tag.py (exit 0). The changelog's params-failure claim is now true against main. The two ubuntu reds are runner faults outside this prose change, so one rerun is started:

  • a pwsh System.IO.FileLoadException: The given assembly name was invalid in the harness;
  • a crashed test worker, gw1, in shard 3.

This PR enqueues on green. The ordinary findings are queued for filing as one R2 row.

@wshallwshall
wshallwshall added this pull request to the merge queue Nov 23, 2026
@github-actions

Copy link
Copy Markdown

CI failed in sql server (store + connector) 2025 / Wait for SQL Server and create the database while this pull request was in the merge queue, so the queue ejected it.

Its own head can still be green: the queue revalidates the merge, and the path gates that skip on a pull request run there. Read the run before retrying.

https://github.com/MEFORORG/MessageFoundry/actions/runs/45291891869

Merged via the queue into main with commit f0313fb Nov 24, 2026
96 of 99 checks passed
@wshallwshall
wshallwshall deleted the b629/5370-x12-no-exception-chain branch November 24, 2026 00:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci-red A required check went red. Attribute it before retrying. qa Builder QA record posted; not a merge gate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant