|
| 1 | +# Session (2026-12-05T01:11:01.000Z) |
| 2 | + |
| 3 | +**Agent:** Claude Code |
| 4 | +**Title:** The answer of a function that answers for itself carries its execution, and a caller's record holds |
| 5 | +its annotations under `annotations` - built test first, the twin 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 Node twin's log is 2026-12-05-011126.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.send_event()` 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 | +- **Found at the build, a second defect.** `EventBus.emit` wrote the annotations of a caller's record under the |
| 24 | + key `notes`. A quality round of 2026-11-16 renamed a parameter that shadowed `annotations` and the key with |
| 25 | + it, two days after the record was introduced, so 4.12.30 and 4.12.31 carry it. Every other record, the Node |
| 26 | + pack and the engines write `annotations`, and the forwarder's span mapping reads that key. |
| 27 | + |
| 28 | +## What was built |
| 29 | + |
| 30 | +- **`bus.py`:** an interceptor's execution is kept in a context variable beside the trace (`_Execution`: the |
| 31 | + trace context, the request's reply address, the start). `stamp_answer` gives an unmarked envelope that is |
| 32 | + sent from inside the execution to that reply address the execution's span, its annotations and the elapsed |
| 33 | + time, and the sender and the trace where it has none. A worker starts with a clean context, as it does for |
| 34 | + the trace. `emit` writes `annotations`. |
| 35 | +- **`registry.py`:** `send_event` calls `stamp_answer`, so every reply path goes through it: a handler's own |
| 36 | + envelope and the error envelope of an uncaught exception. |
| 37 | +- **`server.py`:** for a call with the `rpc` tag to an interceptor, the host writes the function's round-trip |
| 38 | + record for a single-shot answer and for a timeout, as `_deliver` does for a function that returns its answer. |
| 39 | +- **Not touched, by rule:** an envelope to another route; a stream's segments, which the stream writer stamps; |
| 40 | + the `exec_time` and the sender of an answer that another function wrote. |
| 41 | +- **The pages:** the streaming guide names `registry.send_event()` and says what the answer carries; the |
| 42 | + tracing section of the configuration guide gains the rule; two entries under Fixed in the CHANGELOG. |
| 43 | + |
| 44 | +## Decisions |
| 45 | + |
| 46 | +- **The maintainer's:** the check, and the fix. |
| 47 | +- **Mine:** |
| 48 | + - **The stamp is in the one place every reply passes,** `send_event`, and it reads the execution from a |
| 49 | + context variable, so a handler needs no new call and a sync handler on an executor thread is covered. |
| 50 | + - **Which envelope is the answer:** unmarked, to the request's reply address, sent from inside the |
| 51 | + execution. Anything else is left alone. |
| 52 | + - **The span is the execution's, the time is kept when the envelope has one.** The record is the caller's |
| 53 | + record of its call to this function; a relayed answer says how long its writer took, as the Rust |
| 54 | + engine's client leaves it. |
| 55 | + - **The annotations follow this pack's worker:** the execution's keys win, as in `_execute`. The Node |
| 56 | + pack's worker lets the reply's own keys win, and its stamp follows that. The difference is older than |
| 57 | + this change and is not closed here. |
| 58 | + - **The host's record under the `rpc` tag only,** so a call that is no request-response keeps the one |
| 59 | + record its execution writes; a test holds that. |
| 60 | + - **The `notes` key rides in this commit:** the record it repairs is the one the new tests read. It can be |
| 61 | + split out on the maintainer's word. |
| 62 | + - **A declared limit, not engineered:** a handler that returns before its answer is sent. The answer is |
| 63 | + stamped with the time until it was sent; the worker's own record, written for a call with a reply |
| 64 | + route, holds the time until the handler returned. |
| 65 | +- **Seen beside it, not changed:** a single-shot answer relayed by the host keeps the sink's route name in its |
| 66 | + `to` field on the wire, where a stream's envelopes are cleared of it. |
| 67 | + |
| 68 | +## Verification |
| 69 | + |
| 70 | +- `tests/test_interceptor_answer.py`, nine tests with functions that work for 300 ms: eight failed against the |
| 71 | + pack as it was, and the ninth, which guards a call without the `rpc` tag against a second record, passed |
| 72 | + before and after. |
| 73 | +- `pytest`: 3,025 passed, 76 skipped. `ruff check .`: clean. `basedpyright`: 0 errors. |
| 74 | +- `mkdocs build --strict`: exit 0. By script, everything from `## Version 4.12.31` down equals the tag's text. |
| 75 | +- Not run: a live drive from an engine. |
| 76 | + |
| 77 | +## The commit |
| 78 | + |
| 79 | +- One commit, `675ee99`, on the branch `fix/interceptor-answer-trace-context` from `main` at `3d1f701`, seven |
| 80 | + files; no memory file in it. The Node twin is `57a4d45` on a branch of the same name in its repository. |
| 81 | +- **Pushed and raised on the maintainer's word ("Open both PRs"),** after the remote was read: `origin/main` |
| 82 | + at the branch's base, no branch of that name, one open pull request of another branch. #98, one commit, its |
| 83 | + title the commit's; the Node twin is mercury-nodejs #158, and each names the other. Read once after the push: |
| 84 | + mergeable, the memory and docs checks passed, the two test jobs running, none failing. Not merged. |
| 85 | +- **Merged by the maintainer:** #98, merge `df90f71`, 2026-12-05T01:29:19Z; the next log, 2026-12-05-013448.md, |
| 86 | + reads it on the remote and continues from it. |
| 87 | + |
| 88 | +## Doc Gaps |
| 89 | + |
| 90 | +(none) |
| 91 | + |
| 92 | +## Memory References |
| 93 | + |
| 94 | +- Referenced: |
| 95 | + - `trace-records-engine-parity`: the rule that every traced execution leaves exactly one record and that |
| 96 | + the side which records it mirrors the Java engine decided the stamp, the host's record under the `rpc` |
| 97 | + tag and the guard test; the fact gains the interceptor's answer. |
| 98 | +- Created: (none). |
| 99 | +- Reactivated: |
| 100 | + - `trace-records-engine-parity`: an archive candidate, relied on and extended here. |
| 101 | +- Superseded: (none). |
0 commit comments