Files
smart-compact/docs/devlog/20261115-reviewer-fanout-audit-hardening_log.md
T
AlexKucera 54ee2a57eb docs: add session log, learnings, and glossary
Devlog for the 4-round reviewer-fanout audit with decisions and
gotchas; AGENTS.md gains GitNexus code-intelligence boilerplate
plus Project Learnings and Session Logs sections; GLOSSARY.md
defines warn/force tiers and the compaction cycle.
2026-11-15 19:27:40 +01:00

60 lines
5.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Reviewer-fanout audit of smart-compact initial commit
> **Date:** 2026-11-15
> **Type:** generic
> **Reference:** commit `2c6d989` (initial) → working tree; review rounds 1–4
## Goal
Audit the smart-compact extension (two-tier context management for Pi) with a fresh-context reviewer fanout — one reviewer each for ponytail-review, security-review, and review — then fix every accepted finding and repeat until all reviewers report no issues.
## What Was Done
- Ran 4 review rounds via `runs.all([...])` fanout (3 reviewer children per round, `context: "fresh"`, read-only, diff artifacts materialized to `/tmp`).
- Fixed 12 accepted findings total; round 4 returned "No issues found" from all three reviewers.
- `index.ts` — force tier moved from `turn_end` to `agent_settled` (manual compaction aborts active runs); settled handler now awaits compaction completion; per-field config validation with default fallback; `lastKnownTokens` cleared on `session_compact`; deleted duplicate `SmartCompactUserConfig` interface (use `Partial<SmartCompactConfig>`); removed unreachable `"DISABLED"` status branch.
- `harness.ts` — new committed mock harness, 15 tests, `node --test harness.ts`, 15/15 green (Node 26.12.1, type stripping).
- `README.md` — corrected precedence claim (threshold ordering ≠ execution ordering), documented `agent_settled` trigger, honest verification section.
- Rebuilt GitNexus index (44 nodes, 65 edges, 2 flows) — generated `AGENTS.md`/`CLAUDE.md`/`.claude/` boilerplate alongside.
## Decisions & Rationale
| Decision | Rationale |
|----------|-----------|
| Force tier fires on `agent_settled`, never `turn_end` | Pi 1.5.2 `AgentSession.compact()` aborts the active run and never resumes the interrupted turn (`dist/core/agent-session.js:2321–2327`); built-in mid-run compaction preserves the run instead. `agent_settled` is idle-guaranteed (`ctx.isIdle()` true), so compaction aborts nothing. |
| Settled handler awaits compaction completion (promise around `onComplete`/`onError`) | `ctx.compact()` returns immediately; prompts deferred from settled handlers (and print-mode message loops) otherwise race an in-flight compaction and can be rejected. Awaiting also keeps the in-flight lock honest. |
| Built-in threshold stays the mid-run actor; docs claim narrowed | `(1 − forceFraction) × window > reserveTokens` orders thresholds, not execution — a run crossing both before settling lets Pi compact first. Safe: it preserves the run. |
| Per-field config validation (finite positive tokens, fractions in (0,1), boolean enabled; fall back to defaults) | `forceTokens: null` made `Math.min(null, …) → 0` (compaction every turn); non-numeric strings → `NaN` silently disabled tiers. Robustness, not security (trust ruling below). |
| Settings files ruled trusted operator input | Locally-installed extension; repo write access already implies stronger channels (AGENTS.md instructions, source itself). Security reviewer filed validation as robustness only. |
| Harness = `node:test` + type stripping, zero deps | Node ≥ 22.18 runs `.ts` natively; keeps "single file, no dependencies" property of the extension. Config injected via temp project `.pi/settings.json` (all fields set, so global user config can't leak into assertions). |
## Gotchas & Fixes
| Problem | Root Cause | Fix |
|---------|------------|-----|
| Reviewer children blocked asking for `git show` artifacts (3 supervisor requests) | Reviewer agents have no shell/git; `watchdog_diff` excludes committed ranges | Materialize diffs to `/tmp/*.diff` up front; for untracked files use `git add -N` (intent-to-add) so `git diff HEAD` includes them |
| `subagent({workflow: true})` rejected: "no text" / reads only the calling message | The ```js workflow block must be in the SAME message as the call | Re-issue with `options: { script: "..." }` instead of `workflow: true` |
| Harness deadlocked after the await fix (test run hung 120s) | The in-flight-lock test awaited a handler whose mock compaction never calls a callback — the awaited promise never settles | Don't await never-settling handler promises in tests; fire without awaiting, then assert the lock blocks the second call |
| `edit` replace failed on header comment | `old_text` dropped two leading spaces (` * ` comment continuation) — exact match required | Re-read the region, edit via LINE:HASH anchors (`set_line`/`replace_lines`) |
## Files Changed
| File | Change Summary |
|------|----------------|
| `index.ts` | Force tier → `agent_settled` with awaited compaction; config validation; token-cache clearing; interface dedupe; dead branch removed |
| `README.md` | Corrected trigger docs, precedence caveat, guards, verification section |
| `harness.ts` | New: 15-test mock harness (`node --test harness.ts`) |
| `AGENTS.md` | GitNexus boilerplate + Session Logs / Project Learnings sections |
| `CLAUDE.md`, `.claude/` | Generated by `gitnexus analyze` (boilerplate mirror + skills copies) |
| `docs/devlog/` | This log + INDEX.md |
## Open Items & Next Steps
- [ ] Live-session validation of the first real warn crossing (100k) and first force compaction at settle — wording of the notice message may need tuning (`index.ts` single string)
- [ ] Policy decision: keep regenerating vs gitignoring `CLAUDE.md`/`.claude/` on future `gitnexus analyze` runs
- [ ] Consider a `pi -p` end-to-end smoke test script if the harness ever grows beyond mock-level
---
*Log written by write-log skill*