sensorium-trace 0.18.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (135) hide show
  1. sensorium/__init__.py +0 -0
  2. sensorium/__main__.py +4 -0
  3. sensorium/_c/rt/sensorium_c_rt.c +1446 -0
  4. sensorium/_typescript/package-lock.json +68 -0
  5. sensorium/_typescript/package.json +39 -0
  6. sensorium/_typescript/src/bindings.mjs +792 -0
  7. sensorium/_typescript/src/cap.mjs +227 -0
  8. sensorium/_typescript/src/capabilities.mjs +40 -0
  9. sensorium/_typescript/src/dbg.mjs +348 -0
  10. sensorium/_typescript/src/escape.mjs +351 -0
  11. sensorium/_typescript/src/focus.mjs +135 -0
  12. sensorium/_typescript/src/hook.mjs +127 -0
  13. sensorium/_typescript/src/index.mjs +1 -0
  14. sensorium/_typescript/src/naming.mjs +63 -0
  15. sensorium/_typescript/src/positions.mjs +37 -0
  16. sensorium/_typescript/src/probe.mjs +246 -0
  17. sensorium/_typescript/src/qualname.mjs +236 -0
  18. sensorium/_typescript/src/redact.mjs +711 -0
  19. sensorium/_typescript/src/register.mjs +15 -0
  20. sensorium/_typescript/src/resolve.mjs +260 -0
  21. sensorium/_typescript/src/rt.mjs +798 -0
  22. sensorium/_typescript/src/setup.mjs +11 -0
  23. sensorium/_typescript/src/tally.mjs +164 -0
  24. sensorium/_typescript/src/tasks.mjs +175 -0
  25. sensorium/_typescript/src/transform.mjs +800 -0
  26. sensorium/_typescript/src/vite.mjs +99 -0
  27. sensorium/c/__init__.py +8 -0
  28. sensorium/c/cc.py +612 -0
  29. sensorium/c/cli.py +60 -0
  30. sensorium/c/convert.py +669 -0
  31. sensorium/c/decode.py +300 -0
  32. sensorium/c/driver.py +365 -0
  33. sensorium/c/dwarf.py +706 -0
  34. sensorium/c/format.py +271 -0
  35. sensorium/c/pkg.py +187 -0
  36. sensorium/c/plan.py +277 -0
  37. sensorium/cli.py +140 -0
  38. sensorium/driver.py +47 -0
  39. sensorium/exit.py +33 -0
  40. sensorium/invocations.py +83 -0
  41. sensorium/limits.py +253 -0
  42. sensorium/mcp/__init__.py +0 -0
  43. sensorium/mcp/audit.py +162 -0
  44. sensorium/mcp/child.py +240 -0
  45. sensorium/mcp/cmd.py +101 -0
  46. sensorium/mcp/jsonrpc.py +172 -0
  47. sensorium/mcp/result.py +187 -0
  48. sensorium/mcp/schema.py +390 -0
  49. sensorium/mcp/server.py +493 -0
  50. sensorium/mcp/tools.py +299 -0
  51. sensorium/paths.py +80 -0
  52. sensorium/query/__init__.py +0 -0
  53. sensorium/query/caps.py +150 -0
  54. sensorium/query/dbg_dialects.py +64 -0
  55. sensorium/query/diff_cmd.py +748 -0
  56. sensorium/query/diff_notes.py +117 -0
  57. sensorium/query/exceptions_c.py +263 -0
  58. sensorium/query/exceptions_cmd.py +788 -0
  59. sensorium/query/exceptions_group.py +571 -0
  60. sensorium/query/exceptions_invocation.py +487 -0
  61. sensorium/query/exceptions_rust.py +683 -0
  62. sensorium/query/exceptions_typescript.py +688 -0
  63. sensorium/query/expr.py +606 -0
  64. sensorium/query/failures_cmd.py +306 -0
  65. sensorium/query/flow_cmd.py +778 -0
  66. sensorium/query/flow_report.py +128 -0
  67. sensorium/query/flow_values.py +195 -0
  68. sensorium/query/fmt.py +280 -0
  69. sensorium/query/frame_cmd.py +237 -0
  70. sensorium/query/grep_cmd.py +156 -0
  71. sensorium/query/help.py +18 -0
  72. sensorium/query/info_cmd.py +527 -0
  73. sensorium/query/info_rust.py +214 -0
  74. sensorium/query/info_typescript.py +261 -0
  75. sensorium/query/js_inspect.py +394 -0
  76. sensorium/query/moves.py +254 -0
  77. sensorium/query/redact_cmd.py +304 -0
  78. sensorium/query/refocus_cmd.py +661 -0
  79. sensorium/query/refocus_env.py +493 -0
  80. sensorium/query/refocus_facts.py +269 -0
  81. sensorium/query/refocus_licence.py +187 -0
  82. sensorium/query/refocus_report.py +327 -0
  83. sensorium/query/refocus_rust.py +537 -0
  84. sensorium/query/refocus_threads.py +197 -0
  85. sensorium/query/refocus_typescript.py +756 -0
  86. sensorium/query/refocus_world.py +666 -0
  87. sensorium/query/runs_cmd.py +213 -0
  88. sensorium/query/rust_debug.py +176 -0
  89. sensorium/query/sites.py +171 -0
  90. sensorium/query/tree_cmd.py +511 -0
  91. sensorium/query/tree_threads.py +168 -0
  92. sensorium/query/vocab.py +723 -0
  93. sensorium/query/watch_cmd.py +657 -0
  94. sensorium/record/__init__.py +0 -0
  95. sensorium/record/boot.py +797 -0
  96. sensorium/record/boot_io.py +141 -0
  97. sensorium/record/budget.py +135 -0
  98. sensorium/record/capture.py +433 -0
  99. sensorium/record/children.py +755 -0
  100. sensorium/record/children_merge.py +179 -0
  101. sensorium/record/elide.py +55 -0
  102. sensorium/record/fingerprint.py +26 -0
  103. sensorium/record/thread_starts.py +261 -0
  104. sensorium/record/tracer.py +798 -0
  105. sensorium/record/tracer_exc.py +199 -0
  106. sensorium/record/tracer_frames.py +618 -0
  107. sensorium/redact.py +304 -0
  108. sensorium/redact_content.py +156 -0
  109. sensorium/redact_key.py +317 -0
  110. sensorium/redact_store.py +502 -0
  111. sensorium/redact_values.py +433 -0
  112. sensorium/store/__init__.py +0 -0
  113. sensorium/store/db.py +284 -0
  114. sensorium/store/gc.py +360 -0
  115. sensorium/store/payloads.py +69 -0
  116. sensorium/store/reader.py +438 -0
  117. sensorium/store/writer.py +283 -0
  118. sensorium/ts/__init__.py +10 -0
  119. sensorium/ts/build.py +783 -0
  120. sensorium/ts/cli.py +130 -0
  121. sensorium/ts/driver.py +472 -0
  122. sensorium/ts/focus.py +146 -0
  123. sensorium/ts/harness.py +314 -0
  124. sensorium/ts/ingest.py +380 -0
  125. sensorium/ts/invocation.py +252 -0
  126. sensorium/ts/pkg.py +167 -0
  127. sensorium/ts/redaction.py +64 -0
  128. sensorium/ts/spool.py +168 -0
  129. sensorium/ts/truncation.py +81 -0
  130. sensorium/ts/wrapper.py +255 -0
  131. sensorium_trace-0.18.2.dist-info/METADATA +245 -0
  132. sensorium_trace-0.18.2.dist-info/RECORD +135 -0
  133. sensorium_trace-0.18.2.dist-info/WHEEL +4 -0
  134. sensorium_trace-0.18.2.dist-info/entry_points.txt +3 -0
  135. sensorium_trace-0.18.2.dist-info/licenses/LICENSE +21 -0
