diff --git a/.claude/memory/blockers.md b/.claude/memory/blockers.md index f6a9988..2d0fa05 100644 --- a/.claude/memory/blockers.md +++ b/.claude/memory/blockers.md @@ -384,6 +384,7 @@ rules: - **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//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. +- **Status (2026-11-13)**: resolved 6c10d3a: origin = /etc/systemd/system/ssh.service.d/override.conf OOMScoreAdjust=-1000 (root, 2026-09-22) inherited sshd → tmux → dtach → claude; scopes reject the property; lib/cc.sh inner bash raises /proc/self/oom_score_adj to 500 raise-only before exec claude (T7-oom). Live proof = a fresh cc session (user); the sshd override stays (user's call) ## BLK-045 — Hook-running test suites could reach real claude CLI: fail-open inline stubs, 3 suites unstubbed [resolved] (2026-11-06) diff --git a/.claude/memory/journal.md b/.claude/memory/journal.md index 537daef..f74c712 100644 --- a/.claude/memory/journal.md +++ b/.claude/memory/journal.md @@ -736,3 +736,4 @@ rules: - 2026-11-13: /hotfix blk022-burial (block E4): lib/tests/guard-bash.test.sh (SKIP-only, 214 cases) + 2 census ALLOW rows deleted; BLK-022 superseded by BDR-125 phase 2 (static rules + routing guard); security PASS (LOW: no executable destructive-command suite left, accepted). - /feat design-hook-removal (block E1): hooks/design-toolchain-reminder.sh + test + UserPromptSubmit entry deleted (9c038fd), T7c → T8i synthetic fixture, docs 19ec5b7 (CHANGELOG Removed wording = doc-syncer draft, user asked no mid-run questions). BDR-148. Gates 0 MET / 1 four oracles MET / 2 PASS, make test all green. Open sessions log one non-blocking hook error per prompt until restart. - /feat skill-routing-descriptions (block E2): CLAUDE.global.md § Skill routing 311 → 306 lines, 6 lines dropped into bugfix/ship-feature descriptions (3b30153, docs 88b67ab). Feater died mid-run (API 403 Cloudflare) after the 3 edits: gates proved the diff, no re-dispatch. Verifier caught a contract ledger bug: 1b. row absorbed by gates.sh → LRN-284, row renumbered 6. BDR-149. +- /bugfix cc-oom-score-adj (block G): BLK-044 root cause = sshd drop-in OOMScoreAdjust=-1000 inherited; lib/cc.sh raises oom_score_adj to 500 raise-only (6c10d3a, T7-oom, docs f5ce4ae). Gates 0 MET / 1 two rounds (80-col + redirect order) / 2 PASS, make test green. Live proof needs a fresh cc session (user). LRN-285. diff --git a/.claude/memory/learnings.md b/.claude/memory/learnings.md index c07028e..6611273 100644 --- a/.claude/memory/learnings.md +++ b/.claude/memory/learnings.md @@ -2072,3 +2072,8 @@ Rule: when editing a doctrine file under structure locks, grep the test's lock s - **Context**: E2 contract 2026-11-13 wrote a criterion `1b.`; `gates.sh run` printed VERDICT MET; fresh verifier found criterion 1 EVIDENCE still PENDING. - **Pattern**: `lib/gates.sh` `_absorb` recognizes a criterion only as `^([0-9]+)\.` (gates.sh:88). A `1b.`/`2a.` row = continuation of the previous criterion: its CHECK/EXPECT overwrite that criterion's own (`_set_attr`, :71-79), its EVIDENCE lands on the wrong line. Result = false MET by ledger clobbering, the real oracle of criterion 1 never runs. - **Apply**: contract criteria = integer labels only; a sub-case gets the next integer (`6.`), never a letter suffix. Verifier re-running every CHECK by hand caught it: keep that habit. Candidate fix (TODO): gates.sh warns on `^[0-9]+[a-z]\.` rows. + +## LRN-285 — oom_score_adj leaks from a service drop-in to every descendant; scopes reject OOMScoreAdjust; raise it in the exec'ing shell (2026-11-13) +- **Context**: BLK-044 (block G 2026-11-13): claude via `cc` at oom_score_adj -1000, origin "unknown" for weeks. +- **Pattern**: oom_score_adj is inherited across fork/exec; a service-level `OOMScoreAdjust=` (here sshd's drop-in `/etc/systemd/system/ssh.service.d/override.conf`) leaks into every interactive descendant (tmux server → shell → dtach → claude). Trace = walk `/proc//oom_score_adj` up the parent chain, then `systemctl cat` the first unit. `systemd-run --scope -p OOMScoreAdjust=…` fails ("Unknown assignment": scopes take no exec-context properties). Raising one's own value needs no privilege; lowering does. +- **Apply**: a per-session fix = write `/proc/self/oom_score_adj` in the shell that `exec`s the target (raise-only guard `-lt N`, stderr silenced BEFORE the `>` open so a failed open stays quiet). Proof = `/proc//oom_score_adj` of a fresh session; a running session never reflects the fix. `choom -n N -- cmd` (util-linux) is the equivalent binary. diff --git a/.claude/tasks/TODO.md b/.claude/tasks/TODO.md index d90333c..1eb7b37 100644 --- a/.claude/tasks/TODO.md +++ b/.claude/tasks/TODO.md @@ -12,7 +12,7 @@ Decisions at start (asked once): faunosteo memory v2 on `chore/memory-v2` off de - [x] D D1b (BDR-147, feature/digest-todo-fallback merged): digest Actionable ##/### else first 3 + overflow marker, seeds emit `## Actionable`, Session start reads no TODO; 6 repos migrated insert-only on `chore/todo-actionable`, merged on ask (robin_petier 7f87947, config, integration_alphalink, zenquality, game, faunosteo via scratch worktrees); faunosteo stale worktree entries pruned (dirs already gone) - [x] E (2026-11-13): E1 design hook deleted, BDR-148 (9c038fd, T7c → T8i); E2 Skill routing 311 → 306 lines, bugfix/ship-feature triggers, BDR-149 (3b30153); E4 BLK-022 buried (ce62d2b); rtk `cat|head|tail *.env*` forms benched: `rtk cat|head|tail --help` = coreutils pass-through (rtk 0.50.0), all 6 forms live and kept, T42 list unchanged; E3 `npm -g` 4 deny lines NOT removed: sub-agent dispatch refused by the auto-mode classifier (Undermining Oversight), branch bugfix/npm-global-deny empty, patch handed to the user in the run report (user hand edit, as before the run) - [ ] F faunosteo `chore/memory-v2`: `memory.sh upgrade`, `/context` before/after, /prune-memory there for BDR-080 (noisy) + LRN-080 (promotion); never merged by me -- [ ] G BLK-044: trace `oom_score_adj` origin (unit, cc.sh), `OOMScoreAdjust` on the `cc` scope, proof via `/proc//oom_score_adj` +- [x] G (2026-11-13): BLK-044 resolved, origin = sshd drop-in OOMScoreAdjust=-1000 inherited; lib/cc.sh raises oom_score_adj to 500 raise-only (6c10d3a, T7-oom, LRN-285); live proof `/proc//oom_score_adj` = 500 needs a fresh `cc` session (user, this session predates the fix) - [ ] H residuals in order: phase 0 (project-rules.sh emit/extract/`..`), 4a (BLK-038, MIGRATION.md:209), 5 (fragment key allowlist), 2 LOWs (awk, `mkdir -m 700`, `cat x.key`, doctor.sh:255), 4d follow-ups (transcripts per (root, session, agent), image prompts, threshold boundary tests, `tsc`, `l:` one global key), BUGS-FOUND unfixed since 11-09, LRN-270 bisect (user-run), doctor skillOverrides residue; a residual NOT done = justified in the TODO line removal - [ ] I model-router live checks: W4-B AC9 + parentModel done from transcripts/logs; Fable-out-of-credits + StopFailure closed "not reproducible, reopen on incident" - [ ] J /reconcile, CHANGELOG (gate 1 at 57 % delivered + each block), 0 BDR-125 line left, EVAL of the run, /close diff --git a/.claude/tasks/contracts/2026-11-13-cc-oom-score-adj-1210.md b/.claude/tasks/contracts/2026-11-13-cc-oom-score-adj-1210.md new file mode 100644 index 0000000..abf125e --- /dev/null +++ b/.claude/tasks/contracts/2026-11-13-cc-oom-score-adj-1210.md @@ -0,0 +1,34 @@ +# CONTRACT — cc-oom-score-adj (BLK-044, block G) +- date: 2026-11-13 | flow: bugfix | branch: bugfix/cc-oom-score-adj (off develop) +- status: active + +## REQUEST (verbatim — IMMUTABLE) +BLK-044 (block G): claude processes started via `cc` inherit oom_score_adj -1000. Root cause traced 2026-11-13: /etc/systemd/system/ssh.service.d/override.conf (root, 2026-09-22) sets `OOMScoreAdjust=-1000` on sshd; sshd → tmux → dtach → claude inherit it; `systemd-run --user --scope -p OOMScoreAdjust=500` fails ("Unknown assignment", scopes reject the property); an unprivileged write `echo 500 > /proc/self/oom_score_adj` inside the scope works (raising is allowed). Fix in lib/cc.sh: the inner `bash -c` writes 500 to /proc/self/oom_score_adj (ignore failure, never lower) before `exec claude`, so the OOM killer can pick a runaway claude first; lib/tests/cc.test.sh gains a check (the stub claude prints /proc/self/oom_score_adj or the inner script's write is asserted hermetically); proof = a new `cc` session's `/proc//oom_score_adj` = 500 (the user starts one; this session was started before the fix). The sshd override itself is the user's (root) call, left in place. + +## CLARIFICATIONS +- [gated 2026-11-13, internal] raise-only guard: the write runs only when the current value is below 500 (`[ "$(cat /proc/self/oom_score_adj)" -lt 500 ]`), stderr to /dev/null; a missing /proc leaves exec untouched. Value 500 = claude dies before shells at 0, after a genuine leak at 1000. +- [gated] test shape: the stub claude prints `oom=`; the check expects 500 when the runner's own value is < 500, else the runner's value unchanged (raise-only property proven either way). + +## ACCEPTANCE CRITERIA +1. lib/cc.sh inner script raises oom_score_adj to 500 before exec, raise-only (r1 expected 21; the header comment names it too → 3 lines). + CHECK: cd /home/bchanot/Documents/claude && echo $(grep -c 'oom_score_adj' lib/cc.sh)$(grep -c -- '-lt 500' lib/cc.sh) + EXPECT: 31 + EVIDENCE: MET exit=0 marker-found :: 31 +2. Regression test present and green. + CHECK: cd /home/bchanot/Documents/claude && bash lib/tests/cc.test.sh 2>&1 | tail -1 + EXPECT: FAIL=0 + EVIDENCE: MET exit=0 marker-found :: PASS=31 FAIL=0 +3. Hermetic proof: the inner script, run with the test stubs, lands claude at 500 when started below 500. + CHECK: cd /home/bchanot/Documents/claude && grep -c 'oom=' lib/tests/cc.test.sh | grep -c '^[1-9]' + EXPECT: 1 + EVIDENCE: MET exit=0 marker-found :: 1 +4. shellcheck clean on lib/cc.sh and lib/tests/cc.test.sh (-x: the test sources claude-stub.sh, SC1091 info predates the fix). + CHECK: cd /home/bchanot/Documents/claude && shellcheck -x lib/cc.sh lib/tests/cc.test.sh && echo SC-OK + EXPECT: SC-OK + EVIDENCE: MET exit=0 marker-found :: SC-OK +5. Live proof (manual, user): a new `cc` session → `cat /proc//oom_score_adj` prints 500; this session predates the fix. +6. make test green (manual, bun on PATH). + (manual: run 2026-11-13 on the final tree, `PATH=$HOME/.bun/bin:$PATH make test` → "SUITE: all GREEN / all suites green") + +## FILE SCOPE +lib/cc.sh (inner bash -c script + header comment), lib/tests/cc.test.sh. BLK-044 status → STEP 8 via memory.sh; MIGRATION/README mention → STEP 7 doc sync. diff --git a/CHANGELOG.md b/CHANGELOG.md index 24118e2..c80dc2e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,9 @@ Format follows [Keep a Changelog](https://keepachangelog.com/) and this project ### Removed - `hooks/design-toolchain-reminder.sh`, its `UserPromptSubmit` entry in `settings.json` (`ctx7-reminder` stays the only one) and its suite `lib/tests/design-toolchain-reminder.test.sh`. Measured 2026-10-31: 59 fires, 0 Reads of `rules/web-building.md`. Design routing stays with the `rules/web-building.md` path rule and the `CLAUDE.global.md` pointer. The fire log `~/.claude/logs/design-toolchain-fires.log` is left in place. +### Fixed +- `cc [profile]` (lib/cc.sh) raises the session's `oom_score_adj` to 500 before `exec claude` (raise-only, silent if the write fails). sshd's systemd override `OOMScoreAdjust=-1000` was inherited through tmux and dtach by every claude started with `cc`, so the OOM killer never picked a runaway session; `systemd-run --scope` rejects that property, hence the write inside the session (BLK-044). Test: `lib/tests/cc.test.sh` T7-oom. + ## [3.0.0] — 2026-11-12 ### Added diff --git a/lib/cc.sh b/lib/cc.sh index 3ce9770..a82a94c 100644 --- a/lib/cc.sh +++ b/lib/cc.sh @@ -16,6 +16,8 @@ # flag overrides; to change packs, start another `cc `. # Without a profile: manifest defaults + local settings, as before. # TMPDIR goes to ~/.cache/claude-tmp either way (BLK-021). +# oom_score_adj is raised to 500 inside the session (BLK-044: sshd's -1000 +# is inherited), raise-only. # ============================================================ _cc_name_ok() { [[ "$1" =~ ^[a-z0-9][a-z0-9-]*$ ]]; } @@ -45,6 +47,8 @@ cc() { dtach -c "$HOME/.dtach/${name}" -e '^\' \ bash -c 'set -a; [ -f "$HOME/.claude/.env" ] && . "$HOME/.claude/.env" set +a + [ "$(cat /proc/self/oom_score_adj 2>/dev/null)" -lt 500 ] \ + 2>/dev/null && echo 500 2>/dev/null > /proc/self/oom_score_adj if [ -n "$CLAUDE_PROFILE_SETTINGS" ]; then exec claude --settings "$CLAUDE_PROFILE_SETTINGS" fi diff --git a/lib/tests/cc.test.sh b/lib/tests/cc.test.sh index d19b47d..057cee9 100644 --- a/lib/tests/cc.test.sh +++ b/lib/tests/cc.test.sh @@ -3,7 +3,8 @@ # list + rc 2, no session; a profile → claude --settings with # CLAUDE_PROFILE / CLAUDE_PROFILE_SETTINGS / TMPDIR exported through # systemd-run + dtach; no profile → plain claude, TMPDIR still set; .env -# sourced. Hermetic: PATH shims, HOME in a fixture holding .claude/lib. +# sourced; oom_score_adj raised to 500 (raise-only). +# Hermetic: PATH shims, HOME in a fixture holding .claude/lib. set -u unset CLAUDE_PROFILE CLAUDE_PROFILE_SETTINGS ROOT="$(cd "$(dirname "$0")/../.." && pwd)" @@ -31,7 +32,8 @@ cat > "$FX/bin/claude" <<'EOT' #!/usr/bin/env bash { echo "claude argv: $*"; echo "CLAUDE_PROFILE=${CLAUDE_PROFILE-unset}" echo "CLAUDE_PROFILE_SETTINGS=${CLAUDE_PROFILE_SETTINGS-unset}" - echo "TMPDIR=${TMPDIR-unset}"; echo "canary=${CC_ENV_CANARY-unset}"; } >> "$CC_LOG" + echo "TMPDIR=${TMPDIR-unset}"; echo "canary=${CC_ENV_CANARY-unset}" + echo "oom=$(cat /proc/self/oom_score_adj 2>/dev/null)"; } >> "$CC_LOG" EOT chmod +x "$FX/bin/"* # shellcheck source=lib/tests/claude-stub.sh @@ -72,5 +74,7 @@ done printf 'CC_ENV_CANARY=1\n' > "$FX/home/.claude/.env" : > "$CC_LOG"; cc s4 webx; check_has T4-env "$(cat "$CC_LOG")" "canary=1" +want=$(cat /proc/self/oom_score_adj); [ "$want" -lt 500 ] && want=500 +check_has T7-oom "$(cat "$CC_LOG")" "oom=$want" check T5-shellcheck "$(shellcheck "$ROOT/lib/cc.sh" >/dev/null 2>&1 && echo ok)" ok printf 'PASS=%s FAIL=%s\n' "$pass" "$fail"; [ "$fail" -eq 0 ]