instar 1.3.1146 → 1.3.1147

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.
@@ -2,7 +2,7 @@
2
2
  "schemaVersion": 1,
3
3
  "generatedFrom": "source-tree",
4
4
  "registrySha256": "81b53363a440e832672618965540b3e507ae0d93adcc67ec2b93daf7933b3ab4",
5
- "packageVersion": "1.3.1146",
5
+ "packageVersion": "1.3.1147",
6
6
  "guards": [
7
7
  {
8
8
  "ref": "docs/audits/phase-b/f10-triage.md",
@@ -1,5 +1,5 @@
1
1
  {
2
- "sha256": "675498ac7f3b9a5fd07a57a530eba5cc8645d84aede82b6f03348f7f502edb8a",
2
+ "sha256": "20cdf255a4e7e5577036fc766d33e560f5fdca277d059195494ac048766322aa",
3
3
  "registrySha256": "81b53363a440e832672618965540b3e507ae0d93adcc67ec2b93daf7933b3ab4",
4
- "packageVersion": "1.3.1146"
4
+ "packageVersion": "1.3.1147"
5
5
  }
@@ -2,5 +2,5 @@
2
2
  "sha256": "81b53363a440e832672618965540b3e507ae0d93adcc67ec2b93daf7933b3ab4",
3
3
  "articleCount": 88,
4
4
  "generatedFrom": "docs/STANDARDS-REGISTRY.md",
5
- "packageVersion": "1.3.1146"
5
+ "packageVersion": "1.3.1147"
6
6
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "instar",
3
- "version": "1.3.1146",
3
+ "version": "1.3.1147",
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",
@@ -25,6 +25,29 @@
25
25
  * line or the line directly above:
26
26
  * // lint-allow-blocking-scan: <why this can't run periodically>
27
27
  *
28
+ * ── 2026-08-14: the command name does not have to be written at the callsite.
29
+ * The original pattern required the scan command as a string literal INSIDE the
30
+ * call, so putting the name one step away walked past it — while the event loop
31
+ * stalled just the same, because the incident was about what the process DOES,
32
+ * not how the argument was spelled. instar-codey reproduced the concatenation
33
+ * form (`const cmd = 'pg' + 'rep'; execFileSync(cmd, ['node'])` → exit 0) while
34
+ * auditing rename-defeatable checks, and scoped the fix.
35
+ *
36
+ * NOW RESOLVED before the decision: literal `+` chains, local `const` string
37
+ * bindings, and import aliases of the sync entry points. The VALUE decides, so
38
+ * `const pgrep = 'tmux'` is legal and `const cmd = 'psql'` is not a `ps`.
39
+ *
40
+ * DELIBERATELY NOT CLOSED, so it is stated rather than implied:
41
+ * · A call split across MULTIPLE LINES. This lint is line-oriented; making it
42
+ * multi-line means an AST, which is a different check at a different layer.
43
+ * Pre-existing, not introduced here.
44
+ * · A command read from config, an argv, or another module. Not foldable
45
+ * without dataflow analysis, and guessing would over-block correct code —
46
+ * the more expensive failure for a check that blocks commits.
47
+ * · Scope: bindings are collected file-wide rather than per-scope, so an
48
+ * identifier bound twice to DIFFERENT values is treated as unresolvable and
49
+ * never flagged. That is the safe direction, chosen on purpose.
50
+ *
28
51
  * Exit codes: 0 — clean; 1 — at least one violation.
29
52
  *
30
53
  * Usage:
@@ -46,11 +69,112 @@ const ROOT = path.resolve(path.dirname(__filename), '..');
46
69
  const SCAN_DIRS = ['src/monitoring', 'src/server'];
47
70
  const EXTENSIONS = new Set(['.ts', '.tsx', '.js', '.mjs', '.cjs']);
48
71
 
49
- // A synchronous child-process call whose command literal is a process-scan tool.
50
- // Matches e.g. spawnSync('pgrep', …) execFileSync('lsof', …) execSync('ps …')
51
- const VIOLATION = /\b(spawnSync|execSync|execFileSync)\s*\(\s*['"`]\s*(ps|pgrep|lsof|pkill)\b/;
72
+ // The scan commands themselves. Word-boundary matched against the RESOLVED
73
+ // command value, so `psql` never counts as `ps`.
74
+ const SCAN_COMMAND = /^(ps|pgrep|lsof|pkill)\b/;
75
+
76
+ // The synchronous child-process entry points. Import aliases of these are
77
+ // resolved per-file below — `import { execFileSync as run }` then `run('pgrep')`
78
+ // stalls the loop exactly as much as calling it by its own name.
79
+ const SYNC_BUILTINS = ['spawnSync', 'execSync', 'execFileSync'];
80
+
52
81
  const ALLOW = /lint-allow-blocking-scan:/;
53
82
 
83
+ /** A string literal, or a `+` chain of string literals. Nothing else folds. */
84
+ const FOLDABLE = /^\s*(?:(?:'[^'\\]*'|"[^"\\]*"|`[^`\\$]*`)\s*\+\s*)*(?:'[^'\\]*'|"[^"\\]*"|`[^`\\$]*`)\s*$/;
85
+
86
+ /**
87
+ * Fold an expression to its string value, or null if it is not a pure literal
88
+ * chain. `'pg' + 'rep'` → `pgrep`. A template with `${}` never folds.
89
+ */
90
+ function foldLiteral(expr) {
91
+ if (!FOLDABLE.test(expr)) return null;
92
+ const parts = expr.match(/'[^'\\]*'|"[^"\\]*"|`[^`\\$]*`/g);
93
+ if (!parts) return null;
94
+ return parts.map((p) => p.slice(1, -1)).join('');
95
+ }
96
+
97
+ /**
98
+ * Local `const NAME = <literal chain>` bindings, file-wide.
99
+ *
100
+ * Deliberately NOT scope-aware: this is a line-oriented lint, not a compiler.
101
+ * The safe direction for a check that BLOCKS COMMITS is to refuse to resolve
102
+ * anything ambiguous, so an identifier bound more than once to DIFFERENT values
103
+ * is recorded as unresolvable and never produces a violation. Over-blocking
104
+ * correct code is the more expensive failure here.
105
+ */
106
+ function collectStringConsts(lines) {
107
+ const map = new Map();
108
+ const conflicted = new Set();
109
+ const DECL = /\b(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*(?::\s*[^=]+?)?=\s*([^;\n]+)/g;
110
+ for (const line of lines) {
111
+ const trimmed = line.trimStart();
112
+ if (/^(\/\/|\*|\/\*)/.test(trimmed)) continue; // a commented-out const binds nothing
113
+ DECL.lastIndex = 0;
114
+ let m;
115
+ while ((m = DECL.exec(line)) !== null) {
116
+ const [, name, rhs] = m;
117
+ const value = foldLiteral(rhs);
118
+ if (value === null) { conflicted.add(name); continue; }
119
+ if (map.has(name) && map.get(name) !== value) conflicted.add(name);
120
+ else map.set(name, value);
121
+ }
122
+ }
123
+ for (const name of conflicted) map.delete(name);
124
+ return map;
125
+ }
126
+
127
+ /** Names in this file that reach a synchronous child-process call. */
128
+ function collectSyncNames(text) {
129
+ const names = new Set(SYNC_BUILTINS);
130
+ const IMPORT = /import\s*\{([^}]*)\}\s*from\s*['"]node:child_process['"]/g;
131
+ let m;
132
+ while ((m = IMPORT.exec(text)) !== null) {
133
+ for (const clause of m[1].split(',')) {
134
+ const alias = clause.match(/([A-Za-z_$][\w$]*)\s+as\s+([A-Za-z_$][\w$]*)/);
135
+ if (alias && SYNC_BUILTINS.includes(alias[1])) names.add(alias[2]);
136
+ }
137
+ }
138
+ return names;
139
+ }
140
+
141
+ /**
142
+ * The first argument of `name(` starting at `from`, as source text. Bounded to
143
+ * the line, matching this lint's existing granularity — a call split across
144
+ * lines is a separate, pre-existing gap, declared in the header rather than
145
+ * silently implied.
146
+ */
147
+ function firstArg(line, from) {
148
+ let depth = 0;
149
+ for (let i = from; i < line.length; i++) {
150
+ const c = line[i];
151
+ if (c === '(' || c === '[' || c === '{') depth++;
152
+ else if (c === ')' || c === ']' || c === '}') {
153
+ if (depth === 0) return line.slice(from, i);
154
+ depth--;
155
+ } else if (c === ',' && depth === 0) return line.slice(from, i);
156
+ }
157
+ return line.slice(from);
158
+ }
159
+
160
+ /**
161
+ * Does this line perform a synchronous scan? Resolves the command through
162
+ * literal folding and local constants before deciding.
163
+ */
164
+ function scanViolation(line, syncNames, constMap) {
165
+ for (const name of syncNames) {
166
+ const call = new RegExp(`\\b${name}\\s*\\(`, 'g');
167
+ let m;
168
+ while ((m = call.exec(line)) !== null) {
169
+ const arg = firstArg(line, m.index + m[0].length).trim();
170
+ let value = foldLiteral(arg);
171
+ if (value === null && /^[A-Za-z_$][\w$]*$/.test(arg)) value = constMap.get(arg) ?? null;
172
+ if (value !== null && SCAN_COMMAND.test(value.trim())) return true;
173
+ }
174
+ }
175
+ return false;
176
+ }
177
+
54
178
  const inScanDir = (p) => SCAN_DIRS.some((d) => p.startsWith(d + '/'));
55
179
 
56
180
  function listFiles() {
@@ -86,10 +210,12 @@ for (const rel of listFiles()) {
86
210
  let content;
87
211
  try { content = fs.readFileSync(full, 'utf-8'); } catch { continue; }
88
212
  const lines = content.split('\n');
213
+ const syncNames = collectSyncNames(content);
214
+ const constMap = collectStringConsts(lines);
89
215
  for (let i = 0; i < lines.length; i++) {
90
216
  const trimmed = lines[i].trimStart();
91
217
  if (/^(\/\/|\*|\/\*)/.test(trimmed)) continue; // comment-only mention
92
- if (!VIOLATION.test(lines[i])) continue;
218
+ if (!scanViolation(lines[i], syncNames, constMap)) continue;
93
219
  // Inline justification on this line or within the comment block directly
94
220
  // above (scan back up to 4 lines so a multi-line reason is honoured).
95
221
  let allowed = false;
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "$schema": "./builtin-manifest.schema.json",
3
3
  "schemaVersion": 1,
4
- "generatedAt": "2026-08-14T22:54:06.076Z",
5
- "instarVersion": "1.3.1146",
4
+ "generatedAt": "2026-08-14T23:03:50.148Z",
5
+ "instarVersion": "1.3.1147",
6
6
  "entryCount": 202,
7
7
  "entries": {
8
8
  "hook:session-start": {
@@ -2,7 +2,7 @@
2
2
  "schemaVersion": 1,
3
3
  "generatedFrom": "source-tree",
4
4
  "registrySha256": "81b53363a440e832672618965540b3e507ae0d93adcc67ec2b93daf7933b3ab4",
5
- "packageVersion": "1.3.1146",
5
+ "packageVersion": "1.3.1147",
6
6
  "guards": [
7
7
  {
8
8
  "ref": "docs/audits/phase-b/f10-triage.md",
@@ -1,5 +1,5 @@
1
1
  {
2
- "sha256": "675498ac7f3b9a5fd07a57a530eba5cc8645d84aede82b6f03348f7f502edb8a",
2
+ "sha256": "20cdf255a4e7e5577036fc766d33e560f5fdca277d059195494ac048766322aa",
3
3
  "registrySha256": "81b53363a440e832672618965540b3e507ae0d93adcc67ec2b93daf7933b3ab4",
4
- "packageVersion": "1.3.1146"
4
+ "packageVersion": "1.3.1147"
5
5
  }
@@ -2,5 +2,5 @@
2
2
  "sha256": "81b53363a440e832672618965540b3e507ae0d93adcc67ec2b93daf7933b3ab4",
3
3
  "articleCount": 88,
4
4
  "generatedFrom": "docs/STANDARDS-REGISTRY.md",
5
- "packageVersion": "1.3.1146"
5
+ "packageVersion": "1.3.1147"
6
6
  }
@@ -0,0 +1,55 @@
1
+ # Upgrade Guide — vNEXT
2
+
3
+ <!-- assembled-by: assemble-next-md -->
4
+ <!-- bump: patch -->
5
+
6
+ ## What Changed
7
+
8
+ `scripts/lint-no-blocking-process-scans.js` enforces root cause #4 of the 2026-06-07 "server temporarily
9
+ down" post-mortem: a synchronous `ps`/`pgrep`/`lsof`/`pkill` on a runtime hot path blocks the single-threaded
10
+ event loop, those commands get slow under exactly the load that makes monitors fire, and the cumulative
11
+ stall starved `/health` until the supervisor restarted a server that was alive the whole time.
12
+
13
+ The check required the scan command as a string literal inside the call, so the name one step away walked
14
+ past it while the event loop stalled identically:
15
+
16
+ ```js
17
+ const cmd = 'pgrep'; execFileSync(cmd, ['node']); // was not caught
18
+ const cmd = 'pg' + 'rep'; execFileSync(cmd, ['node']); // was not caught
19
+ import { execFileSync as run } from 'node:child_process';
20
+ run('pgrep', ['node']); // was not caught
21
+ ```
22
+
23
+ instar-codey reproduced the concatenation form against the shipped lint (exit 0) while auditing
24
+ rename-defeatable checks, and scoped the remedy. The command is now resolved before the rule is applied:
25
+ literal `+` chains fold, local `const` string bindings resolve, and import aliases of the three sync entry
26
+ points are followed.
27
+
28
+ Three choices keep it from flagging correct code, each with its own test: the resolved VALUE decides and
29
+ never the variable name (`const pgrep = 'tmux'` is legal); matching is whole-word (`psql` is not `ps`); and
30
+ an identifier bound to two different values in one file is treated as unresolvable and never flagged. Async
31
+ calls stay legal — moving to async is the remedy the rule exists to push toward.
32
+
33
+ Deliberately left open and stated in the header: calls split across multiple lines (line-oriented lint;
34
+ closing it means an AST), and commands read from config/argv/another module (needs dataflow analysis, and
35
+ guessing would over-block).
36
+
37
+ ## What to Tell Your User
38
+
39
+ None — internal change (no user-facing surface).
40
+
41
+ ## Summary of New Capabilities
42
+
43
+ None — internal change (no user-facing surface).
44
+
45
+ ## Evidence
46
+
47
+ - `tests/unit/lint-no-blocking-process-scans.test.ts` — 14/14 green (5 original + 9 added).
48
+ - Negative control: tests written BEFORE the fix and run against the shipped lint — **4 of 14 fail**
49
+ (const concatenation, plain variable, inline concatenation, import alias). The other 10 pass both ways,
50
+ which is what makes them controls.
51
+ - Real-tree verdict: `node scripts/lint-no-blocking-process-scans.js` → `clean`, exit 0 — no new flags on
52
+ existing code.
53
+ - Full `npm run lint` chain green.
54
+ - Side-effects review: `upgrades/side-effects/blocking-process-scan-command-resolution.md`.
55
+ - ELI16: `docs/specs/blocking-process-scan-command-resolution.eli16.md`.
@@ -0,0 +1,109 @@
1
+ # Side-Effects Review — blocking-process-scan lint resolves the command before deciding
2
+
3
+ **Version / slug:** `blocking-process-scan-command-resolution`
4
+ **Date:** `2026-08-14`
5
+ **Author:** `echo`
6
+ **Second-pass reviewer:** `not required — Tier 1 declared (CI-only tooling, riskFloor 1). No spec change: the §rule is unchanged; the check now resolves the command value before applying the same rule.`
7
+
8
+ ## Summary of the change
9
+
10
+ `scripts/lint-no-blocking-process-scans.js` enforces the topic-21816 post-mortem's root cause #4: a
11
+ synchronous `ps`/`pgrep`/`lsof`/`pkill` on a runtime hot path blocks the single-threaded event loop, and those
12
+ commands get slow under exactly the load that makes monitors fire — the cumulative stall starved `/health`,
13
+ the supervisor declared the live server unresponsive, and restarted it.
14
+
15
+ The check required the scan command as a string literal INSIDE the call:
16
+ `/\b(spawnSync|execSync|execFileSync)\s*\(\s*['"\`]\s*(ps|pgrep|lsof|pkill)\b/`. Putting the name one step
17
+ away walked past it, while the event loop stalled just the same — the incident was about what the process
18
+ DOES, not how the argument was spelled. instar-codey reproduced the concatenation form against the shipped
19
+ lint (`const cmd = 'pg' + 'rep'; execFileSync(cmd, ['node'])` → exit 0) and scoped the fix.
20
+
21
+ The command is now RESOLVED before the rule is applied: literal `+` chains fold, local `const` string bindings
22
+ resolve, and import aliases of the three sync entry points are followed.
23
+
24
+ ## Decision-point inventory
25
+
26
+ - `scanViolation()` — REPLACES the literal-only regex — resolves then decides. CI-time only; never runtime.
27
+ - `foldLiteral()` — ADD — pure literal chains only; a template with `${}` never folds.
28
+ - `collectStringConsts()` — ADD — file-wide, and **deliberately refuses ambiguity** (see §1).
29
+ - `collectSyncNames()` — ADD — follows `import { execFileSync as run } from 'node:child_process'`.
30
+ - The allow comment, the comment-only skip, the scan dirs, and the async remedy are all unchanged.
31
+ - No runtime block/allow decisions added or modified. This runs in `npm run lint` and CI only.
32
+
33
+ ## 1. Over-block
34
+
35
+ This is the failure that matters here: the lint blocks commits, so flagging correct code costs more than
36
+ missing a case. Three structural choices push against it, and each has a test:
37
+
38
+ - **The VALUE decides, never the name.** `const pgrep = 'tmux'` is legal; the identifier being called `pgrep`
39
+ is irrelevant.
40
+ - **Word-boundary on the resolved value.** `psql` is not `ps`; `pstree` is not `ps`.
41
+ - **Ambiguity resolves to NOT-flagged.** Bindings are collected file-wide rather than per-scope (a
42
+ line-oriented lint is not a compiler). An identifier bound more than once to DIFFERENT values is recorded as
43
+ unresolvable and never produces a violation — the safe direction, chosen on purpose.
44
+
45
+ Async calls are untouched: `execFile(cmd, …)` with a folded command stays legal, because async yielding the
46
+ loop IS the remedy this lint exists to push people toward.
47
+
48
+ Verified against the real tree: `src/monitoring` + `src/server` report clean, exit 0 — the widened check
49
+ introduces no new flags on existing code.
50
+
51
+ ## 2. Under-block
52
+
53
+ Stated in the header rather than implied:
54
+
55
+ - **A call split across multiple lines.** This lint is line-oriented; making it multi-line means an AST, which
56
+ is a different check at a different layer. Pre-existing — not introduced here.
57
+ - **A command read from config, argv, or another module.** Not foldable without dataflow analysis, and
58
+ guessing would over-block.
59
+ - Scope is still the two hot dirs (`src/monitoring`, `src/server`). `src/core`'s tmux-heavy session plumbing
60
+ remains the separate, larger conversion tracked in the post-mortem follow-up.
61
+
62
+ ## 3. Level-of-abstraction fit
63
+
64
+ Same layer as the shipped check — line-oriented regex over source, no AST, no type information, no new
65
+ dependency. The added machinery (fold, const map, alias map, first-arg extractor) is the minimum needed to
66
+ answer "what command does this actually run?" without climbing to a parser. Codey rated this scope
67
+ "low/medium FP risk if limited to child_process sync aliases plus literal/constant-folded command values in
68
+ src/monitoring and src/server" — that is exactly the scope implemented.
69
+
70
+ ## 4. Signal vs authority compliance
71
+
72
+ Unchanged. A CI guard, not a runtime authority. It forbids a synchronous enumeration on the hot path; the
73
+ async equivalent remains the sanctioned path, and the reviewed one-shot escape hatch still works.
74
+
75
+ ## 5. Interactions
76
+
77
+ - `npm run lint` chain (`package.json`) — position unchanged; full chain green.
78
+ - `--staged` path and explicit-file args unchanged in behaviour.
79
+ - Husky pre-commit / CI run the same chain.
80
+ - No source module, route, config key, or state file is touched.
81
+
82
+ ## 6. External surfaces
83
+
84
+ None. No HTTP route, no config key, no user-visible message, no CLAUDE.md template change (developer-facing
85
+ tooling, not an agent capability). Agent Awareness Standard does not apply.
86
+
87
+ ## 7. Rollback cost
88
+
89
+ `git revert` of one script plus one test file. No migration, no state, no deployed artifact.
90
+
91
+ ## Conclusion
92
+
93
+ Ship. Four evasions closed, each with a test that fails without the fix; six anti-over-block controls added
94
+ alongside; real tree verified clean.
95
+
96
+ ## Second-pass review (if required)
97
+
98
+ Not required at Tier 1. Independent corroboration exists regardless: instar-codey reproduced the evasion
99
+ separately and pre-scoped the remedy, including the warning not to overmatch all sync child-process calls.
100
+
101
+ ## Evidence pointers
102
+
103
+ - `tests/unit/lint-no-blocking-process-scans.test.ts` — 14/14 green (5 original + 9 added).
104
+ - Negative control: tests written BEFORE the fix and run against the shipped lint — **4 of 14 fail**
105
+ (const concatenation, plain variable, inline concatenation, import alias); the 10 others pass both ways,
106
+ which is what makes the controls controls.
107
+ - Real-tree verdict: `node scripts/lint-no-blocking-process-scans.js` → `clean`, exit 0.
108
+ - Full `npm run lint` chain green.
109
+ - Source incident: `docs/postmortems/2026-06-07-server-temporarily-down.md` (root cause #4).