chore(memory): BLK-043 fork bomb resolved in 49aa2ff, BLK-044 open, contract and plans

This commit is contained in:
bchanot committed 2026-11-06 11:38:48 +01:00
1 parent fb2a4ff5ba
commit fd646a611a
6 files changed
+321 -1

No files matched your search

+13
View File
@@ -370,3 +370,16 @@ rules:
- **Real cause**: no rule or guard named package/archive extraction into system dirs; the ssh deny rule did not cover vaas-cli ssh; extraction improvised instead of telling the user there was no package manager.
- **Solution**: `hooks/extract-guard.sh` (deny before run, quoted remote scripts re-scanned) + soft_deny line + doctrine bullet (list first, extract into a literal mktemp -d path, PATH/PYTHONPATH, no package manager → tell the user). See the extract-guard BDR.
- **Status**: resolved 2026-11-05.
## BLK-043 — detect_plan CLI fallback forks claude from SessionStart hook: recursive fork bomb, OOM, reboot [open] (2026-11-06)
- **Friction**: `make test suite=lib/tests/session-digest.test.sh` (uncommitted SD13 cases) ate 14 GiB in 45 s, 2026-11-05 23:49; earlyoom killed valheim, node, mariadb, docker, audio; kernel OOM; machine rebooted 23:55; all sessions + RC lost. OOM dump: 126 `claude`, 396 `bash`, 124 `sh`.
- **Real cause**: `lib/detect-plugins.sh` `detect_plan` falls back to `claude config get planType` when `$HOME/.claude.json` lacks plan markers. claude 2.1.318 has no `config` subcommand → words read as prompt → full session → its SessionStart hook (`hooks/session-start.sh:158`) calls `detect_plan` again, same HOME → unbounded recursion. SD13 `mkhome` linked `~/.claude/*` but not `~/.claude.json`. Prod survives only via internal flags `tengu_cobalt_compass` + `tengu_harbor` in `~/.claude.json`; flag rename upstream → every session start recurses.
- **Solution**: pending /bugfix (plan `.claude/tasks/plans/2026-11-06-detect-plan-fork-bomb-0030.md`): CLI fallback dropped (default pro), hook recursion guard env marker, suite-wide `claude` stub in PATH + regression cases.
- **Status**: open 2026-11-06, fix in progress.
- **Status (2026-11-06)**: resolved 49aa2ff (hotfix/detect-plan-fork-bomb): CLI fallback dropped, env guard SESSION_START_RUNNING, lib/tests/detect-plan.test.sh red on main lib, green after; merge pending user
## BLK-044 — claude processes run with oom_score_adj -1000 of unknown origin: OOM killers spare a runaway claude [open] (2026-11-06)
- **Friction**: during the detect_plan fork bomb (2026-11-05 23:49), every `claude`, `bash`, `grep` child carried `oom_score_adj=-1000`; earlyoom and kernel OOM could not kill the runaway, killed every other service instead (valheim, mariadb, docker, networkd, logind) until reboot. Live session 2026-11-06 still shows `-1000`.
- **Real cause**: unknown. Not set by the repo (`lib/cc.sh`, hooks: no OOMScoreAdjust). Suspects: inherited from launcher (dtach under `systemd-run --user --scope`, sshd, or the RC/remote-control process).
- **Solution**: none yet. Next: trace `/proc/<pid>/oom_score_adj` up the parent chain of a live claude; then set `OOMScoreAdjust` (e.g. 500) on the `cc` scope so a claude runaway dies first.
- **Status**: open 2026-11-06.
+3
View File
@@ -696,3 +696,6 @@ rules:
## 2026-11-05
- 2026-11-05: extract-guard built on feature/extract-guard (hook, soft_deny, doctrine; verifier CONFORME, security PASS); live in settings working copy; 4c paused at plan r2; merge pending user.
## 2026-11-06
- 2026-11-06: machine OOM reboot 2026-11-05 23:55 root-caused: detect_plan `claude config get planType` fork bomb via SessionStart (BLK-043), SD13 fake HOME trigger. /bugfix: 3 lenses → r2 (hotfix off main, worktree), GATE 0 MET, verifier ECARTS(1 SC2016) → CONFORME, security PASS ×2; 49aa2ff. BLK-044 open (oom_score_adj -1000). Merge + Part B pending.
+4 -1
View File
@@ -117,9 +117,12 @@ Shared rules for every phase:
- [x] shortcut (done in 4c, Task 1: the lexical reader is gone, statuses come from `memory.sh index`): `mods/memory/hooks/register.ts` `isSuperseded` is a lexical reader, not memory.sh's status parser; upgrade = share that parser when 4c needs it (final review M11)
- **4c read side (built 2026-11-05 on feature/memory-recall, merge pending).** Two channels only: intent recall at `prompt.submit` for classifier labels design/analysis or the first coding prompt after idle (BM25 top-30 over title + lesson + body → haiku keeps ≤3, bounded 3 s, fail open) and tool-error 4-gram match (PostToolUse; a classic hook is acceptable if the mod ledger is not needed). Session digest (open BLK via the status parser, actionable TODO, last journal line) in `hooks/session-start.sh` on `source: startup|compact|clear` (native matchers; the mod's `session.compact` only skips); a SubagentStart twin if sub-agents need it. Injection = ID + title + lesson line; superseded never injected; budget ~1.5k chars per turn; once per context. Deferred: Read path triggers, Bash command triggers, "critical → deny once", Tier 1, cross-repo scope=global index, `memory_search` tool.
- 4c follow-up from the 4b live proof (2026-11-04): `memory_pending` lists milestones of the current session only, so a `/capitalize` run right after `/clear` misses the previous session's `fix:`/finish milestones (they stay in the store). Option: list earlier-session milestones marked `(earlier session)`. Doctrine (capitalize before /clear) covers the normal path.
- **4d feedback and promotion.** The injection log now exists (4c, store key `l:<root>`); 4d waits on its data. DEFERRED until a plain injection log (ID, trigger kind, turn, cited or not) shows misses or noise; then /prune-memory reads it and promotion to a mechanism follows BDR-100.
- **4d feedback and promotion.** Plan r1 (draft, not challenged): `.claude/tasks/plans/2026-11-05-memory-feedback-4d-1834.md`. Log read 2026-11-05: 1 real record, no decision possible; it cannot show usefulness or misses alone and transcripts live 7 days. Order: 4d.1 log fields `cands` + `ms` → 4d.2 weekly reader (log × transcripts, labels.tsv) → 4d.3 gate (≥20 prompt + ≥10 tool injections, or 5 weeks) with thresholds fixed now → 4d.4 /prune-memory + BDR-100 promotion, conditional. Starts after the 4c merge; 4 open choices in the plan.
- [ ] shortcut: the injection log lives under `l:<root>` store keys (about 28 KiB each, 200 records and 64 KiB at most); `sweepLogs` counts them with the `p:` keys and evicts the oldest log key (by its newest record, never the current root's) once the total nears the engine's 4 MiB store cap; upgrade = one global log key or a smaller per-root cap (`mods/memory/hooks/register.ts`).
- [ ] residual: the pre-existing `memory.sh check` call in `hooks/session-start.sh` is not time-bounded (the digest's `memory.sh index blocker` call is); upgrade = wrap it in `timeout 2`.
- [ ] BLK-043 hotfix `49aa2ff` on hotfix/detect-plan-fork-bomb (worktree ../claude-hotfix-wt): merge on user signal (`gitflow finish` → main + develop), then `git worktree remove`; then Part B on this branch: suite-wide `claude` PATH stub + final empty-log check in `lib/tests/session-digest.test.sh` BEFORE SD13/SD14 run again (plan `.claude/tasks/plans/2026-11-06-detect-plan-fork-bomb-0030.md` r2).
- [ ] shortcut (BLK-043 gate 2 LOWs): `lib/tests/detect-plan.test.sh` unchecked `mktemp -d` (empty WORK → real `claude probe`), `bash -c "source '$LIB'"` interpolation, no `GIT_CEILING_DIRECTORIES` on hook runs; and the memory, graphify-gate, push-guard suites run the hook with no `claude` stub. Upgrade = `|| exit 1` + `command -v claude` assert, positional args, ceiling dir, shared stub helper.
- [ ] BLK-044: trace origin of `oom_score_adj=-1000` on claude processes; set `OOMScoreAdjust` on the `cc` scope so a runaway claude dies first.
- Proof: recall precision on ≥20 real prompts and ≥10 real errors, target ≥ the 14/22 baseline; digest after a real compaction; redaction test on the ledger; `/context` delta; captured-failure demo: an error from session N recalled in session N+1.
### Actionable
@@ -0,0 +1,53 @@
# CONTRACT — detect-plan-fork-bomb
- date: 2026-11-06 | flow: bugfix | branch: hotfix/detect-plan-fork-bomb (worktree /home/bchanot/Documents/claude-hotfix-wt, off main 4093cca)
- status: active
## REQUEST (verbatim — IMMUTABLE)
oui lance le bugfix maintenat pour regler cette escalade et met dnas blockers
(context, the bug as received: `make test suite=lib/tests/session-digest.test.sh` filled the RAM, OOM, machine reboot 2026-11-05 23:55; root cause `lib/detect-plugins.sh` `detect_plan` falls back to `claude config get planType`, which starts a full session whose SessionStart hook calls `detect_plan` again: recursive fork bomb. Plan: `.claude/tasks/plans/2026-11-06-detect-plan-fork-bomb-0030.md` r2.)
## CLARIFICATIONS
Q: landing branch? / A: hotfix/* off main, in a separate git worktree; finish merges main + develop; the session-digest stub (Part B) goes to feature/memory-recall after. [gated 2026-11-06]
Q: safety order / A: NEVER run `hooks/session-start.sh`, `make test` (any form) or any suite that runs the hook, in either tree, before fix 1 is on disk in the worktree. The red proof runs `detect_plan` directly (no hook) with the `claude` stub on PATH. Every suite run goes through `systemd-run --user --scope -q -p TasksMax=256`. Never run the real `claude` CLI. [gated 2026-11-06]
Q: BLK entry / A: BLK-043 (fork bomb, open → resolved at commit) and BLK-044 (oom_score_adj -1000, open) written 2026-11-06. [gated 2026-11-06]
## ACCEPTANCE CRITERIA
1. `detect_plan` in the worktree calls no `claude` CLI; the vulnerable call exists on main (positive control).
CHECK: cd /home/bchanot/Documents/claude-hotfix-wt && git show main:lib/detect-plugins.sh | grep -q 'claude config get planType' && ! grep -nE '(^|[^A-Za-z_./-])claude[[:space:]]+[a-z-]' lib/detect-plugins.sh && echo C1_NO_CLI
EXPECT: C1_NO_CLI
EVIDENCE: MET exit=0 marker-found :: C1_NO_CLI
2. Regression suite `lib/tests/detect-plan.test.sh` exists and passes on the fixed tree, contained.
CHECK: cd /home/bchanot/Documents/claude-hotfix-wt && test -f lib/tests/detect-plan.test.sh && systemd-run --user --scope -q -p TasksMax=256 bash lib/tests/detect-plan.test.sh && echo C2_GREEN
EXPECT: C2_GREEN
EVIDENCE: MET exit=0 marker-found :: detect-plan: 9 passed, 0 failed C2_GREEN
3. Symptom reproduced: the same suite FAILS when pointed at main's `lib/detect-plugins.sh` (the suite takes the lib path from `DETECT_PLUGINS_LIB`, default the repo copy), and the stub, not a real `claude`, caught the call.
CHECK: cd /home/bchanot/Documents/claude-hotfix-wt && git show main:lib/detect-plugins.sh > /home/bchanot/.cache/claude-tmp/claude-1000/-home-bchanot-Documents-claude/fb6518b7-0114-4bfb-9d49-04965b322457/scratchpad/main-detect-plugins.sh && if DETECT_PLUGINS_LIB=/home/bchanot/.cache/claude-tmp/claude-1000/-home-bchanot-Documents-claude/fb6518b7-0114-4bfb-9d49-04965b322457/scratchpad/main-detect-plugins.sh systemd-run --user --scope -q -p TasksMax=256 bash lib/tests/detect-plan.test.sh >/home/bchanot/.cache/claude-tmp/claude-1000/-home-bchanot-Documents-claude/fb6518b7-0114-4bfb-9d49-04965b322457/scratchpad/c3.out 2>&1; then false; else grep -q 'FAIL T1-no-json-calls' /home/bchanot/.cache/claude-tmp/claude-1000/-home-bchanot-Documents-claude/fb6518b7-0114-4bfb-9d49-04965b322457/scratchpad/c3.out && echo C3_RED_BEFORE; fi
(amended 2026-11-06 by the orchestrator before GATE 0: same check, literal scratchpad paths instead of `rm -rf "$t"`; fail line pinned to the regression case)
EXPECT: C3_RED_BEFORE
EVIDENCE: MET exit=0 marker-found :: C3_RED_BEFORE
4. The suite proves its stub is reached (positive control: a `claude` call through PATH logs exactly 1 line before the absence checks), calls `detect_plan` directly with a HOME holding no `.claude.json` and asserts output `pro` with 0 new logged calls.
(judged by the verifier from the suite source)
5. Recursion guard: `hooks/session-start.sh` exits 0 with no output when `SESSION_START_RUNNING` is set, and otherwise exports `SESSION_START_RUNNING=1` before any child process. The suite asserts both: an early-exit case, and a child of the hook (a PATH stub `git`) that records `1`. The hook comment states the guard is defense-in-depth with no live caller and relies on Claude Code passing env to hooks.
CHECK: cd /home/bchanot/Documents/claude-hotfix-wt && grep -q 'SESSION_START_RUNNING' hooks/session-start.sh && grep -q 'SESSION_START_RUNNING' lib/tests/detect-plan.test.sh && echo C5_GUARD_PRESENT
EXPECT: C5_GUARD_PRESENT
EVIDENCE: MET exit=0 marker-found :: C5_GUARD_PRESENT
6. Dead code removed: `detect_plan` docstring says it returns max or pro (no free); the `free)` arm of the plan `case` in `hooks/session-start.sh` is gone.
CHECK: cd /home/bchanot/Documents/claude-hotfix-wt && ! grep -nE '^[[:space:]]*free\)' hooks/session-start.sh && ! grep -niE 'max, pro, or free' lib/detect-plugins.sh && echo C6_NO_DEAD
EXPECT: C6_NO_DEAD
EVIDENCE: MET exit=0 marker-found :: C6_NO_DEAD
7. shellcheck clean on the three files.
CHECK: cd /home/bchanot/Documents/claude-hotfix-wt && shellcheck lib/detect-plugins.sh hooks/session-start.sh lib/tests/detect-plan.test.sh && echo C7_LINT
EXPECT: C7_LINT
EVIDENCE: MET exit=0 marker-found :: C7_LINT
8. Full suite green once, contained (LRN-209: one full run before finish).
CHECK: cd /home/bchanot/Documents/claude-hotfix-wt && systemd-run --user --scope -q -p TasksMax=512 make test >/home/bchanot/.cache/claude-tmp/claude-1000/-home-bchanot-Documents-claude/fb6518b7-0114-4bfb-9d49-04965b322457/scratchpad/hotfix-maketest.log 2>&1; rc=$?; tail -5 /home/bchanot/.cache/claude-tmp/claude-1000/-home-bchanot-Documents-claude/fb6518b7-0114-4bfb-9d49-04965b322457/scratchpad/hotfix-maketest.log; [ "$rc" -eq 0 ] && echo C8_SUITE_GREEN
EXPECT: C8_SUITE_GREEN
EVIDENCE: MET exit=0 marker-found :: GREEN ✓ G3 strict-YAML: all agents/*.md frontmatter parse GREEN ✓ G4 hermetic: run-reconcile.sh reads fixtures only, not the live registry G…
## FILE SCOPE
In /home/bchanot/Documents/claude-hotfix-wt only:
- lib/detect-plugins.sh (detect_plan)
- hooks/session-start.sh (guard at top; `free)` arm)
- lib/tests/detect-plan.test.sh (new)
Nothing in /home/bchanot/Documents/claude (the feature/memory-recall tree and its uncommitted work).
@@ -0,0 +1,138 @@
# Phase 4d memory feedback and promotion: plan (2026-11-05)
BDR-125 phase 4d, host `mods/memory` (BDR-137). Input: the 4c injection log,
store key `l:<root>` (`LogRecord` in `mods/memory/hooks/register.ts`).
Status: draft r1, not challenged, not gated. Starts after the 4c merge.
## What the log holds (read 2026-11-05, 18:30)
- Real use: 1 record. This repo, trigger `fresh`, outcome `injected`, IDs
BDR-125, BDR-137, LRN-261: the prompt that asked for this plan.
- Plus 1 headless proof record (tool channel, fixture BLK-001, temp repo).
- Expected rate in this repo (RECALL.md, 14 days, after the content floor):
about 15 triggered asks per 14 days, 3 tool-channel injections.
No decision can come from this. The TODO gate ("deferred until the log shows
misses or noise") is not met, and the log alone can never meet it, for the
three reasons below.
## Gaps between the log and the 4d questions
1. Usefulness is not recorded. The 4d design (queue challenge 2026-10-25)
asked for "cited or not"; a record holds `at, session, agent, channel,
ids, trigger, outcome`. Relevance needs the prompt and the reply, and
both live in the transcript, not in the store.
2. Misses leave no trace. The log lists what came, never what should have
come. Example: this plan's prompt did not bring BDR-100, the promotion
rule the TODO 4d line cites, and nothing records that.
3. Transcripts live 7 days (`cleanupPeriodDays: 7`, job7 step D, secret
hygiene). A single log-to-transcript join at the gate, about 3 weeks
out, would find most turns gone. Older transcripts survive today; the
setting does not promise it.
Minor: a prompt-channel `none` mixes "BM25 found no candidate" and "haiku
declined" (both paths in `recallFor`); rerank latency is not logged, only
the `timeout` outcome.
## 4d.1 Two log fields (mod, /feat after the 4c merge)
- Prompt records gain `cands` (BM25 candidates after the seen filter, 0-30)
and `ms` (rerank wall time, absent when no rerank ran). Both optional in
`isLogRecord`: records written before stay valid.
- Size: about 40 bytes more per record, 200 records stay under 40 KiB
(cap 64 KiB).
- Nothing else enters the store: no prompt text, no reply text (LRN-124),
no runtime cited flag (it would need a Stop hook reading the transcript
every turn, for a signal the offline join gets at no runtime cost).
- Proof: kit tests for both fields, an old-shape record still loads, the
`none` split visible on a fixture with zero candidates.
## 4d.2 Weekly reader (harness, no runtime change)
- `feedback.ts` (bun) beside this plan. It reuses `recall-bench.ts`'s
transcript loader (`findFiles`, `records`, `composerText`, exported, not
copied) and the mod's own functions (no port, LRN-261).
- Reads every `l:` key of the store file, all roots. The file path is
engine-internal (`~/.claude/plugins/store/memory_skills-dir-*.json`):
a renamed file fails loudly, acceptable for a measurement tool.
- Joins each record to its transcript by `session` and `at`:
- prompt channel: the composer prompt it answered and the assistant turn
that followed;
- tool channel: the failing command and the next 3 Bash results of the
same session (retry succeeded or not).
- Per injected entry: `cited` (the ID appears in the turn's assistant
text, a lower bound) and a relevance label (controller labels, the user
spot-checks: the 4c method).
- Misses: on up to 5 triggered asks per run, the controller searches the
registries for relevant entries the recall did not bring, and names the
cause (no lexical overlap, BM25 rank over 30, haiku declined). The
FR-prompt vs EN-entry gap is the expected first cause.
- Persists `labels.tsv` (at, root name, channel, trigger, outcome, cands,
ID, cited, label): IDs and enums only, committed. Labelled records are
skipped on the next run; prompt and reply text stay in the scratchpad.
- Writes `FEEDBACK.md`: counts and shares only.
- Cadence: once a week, inside the 7-day window, about 10 minutes of label
checks for the user.
## 4d.3 Gate and decisions fixed before the data
Gate: at least 20 labelled injected prompt asks and 10 tool injections (the
BDR-125 proof line), or 5 weeks after the 4c merge, whichever comes first.
At the date cap with a smaller n: report "insufficient sample" with the n,
extend once or close.
| Signal | Threshold | Action |
|---|---|---|
| prompt precision (relevant / injected entries) | at least 64 % | keep |
| same, below 64 % | worst trigger kind below 50 % | tighten or drop that trigger (idle first: the 4c noise sat there) |
| precision of the 3rd pick | below 40 % | cap at 2 entries |
| timeout + paused share (asks with `cands` > 0) | above 25 % | revisit `RERANK_MS` or skip the rerank on short lists |
| `ms` p90 | below 2500 | lower `RERANK_MS`: every triggered prompt waits that long |
| tool precision | below 50 % | require 2 matched grams, or exclude the entry |
| misses in the sample | 1 ask in 3 or more | diagnose by cause; no fix built ahead |
| entry injected 3 times or more, 0 relevant | any | noisy: /prune-memory rewrites it |
| entry relevant 3 times or more, in 2 sessions or more | any | promotion candidate (BDR-100) |
Each action is its own /feat or /hotfix with the measurement attached. 4d
builds no tuning before the gate.
## 4d.4 Promotion and /prune-memory (conditional)
Built only if the gate shows at least one noisy entry or one promotion
candidate; otherwise closed with the measurement, like phase 3.
- Promotion stays a proposal: the reader lists each candidate with its
counts, the user picks, the mechanism (guard, test, skill step) becomes
its own TODO run, and the entry links the mechanism's commit. Never
automatic.
- /prune-memory STEP 1 gains "D. Recall feedback": reads `labels.tsv`
through one lib script that holds the thresholds (doctrine "After code
changes" step 4); noisy entries join section C, promotion candidates go
to STEP 2 as TODO lines.
- Open at that point: where other repos keep their labels (the mod logs
every root, the reader lives in this repo).
## Open choices (user)
1. Cadence vs retention: weekly reader runs (recommended); or raise
`cleanupPeriodDays` for the window (reverses job7 step D, transcripts
carry secrets); or one run at the gate on a single week.
2. 4d.1 fields `cands` and `ms`: add them (recommended) or measure with the
current record.
3. Gate numbers and the 5-week cap.
4. Promotion threshold: relevant 3 times in 2 sessions.
## Prerequisite: 4c merge
- Recall half of the interactive proof seen in this session: a fresh design
prompt brought 3 entries, all relevant to the ask by the controller's
reading (labeller and beneficiary are the same model: unchecked).
- Still owed: the digest after a real `/compact`, the 4c gates, the user's
"merge it".
## Out of scope
Runtime cited flag, prompt text in the store, the 4c deferrals (Read and
Bash command triggers, critical deny-once, Tier 1, cross-repo index,
`memory_search`), the `l:<root>` cross-root shortcut and the unbounded
`memory.sh check` residual (own TODO lines).
@@ -0,0 +1,110 @@
# Bugfix plan: detect_plan fork bomb (2026-11-06)
## Diagnosis
BUG: running `lib/tests/session-digest.test.sh` (uncommitted SD13 cases)
filled 14 GiB of RAM in 45 s; 2026-11-05 23:49 → OOM → reboot 23:55.
Kernel OOM dump: 126 `claude`, 396 `bash`, 124 `sh`, all
`oom_score_adj=-1000`.
ROOT CAUSE: `lib/detect-plugins.sh:85` `detect_plan` falls back to
`claude config get planType` when `$HOME/.claude.json` lacks the plan
markers or is absent. claude 2.1.318 has no `config` subcommand
(`claude config --help` prints the main usage), so the words are read
as a prompt and a full session starts. Its SessionStart hook
(`hooks/session-start.sh:158` → `detect_plan`) runs with the same HOME,
finds the same missing markers, starts another `claude`: unbounded
recursion. SD13's `mkhome` builds a HOME that links `~/.claude/*` but
not `~/.claude.json`, so the fallback fires.
EVIDENCE: journal boot -1 (earlyoom + kernel OOM table), transcript
90b2c305 (`make test suite=lib/tests/session-digest.test.sh` at
23:49:07, result at 23:51:28), `claude config --help` output.
BLAST RADIUS: production too. Real sessions survive only because
`~/.claude.json` holds `tengu_cobalt_compass` + `tengu_harbor` (internal
feature flags). If upstream renames them, every session start recurses.
`detect_plan` is called only from `hooks/session-start.sh:158`. No other
hook or lib calls the `claude` CLI (`lib/cc.sh` is the user launcher).
The hook header already promises "Filesystem only, except one git fetch".
RELATED MEMORY: no BLK/BDR/LRN bears (grep detect_plan, fork, recurs,
oom, planType).
## Fix plan
1. `lib/detect-plugins.sh` `detect_plan`: delete the `claude config get
planType` fallback and its `case`; markers absent → `echo "pro"`
(the existing default). Comment states why the CLI is never called
(a hook-launched `claude` re-enters this hook).
2. `hooks/session-start.sh`: recursion guard at the top, before stdin
is read: `[ -n "${CLAUDE_SS_RUNNING:-}" ] && exit 0; export
CLAUDE_SS_RUNNING=1`. The variable lives only in the hook's process
tree: a sibling session never sees it; any `claude` a future change
spawns from the hook gets a silent no-op hook instead of a cascade.
3. `lib/tests/session-digest.test.sh` (keeps the uncommitted SD13/SD14
cases intact):
- suite-wide stub: `$WORK/stub/claude` writes one line to
`$WORK/claude-calls` and exits 0; `PATH="$WORK/stub:$PATH"` exported
before any case. A regression then records a call instead of
forking a real session. SD13h's `PATH="$bin"` already holds no
claude.
- SD15a: `HOME` without `.claude.json` (mkhome as is), hook runs →
`claude-calls` absent/empty.
- SD15b: `CLAUDE_SS_RUNNING=1` set → hook prints nothing, rc 0.
- SD15c: `detect_plan` sourced alone with an empty HOME prints `pro`.
Replaces the `ulimit -u` idea: the per-user process cap counts every
process of the user (hundreds of live ones), so a value is either
too tight (spurious red) or too loose (no protection); the stub is
deterministic.
ORDER: fix 1 lands before the suite runs again (DO NOT run the suite
on the current tree).
RISK: low. Plan detection for users without the markers now always
reports Pro (banner budget label only). Guard: a user who runs the hook
by hand from inside a hook-spawned shell sees nothing (no such use).
Out of scope: origin of `oom_score_adj=-1000` on claude processes
(recorded as an open BLK), plan detection accuracy.
## Revision r2 (after 3-lens challenge, 2026-11-06)
Challenge: simplicity SOLID (4 MINOR), correctness CONCERNS (1 MAJOR),
robustness CONCERNS (3 MAJOR). Named changes:
- R1 (correctness 1, robustness 3: landing). The fallback is on main and
develop. The fix splits in two:
- Part A, on its own branch off main or develop (user choice), in a
separate `git worktree` (so `~/.claude/hooks` and `~/.claude/lib`,
symlinked to the main working tree, never flip to another branch and
the uncommitted 4c work stays untouched): fix 1, fix 2, and a
standalone regression suite `lib/tests/detect-plan.test.sh` that
needs nothing from feature/memory-recall.
- Part B, on feature/memory-recall after Part A merges: suite-wide
stub in session-digest.test.sh + final empty-log assertion.
- R2 (robustness 1+2, correctness 2+4: proof). The stub is written with
the log path expanded at creation, `chmod +x`, and a positive control
first calls `claude` through PATH and asserts 1 logged line (stub
reached). The regression case calls `detect_plan` directly (no hook,
no recursion path) with an empty HOME and asserts output `pro` AND
0 new log lines. Red proof: that case runs once against the pre-fix
lib (safe: stub catches the single call) and must fail, then pass
after fix 1. Copied into the contract as [gated]: never run the hook,
`make test` or the session-digest suite before fix 1 is on disk.
- R3 (correctness 3, robustness 5: guard). Guard kept as
defense-in-depth (the -1000 adj made the runaway unkillable), renamed
`SESSION_START_RUNNING` (simplicity 4, repo convention). The hook
comment says it has no live caller and that it relies on claude
passing env to its hooks. Test: hook run with the variable set prints
nothing, rc 0; and a PATH stub `git` writes `$SESSION_START_RUNNING`
seen by the hook's child, asserting `1` (proves the export).
- R4 (simplicity 2, correctness 5: dead code). detect_plan docstring
"max or pro"; the `free)` arm at session-start.sh:162 dropped.
- R5 (simplicity 3): SD15a/SD15c dropped from Part B; one final
cumulative empty-log check covers every hook run of the suite.
- R6 (robustness 6: containment). The first run of each suite after the
fix goes through `systemd-run --user --scope -p TasksMax=256` (cgroup
pids cap counting only that scope).
- Deferred to TODO (robustness 4, MINOR): stub in memory, graphify-gate
and push-guard suites, which run the hook with the real HOME.