instar 1.3.739 → 1.3.740

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.
@@ -67,10 +67,34 @@ export interface ReapLogEntry {
67
67
  /** Notify entries: the outcome this record asserts. */
68
68
  outcome?: ReapNotifyOutcome;
69
69
  }
70
+ /** Optional overrides for the self-limiting caps — primarily so tests can
71
+ * trigger rotation without writing 16MB. Production uses the module defaults. */
72
+ export interface ReapLogOptions {
73
+ maxLogBytes?: number;
74
+ tailReadBytes?: number;
75
+ maxSkipState?: number;
76
+ }
70
77
  export declare class ReapLog {
71
78
  private readonly logPath;
72
79
  private readonly machineId?;
73
- constructor(stateDir: string, machineId?: () => string | undefined);
80
+ private readonly maxLogBytes;
81
+ private readonly tailReadBytes;
82
+ private readonly maxSkipState;
83
+ /** session name → last-LOGGED skip signature (`${reason}::${skipped}`).
84
+ * A `recordSkipped` whose signature equals the session's last-logged one is
85
+ * the SAME permanent veto being re-evaluated at tick speed (open-commitment,
86
+ * not-lease-holder, protected …) — it is NOT re-appended. This is the
87
+ * primary cure for the reaper self-inflicted log flood (3218 open-commitment
88
+ * + 1608 not-lease-holder repeat rows ⇒ 142MB, 2026-07-03): mirror the
89
+ * reaper-audit "log on transition, not every tick" pattern. Cleared when the
90
+ * session is reaped so a same-named successor logs its first skip fresh. */
91
+ private readonly skipState;
92
+ /** Cheap running estimate of the current log's byte size, so rotation is
93
+ * decided WITHOUT a statSync on every append. Seeded from the real size on
94
+ * first append, then advanced by each write; re-synced on rotation. -1 =
95
+ * not yet seeded. */
96
+ private approxSize;
97
+ constructor(stateDir: string, machineId?: () => string | undefined, opts?: ReapLogOptions);
74
98
  recordReaped(e: {
75
99
  session: string;
76
100
  tmuxSession: string;
@@ -103,8 +127,26 @@ export declare class ReapLog {
103
127
  skipped: string;
104
128
  origin?: 'operator' | 'autonomous';
105
129
  }): void;
130
+ /** Record a session's last-logged skip signature, enforcing the map ceiling
131
+ * (oldest-first prune — Map preserves insertion order). Re-inserting an
132
+ * existing key does not reorder it, which is fine: churny NEW names are the
133
+ * growth risk, and those get pruned. */
134
+ private rememberSkip;
135
+ /** Forget a session's skip state — call when the session is gone (reaped) so a
136
+ * same-named successor logs its first skip fresh and the map can't leak. */
137
+ private forgetSkip;
106
138
  private append;
107
- /** Read the most-recent `limit` entries (newest last), tolerating partial/corrupt lines. */
139
+ /** Roll the log to `<path>.1` (single retained generation) once it would cross
140
+ * MAX_LOG_BYTES, so the file can never grow unbounded. Rename is O(1) — no
141
+ * data rewrite on the append hot path (rewriting a large file synchronously
142
+ * here would reintroduce the very event-loop stall we're removing). Seeds the
143
+ * cheap size estimate from the real file size on first use. */
144
+ private rotateIfNeeded;
145
+ /** Read the most-recent `limit` entries (newest last), tolerating partial/corrupt lines.
146
+ * Only the last TAIL_READ_BYTES of each file are ever read, so a large log can
147
+ * never be slurped whole into memory (the readFileSync-whole-file freeze). If
148
+ * the current file's tail doesn't yield enough rows and a rotated `.1` backup
149
+ * exists, its tail is merged so recent history survives a rotation boundary. */
108
150
  read(limit?: number): ReapLogEntry[];
109
151
  private normalizeEntry;
110
152
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ReapLog.d.ts","sourceRoot":"","sources":["../../src/monitoring/ReapLog.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAKH;;;;;GAKG;AACH,MAAM,MAAM,iBAAiB,GACzB,UAAU,GACV,MAAM,GACN,uBAAuB,GACvB,UAAU,GACV,gBAAgB,CAAC;AAUrB,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX;oFACgF;IAChF,IAAI,EAAE,QAAQ,GAAG,SAAS,GAAG,QAAQ,CAAC;IACtC,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,yEAAyE;IACzE,MAAM,EAAE,MAAM,CAAC;IACf;+BAC2B;IAC3B,WAAW,EAAE,UAAU,GAAG,iBAAiB,GAAG,WAAW,M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;QACpB,MAAM,EAAE,MAAM,CAAC;QACf,WAAW,CAAC,EAAE,UAAU,GAAG,iBAAiB,CAAC;QAC7C,MAAM,CAAC,EAAE,UAAU,GAAG,YAAY,CAAC;QACnC,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,UAAU,CAAC,EAAE,UAAU,GAAG,sBAAsB,CAAC;QACjD,OAAO,CAAC,EAAE,OAAO,CAAC;QAClB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;QACxB,cAAc,CAAC,EAAE,YAAY,GAAG,YAAY,CAAC;KAC9C,GAAG,IAAI;IAqBR;;;;;OAKG;IACH,YAAY,CAAC,CAAC,EAAE;QACd,QAAQ,EAAE,MAAM,CAAC;QACjB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;QACvB,OAAO,EAAE,iBAAiB,CAAC;QAC3B,oEAAoE;QACpE,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB,GAAG,IAAI;IAeR,aAAa,CAAC,CAAC,EAAE;QACf,OAAO,EAAE,MAAM,CAAC;QAChB,WAAW,EAAE,MAAM,CAAC;QACpB,MAAM,EAAE,MAAM,CAAC;QACf,OAAO,EAAE,MAAM,CAAC;QAChB,MAAM,CAAC,EAAE,UAAU,GAAG,YAAY,CAAC;KACpC,GAAG,IAAI;IAyBR;;;6CAGyC;IACzC,OAAO,CAAC,YAAY;IASpB;iFAC6E;IAC7E,OAAO,CAAC,UAAU;IAIlB,OAAO,CAAC,MAAM;IAYd;;;;oEAIgE;IAChE,OAAO,CAAC,cAAc;IAmBtB;;;;qFAIiF;IACjF,IAAI,CAAC,KAAK,SAAM,GAAG,YAAY,EAAE;IAoBjC,OAAO,CAAC,cAAc;CA+CvB"}
@@ -14,6 +14,47 @@
14
14
  */
15
15
  import fs from 'node:fs';
16
16
  import path from 'node:path';
17
+ /**
18
+ * Read only the last `maxBytes` of a file and return its non-empty lines,
19
+ * newest last. Bounded by construction: an arbitrarily large log is never
20
+ * loaded whole (the readFileSync-whole-file pattern that froze the event loop
21
+ * on a 142MB reap-log, 2026-07-03). If the read starts mid-file (the file is
22
+ * larger than `maxBytes`), the first — possibly partial — line is dropped so a
23
+ * torn record is never mis-parsed. Never throws; an absent/unreadable file
24
+ * yields [].
25
+ */
26
+ function tailLines(filePath, maxBytes) {
27
+ let fd;
28
+ try {
29
+ const size = fs.statSync(filePath).size;
30
+ if (size === 0)
31
+ return [];
32
+ const readBytes = Math.min(size, maxBytes);
33
+ const start = size - readBytes;
34
+ const buf = Buffer.allocUnsafe(readBytes);
35
+ fd = fs.openSync(filePath, 'r');
36
+ fs.readSync(fd, buf, 0, readBytes, start);
37
+ const text = buf.toString('utf-8');
38
+ const lines = text.split('\n');
39
+ // Dropped: a leading partial line when we didn't read from byte 0.
40
+ if (start > 0 && lines.length > 0)
41
+ lines.shift();
42
+ return lines.filter((l) => l.trim().length > 0);
43
+ }
44
+ catch {
45
+ return []; // @silent-fallback-ok — absent/unreadable ⇒ no rows.
46
+ }
47
+ finally {
48
+ if (fd !== undefined) {
49
+ try {
50
+ fs.closeSync(fd);
51
+ }
52
+ catch {
53
+ /* fd already gone */
54
+ }
55
+ }
56
+ }
57
+ }
17
58
  const NOTIFY_OUTCOMES = new Set([
18
59
  'enqueued',
19
60
  'sent',
@@ -21,12 +62,47 @@ const NOTIFY_OUTCOMES = new Set([
21
62
  'no-topic',
22
63
  'enqueue-failed',
23
64
  ]);
65
+ /** Rotate the reap-log once it crosses this many bytes. The current file is
66
+ * renamed to `<path>.1` (O(1), no data rewrite) and a fresh file started, so
67
+ * the on-disk log can NEVER grow unbounded — even if some future caller floods
68
+ * it past the transition-dedup below. One backup generation is retained;
69
+ * `read()` merges its tail so recent history survives a rotation boundary. */
70
+ const MAX_LOG_BYTES = 16 * 1024 * 1024;
71
+ /** `read()` only ever pulls the last this-many bytes of a log file, so a large
72
+ * reap-log can never be slurped whole into memory (the 142MB readFileSync +
73
+ * split that blocked the event loop, 2026-07-03). Generous vs the default
74
+ * `limit` of 200 rows (~300 B/row ⇒ ~6.5k rows fit in 2 MB). */
75
+ const TAIL_READ_BYTES = 2 * 1024 * 1024;
76
+ /** Cap on the in-memory transition-dedup map. Live session names are bounded
77
+ * (dozens); this is a safety ceiling so a pathological churn of distinct names
78
+ * can't grow the map without bound. Oldest entries are pruned first. */
79
+ const MAX_SKIP_STATE = 2000;
24
80
  export class ReapLog {
25
81
  logPath;
26
82
  machineId;
27
- constructor(stateDir, machineId) {
83
+ maxLogBytes;
84
+ tailReadBytes;
85
+ maxSkipState;
86
+ /** session name → last-LOGGED skip signature (`${reason}::${skipped}`).
87
+ * A `recordSkipped` whose signature equals the session's last-logged one is
88
+ * the SAME permanent veto being re-evaluated at tick speed (open-commitment,
89
+ * not-lease-holder, protected …) — it is NOT re-appended. This is the
90
+ * primary cure for the reaper self-inflicted log flood (3218 open-commitment
91
+ * + 1608 not-lease-holder repeat rows ⇒ 142MB, 2026-07-03): mirror the
92
+ * reaper-audit "log on transition, not every tick" pattern. Cleared when the
93
+ * session is reaped so a same-named successor logs its first skip fresh. */
94
+ skipState = new Map();
95
+ /** Cheap running estimate of the current log's byte size, so rotation is
96
+ * decided WITHOUT a statSync on every append. Seeded from the real size on
97
+ * first append, then advanced by each write; re-synced on rotation. -1 =
98
+ * not yet seeded. */
99
+ approxSize = -1;
100
+ constructor(stateDir, machineId, opts = {}) {
28
101
  this.logPath = path.join(stateDir, '..', 'logs', 'reap-log.jsonl');
29
102
  this.machineId = machineId;
103
+ this.maxLogBytes = opts.maxLogBytes ?? MAX_LOG_BYTES;
104
+ this.tailReadBytes = opts.tailReadBytes ?? TAIL_READ_BYTES;
105
+ this.maxSkipState = opts.maxSkipState ?? MAX_SKIP_STATE;
30
106
  }
31
107
  recordReaped(e) {
32
108
  this.append({
@@ -44,6 +120,9 @@ export class ReapLog {
44
120
  ...(e.workEvidence && e.workEvidence.length > 0 ? { workEvidence: e.workEvidence } : {}),
45
121
  ...(e.evidenceSource ? { evidenceSource: e.evidenceSource } : {}),
46
122
  });
123
+ // The session is gone — drop its skip-dedup state so a same-named successor
124
+ // logs its first skip fresh and the map never leaks reaped names.
125
+ this.forgetSkip(e.session);
47
126
  }
48
127
  /**
49
128
  * Append one reap-notice delivery outcome record (reap-notify spec R1.3).
@@ -66,6 +145,18 @@ export class ReapLog {
66
145
  });
67
146
  }
68
147
  recordSkipped(e) {
148
+ // Log-on-transition: a reaper evaluates a permanently-vetoed session
149
+ // (open-commitment, not-lease-holder, protected, …) on EVERY tick and would
150
+ // emit an identical `skipped` row each time — 5k+ repeat rows ⇒ a 142MB log
151
+ // that froze the event loop when read (2026-07-03). Only append when the
152
+ // skip STATE changes for this session; a re-evaluation with the same
153
+ // (reason, skipped) is the same veto and is dropped. The reaper keeps
154
+ // evaluating every tick, so the moment the veto lifts (commitment closes,
155
+ // lease moves) the state changes and the next skip — or the reap — logs.
156
+ const sig = `${e.reason}::${e.skipped}`;
157
+ if (this.skipState.get(e.session) === sig)
158
+ return;
159
+ this.rememberSkip(e.session, sig);
69
160
  this.append({
70
161
  ts: new Date().toISOString(),
71
162
  type: 'skipped',
@@ -78,27 +169,77 @@ export class ReapLog {
78
169
  machine: this.machineId?.(),
79
170
  });
80
171
  }
172
+ /** Record a session's last-logged skip signature, enforcing the map ceiling
173
+ * (oldest-first prune — Map preserves insertion order). Re-inserting an
174
+ * existing key does not reorder it, which is fine: churny NEW names are the
175
+ * growth risk, and those get pruned. */
176
+ rememberSkip(session, sig) {
177
+ this.skipState.set(session, sig);
178
+ while (this.skipState.size > this.maxSkipState) {
179
+ const oldest = this.skipState.keys().next().value;
180
+ if (oldest === undefined)
181
+ break;
182
+ this.skipState.delete(oldest);
183
+ }
184
+ }
185
+ /** Forget a session's skip state — call when the session is gone (reaped) so a
186
+ * same-named successor logs its first skip fresh and the map can't leak. */
187
+ forgetSkip(session) {
188
+ this.skipState.delete(session);
189
+ }
81
190
  append(entry) {
82
191
  try {
83
192
  fs.mkdirSync(path.dirname(this.logPath), { recursive: true });
84
- fs.appendFileSync(this.logPath, JSON.stringify(entry) + '\n');
193
+ const line = JSON.stringify(entry) + '\n';
194
+ this.rotateIfNeeded(Buffer.byteLength(line));
195
+ fs.appendFileSync(this.logPath, line);
196
+ if (this.approxSize >= 0)
197
+ this.approxSize += Buffer.byteLength(line);
85
198
  }
86
199
  catch {
87
200
  // never throw from the audit sink
88
201
  }
89
202
  }
90
- /** Read the most-recent `limit` entries (newest last), tolerating partial/corrupt lines. */
91
- read(limit = 200) {
92
- let raw;
203
+ /** Roll the log to `<path>.1` (single retained generation) once it would cross
204
+ * MAX_LOG_BYTES, so the file can never grow unbounded. Rename is O(1) — no
205
+ * data rewrite on the append hot path (rewriting a large file synchronously
206
+ * here would reintroduce the very event-loop stall we're removing). Seeds the
207
+ * cheap size estimate from the real file size on first use. */
208
+ rotateIfNeeded(incomingBytes) {
209
+ if (this.approxSize < 0) {
210
+ try {
211
+ this.approxSize = fs.statSync(this.logPath).size;
212
+ }
213
+ catch {
214
+ this.approxSize = 0; // absent file ⇒ empty
215
+ }
216
+ }
217
+ if (this.approxSize + incomingBytes <= this.maxLogBytes)
218
+ return;
93
219
  try {
94
- raw = fs.readFileSync(this.logPath, 'utf-8');
220
+ fs.renameSync(this.logPath, `${this.logPath}.1`); // overwrites a prior .1
95
221
  }
96
222
  catch {
97
- // @silent-fallback-ok — no log file yet means no reaps recorded; an empty
98
- // list is the correct answer, not a degraded one.
99
- return [];
223
+ // @silent-fallback-ok — if the roll fails the append still proceeds; the
224
+ // read path is tail-bounded so an oversize file is a perf hit, never a
225
+ // correctness failure.
226
+ }
227
+ this.approxSize = 0;
228
+ }
229
+ /** Read the most-recent `limit` entries (newest last), tolerating partial/corrupt lines.
230
+ * Only the last TAIL_READ_BYTES of each file are ever read, so a large log can
231
+ * never be slurped whole into memory (the readFileSync-whole-file freeze). If
232
+ * the current file's tail doesn't yield enough rows and a rotated `.1` backup
233
+ * exists, its tail is merged so recent history survives a rotation boundary. */
234
+ read(limit = 200) {
235
+ const wanted = limit > 0 ? limit : Number.MAX_SAFE_INTEGER;
236
+ let lines = tailLines(this.logPath, this.tailReadBytes);
237
+ if (lines.length < wanted) {
238
+ // Backfill from the rotated generation (older lines first).
239
+ const older = tailLines(`${this.logPath}.1`, this.tailReadBytes);
240
+ if (older.length > 0)
241
+ lines = older.concat(lines);
100
242
  }
101
- const lines = raw.split('\n').filter((l) => l.trim().length > 0);
102
243
  const tail = limit > 0 ? lines.slice(-limit) : lines;
103
244
  const out = [];
104
245
  for (const line of tail) {
@@ -1 +1 @@
1
- {"version":3,"file":"ReapLog.js","sourceRoot":"","sources":["../../src/monitoring/ReapLog.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAe7B,MAAM,eAAe,GAAwB,IAAI,GAAG,CAAC;IACnD,UAAU;IACV,MAAM;IACN,uBAAuB;IACvB,UAAU;IACV,gBAAgB;CACjB,CAAC,CAAC;AAmDH,MAAM,OAAO,OAAO;IACD,OAAO,CAAS;IAChB,SAAS,CAA4B;IAEtD,YAAY,QAAgB,EAAE,SAAoC;QAChE,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,gBAAgB,CAAC,CAAC;QACnE,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;IAED,YAAY,CAAC,CAWZ;QACC,IAAI,CAAC,MAAM,CAAC;YACV,EAAE,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;YAC5B,IAAI,EAAE,QAAQ;YACd,OAAO,EAAE,CAAC,CAAC,OAAO;YAClB,WAAW,EAAE,CAAC,CAAC,WAAW;YAC1B,MAAM,EAAE,CAAC,CAAC,MAAM;YAChB,WAAW,EAAE,CAAC,CAAC,WAAW,IAAI,UAAU;YACxC,MAAM,EAAE,CAAC,CAAC,MAAM;YAChB,GAAG,CAAC,CAAC,CA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C,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACxE,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAChC,CAAC;IACJ,CAAC;CACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "instar",
3
- "version": "1.3.739",
3
+ "version": "1.3.740",
4
4
  "description": "Coherence infrastructure for self-evolving AI agents — on the Claude Code or Codex subscription you already have.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "$schema": "./builtin-manifest.schema.json",
3
3
  "schemaVersion": 1,
4
- "generatedAt": "2026-07-03T22:57:15.282Z",
5
- "instarVersion": "1.3.739",
4
+ "generatedAt": "2026-07-03T23:17:57.781Z",
5
+ "instarVersion": "1.3.740",
6
6
  "entryCount": 202,
7
7
  "entries": {
8
8
  "hook:session-start": {
@@ -0,0 +1,65 @@
1
+ # Upgrade Guide — vNEXT
2
+
3
+ <!-- assembled-by: assemble-next-md -->
4
+ <!-- bump: patch -->
5
+
6
+ ## What Changed
7
+
8
+ Three self-limiting changes to `src/monitoring/ReapLog.ts` (the audit trail behind
9
+ `GET /sessions/reap-log`) that stop the reaper from flooding — and freezing on — its own log.
10
+
11
+ The reaper re-evaluates every session on each tick. When a session **can't** be reaped yet — it
12
+ holds an open commitment, or it belongs to another machine (`not-lease-holder`), or it's
13
+ protected — the reaper skips it and recorded a `skipped` row **every tick**. On a live agent
14
+ that produced 3218 `open-commitment` + 1608 `not-lease-holder` **identical repeat rows** and
15
+ grew `reap-log.jsonl` to **142MB / 463k lines** (observed 2026-07-03). Worse, `read()` did
16
+ `fs.readFileSync(WHOLE file).split('\n')` just to return the last N rows — a 142MB slurp that
17
+ **blocked the event loop** (~90s CPU-bound stalls) whenever the route was queried.
18
+
19
+ - **Write-side transition dedup (primary cure).** `recordSkipped()` now logs on *transition*:
20
+ it keeps an in-memory `session → last-logged skip signature (${reason}::${skipped})` map and
21
+ drops a re-append when the signature is unchanged — mirroring the sibling `reaper-audit.jsonl`
22
+ "log on change, not every tick" discipline. State is cleared when the session is reaped
23
+ (`forgetSkip`) so a same-named successor logs fresh and the map can't leak (hard ceiling
24
+ `MAX_SKIP_STATE`, 2000, oldest-pruned). The reaper still **evaluates** every tick, so the
25
+ moment a veto lifts the next skip — or the reap — is logged.
26
+ - **Read-side bounded tail.** `read()` now reads only the last `TAIL_READ_BYTES` (2MB) via a
27
+ positional `readSync`, drops a torn leading line, and merges the rotated `.1` tail if needed —
28
+ so a large log can never be slurped whole into memory again.
29
+ - **Size-cap rotation (defense-in-depth).** `append()` rolls the file to `<path>.1` (O(1)
30
+ `renameSync`, no hot-path rewrite) once it crosses `MAX_LOG_BYTES` (16MB), so it can never
31
+ grow unbounded even if a future caller floods it.
32
+
33
+ Caps are overridable via an optional `ReapLogOptions` constructor arg (defaults = the module
34
+ constants) purely so tests can trigger rotation cheaply; the production callsite is unchanged.
35
+
36
+ ## What to Tell Your User
37
+
38
+ If your agent's server ever felt like it "froze for a minute" periodically, or your disk was
39
+ filling up with a giant session-audit log, this is a fix for that. The background tidier that
40
+ closes finished sessions was writing the same "couldn't clean this up yet" note thousands of
41
+ times, and reading that log loaded the whole thing at once. Now it writes the note once and
42
+ reads only the end of the file. Nothing you do changes — your "why did my session vanish?"
43
+ history is still complete (the first skip, every change of reason, and every actual close are
44
+ all still recorded); it just stops the duplicate spam and the stall it caused, and a log that's
45
+ already huge stops growing and gets trimmed automatically.
46
+
47
+ ## Summary of New Capabilities
48
+
49
+ None — this is a reliability fix to existing behavior, not a new capability. The session-audit
50
+ history keeps the same shape and meaning; it's just bounded and de-duplicated now.
51
+
52
+ ## Evidence
53
+
54
+ - `npx vitest run tests/unit/reap-log.test.ts` → **16 tests, 0 failures** (transition-dedup:
55
+ identical-skip-suppressed, reason-transition-logs, per-session independence, re-log-after-reap;
56
+ bounded read returns correct last-N; rotation to `.1` + cross-boundary merge + live file
57
+ bounded; absent-file empty read).
58
+ - `npx vitest run tests/unit/reap-log.test.ts tests/unit/session-reaper.test.ts
59
+ tests/unit/reap-notifier.test.ts tests/unit/reap-guard.test.ts` → **115 tests, 0 failures**
60
+ (reaper family regression-clean; `normalizeEntry` whitelist untouched).
61
+ - `npx tsc --noEmit -p tsconfig.json` → **0 errors**.
62
+ - Independent second-pass reviewer: **Concur** — observability-only, touches no kill/keep
63
+ decision; no operator-needed row hidden; read/rotation off-by-one-clean.
64
+ - Side-effects review: `upgrades/side-effects/reaper-log-flood-fix.md` (8 questions +
65
+ signal-vs-authority + multi-machine posture + second-pass concurrence).
@@ -0,0 +1,39 @@
1
+ # Reaper log-flood fix — Plain-English Overview
2
+
3
+ > The one-line version: the reaper was scribbling the same "couldn't clean this up" note into an audit file thousands of times a minute until the file grew to 142MB and froze the whole server when anything read it — this makes it write the note once and read the file in small bites.
4
+
5
+ ## The problem in one breath
6
+
7
+ Every agent has a background "reaper" that tidies up finished sessions. When a session CAN'T be tidied yet (it has an open promise to the user, or it belongs to another machine), the reaper politely skips it — and writes a one-line "skipped, here's why" note to an audit log. The bug: it re-checks and re-writes that identical note on every single tick, forever. On a live agent that piled up 3,218 + 1,608 duplicate notes and grew the log to 142MB. Worse, the code that READS that log loaded the entire 142MB into memory at once, which pegged a CPU and froze the server for ~90 seconds each time.
8
+
9
+ ## What already exists
10
+
11
+ - **The reaper** — the background tidier that decides which sessions to close. Its actual close/keep decisions are correct and are NOT changed by this work.
12
+ - **`reap-log.jsonl`** — the "why did my session vanish?" audit trail. One line per close, one line per refused close. This is the file that ballooned.
13
+ - **`reaper-audit.jsonl`** — a SEPARATE, sibling audit file that already does the right thing: it only writes when a decision CHANGES, not on every tick. It stayed tiny (under half a megabyte). We copy its proven habit.
14
+
15
+ ## What this adds
16
+
17
+ The reaper's skip-note now follows the same "only write when something changed" rule its sibling already uses. If a session is skipped for the exact same reason as last time, no new note is written. The moment the reason changes — the promise closes, the session moves machines, or it finally gets reaped — a fresh note is written, so the audit trail still tells the true story with none of the spam.
18
+
19
+ Two more safety belts:
20
+
21
+ - **Small-bite reading** — reading the log now pulls only the last couple of megabytes off the end of the file instead of the whole thing, so even a giant log can never freeze the server again.
22
+ - **Auto-rotation** — if the file ever crosses 16MB anyway, it's instantly rolled aside to a single backup and a fresh file is started, so it can never grow without bound. Reading transparently stitches the backup back in so recent history is never lost.
23
+
24
+ ## The new pieces
25
+
26
+ - **Transition dedup (in-memory)** — a tiny table remembering each session's last-written skip reason. It's per-machine, capped at 2,000 entries (sessions are only ever a few dozen in practice), and forgotten the instant a session is reaped so it can't leak. It is NOT allowed to change any close/keep decision — it only decides whether a LOG LINE is worth writing.
27
+ - **Bounded tail reader** — reads the end of the file only. It carefully drops a half-a-line at the read boundary so a torn record is never mis-parsed.
28
+ - **Size-cap rotation** — an instant rename (no slow file rewrite) when the file gets too big.
29
+
30
+ ## The safeguards
31
+
32
+ - The reaper's real authority — which sessions live or die — is untouched. This is purely about how much it writes and how the file is read.
33
+ - Nothing is lost from the audit story: first-skip, every change-of-reason, and every actual reap are all still recorded. Only the identical-to-last-time repeats are dropped.
34
+ - It's per-machine by design (each machine audits its own reaping), matching the sibling file. No cross-machine syncing to get wrong.
35
+ - Rollback is a one-file revert with no data migration — old fat logs and new backups both read correctly through the new reader.
36
+
37
+ ## What you need to decide
38
+
39
+ Nothing structural — this is a contained, low-risk hygiene fix with full unit-test coverage (16 focused tests; 115 reaper-family tests green). The one judgment call baked in: we accept losing the per-tick "still skipped at 12:00:01, still skipped at 12:00:02…" heartbeat in exchange for a log that doesn't self-destruct. That trade matches what the sibling audit file already chose, so it's a consistent, already-proven decision rather than a new gamble.
@@ -0,0 +1,90 @@
1
+ # Side-Effects Review — Reaper self-inflicted log-flood fix (ReapLog transition-dedup + bounded read + rotation)
2
+
3
+ **Version / slug:** `reaper-log-flood-fix`
4
+ **Date:** `2026-07-03`
5
+ **Author:** `Echo (instar-dev agent)`
6
+ **Second-pass reviewer:** `reviewer subagent (see appended concurrence)`
7
+
8
+ ## Summary of the change
9
+
10
+ Three self-limiting changes to `src/monitoring/ReapLog.ts`, the append-only audit trail behind `GET /sessions/reap-log`:
11
+
12
+ 1. **Write-side transition dedup (primary cure).** `recordSkipped()` now logs on TRANSITION only — it keeps an in-memory `session → last-logged skip signature (${reason}::${skipped})` map and drops a re-append when the signature is unchanged. The reaper re-evaluates a permanently-vetoed session (`open-commitment`, `not-lease-holder`, `protected`) on every tick and previously appended an identical `skipped` row each time — on a live agent this produced 3218 `open-commitment` + 1608 `not-lease-holder` repeat rows and grew the log to 142MB / 463k lines (observed 2026-07-03). The dedup state is cleared when the session is reaped (`recordReaped` → `forgetSkip`) so a same-named successor logs fresh and the map cannot leak. The map has a hard ceiling (`MAX_SKIP_STATE`, default 2000, oldest-pruned).
13
+ 2. **Read-side bounded tail (fixes the freeze-on-read).** `read()` previously did `fs.readFileSync(WHOLE file).split('\n')` just to return the last `limit` rows — a 142MB slurp + split that blocked the event loop when the route was queried. It now reads only the last `TAIL_READ_BYTES` (default 2MB) of the file via a positional `readSync`, drops a leading partial line, and merges the rotated `.1` tail if the live file doesn't yield enough rows.
14
+ 3. **Size-cap rotation (defense-in-depth).** `append()` rolls the file to `<path>.1` (O(1) `renameSync`, no data rewrite on the hot path) once it would cross `MAX_LOG_BYTES` (default 16MB), so the file can never grow unbounded even if a future caller floods it. One backup generation is retained; `read()` merges it.
15
+
16
+ The caps are overridable via an optional `ReapLogOptions` constructor arg (defaults = module constants) purely so tests can trigger rotation cheaply. The production callsite (`src/commands/server.ts`) is unchanged.
17
+
18
+ ## Decision-point inventory
19
+
20
+ This change touches NO block/allow/gate decision point. `ReapLog` is a read-only observability sink — the class docstring states it "never gates or mutates a session — it only records." The reaper's keep/kill authority (`SessionManager` / `SessionReaper`) is entirely untouched; only the LOGGING cadence and READ mechanics change.
21
+
22
+ - `ReapLog.recordSkipped` — modify — logs on transition instead of every tick (observability cadence only).
23
+ - `ReapLog.read` — modify — bounded tail read instead of whole-file slurp (I/O mechanics only).
24
+ - `ReapLog.append` — modify — adds O(1) size-cap rotation (I/O mechanics only).
25
+
26
+ ---
27
+
28
+ ## 1. Over-block
29
+
30
+ No block/allow surface — over-block not applicable. `ReapLog` never blocks a session. The only "suppression" is of DUPLICATE LOG ROWS for an unchanged skip state, which is the intended behavior (mirrors the existing `reaper-audit.jsonl` log-on-transition pattern).
31
+
32
+ ---
33
+
34
+ ## 2. Under-block
35
+
36
+ No block/allow surface — under-block not applicable. In audit-fidelity terms, the analogue is "what does the log no longer record?": it no longer records a fresh row for an UNCHANGED skip state on each tick. It STILL records: the first skip (transition into skipped), every change of skip reason, and every reap. A reviewer asking "is this session still being skipped?" reads the most recent skip row plus the absence of a later reap — the same answer, without 5000 duplicate rows. Loss of the per-tick "still skipped at time T" heartbeat is intentional and matches reaper-audit.
37
+
38
+ ---
39
+
40
+ ## 3. Level-of-abstraction fit
41
+
42
+ Correct layer. The dedup lives INSIDE `ReapLog` (the class that owns the log), so it covers every caller — not bolted onto the single `reapBlocked` event wiring in `server.ts`, which would leave other/future callers un-deduped. The read/rotation are pure file mechanics that belong on the class that owns the file. This is a detector/observability primitive, not an authority — it produces no signal consumed by any gate. It mirrors the already-shipped `reaper-audit.jsonl` transition pattern rather than inventing a new one.
43
+
44
+ ---
45
+
46
+ ## 4. Signal vs authority compliance
47
+
48
+ Compliant. The change adds NO blocking authority and NO brittle decision logic in front of any gate. It is a data-sink optimization: fewer duplicate rows written, bounded bytes read. `docs/signal-vs-authority.md` governs decision points; this change has none.
49
+
50
+ ---
51
+
52
+ ## 5. Interactions
53
+
54
+ - **Mirrors, does not shadow, `reaper-audit.jsonl`.** That sink already logs reaper decisions on transition; this brings `reap-log.jsonl`'s skip rows to the same discipline. They remain separate files with separate purposes.
55
+ - **`recordReaped` → `forgetSkip` ordering.** Reap clears the skip-state so a same-named successor logs fresh. A reap for a session never previously skipped is a harmless no-op delete.
56
+ - **No race with cleanup.** `ReapLog` is synchronous and single-process; the rotation `renameSync` is atomic. A concurrent reader mid-rotation either sees the old file (pre-rename) or the new empty file + `.1` (post-rename) — `read()` merges `.1`, so no window loses the newest rows.
57
+ - **`normalizeEntry` untouched** — the notify/skipped/reaped type + field whitelist that other tests guard is unchanged; all 115 reaper-family unit tests pass.
58
+
59
+ ---
60
+
61
+ ## 6. External surfaces
62
+
63
+ - **`GET /sessions/reap-log`** — same JSON shape, same newest-last ordering, same `limit` semantics. The only observable difference: far fewer duplicate `skipped` rows, and the route no longer blocks the event loop on a large file. No API contract change.
64
+ - No change visible to other agents or users beyond the route above. No dependency on timing or conversation state.
65
+ - **Pre-existing on-disk bloat is not rewritten by this change.** A file already at 142MB stays until the next rotation trims it (or an operator archives it, as was done live on 2026-07-03). The bounded READ means even a still-large file no longer freezes the loop; the write-side dedup means it stops growing.
66
+
67
+ ---
68
+
69
+ ## 7. Multi-machine posture (Cross-Machine Coherence)
70
+
71
+ **Machine-local BY DESIGN.** `reap-log.jsonl` is a per-machine audit of that machine's own reap decisions (the log path is under the machine's own `logs/`, and `GET /sessions/reap-log` already reports only the local machine's entries — pool-scope reap history is not a feature). The in-memory `skipState` dedup map is likewise per-process and correctly scoped to the machine doing the reaping. No replication, no proxied read, no cross-machine state. This matches the existing `reaper-audit.jsonl` posture. No topic-transfer, one-voice, or URL-durability concerns (it is not user-facing and generates no links).
72
+
73
+ ---
74
+
75
+ ## 8. Rollback cost
76
+
77
+ Low. The change is contained to one file (`ReapLog.ts`) plus its unit tests. Back-out is a straight revert — no data migration (the on-disk format is unchanged; older whole-file logs and `.1` backups both read correctly through the new tail reader). If the transition-dedup were ever suspected of hiding a needed row, reverting restores per-tick logging immediately. No agent-state repair, no hot-fix data surgery. The caps are constructor-overridable if a deployment needs different thresholds without a code change.
78
+
79
+ ---
80
+
81
+ ## Second-pass review (independent reviewer subagent)
82
+
83
+ **Concur with the review.** The change is observability-only and touches no kill/keep decision — the reaper still evaluates every tick, so the transition-dedup can never strand an operator's "why did my session vanish / not get reaped?" answer.
84
+
85
+ 1. **Transition-dedup:** correctly keyed on `${reason}::${skipped}`; suppresses only a byte-identical re-evaluation of the same permanent veto. Any genuine change (veto lifts → reap row always appends since `recordReaped` has no dedup; reason changes → new signature → new row) is still logged. `forgetSkip` on reap prevents both the stale-successor bug and unbounded map growth, backed by the `MAX_SKIP_STATE` oldest-first ceiling. No operator-needed row is hidden.
86
+ 2. **Bounded read:** traced the merge/tail logic — older `.1` correctly prepended to newer live, `.slice(-limit)` keeps the newest, leading partial line dropped only when `start > 0`, trailing empty line filtered, `.1` read only when live yields `< wanted`. No off-by-one, no torn record, newest row never dropped, no cross-file duplication (rename→fresh-empty-live).
87
+ 3. **Rotation:** O(1) `renameSync` off the hot path; `approxSize` seeded once then advanced per-write (no per-append stat); a pre-existing 142MB file rotates on the first append. On-disk bounded to `live (≤cap) + .1 (≤cap)` since each rotation overwrites the prior `.1`. Concurrent reader sees a consistent pre/post-rename state, both handled by `read()`.
88
+ 4. **Signal-vs-authority:** no blocking authority added; `SessionReaper`/`SessionManager` kill logic untouched; audit-sink failures swallow silently rather than perturbing behavior.
89
+
90
+ No correctness defect found. Tests exercise both sides of the dedup boundary, the rotation/merge boundary, and the absent-file path. Sound to merge.