Skip to content

Commit fa7b2bf

Browse files
authored
Merge pull request #87 from Accenture/feature/primitive-event-bus
Primitive event bus, local PostOffice delivery, and the engines' actuator endpoints
2 parents 31b0499 + 329c931 commit fa7b2bf

19 files changed

Lines changed: 1184 additions & 125 deletions

‎CHANGELOG.md‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,28 @@
22

33
## 0.1.0 (unreleased)
44

5+
- Actuator endpoints `/info`, `/info/routes`, `/env`, `/health` and `/livenessprobe` -
6+
the engines' operational surface, for Kubernetes probes and one-dashboard monitoring
7+
of polyglot installations. Health check functions are normal registered functions
8+
speaking the engines' `type=info` / `type=health` interface contract, listed in
9+
`mandatory.health.dependencies` / `optional.health.dependencies` and called through
10+
the event bus. `/health` answers `UP` (200) / `DOWN` (400); `/livenessprobe` follows
11+
the most recent health outcome.
12+
- `log.format` carries the engines' three presentations: `text` (default), `json`
13+
(pretty-printed) and `compact` (single-line JSONL for log aggregators). A sample
14+
`examples/resources/application.yml` demonstrates the resources convention and the
15+
well-known keys.
16+
- Primitive in-process event bus - the single dispatch pipeline: one FIFO mailbox per
17+
route consumed by `instances` worker loops (the parameter is faithful); RPC deliveries
18+
are ttl-bounded with a dead-work skip; drop-n-forget returns the 202-shape ack. The
19+
HTTP host and the local side of PostOffice are thin ingress adapters over it. No spill
20+
tier and no queue cap by design - back-pressure belongs to the engines' flows/graphs;
21+
a leaf host fails fast by deadline. An in-flight RPC holds the process open (at most
22+
until its deadline); an idle bus holds nothing.
23+
- PostOffice without an endpoint delivers locally (engine semantics): private routes are
24+
callable in-app while the wire keeps its 403; headers pass verbatim; the reply envelope
25+
shape is identical to the remote path.
26+
527
Repository repurposed for the Mercury Composable **polyglot initiative** (August 2026):
628
instead of re-porting the full composable foundation, the fresh start is a lightweight
729
wrapper of the engines' Event-over-HTTP protocol.

‎README.md‎

Lines changed: 64 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ This package is a deliberately **lightweight wrapper of the Event-over-HTTP prot
1111
registered functions,
1212
- a **thin client** (`PostOffice`) to call functions on peer applications the same way,
1313
- the **standard event envelope wire format** codec (language-neutral MsgPack), and
14+
- a **primitive in-process event bus** — the single dispatch pipeline: one FIFO mailbox
15+
per route consumed by `instances` worker loops, and
1416
- the **minimalist utilities** shared with the engines for consistency: configuration
1517
management, logging in the engines' presentation format, and distributed-trace context.
1618

@@ -43,7 +45,7 @@ Run it:
4345

4446
```bash
4547
npm install && npm run build
46-
node dist/src/cli.js app.mjs --port 8087 # or: mercury-serve app.mjs --port 8087
48+
node dist/src/cli.js app.mjs -Drest.server.port=8087 # or: mercury-serve app.mjs -Drest.server.port=8087
4749
```
4850

4951
Call it from a Mercury engine application with two configuration entries and no code —
@@ -78,6 +80,24 @@ status and reply headers). Node.js is non-blocking by nature; handlers may be as
7880
- Functions must be stateless; anything you must keep belongs to the caller's flow model
7981
or state machine.
8082

83+
### Local function calls
84+
85+
`PostOffice` **without an endpoint** delivers through this application's own event bus —
86+
the engines' semantics for an in-app `po` call:
87+
88+
- `isPrivate: true` means exactly what it means in the engines: callable **in-app only**.
89+
Local calls reach private and public routes alike; the HTTP host keeps answering 403
90+
for private targets from the wire.
91+
- `instances` is faithful: each route has one FIFO mailbox consumed by that many worker
92+
loops. RPC waits are bounded by `timeoutMs` (the standard 408 envelope on breach), and
93+
a queued call whose caller already timed out is skipped, never wastefully executed.
94+
- There is **no spill tier and no queue cap** by design: back-pressure belongs to the tier
95+
that owns recovery — the engines' flows and graphs. A leaf host fails fast by deadline
96+
instead of hoarding work.
97+
98+
Local eventing is for simple leaf-side composition. Workflow processing belongs in Event
99+
Script and Knowledge Graph on the engines — that boundary is the architecture.
100+
81101
## Configuration, logging, telemetry
82102

