|
| 1 | +# Session (2026-12-05T01:11:26.000Z) |
| 2 | + |
| 3 | +**Agent:** Claude Code |
| 4 | +**Title:** The answer of a function that answers for itself carries its execution - built test first, the twin |
| 5 | +of mercury-python's fix and of the engines' fix for their HTTP client |
| 6 | +**User:** the maintainer, in a session of the Java engine's repository: "the language packs have a minimalist |
| 7 | +in-memory event bus. Please also check if this flaw also applies to them."; then, to the question whether to fix |
| 8 | +the flaw in both packs next: "Fix the packs"; then "Open both PRs". |
| 9 | + |
| 10 | +The lead record is the Java repository's log 2026-12-05-004003.md and its thread |
| 11 | +`pack-interceptor-answer-trace-context`. The Python twin's log is 2026-12-05-011101.md in its repository. |
| 12 | + |
| 13 | +## What was found |
| 14 | + |
| 15 | +- **The flaw, by a probe (2026-12-04).** An interceptor receives the raw envelope and answers through its reply |
| 16 | + address; the caller writes the record of a request-response call from the first reply. A reply that a handler |
| 17 | + builds and sends with `registry.sendEvent()` carried nothing of its execution, so the record held no |
| 18 | + `exec_time`, no `span_id` and no annotations. The reply carried no trace either, so a function that received |
| 19 | + it through a reply route ran untraced. |
| 20 | +- **Found at the build, the wire path.** A request-response call that arrives at `/api/event` for an |
| 21 | + interceptor left no record of the function at all: the execution writes none under the `rpc` tag, and the |
| 22 | + host wrote the function's round trip only for a function that returns its answer. A timeout left none either. |
| 23 | +- **Not here:** the Python pack's caller records held their annotations under `notes`; this pack's `emit` |
| 24 | + writes `annotations`, and the reference test passed before the change. |
| 25 | + |
| 26 | +## What was built |
| 27 | + |
| 28 | +- **`bus.ts`:** an interceptor's execution is kept in an `AsyncLocalStorage` beside the trace (`Execution`: the |
| 29 | + trace context, the request's reply address, the start). `stampAnswer` gives an unmarked envelope that is sent |
| 30 | + from inside the execution to that reply address the execution's span, its annotations and the elapsed time, |
| 31 | + and the sender and the trace where it has none. The error envelope of an uncaught exception is built after |
| 32 | + the handler's context has ended, so it is stamped with the execution handed over. A worker starts with a |
| 33 | + clean context, as it does for the trace. |
| 34 | +- **`registry.ts`:** `sendEvent` calls `stampAnswer`, so every reply path goes through it. |
| 35 | +- **`server.ts`:** for a call with the `rpc` tag to an interceptor, the host writes the function's round-trip |
| 36 | + record for a single-shot answer and for a timeout, as `deliver` does for a function that returns its answer. |
| 37 | +- **Not touched, by rule:** an envelope to another route; a stream's segments, which the stream writer stamps; |
| 38 | + the `exec_time` and the sender of an answer that another function wrote. |
| 39 | +- **The pages:** the streaming guide says what the answer carries; the tracing section of the configuration |
| 40 | + guide gains the rule; one entry under Fixed in the CHANGELOG. |
| 41 | + |
| 42 | +## Decisions |
| 43 | + |
| 44 | +- **The maintainer's:** the check, and the fix. |
| 45 | +- **Mine:** |
| 46 | + - **The stamp is in the one place every reply passes,** `sendEvent`, and it reads the execution from the |
| 47 | + asynchronous context, so a handler needs no new call. |
| 48 | + - **Which envelope is the answer:** unmarked, to the request's reply address, sent from inside the |
| 49 | + execution. Anything else is left alone. |
| 50 | + - **The span is the execution's, the time is kept when the envelope has one.** The record is the caller's |
| 51 | + record of its call to this function; a relayed answer says how long its writer took. |
| 52 | + - **The annotations follow this pack's worker:** the reply's own keys win, as in `execute`. The Python |
| 53 | + pack's worker lets the execution's keys win, and its stamp follows that. The difference is older than |
| 54 | + this change and is not closed here. |
| 55 | + - **The marker is read in `bus.ts`:** `event-stream.ts` imports the bus and the registry, so importing |
| 56 | + `streamSignal` into the bus would close a cycle that the registry's default instance cannot start in. |
| 57 | + - **The host's record under the `rpc` tag only,** so a call that is no request-response keeps the one |
| 58 | + record its execution writes; a test holds that. |
| 59 | + - **A declared limit, not engineered:** a handler that returns before its answer is sent. The answer is |
| 60 | + stamped with the time until it was sent; the worker's own record, written for a call with a reply |
| 61 | + route, holds the time until the handler returned. |
| 62 | +- **Seen beside it, not changed:** a single-shot answer relayed by the host keeps the sink's route name in its |
| 63 | + `to` field on the wire, where a stream's envelopes are cleared of it. |
| 64 | + |
| 65 | +## Verification |
| 66 | + |
| 67 | +- `test/interceptor-answer.test.ts`, nine tests with functions that work for 300 ms: seven failed against the |
| 68 | + pack as it was; the reference test of a function that returns its answer and the guard of a call without the |
| 69 | + `rpc` tag passed before and after. |
| 70 | +- `npm test`: 2,945 tests, 2,869 passed, 76 skipped, none failed. |
| 71 | +- `mkdocs build --strict`: exit 0. By script, everything from `## 4.12.31` down equals the tag's text. |
| 72 | +- Not run: a live drive from an engine. |
| 73 | + |
| 74 | +## The commit |
| 75 | + |
| 76 | +- One commit, `57a4d45`, on the branch `fix/interceptor-answer-trace-context` from `main` at `7ac67b4`, seven |
| 77 | + files; no memory file in it. The Python twin is `675ee99` on a branch of the same name in its repository. |
| 78 | +- **Pushed and raised on the maintainer's word ("Open both PRs"),** after the remote was read: `origin/main` |
| 79 | + at the branch's base, no branch of that name, no open pull request. #158, one commit, its title the commit's; |
| 80 | + the Python twin is mercury-python #98, and each names the other. Read once after the push: mergeable, one |
| 81 | + memory check passed, the test and docs jobs running, none failing. Not merged. |
| 82 | +- **Merged by the maintainer:** #158, merge `1dbb20a`, 2026-12-05T01:29:09Z; the next log, 2026-12-05-013504.md, |
| 83 | + reads it on the remote and continues from it. |
| 84 | + |
| 85 | +## Doc Gaps |
| 86 | + |
| 87 | +(none) |
| 88 | + |
| 89 | +## Memory References |
| 90 | + |
| 91 | +- Referenced: |
| 92 | + - `trace-records-engine-parity`: the rule that every traced execution leaves exactly one record and that |
| 93 | + the side which records it mirrors the Java engine decided the stamp, the host's record under the `rpc` |
| 94 | + tag and the guard test; the fact gains the interceptor's answer. |
| 95 | +- Created: (none). |
| 96 | +- Reactivated: |
| 97 | + - `trace-records-engine-parity`: an archive candidate, relied on and extended here. |
| 98 | +- Superseded: (none). |
0 commit comments