Skip to content

feat(engine): Atrium convergence — engine module, stability contract, clock-injectability, supply-chain, event-sourced rehydration - #120

Merged
JAORMX merged 6 commits into
mainfrom
feat/atrium-convergence
Jun 19, 2026
Merged

JAORMX merged 6 commits into
mainfrom
feat/atrium-convergence

Conversation

@JAORMX

@JAORMX JAORMX commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Closes #113 #114 #115 #116 #118.

The atrium-convergence issue set: make engine/ a clean, dependable, embeddable library so Atrium can import the core and inject its own adapters (LLM-Gateway, MCP-Gateway, an event-log-as-system-of-record session store, its own event schema) — true co-evolution instead of vendoring/divergence. Built on top of PR #119 (session leasing). Kept a monorepo (multi-module workspace, not a repo split).

Each issue went through the full dev-pipeline (architect → implement → independent review panel → iterate → commit-per-issue).

What landed

# Issue Highlights
#116 clock-injectability All ~11 time.Now() sites in the engine core route through the injected port.Clock via a nil-safe Engine.now(); ephemeral child-session ids use an atomic counter (collision-safe under a fake clock, unlike UnixNano); an AST arch guard forbids time.Now/Since/Until in core non-test code.
#113 engine as its own Go module engine/go.mod (github.com/stacklok/mecatl/engine) consumed locally via a committed go.work. An external consumer of engine/agent now gets a tiny graph — golang.org/x/sync + doublestar (+ goleak test) — not mecatl's toolhive/k8s/otel/grpc/SDK cone. A dedicated GOWORK=off CI job proves the hygiene. CI/Taskfile cover both modules. ADR 0036.
#114 stability / breaking-change contract engine/COMPATIBILITY.md declares the 7-core-package public surface + v0.x discipline; a text API-snapshot freshness gate (internal/apicheck, golden -update idiom) fails CI on any unflagged change — capturing const values (wire enums) and exported fields/methods; the guarded set is mechanically equal to arch.CorePackages. gorelease is a release-time advisory. ADR 0037.
#118 supply-chain hygiene govulncheck per module — engine strict & clean; the root app hard-gates but allowlists two unfixable-upstream docker CVEs (transitive via toolhive, reachable only in internal/) as documented accepted-risk, fail-closed, still failing on any new reachable vuln. dependabot.yml for both go.mod files + SHA-pinned actions.
#115 event-sourced rehydration engine/adapter/eventsource.Fold (EventLog + SessionMeta → *session.Session) is the reference event-sourced SessionStore.Load; the reconstruction contract (which aggregate fields must round-trip vs are run-scoped) is pinned in COMPATIBILITY.md + the port.SessionStore doc. A new log-only EvUserPrompt event makes the durable log record — and the fold reconstruct — user-role turns (closing a latent ADR-0027 gap: the durable log previously couldn't show what the user asked). ADR 0038.

