instar 1.3.72 → 1.3.74

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 (38) hide show
  1. package/dist/commands/server.d.ts.map +1 -1
  2. package/dist/commands/server.js +24 -4
  3. package/dist/commands/server.js.map +1 -1
  4. package/dist/core/SleepWakeDetector.d.ts +83 -5
  5. package/dist/core/SleepWakeDetector.d.ts.map +1 -1
  6. package/dist/core/SleepWakeDetector.js +117 -11
  7. package/dist/core/SleepWakeDetector.js.map +1 -1
  8. package/dist/core/UsherActedCorrelator.d.ts +96 -0
  9. package/dist/core/UsherActedCorrelator.d.ts.map +1 -0
  10. package/dist/core/UsherActedCorrelator.js +175 -0
  11. package/dist/core/UsherActedCorrelator.js.map +1 -0
  12. package/dist/core/UsherSignalStore.d.ts +26 -2
  13. package/dist/core/UsherSignalStore.d.ts.map +1 -1
  14. package/dist/core/UsherSignalStore.js +17 -2
  15. package/dist/core/UsherSignalStore.js.map +1 -1
  16. package/dist/core/types.d.ts +17 -0
  17. package/dist/core/types.d.ts.map +1 -1
  18. package/dist/core/types.js.map +1 -1
  19. package/dist/scaffold/templates.d.ts.map +1 -1
  20. package/dist/scaffold/templates.js +6 -0
  21. package/dist/scaffold/templates.js.map +1 -1
  22. package/dist/server/AgentServer.d.ts +3 -0
  23. package/dist/server/AgentServer.d.ts.map +1 -1
  24. package/dist/server/AgentServer.js +2 -0
  25. package/dist/server/AgentServer.js.map +1 -1
  26. package/dist/server/routes.d.ts +8 -0
  27. package/dist/server/routes.d.ts.map +1 -1
  28. package/dist/server/routes.js +26 -0
  29. package/dist/server/routes.js.map +1 -1
  30. package/dist/server/usherRoutes.d.ts.map +1 -1
  31. package/dist/server/usherRoutes.js +7 -1
  32. package/dist/server/usherRoutes.js.map +1 -1
  33. package/package.json +1 -1
  34. package/src/data/builtin-manifest.json +47 -47
  35. package/src/scaffold/templates.ts +6 -0
  36. package/upgrades/1.3.73.md +73 -0
  37. package/upgrades/1.3.74.md +95 -0
  38. package/upgrades/side-effects/usher-precision-loop.md +131 -0