83103
The same conventions as the engines, so a polyglot installation stays uniform:
@@ -86,12 +106,14 @@ The same conventions as the engines, so a polyglot installation stays uniform:
86106
|-----|---------|---------|
87107
| `application.name` | application identity in logs | `application` |
88108
| `rest.server.port` | Event API port | `8085` |
89-
| `log.format` | `text` or `json` | `text` |
109+
| `log.format` | `text`, `json` (pretty-printed) or `compact` (single-line JSONL) | `text` |
90110
| `log.level` | log level (`LOG_LEVEL` env var wins) | `INFO` |
91111

92112
Configuration lives in the `resources` folder, mirroring the engines:
93-
`resources/application.yml` (or `.yaml` / `.properties`), or an explicit `--config` path.
94-
Values support `${ENV_VAR:default}` substitution. Runtime parameter overrides use the
113+
`resources/application.yml` (or `.yaml` / `.properties`) in the working directory or next
114+
to the application file, or an explicit `--config` path — see
115+
[`examples/resources/application.yml`](examples/resources/application.yml) for a worked
116+
sample. Values support `${ENV_VAR:default}` substitution. Runtime parameter overrides use the
95117
same `-D` syntax as the Java engine and the Rust port — checked first on every read
96118
(`appConfig().set(key, value)` does the same programmatically, the `f:setConfig` analog):
97119

@@ -105,6 +127,38 @@ Log lines follow the Java reference engine's pattern for one-aggregation consist
105127
2026-08-22 10:15:30.123 INFO app:12 - Loaded PUBLIC hello.node, instances=10
106128
```
107129

130+
## Actuator endpoints
131+
132+
The host serves the engines' operational endpoints on the same port as `/api/event`, so
133+
Kubernetes probes and dashboards treat a Node.js app exactly like a Java or Rust engine app:
134+
135+
| Endpoint | Purpose |
136+
|----------|---------|
137+
| `GET /info` | app identity, runtime, origin id, start time, uptime |
138+
| `GET /info/routes` | registered routes split by visibility, with instance counts |
139+
| `GET /env` | selected environment variables and configuration parameters |
140+
| `GET /health` | dependency health checks — `UP` (HTTP 200) or `DOWN` (HTTP 400) |
141+
| `GET /livenessprobe` | `OK` while the last health outcome was good, else HTTP 400 |
142+
143+
Configuration keys carry the engines' names: `info.app.version`, `info.app.description`,
144+
`show.env.variables` and `show.application.properties` (opt-in lists — secrets are never
145+
dumped wholesale), and `mandatory.health.dependencies` / `optional.health.dependencies`
146+
(routes of health check functions; optional ones never change the overall status). A
147+
health check function is a normal registered function — usually private — speaking the
148+
engines' interface contract, called through the event bus:
149+
150+
```javascript
151+
preload('demo.health', { isPrivate: true }, async (headers, _body) => {
152+
if (headers.type === 'info') {
153+
return { service: 'demo.service', href: 'http://127.0.0.1' };
154+
}
155+
return 'demo.service is running fine'; // a non-200 reply marks it down
156+
});
157+
```
158+
159+
Kubernetes wiring: point `livenessProbe` at `/livenessprobe` and `readinessProbe` at
160+
`/health`.
161+
108162
## Wire compatibility
109163

110164
The codec implements the
@@ -120,10 +174,12 @@ millisecond precision; binary payloads are `Uint8Array`.
120174

121175
## Scope
122176

123-
This package intentionally contains **no event bus, no flows, no graphs and no
124-
orchestration** — those live in the engines. It provides functions plus the minimalist
125-
foundation utilities, keeping Node.js fast to prototype with while the composable core
126-
guarantees the architecture.
177+
This package intentionally contains **no orchestration: no flows, no graphs, no
178+
persistence, no pub/sub broadcast** — those live in the engines. What it does carry is
179+
deliberately minimal: functions, a primitive in-process event bus (route mailboxes +
180+
workers, RPC and drop-n-forget — nothing more), and the minimalist foundation utilities,
181+
keeping Node.js fast to prototype with while the composable core guarantees the
182+
architecture.
127183

128184
## License
129185

‎examples/demo-app.mjs‎

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
/**
22
* Demo polyglot functions.
33
*
4-
* Run: node dist/src/cli.js examples/demo-app.mjs --port 8087
4+
* Run: node dist/src/cli.js examples/demo-app.mjs
5+
*
6+
* Configuration comes from examples/resources/application.yml (the engines'
7+
* "resources" convention - port 8087, the demo.health dependency, log format);
8+
* override any key with -Dkey=value, e.g. -Drest.server.port=8090.
59
*
610
* Then map a route from a Mercury engine application (event-over-http.yaml):
711
*
@@ -25,3 +29,25 @@ preload('hello.node', { instances: 10 }, async (headers, body) => {
2529
preload('hello.declarative', { instances: 10 }, async (headers, body) => {
2630
return { body, headers, language: 'node.js' };
2731
});
32+
33+
// Private helper - callable in-app only (the HTTP host answers 403 for it).
34+
preload('demo.suffix.helper', { instances: 10, isPrivate: true }, async (_headers, body) => {
35+
return { text: `${body?.text ?? ''}!`, language: 'node.js' };
36+
});
37+
38+
// Local composition: a public function calls a private sibling through the bus.
39+
preload('hello.chain', { instances: 10 }, async (_headers, body) => {
40+
const { PostOffice } = await import('../dist/src/index.js');
41+
const reply = await new PostOffice().request('demo.suffix.helper', body, { timeoutMs: 5000 });
42+
return reply.body;
43+
});
44+
45+
// Health check speaking the engines' interface contract (type=info / type=health).
46+
// Activated for the /health actuator endpoint by mandatory.health.dependencies
47+
// in examples/resources/application.yml (or a -D override).
48+
preload('demo.health', { instances: 5, isPrivate: true }, async (headers, _body) => {
49+
if (headers.type === 'info') {
50+
return { service: 'demo.service', href: 'http://127.0.0.1' };
51+
}
52+
return 'demo.service is running fine';
53+
});

‎examples/resources/application.yml‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Sample configuration - the engines' "resources" convention.
2+
# mercury-serve loads resources/application.yml from the working directory, or from
3+
# the resources folder next to the application file (this one). Any key can be
4+
# overridden at run time with the engines' -D syntax, e.g.:
5+
# node dist/src/cli.js examples/demo-app.mjs -Drest.server.port=8090 -Dlog.format=compact
6+
7+
application.name: 'demo-app'
8+
info.app.description: 'Mercury Composable polyglot demo'
9+
10+
rest.server.port: 8087
11+
12+
# text (default) | json (pretty-printed) | compact (single-line JSONL)
13+
log.format: text
14+
log.level: INFO
15+
16+
# Actuator /health dependencies - routes of health check functions speaking the
17+
# engines' type=info / type=health contract (demo.health in demo-app.mjs).
18+
mandatory.health.dependencies: 'demo.health'
19+
20+
# Opt-in lists for the /env endpoint - nothing is ever dumped wholesale.
21+
show.env.variables: 'LOG_LEVEL'
22+
show.application.properties: 'application.name, rest.server.port'

‎memory/continuity.md‎

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
polyglot initiative: a lightweight Event-over-HTTP function host + thin client, repurposed
1818
August 2026 (the previous full-framework port, up to v4.3.28, lives in git history and on npm)
1919
- **last_enabled:** 2026-08-22
20-
- **last_session:** 2026-08-22 | agent: Claude Code (2026-08-22-175327)
20+
- **last_session:** 2026-08-23 | agent: Claude Code (2026-08-23-031920)
2121
- **last_review:** (none yet)
2222
- **last_invariant_check:** (none yet)
2323
- **repo:** ~/sandbox/mercury-nodejs (origin: github.com/Accenture/mercury-nodejs)
@@ -83,6 +83,36 @@
8383

8484
## Open Threads
8585

86+
- [ ] (feature — **IMPLEMENTED 2026-08-23 on `feature/primitive-event-bus`, commit
87+
`da8ce4c`, tests 39/39; PENDING Eric's PR gate**; lock-step twin of mercury-python
88+
`957d6b7`, where the ratified design record lives: thread-primitive-event-bus)
89+
**Primitive in-process event bus — the single dispatch pipeline.** Per-route FIFO
90+
mailbox + `instances` worker loops (faithful); deliver (ttl → 408, dead-work skip) +
91+
publish (202 ack); host and local PostOffice are thin ingress adapters; `isPrivate`
92+
faithful (in-app callable, wire keeps 403); NO spill tier / NO queue cap — back-pressure
93+
belongs to the engines' flows/graphs. Node-specific ruling: an in-flight RPC's deadline
94+
timer is REFERENCED (pending work holds the process open); an idle bus holds no
95+
handles. Live wire proof: chain → private via bus; wire → private = 403.
96+
<!-- id: thread-primitive-event-bus-node | created: 2026-08-23 | last_used: 2026-08-23 | uses: 1 | tier: working | origin: 2026-08-23-024601 -->
97+
98+
- [ ] (feature — Eric's directive 2026-08-23, **IMPLEMENTED same day on
99+
`feature/primitive-event-bus`, commits `342a854` + `7a8b12c` (twin-alignment round);
100+
python twin `56c002c` + `a674198`; PENDING Eric's PR gate together with the bus**)
101+
**Actuator endpoints — the engines' operational surface for Kubernetes PODs.**
102+
GET `/info`, `/info/routes`, `/env`, `/health`, `/livenessprobe` on the Event API port;
103+
shapes mirror the Rust engine's actuator (the approved minimalist port of Java
104+
`ActuatorServices`), byte-symmetric with python except the runtime block. Health check
105+
functions are normal registered functions speaking the engines' `type=info` /
106+
`type=health` interface contract (Eric's ruling), listed in
107+
`mandatory.health.dependencies` / `optional.health.dependencies` and called through the
108+
event bus; `/health` = UP 200 / DOWN 400 (Java parity); `/livenessprobe` follows the
109+
most recent health outcome. Engine formats verbatim (origin = UTC yyyyMMdd + 32-hex
110+
uuid per the Java reference; elapsedTime boundary quirks pinned). Documented deltas:
111+
no `/info/lib`, no XML, no info cache. `version.ts` = the single TS-side version
112+
source. 10 pins + live demo drives on both wrappers.
113+
Relates [[thread-primitive-event-bus-node]]; serves [[bp-publish-interop-gate]].
114+
<!-- id: thread-actuator-endpoints-node | created: 2026-08-23 | last_used: 2026-08-23 | uses: 1 | tier: working | origin: 2026-08-23-031920 -->
115+
86116
> Mark completed items `- [x]` and leave them in place — the review sweeps them to
87117
> the archive once older than `archive_window` sessions. Don't archive them by hand.
88118
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Session (2026-08-23T02:46:01.000Z)
2+
3+
**Agent:** Claude Code
4+
5+
## Summary
6+
7+
**The primitive in-process event bus implemented — lock-step twin of mercury-python's
8+
`957d6b7` — branch `feature/primitive-event-bus`, commit `da8ce4c`.**
9+
10+
- `bus.ts` (internal): per-route FIFO Mailbox + `instances` worker loops (faithful
11+
parameter; the Semaphore class is gone). `deliver` (RPC, ttl-bounded → 408, dead-work
12+
skip via the settled flag) + `publish` (drop-n-forget, 202-shape ack). Worker owns the
13+
invocation pipeline (runWithTrace, AppException → portable error, execTime, error
14+
logging for un-replied publishes). **Event-loop lifecycle ruling discovered in test:
15+
an in-flight RPC's deadline timer is deliberately REFERENCED (pending work holds the
16+
process open, at most until its deadline); an idle bus holds no handles** — the
17+
unref'd-everything first cut drained the loop mid-test (cancelledByParent).
18+
- HTTP host = thin ingress; PostOffice without an endpoint = local ingress (private
19+
faithful: in-app callable, wire keeps 403); ctor gained the registry parameter.
20+
- Demo chain pair added; README + CHANGELOG document local calls, no-spill/no-cap
21+
posture, the workflow boundary, and the lifecycle ruling.
22+
- Pins: test/bus.test.ts — the same eight as the python twin. Live wire proof green:
23+
`hello.chain` over `/api/event` → `{'text': 'polyglot!', 'language': 'node.js'}`;
24+
direct private → 403.
25+
26+
Follow-up commits: `31c8b0b` (aligned with the python twin's Sonar round — comment
27+
wording + static execute) and `3d866f1` (unshadowed inner PostOffice in the trace-chain
28+
test).
29+
30+
Gates: **tests 39/39** (tsc + node:test). Branch = 3 commits, pending Eric's PR gate.
31+
32+
## Memory References
33+
34+
- referenced: (python-repo id) thread-primitive-event-bus (the ratified design; this repo
35+
implements the twin)
36+
- created: thread-primitive-event-bus-node (tier: working)
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Session (2026-08-23T03:19:20.000Z)
2+
3+
**Agent:** Claude Code
4+
5+
Actuator endpoints on `feature/primitive-event-bus` — the node half of Eric's directive
6+
(wrapper apps deploy as Kubernetes PODs, so they carry the engines' operational surface).
7+
Commits `342a854` (feature) + `7a8b12c` (spelling + origin-test assert, aligning with the
8+
python twin's IDE/Sonar round). Python twin: `56c002c` + `a674198` — the full design
9+
narrative lives in mercury-python's log `2026-08-23-031558` (single-authored, shared
10+
design); this log records the node-side specifics.
11+
12+
## What shipped (node specifics)
13+
14+
- `src/actuator.ts`: GET `/info`, `/info/routes`, `/env`, `/health`, `/livenessprobe`;
15+
shapes mirror the Rust engine's actuator (the approved minimalist port of Java
16+
`ActuatorServices`), byte-symmetric with the python twin except the runtime block
17+
(`{language: "node.js", node: process.version, mercury_composable: VERSION}`).
18+
- Health check functions speak the engines' `type=info` / `type=health` interface
19+
contract through the event bus (Eric's ruling); `mandatory.health.dependencies` /
20+
`optional.health.dependencies` config; UP 200 / DOWN 400; `/livenessprobe` follows the
21+
most recent health outcome. Engine formats verbatim (origin = UTC yyyyMMdd + 32-hex
22+
uuid per the Java reference; elapsedTime boundary quirks pinned).
23+
- `Actuator.handle(pathname, res)` single dispatcher; `server.ts` routes every GET
24+
through it (unknown GET → 404 text). The python twin adopted this dispatcher shape in
25+
its Sonar round — the twins are now structurally symmetric.
26+
- `src/version.ts` becomes the single TS-side version source (`index.ts` re-exports) —
27+
breaks the actuator → index import cycle.
28+
- The pre-release `/health` "OK" scaffolding endpoint is replaced by the real one.
29+
- `examples/demo-app.mjs` gained `demo.health` (private, contract-speaking); README
30+
"Actuator endpoints" section (+ K8s probe wiring); CHANGELOG entry.
31+
32+
## Verification
33+
34+
- 48/48 (`npm test`: tsc + node --test) — 10 actuator pins mirroring the python set
35+
(five shapes, liveness-follows-health, optional-failure-never-downs, teach-message,
36+
elapsed/origin vectors); re-run after the alignment round.
37+
- Live drive: `node dist/src/cli.js examples/demo-app.mjs --port 8398
38+
-Dmandatory.health.dependencies=demo.health` → all five endpoints engine-shaped,
39+
`/health` UP with the full dependency entry, symmetric with python on 8399.
40+
41+
## Follow-up round (Eric's three asks, commit `8ed4266`; python twin `7d5ca6c`)
42+
43+
- `log.format` gains `compact` (single-line JSONL); `json` becomes pretty-printed
44+
(indent 2) — matching the Java engine's JsonAppender/CompactAppender pair (same data
45+
map, two renderings). Full rationale in the python twin's log `2026-08-23-031558`.
46+
- Sample `examples/resources/application.yml` (port 8087, demo.health dependency,
47+
opt-in /env lists) — auto-loaded by the CLI's next-to-app fallback; the demo runs
48+
with plain `node dist/src/cli.js examples/demo-app.mjs`. README quick start teaches
49+
the `-D` override syntax instead of `--port`.
50+
- Live drive through the yml: /health UP under the demo-app identity, /env opted-in
51+
keys, `-Dlog.format=compact` emits JSONL. Gates: 48/48.
52+
53+
## Memory References
54+
55+
- created: thread-actuator-endpoints-node
56+
- referenced: thread-primitive-event-bus-node, bp-publish-interop-gate,
57+
vision-mercury-nodejs

0 commit comments

Comments
 (0)