@@ -0,0 +1,487 @@
1
+ """`exceptions <invocation-id>`: one answer for a whole invocation (N6).
2
+
3
+ WHY A WHOLE INVOCATION IS A UNIT
4
+ --------------------------------
5
+ `cargo sensorium test --workspace` writes one trace per PROCESS. The E6''''
6
+ record's adjudicator therefore asked this command 144 separate questions and
7
+ added the answers up by hand -- 144 headers, 144 tallies, and a per-site
8
+ table built with a text editor -- to learn one thing: what became of the
9
+ workspace's `Err`s. The question was never about a process. `runs` already
10
+ prints the invocation id above the group it names, so that id is the ref
11
+ this mode takes: a spelling the reader has already seen, for a unit they
12
+ already think in.
13
+
14
+ WHAT MERGING MEANS HERE, AND WHAT IT REFUSES TO MEAN
15
+ ----------------------------------------------------
16
+ Shapes merge across processes on the SAME key `exceptions_group` uses
17
+ within one -- the disposition, the site the verdict is about as
18
+ `(file, line, qualname)`, the verdict's own words once ids are masked. The
19
+ FILE is in that key because of this mode: within one process two helpers
20
+ sharing a qualname and a line are rare, and across 144 they are not. The
21
+ first measurement keyed on the printed `qualname L<line>` and merged two
22
+ `sandbox L42`s that were in different test files, booking 18 chains under
23
+ one of them and printing the other nowhere (ruling R-G12). Where two shapes
24
+ of ONE answer still print the same site text, each verdict now names its
25
+ file. Nothing else is merged: the block that is
26
+ printed is the FIRST member's first chain, rendered by the one renderer
27
+ both modes share, so every printed sentence stays true of a NAMED chain in
28
+ a NAMED process. The bracket is what changes. Within one trace it lists the
29
+ group's sibling event ids; across an invocation those ids belong to traces
30
+ the reader did not open, and a list of them would read as one sequence when
31
+ it is eleven. So it names the spread and one entry point instead:
32
+ `[×303 over 11 processes: first e1204 in 20260905-091125-fc7302, +302]`.
33
+
34
+ WHAT IS COUNTED ONCE AND WHAT IS COUNTED PER PROCESS
35
+ -----------------------------------------------------
36
+ The tally is the sum of the members' chain tallies, so it stays comparable
37
+ line-for-line with every per-process record already written. The panics are
38
+ summed for the same reason. The `partial` rows are the UNION, each row
39
+ naming its own process -- a site the reader cannot go and look at is a
40
+ fact they cannot use. And every member that never finalized is NAMED above
41
+ the answer: an unfinalized process is a gap in the whole, and a header that
42
+ counted it as "with none" would report where a recording stopped as
43
+ something a program did.
44
+
45
+ WHAT THIS MODE REFUSES
46
+ ----------------------
47
+ `--after` takes an event id, and an event id belongs to one process; ids
48
+ from 144 processes are not one sequence to resume in. Paging here raises
49
+ `--limit`, which counts shapes.
50
+
51
+ A member whose recorder declares `err_flow: false` refuses the WHOLE
52
+ answer, naming it: a merged count that silently dropped one process would
53
+ be a number missing an unknown amount of the program, which is worse than
54
+ no number.
55
+
56
+ TWO LANGUAGES, ONE GROUPER
57
+ --------------------------
58
+ Both drivers write `meta.invocation`: `cargo sensorium test --workspace`
59
+ writes one trace per test binary, and `sensorium ts run -- npx vitest run`
60
+ one per forked worker. So this mode dispatches PER MEMBER on `meta.lang`
61
+ (`LANGUAGES` below) -- the language's index, its rules, its renderer and
62
+ its tally order -- and the merge itself is `exceptions_group.group_units`,
63
+ which is written about units and sites and knows no language at all.
64
+
65
+ A member of any OTHER language refuses by name: what it is missing is a
66
+ rule, not a record, and the capability sentence would name the wrong
67
+ repair. A member set of TWO languages refuses likewise. One invocation is
68
+ one driver's, so that set cannot exist -- but the refusal is written rather
69
+ than assumed, because the alternative to an impossible-case refusal is an
70
+ impossible-case answer, judged by one language's rules over another's
71
+ records.
72
+ """
73
+ import shlex
74
+ from dataclasses import dataclass, field
75
+ from pathlib import Path
76
+
77
+ from sensorium import paths
78
+ from sensorium.exit import ANSWERED, BAD_CALL, NEGATIVE, UNSETTLED
79
+ from sensorium.query import (caps, exceptions_c, exceptions_group,
80
+ exceptions_rust, exceptions_typescript, runs_cmd)
81
+ from sensorium.query.exceptions_group import (Shape, collisions, group_units,
82
+ print_shape)
83
+ from sensorium.query.fmt import more_note
84
+ from sensorium.store.reader import Trace
85
+
86
+
87
+ @dataclass(frozen=True)
88
+ class Language:
89
+ """Everything this mode needs to know about a member, in ONE row.
90
+
91
+ Four lookup tables keyed on `lang` would be four places to forget when
92
+ a fourth recorder arrives; one row is a thing a reader can check is
93
+ complete. Nothing here is decided by sniffing a key: `meta["lang"]` is
94
+ the whole of the dispatch (R27a), as it is in `runs` and `info`.
95
+ """
96
+ index: object # (trace) -> that language's Index
97
+ units: object # (index) -> the units to judge, in origin order
98
+ classify: object # (trace, unit, index) -> Disposition
99
+ render: object # `exceptions_group.Renderer`
100
+ #: The noun the `raised (...)` line counts, singular and plural.
101
+ #: Rust's pair is deliberately the SAME word twice: that line has read
102
+ #: `N chains` since it shipped, two acceptance records quote it, and
103
+ #: correcting `1 chains` is a change to a Rust answer that this task --
104
+ #: which promised to move no byte of one -- is not the place for.
105
+ raised: tuple
106
+ #: What a member HAS, and what a member's cut therefore hides.
107
+ held: str
108
+
109
+
110
+ LANGUAGES = {
111
+ "rust": Language(exceptions_rust.Index, lambda idx: idx.chains,
112
+ exceptions_rust.classify, exceptions_group.RUST,
113
+ ("chains", "chains"), "Err chains"),
114
+ "typescript": Language(exceptions_typescript.Index,
115
+ lambda idx: idx.units,
116
+ exceptions_typescript.classify,
117
+ exceptions_group.TYPESCRIPT,
118
+ ("raise", "raises"), "throws"),
119
+ "c": Language(exceptions_c.Index, lambda idx: idx.units,
120
+ exceptions_c.classify, exceptions_group.C,
121
+ ("raise", "raises"), "signal raises"),
122
+ }
123
+
124
+
125
+ class InvocationLookupError(paths.TraceLookupError):
126
+ """A ref that named no trace and no invocation either.
127
+
128
+ A subclass of `TraceLookupError` on purpose: `cli.main` already renders
129
+ that one as `error: <sentence>` on stderr with exit 2, which is exactly
130
+ what a ref this command cannot resolve deserves. A second rendering
131
+ would be a second way for one condition to look, and the reader would
132
+ have to learn both.
133
+ """
134
+
135
+
136
+ def resolve_invocation(ref: str) -> tuple[str, list[Path]]:
137
+ """`(invocation id, member paths in file-name order)`.
138
+
139
+ Every trace whose `meta.invocation` equals `ref`, or -- when none does
140
+ -- whose invocation uniquely STARTS with it. Exact wins over prefix, so
141
+ an invocation id that happens to prefix another's still answers for
142
+ itself.
143
+
144
+ Opens every trace in the store once: the invocation is recorded inside
145
+ each trace and nothing indexes it, which is the honest cost of not
146
+ keeping a second, drift-prone table of what is already in the files.
147
+
148
+ Member order is trace file-name order -- the order `runs` prints, and
149
+ the order that decides which member's block is the one printed for a
150
+ merged shape.
151
+ """
152
+ files = sorted(paths.traces_dir().glob("*.db"), key=lambda p: p.name)
153
+ invs = []
154
+ for f in files:
155
+ inv = Trace.open(f).meta.get("invocation")
156
+ invs.append(inv if isinstance(inv, str) else None)
157
+ exact = [f for f, inv in zip(files, invs) if inv == ref]
158
+ if exact:
159
+ return ref, exact
160
+ ids = sorted({inv for inv in invs if inv and inv.startswith(ref)})
161
+ if len(ids) > 1:
162
+ # Answering for either would be a guess about which question was
163
+ # asked; the ids are named so the next call can pick one.
164
+ raise InvocationLookupError(f"{ref!r} is ambiguous: "
165
+ + ", ".join(ids))
166
+ if not ids:
167
+ # Both namespaces were looked in, and the sentence says so: a
168
+ # reader told only "no trace matches" would not know an invocation
169
+ # id was also tried.
170
+ raise InvocationLookupError(f"no trace or invocation matches {ref!r}")
171
+ return ids[0], [f for f, inv in zip(files, invs) if inv == ids[0]]
172
+
173
+
174
+ @dataclass
175
+ class Merged:
176
+ """One shape, seen across an invocation.
177
+
178
+ `shape` is the FIRST member's -- the block that is printed, and whose
179
+ vary sets and CHAINS are unioned with the others' as they arrive, so a
180
+ merged shape is internally consistent: `len(shape.chains)` is the count
181
+ the bracket prints. `trace` and `run_id` are the first member's,
182
+ because the block's ids are its ids.
183
+
184
+ Its `chains` therefore span traces, and `exceptions_group.bracket` must
185
+ never be called on one: that bracket LISTS event ids, and ids from
186
+ different processes are not one sequence. `bracket(merged)` below is
187
+ this mode's, and it names processes instead.
188
+ """
189
+ shape: Shape
190
+ trace: object
191
+ run_id: str
192
+ processes: list = field(default_factory=list) # run ids, member order
193
+
194
+ @property
195
+ def n(self) -> int:
196
+ """Chains, over every member: the shape's own list, so there is no
197
+ second count here to drift away from it."""
198
+ return len(self.shape.chains)
199
+
200
+
201
+ def _processes(n: int) -> str:
202
+ return f"{n} process" if n == 1 else f"{n} processes"
203
+
204
+
205
+ def _units(n: int, words: tuple) -> str:
206
+ """`2 raises` / `1 raise` -- what the `raised (...)` line counts, in the
207
+ members' own language's noun. A count that reads `1 raises` is the tell
208
+ that a number was printed by a template rather than said by anyone."""
209
+ return f"{n} {words[0] if n == 1 else words[1]}"
210
+
211
+
212
+ def _shapes(n: int) -> str:
213
+ """What the header counts, in the noun that says what it is.
214
+
215
+ It read `N swallowing sites`, and N is the number of printed BLOCKS --
216
+ merged shapes whose disposition is swallowed. The two are not equal on
217
+ a real sweep: the E6″′ record has 91 and 98 distinct sites where
218
+ this header printed 103 and 105, and R-G12 widened that gap by making
219
+ the addressing right. The phrase was frozen through both measurements
220
+ deliberately and is free to correct now. `shape` is this command's own
221
+ word for a merged block, printed already by the continuation note. It
222
+ also said `sites` at N=1.
223
+ """
224
+ return f"{n} swallowed shape" if n == 1 else f"{n} swallowed shapes"
225
+
226
+
227
+ def _member_refusal(run_id: str, trace, head) -> str | None:
228
+ """Why this member's record cannot be judged, or None. `head` is the
229
+ `(run id, trace)` of the FIRST member, which the set is one of.
230
+
231
+ Language first: what a member of an unruled language is missing is a
232
+ rule, not a record, and the capability sentence would name the wrong
233
+ repair. Then the SET's own coherence, before anything any one member
234
+ declares: a mixed set is not a member's problem to report.
235
+ """
236
+ if trace.lang not in LANGUAGES:
237
+ return (f"REFUSED: exceptions across an invocation is defined for "
238
+ f"Rust and TypeScript traces; member {run_id} is "
239
+ f"{trace.lang}, which is not ruled")
240
+ if trace.lang != head[1].lang:
241
+ # `runs` groups one invocation and one driver writes it, so this
242
+ # cannot happen -- and if it ever did, judging it would mean
243
+ # reading one language's records by another language's rules.
244
+ return (f"REFUSED: an invocation is one driver's; member {run_id} "
245
+ f"is {trace.lang} and {head[0]} is {head[1].lang}")
246
+ if trace.lang == "c":
247
+ # `err_flow` is the Err and throw record Rust and TypeScript gate
248
+ # on. A C crash is a signal RAISE, judged whether or not that
249
+ # capability was declared.
250
+ return None
251
+ refusal = caps.require(trace, "err_flow", "exceptions")
252
+ return f"REFUSED: {refusal} (member {run_id})" if refusal else None
253
+
254
+
255
+ def _merge(members, lang: Language) -> tuple[list[Merged], dict, dict]:
256
+ """`(merged shapes in first-appearance order, summed unit tally, summed
257
+ reason tally)`.
258
+
259
+ `members` is `(run_id, trace, index)` in member order. The first member
260
+ to show a key owns the printed block; every later member adds its
261
+ units to the count, its run id to the processes, and its differences
262
+ to the vary sets -- which is what makes `origins: 7 distinct` mean
263
+ "across this invocation" rather than "in whichever process printed".
264
+
265
+ One key space, because the set is ONE language: `Shape.key` carries no
266
+ `lang`, and it does not need to.
267
+
268
+ The reasons are summed exactly as the dispositions are, and for the
269
+ same reason: an adjudicator asking what this invocation could not
270
+ settle wants ONE number per reason, not 144 of them to add up. A Rust
271
+ member contributes nothing to it -- the field is TypeScript's -- so a
272
+ Rust answer grows no line.
273
+ """
274
+ merged: list[Merged] = []
275
+ by_key: dict[tuple, Merged] = {}
276
+ tally: dict[str, int] = {}
277
+ reasons: dict[str, int] = {}
278
+ for run_id, trace, idx in members:
279
+ shapes, member_tally, member_reasons = group_units(
280
+ trace, lang.units(idx), idx, lang.classify, lang.render)
281
+ for tag, n in member_tally.items():
282
+ tally[tag] = tally.get(tag, 0) + n
283
+ for reason, n in member_reasons.items():
284
+ reasons[reason] = reasons.get(reason, 0) + n
285
+ for shape in shapes:
286
+ m = by_key.get(shape.key)
287
+ if m is None:
288
+ m = Merged(shape=shape, trace=trace, run_id=run_id)
289
+ by_key[shape.key] = m
290
+ merged.append(m)
291
+ else:
292
+ m.shape.chains.extend(shape.chains)
293
+ m.shape.origins |= shape.origins
294
+ m.shape.messages |= shape.messages
295
+ m.shape.details |= shape.details
296
+ m.shape.hops |= shape.hops
297
+ m.processes.append(run_id)
298
+ return merged, tally, reasons
299
+
300
+
301
+ def bracket(m: Merged) -> str:
302
+ """` [×303 over 11 processes: first e1204 in <run-id>, +302]`.
303
+
304
+ No id list: the members' origin ids belong to eleven different traces,
305
+ and printing them together would read as one sequence a reader could
306
+ page through. What is named instead is where to START -- the process
307
+ and the id of the block printed above -- and how many more there are.
308
+
309
+ A shape seen once still names its process. Within one trace a group of
310
+ one needs no bracket, because the process is the ref the reader typed;
311
+ here it is one of many, and a block that did not say which would be an
312
+ accusation nobody could go and check.
313
+ """
314
+ if m.n == 1:
315
+ return f" [in {m.run_id}]"
316
+ return (f" [×{m.n} over {_processes(len(m.processes))}: first "
317
+ f"e{m.shape.first.origin.id} in {m.run_id}, +{m.n - 1}]")
318
+
319
+
320
+ def _print_partial(members) -> None:
321
+ """The DISTINCT unreachable `?` sites across the invocation, in
322
+ first-appearance order, each row saying where it was seen.
323
+
324
+ A union, not a concatenation (ruling R-G10). `meta.partial` holds, per
325
+ process, the sites of every unit that process LINKED, so in a workspace
326
+ each shared crate's unreachable sites are repeated in every trace that
327
+ links it: concatenating 144 members announced `partial: 432 ?-sites`
328
+ for 3 distinct ones, showed 3 rows all from the first member, and hid
329
+ 429 copies. The count a reader needs is how many PLACES the recorder
330
+ could not watch.
331
+
332
+ Where each site was seen still matters, so a site carried by exactly
333
+ one process names it -- that is the trace to go and read -- and one
334
+ carried by several says how many, rather than listing run ids that
335
+ would outgrow the row.
336
+ """
337
+ rows, seen_at = [], []
338
+ at: dict[tuple, int] = {}
339
+ for run_id, _trace, idx in members:
340
+ for row in (idx.partial or []):
341
+ key = (row.get("qualname"), row.get("file"), row.get("line"),
342
+ row.get("reason"))
343
+ i = at.get(key)
344
+ if i is None:
345
+ at[key] = len(rows)
346
+ rows.append(row)
347
+ seen_at.append([run_id])
348
+ elif seen_at[i][-1] != run_id:
349
+ seen_at[i].append(run_id)
350
+ wheres = [runs[0] if len(runs) == 1 else _processes(len(runs))
351
+ for runs in seen_at]
352
+ # The hint names the FIRST hidden row's process: it is the one a reader
353
+ # continuing the list opens next, and it is a run id `info` takes.
354
+ hidden = seen_at[exceptions_rust.PARTIAL_SHOWN:]
355
+ hint = f"sensorium info {hidden[0][0]}" if hidden else "sensorium info"
356
+ exceptions_rust._print_partial(rows, wheres, hint)
357
+
358
+
359
+ def _ambient(members, lang: Language) -> None:
360
+ """What the RECORDING was not watching, summed over the members --
361
+ each language's own, and nothing standing in for what a recorder does
362
+ not produce.
363
+
364
+ Rust: the union of the `?` sites the transformer could not reach, and
365
+ the panic events. TypeScript: the rejections the process itself
366
+ reported unhandled, which carry no site and so open no block (R1) --
367
+ counted here or counted nowhere, because a merged answer that dropped
368
+ them would be the only place they are said at all.
369
+ """
370
+ if lang is LANGUAGES["rust"]:
371
+ _print_partial(members)
372
+ exceptions_rust._print_panics(
373
+ sum(idx.panics for _r, _t, idx in members))
374
+ return
375
+ if lang is LANGUAGES["c"]:
376
+ # No `?` sites and no unhandled rejections. The TypeScript count
377
+ # below reads `idx.rejections`, which a C index does not carry.
378
+ return
379
+ rejections = sum(len(idx.rejections) for _r, _t, idx in members)
380
+ if rejections:
381
+ print(f"unhandled rejections: {rejections}")
382
+
383
+
384
+ def _header(members, lang: Language) -> int:
385
+ """The invocation line, the INCOMPLETE members and the ambient counts.
386
+ Returns how many members recorded at least one unit."""
387
+ with_units = sum(1 for _r, _t, idx in members if lang.units(idx))
388
+ n = len(members)
389
+ # The invocation line is `runs`' own, extended with the counts: one
390
+ # spelling of "which command was this", not two. The language travels
391
+ # with the meta because `runs` chooses the header's SHAPE by it and
392
+ # never by sniffing a key (R27a), and passing the trace's own `lang`
393
+ # keeps that a fact about the trace rather than an assumption here.
394
+ head = members[0][1]
395
+ print(f"{runs_cmd._header(head.meta, head.lang)} -- {_processes(n)}, "
396
+ f"{with_units} with {lang.held}, {n - with_units} with none")
397
+ for run_id, _trace, idx in members:
398
+ if idx.incomplete:
399
+ # Named BEFORE anything about units: what this process did
400
+ # after its cut is not below, and a reader who met that fact
401
+ # after the answer would have already believed the answer.
402
+ print(f"INCOMPLETE: {run_id} never finalized -- its {lang.held} "
403
+ "after the cut are not below")
404
+ _ambient(members, lang)
405
+ return with_units
406
+
407
+
408
+ def run(args, invocation_id: str, members: list) -> int:
409
+ """`exceptions` over one invocation's traces. `exceptions_cmd.run` has
410
+ validated `--limit` and resolved the ref; `--after` is parsed there too
411
+ but refused here, before a single member is opened."""
412
+ if args.after:
413
+ # An event id is minted per process. Resuming after one would mean
414
+ # "after this id in every trace", which is not a place.
415
+ print(f"--after names an event of one process; this answer spans "
416
+ f"{_processes(len(members))} -- page with --limit")
417
+ return BAD_CALL
418
+ opened = [(p.stem, Trace.open(p)) for p in members]
419
+ for run_id, trace in opened:
420
+ refusal = _member_refusal(run_id, trace, opened[0])
421
+ if refusal:
422
+ # Before any classification, and the whole answer: a merged
423
+ # count is only as honest as its least honest member.
424
+ print(refusal)
425
+ return UNSETTLED
426
+ # Every member is this language: the loop above refused the set that
427
+ # was not, so the row can be taken from the first member and used for
428
+ # all of them.
429
+ lang = LANGUAGES[opened[0][1].lang]
430
+ indexed = [(run_id, t, lang.index(t)) for run_id, t in opened]
431
+ with_chains = _header(indexed, lang)
432
+ incomplete = any(idx.incomplete for _r, _t, idx in indexed)
433
+ if not with_chains:
434
+ # `caps.none_status`, applied to a set: "none" only where every
435
+ # recording is whole. One member that stopped mid-flight makes the
436
+ # invocation's silence a gap rather than an answer.
437
+ print(f"no exceptions recorded across {_processes(len(indexed))}")
438
+ return UNSETTLED if incomplete else NEGATIVE
439
+
440
+ merged, tally, reasons = _merge(indexed, lang)
441
+ chains = sum(m.n for m in merged)
442
+ shapes = sum(1 for m in merged if m.shape.tag == "swallowed")
443
+ # C has no swallow. The clause stays on Rust and TypeScript, byte for
444
+ # byte; printing it for a signal would claim a disposition that does
445
+ # not exist.
446
+ body = (f"raised ({_units(chains, lang.raised)} over "
447
+ f"{_processes(with_chains)}")
448
+ if lang is not LANGUAGES["c"]:
449
+ body += f", {_shapes(shapes)}"
450
+ print(body + "):")
451
+ # Over the whole ANSWER, never per member: the collision this mode
452
+ # exists to have caught is between processes -- `sandbox L42` in two
453
+ # test files, one process each -- so a set computed inside a member
454
+ # would be empty in exactly the case that needs it (R-G12).
455
+ colliding = collisions([m.shape for m in merged])
456
+ shown = 0
457
+ for m in merged:
458
+ if shown >= args.limit:
459
+ break
460
+ print_shape(m.trace, m.shape, bracket(m), m.shape.key in colliding)
461
+ shown += 1
462
+ # The members' language's order, which is what the tally is a tally
463
+ # in: no disposition of one recorder appears in another's line.
464
+ print("dispositions: " + ", ".join(f"{t} {tally[t]}"
465
+ for t in lang.render.tag_order
466
+ if tally.get(t)))
467
+ # §2.3, summed: under the tally it explains, printed once for the whole
468
+ # invocation, and absent where nothing was ambiguous -- the same three
469
+ # rules single-run mode prints it by, spelled a second time here for
470
+ # the same reason the `dispositions:` line above is (P7: the grouper
471
+ # prints blocks; a tally belongs to the mode that summed it).
472
+ # `REASON_ORDER` is TypeScript's table and there is no other: a Rust
473
+ # member contributes no reason at all, so this dict is empty and the
474
+ # line is never reached for one.
475
+ if reasons:
476
+ print("ambiguous by reason: " + ", ".join(
477
+ f"{r} {reasons[r]}"
478
+ for r in exceptions_typescript.REASON_ORDER if reasons.get(r)))
479
+ # Paging raises the limit, as in single-run mode, and the ref carried
480
+ # through is the INVOCATION's: a continuation that named one member
481
+ # would answer a smaller question than the one asked.
482
+ note = more_note(len(merged), shown,
483
+ f"sensorium exceptions {shlex.quote(invocation_id)} "
484
+ f"--limit {len(merged)}")
485
+ if note:
486
+ print(note)
487
+ return ANSWERED