Skip to content

Parse CTO in-process with concerto-clj's Clojure parser - #28

Merged
tbrooke merged 4 commits into
mainfrom
feat/clojure-cto-parser
Sep 26, 2026
Merged

tbrooke merged 4 commits into
mainfrom
feat/clojure-cto-parser

Conversation

@tbrooke

@tbrooke tbrooke commented Sep 26, 2026

Copy link
Copy Markdown
Contributor

What

Model loading no longer needs Node. store/put-model! and load-registry now parse .cto with concerto-clj's instaparse port of Accord's grammar, in-process. TRUSTBLOCKS_CTO_PARSER=cli switches back to Accord's CLI.

  • concerto-clj pinned at 3fd274e (was d80655f). This brings the parser, compiled size validators, and its own concerto-conformance checks.
  • store/default-parser returns :clojure unless the environment variable says cli.
  • parser_test holds the port to Accord's CLI, the reference implementation, on every model this app loads: both templates, model/identity.cto, snow-removal.cto, and late-delivery.cta's models. Both parsers must produce identical metamodel. The test fails, rather than skips, when the CLI is missing.

Verification

  • bin/clj -M:run code-quality: 66 tests, 248 assertions, 0 failures; lint clean.
  • No Node needed: with a fake node that always fails first on PATH and CONCERTO_CLI pointing nowhere, the 29 model-loading tests (library, certification, render, execute) pass and the fake is never called. The same run with TRUSTBLOCKS_CTO_PARSER=cli fails with "concerto CLI not found", as it should.
  • About 100× faster: 12 models parse in ~53 ms in-process, vs ~5.3 s spawning the CLI per file.
  • Walkthrough Part 5 re-run: identical results.

Two flakes found while verifying

Repeated full runs surfaced two intermittent problems. I tracked both down.

  1. concurrent-state-changes-are-never-lost failed about 1 run in 10. With eight writers on one contract, a trigger can lose the optimistic race max-attempts times in a row and be refused as :state-conflict, which Read contract state as of the request's own time; refuse late state changes #19 designed for. The test's real guarantee held in the failing run: every execution that lands is counted, and none is lost. Its assertion that every refusal is :out-of-order was too strict, and now accepts :state-conflict.
  2. A rare PSQLException: The connection attempt failed. In XTDB 2.1, xt/q on a node opens a new local JDBC connection per query and transaction (via with-conn to the node's own pgwire server). A burst of thousands of connections (back-to-back suites, or a stress loop) can exhaust macOS's 16,384 ephemeral ports while sockets sit in TIME_WAIT. A 150-round stress of eight concurrent triggers reproduced it at round 123. This is an environment limit, not trigger logic. It's recorded in AGENTS.md, and it's a question for production: holding or pooling a connection should be evaluated before any real load.

🤖 Generated with Claude Code

tbrooke and others added 4 commits September 25, 2026 19:57
Model loading no longer needs Node. store/put-model! and load-registry
parse with concerto-clj's instaparse port of Accord's CTO grammar
(store/default-parser -> :clojure); TRUSTBLOCKS_CTO_PARSER=cli switches
back to Accord's CLI.

- concerto-clj pinned at 3fd274e (was d80655f): the parser, compiled size
  validators, and its concerto-conformance checks.
- parser_test holds the port to Accord's CLI on every model this app loads
  (both templates, identity.cto, snow-removal.cto, late-delivery.cta):
  identical metamodel from both. It fails, not skips, without the CLI.
- About 100x faster: 12 models parse in ~50 ms in-process vs ~5 s spawning
  the CLI per file.

Node remains for the differential test, the babashka half of the
walkthrough, and the planned TypeScript clause runtime.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
concurrent-state-changes-are-never-lost flaked (about 1 run in 10): with
eight writers on one contract a trigger can lose the optimistic race
max-attempts times running and be refused as :state-conflict, which the
design intends. The test's guarantee -- every execution that lands is
counted, none is silently lost -- held in the failing run; its assertion
that every refusal is :out-of-order was too strict.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@tbrooke
tbrooke merged commit 7520cce into main Sep 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant