instar 1.3.1981 → 1.3.1982

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.
@@ -0,0 +1,139 @@
1
+ # Side-Effects Review — Hook reporter event delivery (real event names and the session id)
2
+
3
+ **Version / slug:** `hook-reporter-event-delivery`
4
+ **Date:** `2026-11-21`
5
+ **Author:** `echo`
6
+ **Second-pass reviewer:** `codex-cli:gpt-6.2-astra (independent, see the section at the end)`
7
+
8
+ ## Summary of the change
9
+
10
+ The built-in command hook reporter read the event name from `hook_event` (Claude Code sends `hook_event_name`) and never
11
+ put the instar session id in the payload, so every Stop, SubagentStart, SubagentStop, TaskCompleted, SessionEnd and
12
+ PreCompact event was stored as `Unknown` and their consumers never ran on the default path. Both copies of the script
13
+ (update path in `PostUpdateMigrator.ts`, new agents in `init.ts`) now read `hook_event_name` first, validate the session
14
+ id once (an invalid id sends nothing), add `instar_session_id` and `instar_session`, and forward six short identifying
15
+ fields bounded in the script. No message text is sent. The `/hooks/events` route applies the native path's bounds to
16
+ those fields with `boundCommandReporterPayload` (new, `NativeHookEvents.ts`) and uses one validated session id for both
17
+ storage and the dispatcher. Spec: `docs/specs/hook-reporter-event-delivery.md`.
18
+
19
+ ## Decision-point inventory
20
+
21
+ - Which events a consumer receives — invariant (Claude Code's own field).
22
+ - Field bounds on the command path — invariant (native bounds reused for the listed fields).
23
+ - Session id sent by the script — invariant (matches the id pattern or is sent nowhere).
24
+
25
+ ## 1. Over-block
26
+
27
+ An agent whose `INSTAR_SESSION_ID` does not match `^[A-Za-z0-9._:-]{1,128}$` now sends no hook events at all (before:
28
+ events were sent with that id). Instar mints ids that match (UUIDs and tmux-safe names), so no real agent is expected to
29
+ hit this; such an id could not be attributed by the route anyway. Fields failing their bound are dropped from the
30
+ payload while the event still arrives: a malformed `agent_id` or `task_id`, an `agent_type` or `instar_session` over
31
+ 128 characters, a relative or over-1024-character `agent_transcript_path`, a `reason` or `trigger` over 64. The route
32
+ now overwrites a caller-supplied `instar_session_id` with its own validated value, or removes it. Consequence for a direct caller that
33
+ supplies the id only in the body (no scoped session and no valid `instar_sid` query): the event is still stored, but
34
+ without a session id, so consumers that require one (Compaction Trigger 1, the practice-fold trigger) do not act on
35
+ it. This is deliberate (the route speaks only for the session it can attribute); the built-in scripts always send the
36
+ query value. No other caller of this route is known in the source tree.
37
+
38
+ ## 2. Under-block
39
+
40
+ Codex bodies without `hook_event_name` and without `tool_name` still arrive as `Unknown` (unchanged). The session
41
+ summary's last-message field and the HelperWatchdog's failure markers from a subagent's final text are not fed by the
42
+ built-in command scripts (they send no message text); they are fed by the native reporter, or by a direct caller of
43
+ `/hooks/events` that posts the text (redacted and cut to its last 200 characters by the route). The practice-fold runner still
44
+ cannot read a handoff reply from the hook; that is a separate spec, and practice folds stay off on Echo until it ships.
45
+
46
+ ## 3. Level-of-abstraction fit
47
+
48
+ Right layer: the defect is in the reporter that every agent runs; the server-side bounds sit beside the native
49
+ projection they mirror. The native reporter (docs/specs/native-hook-events.md) is the long-term path and is unchanged.
50
+
51
+ ## 4. Signal vs authority compliance
52
+
53
+ No authority added. The reporter and route carry events; they decide nothing. They do become new inputs to existing
54
+ consumers that act, exactly as the native path already feeds them: the compaction sentinel (can inject recovery input
55
+ into the compacting session), the pre-compaction flush where enabled (writes durable facts), and the HelperWatchdog
56
+ (alerts behind their own default-off gate). Those consumers' own gates and scopes are unchanged.
57
+
58
+ ## 4b. Judgment-point check
59
+
60
+ No competing-signals decision point is touched; no static heuristic is added.
61
+
62
+ ## 5. Interactions
63
+
64
+ Consumers that start receiving events on the command path, as they already do on the native path: `SubagentTracker`
65
+ (start/stop/session end), Compaction Trigger 1 (scoped to the emitting session; Triggers 2 and 3 already cover
66
+ compaction, and the sentinel dedupes across triggers), the per-instar-session index in `HookEventReceiver` (now
67
+ includes command-path rows), the practice-fold runner's Stop trigger (dev-gated; off on Echo; off on the fleet), and the pre-compaction memory flush
68
+ (`wirePreCompactionFlush`, `PreCompact`): off by default (`preCompactionFlush.enabled`), but ON on Echo, where it has
69
+ been blind on the command path. Where it is on, each delivered `PreCompact` now reaches its flush, which (given an intelligence provider, a
70
+ session id and a readable, non-empty transcript) makes one bounded model call over the transcript
71
+ (`transcriptCharBudget`) and writes at most `maxFactsPerFlush` durable facts when extraction yields any; every delivered `PreCompact` also
72
+ writes an audit entry (including when the flush skips, finds no facts, or the provider errors). Compaction
73
+ Trigger 1 feeds the compaction sentinel, which can inject recovery input into the compacting session (scoped to that
74
+ session; the sentinel already dedupes across its three triggers). Subagent events start the HelperWatchdog's stall
75
+ tracking and logging; its injected alerts stay behind their own default-off gate.
76
+ Codex: `PostToolUse` rows already carried `tool_name` (981 of 981 sampled), so their naming is unchanged; what changes
77
+ is that the dispatcher receives the validated id and the stored row gains session attribution, so per-session
78
+ summaries count these rows;
79
+ its `UserPromptSubmit` rows are named only where Codex sends `hook_event_name` (the test supplies the field; on Echo
80
+ 32 Codex prompt rows were stored named after the local patch, evidence that it does), and no consumer listens for that
81
+ name. The existing wiring test pinning that
82
+ both routes call the shared dispatch function was updated for the validated id variable.
83
+
84
+ ## 6. External surfaces
85
+
86
+ Observable effects beyond storage, where the consuming feature is on: recovery input injected into a compacting
87
+ session, durable memory facts from the pre-compaction flush, and HelperWatchdog alerts (default off). The scripts post
88
+ to `INSTAR_SERVER_URL`, unchanged.
89
+
90
+
91
+ Stored hook-event rows gain names and fields; dashboard session telemetry (`GET /sessions`, summaries) can now show
92
+ command-path subagent and task data. Where the pre-compaction flush is on, durable memory facts are written at
93
+ compaction (bounded, audited). No messages to users, no new routes, no new config. New for direct callers of
94
+ `/hooks/events`: `last_assistant_message` and `task_subject` are now redacted and cut to their last 200 characters
95
+ before storage and dispatch (before this change a direct caller's text was stored as received); the built-in scripts
96
+ send none. Unchanged: a scoped caller's `transcript_path`, `agent_transcript_path` and `cwd` are removed before
97
+ dispatch, so consumers receive no paths from scoped requests.
98
+
99
+ ## 7. Multi-machine posture (Cross-Machine Coherence)
100
+
101
+ Machine-local by design (unchanged): a hook fired by a Claude Code process is delivered over loopback to the server on
102
+ the same host and stored in that machine's `hook-events/`. No user-facing notices, no durable state that moves with a
103
+ topic, no generated URLs. Status surfaces: none new or changed.
104
+
105
+ ## 8. Rollback cost
106
+
107
+ Pure code change. Revert and ship a patch; built-in hooks are overwritten on the next update, so agents return to the
108
+ old script automatically. Stored rows written meanwhile stay valid (extra fields are ignored by older readers). Effects
109
+ of consumers that ran meanwhile are not undone by a revert: durable facts written by an enabled pre-compaction flush stay
110
+ in memory (they are ordinary, audited, removable memory entries), and recovery input already injected stays in those
111
+ sessions' history, as do any HelperWatchdog alerts injected where that gate is on.
112
+
113
+ ## Conclusion
114
+
115
+ Ship. The change restores events that existing consumers were designed for, sends no message text, and is covered by
116
+ an integration test that runs both real script copies against the real server (fails on the old code), plus unit tests:
117
+ `tests/integration/command-hook-reporter.test.ts` (10 tests), `tests/unit/command-hook-reporter-fields.test.ts` (5),
118
+ and the updated wiring assertion in `tests/unit/native-hook-events-consumers.test.ts`. Limits: the init copy is
119
+ compared with the update copy at the wire (byte-identical) rather than also sent through the server, and the
120
+ consumers' own effects (recovery injection, flush writes) are covered by their existing native-path tests, not
121
+ re-exercised end to end here.
122
+
123
+ ## Second-pass review (independent, codex-cli:gpt-6.2-astra, 2026-11-22)
124
+
125
+ Concur with the review.
126
+
127
+ "Both reporters restore event names and attach the instar session ID without forwarding message text. The route uses
128
+ its validated session ID for storage and dispatch, and bounds the new fields before either. The artifact accounts for
129
+ the restored consumer effects, their existing gates, and the changes for direct callers."
130
+
131
+ Earlier runs of the same reviewer raised concerns, each corrected in this artifact before the concurring run: the
132
+ pre-compaction flush consumer and its durable writes and audit entries; recovery injection and watchdog effects that a
133
+ revert cannot undo; direct-caller text redaction being new; scoped callers losing paths; body-only session ids being
134
+ dropped; and a spurious "deleted test suite" that came from comparing against a newer main (the branch was then
135
+ fast-forwarded and the diff taken against the merge base).
136
+
137
+ ## Full-gate metadata correction — 2026-11-22
138
+
139
+ The retained full-gate failure at `000b49408029` was the ladder registry assertion: this spec used `none` for a flagless defect fix, while the established contract requires `not applicable:` followed by a reason. The spec now uses that contract and preserves the rollout sequence. No registry entry is invented and no assertion or runtime behavior changes. This follow-up is Tier 1, two documentation files and no runtime edits. Full-gate requalification remains required.