Notable design decisions & documented limitations

  • go.work is committed (standard monorepo practice; invisible to external go get). Root go.mod gains require …/engine + replace …/engine => ./engine.
  • No hard API breaks — changes are additive or structural; import paths are unchanged.
  • EvUserPrompt is log-only (appended to the durable log, skipped on the live client wire — the EvApproval/EvCompactionArchive precedent; the driving client already has the prompt). Child-content isolation (gauntlet ACP: accept client-provided streaming-HTTP MCP servers #7) holds and is security-reviewed + mutation-guarded: a child's prompt never reaches the parent log.
  • Reconstruction contract limitation (documented): the provider-private replay fields (Message.Reasoning, Message.ProviderPhase, ToolCall.ItemID) are not event-carried, so a pure event-fold is byte-identical-replay-faithful only for providers that don't use them; an event-log-SoR host must carry them in its own event schema. mecatl's own resume still uses the snapshot (which carries them).
  • Govulncheck allowlist: GO-2026-4887 / GO-2026-4883 (docker/docker via toolhive, Fixed: N/A) — accepted-risk, dated, root-only; engine is strict.

Verification (10/10 gates green on the integrated branch)

Root + engine go build / go test -race; the GOWORK=off engine-standalone build+test; lint + go vet both modules; the API stability gate; the vuln gate (engine clean, root allowlisted, fail-closed self-test); offline go run ./cmd/mecademo (full session, now showing user_prompt); matlatl --strict docs (0 broken/orphan/unreachable); task tidy stable; the engine dep-closure confirmed tiny.

Notes

🤖 Generated with Claude Code

JAORMX and others added 5 commits June 19, 2026 06:58
…t.Clock (#116)

All ~11 time.Now() reads in the engine core (engine/ minus engine/adapter/)
now flow through a nil-safe Engine.now() helper, which reads the injected
port.Clock or returns the zero time when no Clock is configured (preserving the
loop's existing optional-Clock contract). This makes the engine fully
clock-injectable so an embedding host can drive every wall-clock read
deterministically.

The ephemeral in-memory child sessions (guardrail checker, fork judge, ask
reviewer, model router) previously derived their ids from time.Now().UnixNano(),
which aliases two children onto one id under a fixed fake clock. They now use a
childSerial atomic counter — collision-free under any clock.

An engine/arch AST guard (TestNoWallClockInEngineCore, with a liveness
self-check) forbids time.Now/Since/Until in core non-test code. Behavioral
tests (TestEngineNow, TestChildSerialDistinctUnderFixedClock) and an e2e wiring
test (TestSubagentChildCreatedAtFromInjectedClock) added.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
engine/ is now module github.com/stacklok/mecatl/engine consumed locally via a
committed go.work (monorepo, not a repo split). External consumers of
engine/agent get the tiny closure (x/sync + doublestar + goleak), not the heavy
toolhive/k8s/otel/grpc/SDK cone. A dedicated GOWORK=off CI job proves the
hygiene; CI/Taskfile cover both modules; ADR 0036 records the why.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
)

engine/COMPATIBILITY.md declares the 7-core-package public surface + v0.x
discipline; a text API-snapshot freshness gate (internal/apicheck, golden
-update idiom) fails CI on any unflagged change to the exported surface —
capturing const VALUES (wire enums) and exported struct fields/methods/
interfaces; the guarded set is mechanically equal to engine/arch.CorePackages;
gorelease is a release-time advisory; ADR 0037 records the decision.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
A `vuln` CI job runs pinned govulncheck for the root AND engine modules; the
engine library is gated with NO allowlist (clean), the root app allowlists two
unfixable-upstream docker CVEs (GO-2026-4887/4883, transitive via toolhive,
reachable only in internal/, Fixed: N/A) as documented accepted-risk while still
failing on any NEW reachable vuln; `.github/dependabot.yml` keeps both go.mod
files + SHA-pinned actions current (grouped, weekly).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…construction contract + EvUserPrompt (#115)

Ship engine/adapter/eventsource.Fold (EventLog+SessionMeta -> *session.Session)
as the reference event-sourced SessionStore.Load rehydration; pin the
reconstruction contract (COMPATIBILITY.md + port.SessionStore doc) — which
aggregate fields must round-trip vs are run-scoped; add EvUserPrompt so the
durable log records and the fold reconstructs user-role turns (closing the
"log can't show what the user asked" gap, ADR 0027 row 11); only the
provider-private reasoning-replay fields remain a documented limitation; reuse
sessnap.RestoreState; determinism + awaiting-drivable + reasoning-divergence +
contract-drift tests; ADR 0038.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@JAORMX JAORMX added the e2e-live Run the live e2e suite on this PR label Jun 19, 2026
…039 (#118)

CI govulncheck flagged three newly-disclosed REACHABLE stdlib vulnerabilities,
all fixed in the Go standard library at go1.26.4:

- GO-2026-5037 (CVE-2026-27145) — crypto/x509: quadratic VerifyHostname cost on
  large DNS SAN lists (DoS). Fixed in: go1.26.4. Reachable via the HTTP client
  TLS path (root only); engine unaffected.
- GO-2026-5038 (CVE-2026-42504) — mime: WordDecoder.DecodeHeader excessive CPU
  on malicious encoded-words (DoS). Fixed in: go1.26.4.
- GO-2026-5039 (CVE-2026-42507) — net/textproto: user input echoed in error
  messages (log/error injection). Fixed in: go1.26.4.

All three are Go-stdlib vulns governed by the `go` directive version that
`go-version-file: go.mod` feeds setup-go. The repo declared `go 1.26.3`, so CI
provisioned go1.26.3 and govulncheck reported the trio. Bumping the `go`
directive to 1.26.4 in both modules (and go.work) is the minimal, durable fix
(decision rule 1: upstream fix exists -> bump, preferred over allowlist). No
go.sum changes — stdlib only. No new allowlist entries.

The ENGINE module is now clean under the strict (no-allowlist) gate. The 2
docker CVEs (GO-2026-4887/4883, Fixed: N/A) remain the only allowlisted,
accepted-risk root findings.

Verified: root gate (allowlist 4887/4883) exit 0; engine strict gate exit 0;
gate self-test all pass; go build (root+engine GOWORK=off); go test -race
(root+engine); golangci-lint+vet (both); task api:check (no API drift); engine
dep-closure still tiny; mecademo full offline session; task tidy stable.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@JAORMX
JAORMX marked this pull request as ready for review June 19, 2026 10:42
@JAORMX
JAORMX merged commit af61fca into main Jun 19, 2026
12 of 13 checks passed
JAORMX added a commit that referenced this pull request Jun 19, 2026
…-convergence arc

Holistic post-merge documentation pass (recon -> fix/enhance -> agent review)
over the per-area surfaces the #120 merge left untouched:

- Architecture pages: ports.md (12 ports incl. SessionLease; the event-sourced
  SessionStore.Load contract; clock-injectability), domain-model.md (EvUserPrompt
  + the full Event field list), observability.md (the 3rd EventLog consumer =
  eventsource.Fold + the two Load implementations), deployment-and-hardening.md
  (#118 govulncheck/dependabot + go 1.26.4), api-surface.md / extensibility.md /
  architecture.md (engine-as-importable-module + stability contract), and the
  modelith model (EventLog now reconstructs user turns, with the replay caveat).
- docs/design/PRODUCTION-READINESS.md: cloud-native Phase 4 (leasing) -> shipped;
  add the engine-convergence (ADR 0036/0037/0038) + supply-chain (#118) rows.
- Skills: cut-release gains the engine/vX.Y.Z submodule-tag mechanics (first tag
  engine/v0.1.0); perf-optimization reflects the two-module (go.work) reality.
- AGENTS.md: EvUserPrompt as the third log-only event (lean) + engine-contract
  See-also. README/usage: importable-engine feature + eventsource.Fold pointer.
- llms.txt regenerated; matlatl --strict green (0 broken/orphan/unreachable).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@JAORMX
JAORMX deleted the feat/atrium-convergence branch July 28, 2026 14:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

e2e-live Run the live e2e suite on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Promote engine/ to its own Go module so external consumers can import the core without the adapter dep-cone

1 participant