@@ -0,0 +1,131 @@
1
+ # Side-Effects Review — Usher precision numerator wiring (rung 4)
2
+
3
+ **Version / slug:** `usher-precision-loop`
4
+ **Date:** `2026-05-28`
5
+ **Author:** `echo`
6
+ **Second-pass reviewer:** `not required` (signal-only observability change, no blocking surface)
7
+ **Spec:** `docs/specs/cwa-usher.md` (approved:true by justin; review-note explicitly names "the usher_acted precision definition that gates rung 5" as the in-scope follow-up this change implements)
8
+
9
+ ## Summary of the change
10
+
11
+ The Usher fires re-surface signals (`UsherSignalStore.recordSignal`) and exposes a
12
+ precision read (`acted / fired`) that the spec designates as the hard precondition
13
+ for rung 5 (mid-task injection). But `UsherSignalStore.markActed` — the precision
14
+ *numerator* — had no caller anywhere, so `acted` was pinned at 0 on every topic
15
+ and precision could never move. This wires the numerator via two correlation paths
16
+ in a new pure helper `src/core/UsherActedCorrelator.ts`: (a) **auto-use** — when the
17
+ agent's outbound reply on a topic uses a re-surfaced context, mark that signal
18
+ `acted(via:'use')`, called from the `POST /telegram/reply` handler in
19
+ `src/server/routes.ts` after a genuine (non-proxy, non-system) reply sends; (b)
20
+ **miss-map** — when the user has to correct the agent (a `HumanAsDetector` signal)
21
+ on a context a recent nudge flagged, mark it `acted(via:'miss')`, called right after
22
+ the inbound `observeInboundMessage` seam in `src/commands/server.ts`. `markActed` now
23
+ also stamps `actedVia`/`actedAt`, and `GET /usher/metrics` reports
24
+ `acted_by_use`/`acted_by_miss`. Files: `UsherSignalStore.ts`, `UsherActedCorrelator.ts`
25
+ (new), `usherRoutes.ts`, `routes.ts` (+`RouteContext.usherSignalStore`),
26
+ `AgentServer.ts` (route ctx wiring), `server.ts` (path-b seam).
27
+
28
+ ## Decision-point inventory
29
+
30
+ The only "decision" this change makes is whether to increment an observability
31
+ counter (`acted`). It gates nothing — no message is blocked, delayed, or altered.
32
+
33
+ - `UsherActedCorrelator.contextCoveredBy` — **add** — pure text-coverage match deciding whether a probe references a fired signal's proposition. Output feeds `markActed` only; no authority over delivery.
34
+ - `routes.ts POST /telegram/reply` (path a) — **pass-through** — the existing send decision is untouched; crediting runs *after* the reply has already gone out.
35
+ - `server.ts` inbound human-detector seam (path b) — **pass-through** — crediting runs after `observeInboundMessage`, which itself is signal-only.
36
+
37
+ ---
38
+
39
+ ## 1. Over-block
40
+
41
+ **What legitimate inputs does this change reject that it shouldn't?**
42
+
43
+ No block/allow surface — over-block not applicable. `markActed` only increments a
44
+ metric; it cannot reject, delay, or modify any inbound or outbound message. Both
45
+ call sites run strictly *after* the message has been processed/sent, and both are
46
+ wrapped best-effort (never throw into the message path).
47
+
48
+ ## 2. Under-block
49
+
50
+ **What failure modes does this still miss?**
51
+
52
+ By design (precision-over-recall — a falsely-HIGH precision is the dangerous
53
+ direction since precision gates rung 5), the correlator deliberately UNDER-credits:
54
+
55
+ - **Path (a) timing race:** the Usher's signal is recorded by an async, LLM-backed
56
+ fire-and-forget loop (~8–10s). A very fast agent reply can land before the signal
57
+ is persisted, so that use goes uncredited. Acceptable: the full reply (after the
58
+ agent's work) usually lands well after the signal persists, and under-crediting
59
+ never inflates the gate.
60
+ - **Short contexts:** a context with fewer than 2 salient terms can never reach the
61
+ `MIN_SHARED=2` threshold, so single-word propositions are never auto-credited.
62
+ - **Recency window:** uses/corrections outside `USE_WINDOW_MS` (6h) / `MISS_WINDOW_MS`
63
+ (24h) are not credited.
64
+
65
+ These are recall gaps, not correctness bugs — the precision number will be a *floor*
66
+ on true usefulness, which is the conservative posture the rung-5 gate wants.
67
+
68
+ ## 3. Level-of-abstraction fit
69
+
70
+ **Is this at the right layer?**
71
+
72
+ Yes. `markActed` already existed on `UsherSignalStore` (the spec's numerator); this
73
+ change only supplies its missing callers. The matching logic lives in a pure,
74
+ unit-tested helper (`UsherActedCorrelator`) rather than inline at the call sites,
75
+ and the two call sites are the two existing seams where the relevant text is already
76
+ in hand (outbound reply text; inbound correction text + its `HumanAsDetector`
77
+ verdict). No higher layer owns "was this nudge used" — this is the layer that has
78
+ both the fired signals and the probe text. No smarter gate exists that should own
79
+ it instead.
80
+
81
+ ## 4. Signal vs authority compliance
82
+
83
+ **Does this hold blocking authority with brittle logic, or produce a signal?**
84
+
85
+ Compliant (`docs/signal-vs-authority.md`). The coverage matcher is intentionally
86
+ brittle (keyword overlap, no LLM) — and that is acceptable *precisely because it has
87
+ zero authority*. It produces a signal (the precision numerator) and nothing else. It
88
+ never blocks, never gates delivery, and feeds only the operator-facing
89
+ `GET /usher/metrics`. A brittle detector with no blocking power is the correct
90
+ pattern; the anti-pattern (brittle check WITH blocking authority) is not present.
91
+
92
+ ## 5. Interactions
93
+
94
+ **Does it shadow another check, get shadowed, double-fire, or race?**
95
+
96
+ - **Idempotency:** `markActed` guards `if (sig.acted) return false`, so paths (a) and
97
+ (b) marking the same signal, or repeated calls, increment `acted` at most once per
98
+ signal. The split counters (`acted_by_use`/`acted_by_miss`) only increment on the
99
+ successful (first) mark.
100
+ - **Ordering on the inbound seam:** path (b) runs in the human-detector callback,
101
+ which is chained *before* the Usher loop callback on the same `onMessageLogged`.
102
+ It correlates the correction against signals fired on PRIOR turns (already
103
+ persisted) — it does not race the current turn's not-yet-fired signal.
104
+ - **No shadowing:** the outbound tone-gate / dedup / ArcCheck path is unchanged;
105
+ crediting runs after the gate passed and the send succeeded, so it cannot affect
106
+ any block/allow outcome.
107
+
108
+ ## 6. External surfaces
109
+
110
+ **Does it change anything visible to other agents, users, or systems?**
111
+
112
+ - `GET /usher/metrics` gains two additive fields (`acted_by_use`, `acted_by_miss`)
113
+ and `acted`/`precision` now actually move. This endpoint is operator-only
114
+ (`INTERNAL_PREFIXES`), not surfaced to end users or other agents.
115
+ - The per-topic `usher/<topicId>.json` store files gain optional `actedVia`/`actedAt`
116
+ on signals — additive; `load()` already tolerates unknown/missing fields and old
117
+ readers ignore them.
118
+ - No change to any message content, no new outbound traffic, nothing visible to
119
+ peer agents. Behavior depends on conversation/topic state but is fully best-effort.
120
+
121
+ ## 7. Rollback cost
122
+
123
+ **If this turns out wrong in production, what's the back-out?**
124
+
125
+ Cheap and clean: revert the commit (a normal patch release). No data migration — the
126
+ new optional fields are tolerated by existing `load()` and ignored by older binaries;
127
+ a topic file written by the new code is readable by the old code and vice-versa.
128
+ Worst case after revert: `precision` returns to its prior pinned-at-0 state (the bug
129
+ this fixes). No agent-state repair, no hot-data fix. Because the change is
130
+ observability-only, a wrong precision number cannot itself cause an outage — at most
131
+ it would mislead the rung-5 decision, which is human-gated and not part of this change.