From 8829d3142c03dd63ce82115395437668bd45dbe6 Mon Sep 17 00:00:00 2001 From: Alexander Kucera Date: Wed, 25 Nov 2026 13:50:41 +0100 Subject: [PATCH] docs: add review and audit session logs Record the architecture review unit (tier property, login clock) and its two-round finish audit as session logs, register both in docs/devlog/INDEX.md and the root AGENTS.md window, and carry the round-1 corrections into the review log (exports, diff counts, which tests use the fake clock). --- AGENTS.md | 2 + ...eview-tier-property-and-login-clock_log.md | 58 ++++++++++++++++++ ...nish-audit-architecture-review-unit_log.md | 59 +++++++++++++++++++ docs/devlog/INDEX.md | 2 + 4 files changed, 121 insertions(+) create mode 100644 docs/devlog/20261125-architecture-review-tier-property-and-login-clock_log.md create mode 100644 docs/devlog/20261125-finish-audit-architecture-review-unit_log.md diff --git a/AGENTS.md b/AGENTS.md index e4bef19..a944337 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -128,5 +128,7 @@ Session logs live in `docs/devlog/` (one per completed task/issue/milestone). Fu | Date | Log | |------|-----| +| 2026-11-25 | [20261125-finish-audit-architecture-review-unit_log.md](docs/devlog/20261125-finish-audit-architecture-review-unit_log.md) | +| 2026-11-25 | [20261125-architecture-review-tier-property-and-login-clock_log.md](docs/devlog/20261125-architecture-review-tier-property-and-login-clock_log.md) | | 2026-11-25 | [20261125-fresh-context-audit-rounds-1-5_log.md](docs/devlog/20261125-fresh-context-audit-rounds-1-5_log.md) | diff --git a/docs/devlog/20261125-architecture-review-tier-property-and-login-clock_log.md b/docs/devlog/20261125-architecture-review-tier-property-and-login-clock_log.md new file mode 100644 index 0000000..2c4ef34 --- /dev/null +++ b/docs/devlog/20261125-architecture-review-tier-property-and-login-clock_log.md @@ -0,0 +1,58 @@ +# Architecture review: catalog tier as a model property, and a clock seam for the login poll loop + +> **Date:** 2026-11-25 +> **Type:** generic +> **Reference:** improve-codebase-architecture review (HTML report in `$TMPDIR`, not committed); grilling round 1–2; supersedes the round-3 decision row in `20261125-fresh-context-audit-rounds-1-5_log.md` + +## Goal + +Run the architecture review on `index.ts`, surface where a module is shallow or a rule has no locality, and implement the candidates the grilling settled, in priority order. + +## What Was Done + +- **Review.** Hot spots taken from `git log` (every fix commit touched `index.ts` and the tests); a fresh-context scout walked the code independently and ranked the same two friction points first. Report: three candidates, a Coherence note, one top recommendation. +- **Candidate 2, retire the tier strip.** The catalog tier now rides on the model as the `catalogTier` property (`TieredModel = Model & { catalogTier?: Tier }`, written by `toModel`, read by `tierOfModel`). `TIER_HEADER`, `untier`, `withoutTierHeader` and the adapter around pi's stream are deleted; `api` hands `openAICompletionsApi()` through untouched. The 35-line strip test is gone; the `toModel` test pins that a tiered model has **no** `headers`. +- **Candidate 1, poll loop testable through `login`.** `login(interaction, clock = realClock)`; `Clock = { now, sleep }`; `realClock` wraps `node:timers/promises` + `Date.now`; `auth.oauth.login` still passes only the interaction. `login` is exported. Five tests drive it through `driveLogin` with an auto-advancing clock: pending → `slow_down` → success (`[5000, 10000]`, one `device_code` event), missing interval → 5000, `0.5` → 1000 floor, deadline cap (`[5000, 5000, 2000]` then "Nous login timed out."), `expired_token` propagates without sleeping; the sixth test uses the real clock and a bare `fetch` mock: a non-OK device-code response throws with its status. +- **Candidate 3, catalog switch owner.** Parked (see Decisions). +- **Closeout.** Root `AGENTS.md` Architecture bullets, `tests/AGENTS.md` export list and clock contract, `CHANGELOG.md` `### Changed` with the upgrade note. `npm run check`: `tsc` clean, 25/25 tests (was 20). + +## Decisions & Rationale + +| Decision | Rationale | +|----------|-----------| +| Tier carried as a model property, not as `Model.headers["x-nous-catalog-tier"]` | pi forwards only `model.headers` into requests (pi-ai `dist/models.js:361,450`; coding-agent `dist/core/model-runtime.js:476`) but persists whole entries and restores them as-is: pi-ai `createProvider.refreshModels` (`dist/models.js:594-619`) sets `dynamicModels` from `context.stored` before any fetch, then persists the refreshed list through `context.publish`. The store is `ModelsStore` (`models-store.js:30`, `/models-store.json`). The header carrier needed four strip points and leaked for two audit rounds; a property needs none. A `tsc` probe against the repo's `paths` exited 0, with and without a new type. | +| One-line `TieredModel` intersection type | `tsc` then checks the write side: the property is written explicitly in a literal typed `TieredModel`, so a misspelled key is an excess-property error. The read side keeps one cast, where it already had one. | +| Accept the one-session edge for models persisted by the old version | Nous ignores the old header and the first interactive start rewrites the store entry (confirmed after the fact: 0 legacy headers in `models-store.json`). A legacy fallback read would need a removal condition and a verification step for no lasting gain. CHANGELOG tells the user to start pi once interactively after upgrading. The premise recorded at decision time was wrong (see Gotchas): whether a legacy-carrier entry existed locally was never established, because the check read `models.json`. | +| Optional clock parameter on `login`, over a hand-rolled mock-timer sleep or a pure wait-decision extraction | Zero-production-change paths are closed: `t.mock.timers` does not capture `node:timers/promises` and jiti does not alias `node:` builtins (both probed on Node 26.12.1). A hand-rolled abortable sleep re-adds code round 1 removed; pure extraction leaves the deadline loop and error propagation untested. Two adapters (real timers, fake clock) make it a real seam, and pi's interface is unchanged. | +| Auto-advancing fake clock (`sleep` adds its ms to `now`) | The deadline falls out of the recorded sleeps, which pins the round-3 cap exactly. A hand-advanced clock was rejected as ceremony. | +| Candidate 3 parked | Deletion test: `apply` already concentrates the rule (two commands, one implementation); the three fixed bugs were ordering and await mistakes a new owner would not have prevented; the `drive()` harness weight is unchanged. Do not re-raise without new evidence. | +| No `GLOSSARY.md`, no ADR | "Catalog tier" is already defined in root `AGENTS.md`; the carrier is easy to reverse and ADR-0001 is untouched. The round-3 devlog row is superseded by this log, not rewritten. | + +## Gotchas & Fixes + +| Problem | Root Cause | Fix | +|---------|------------|-----| +| The whole `index.ts` edit was rejected, nothing written | Two `LINE:HASH` anchors mistyped by hand for lines 310 and 313 | Re-sent with the hashes from the read output; the edit tool rejects atomically, so no partial state | +| `login` treated as already exported in the plan | Misread of line 112 (`async function login`, no `export`) | The export is part of the new signature; `tests/AGENTS.md` lists it | +| Persisted-model check read the wrong file | `~/.pi/agent/models.json` is the user's overrides (`ModelConfig`); the dynamic catalog that `createProvider` restores and persists is `~/.pi/agent/models-store.json` (`ModelsStore`). The earlier recipe (`grep -c x-nous-catalog-tier ~/.pi/agent/models.json`) therefore proved nothing | After the user's test, read `models-store.json`: 0 `x-nous-catalog-tier`, 45 `catalogTier`. Recipe and root `AGENTS.md` now name the right file | + +## Files Changed + +| File | Change Summary | +|------|---------------| +| `index.ts` | `Tier`, `TieredModel`; `toModel` writes `catalogTier`; `tierOfModel` reads it; `TIER_HEADER`, `untier`, `withoutTierHeader` and the then-unused `ProviderStreams` import deleted; `api` passes pi's stream through. internal `Clock` and `realClock`; `login(interaction, clock)` exported; `auth.oauth.login` wraps it. Net +20 −36. | +| `tests/index.test.mjs` | Strip test deleted; `toModel` tier test retargeted to the property with `headers === undefined`; `drive()` helper uses `catalogTier`; `driveLogin` + six `login` tests (five on the fake clock); the fetch mock throws after 100 token polls so a sleep-less regression fails instead of hanging | +| `AGENTS.md` | Architecture: carrier bullet rewritten; `login` clock bullet added; session-log window refreshed | +| `tests/AGENTS.md` | Purpose mentions the poll loop and no wall-clock time; export list; `login` clock and `driveLogin` contract; why mock timers and jiti aliasing cannot be used | +| `CHANGELOG.md` | `### Changed`: carrier move and the upgrade note | +| `docs/devlog/20261125-architecture-review-tier-property-and-login-clock_log.md`, `docs/devlog/INDEX.md` | This log and the index row | + +## Open Items & Next Steps + +- [x] Live check of the carrier: done by the user on 2026-11-25 — toggled full, free and promo, restarted with free active, `/model` listed only free models, then returned to full (which removes the flag file). On disk afterwards: `~/.pi/agent/models-store.json` `nous-portal` entry with 409 models, 45 `catalogTier` (3 free, 42 promo), 0 `x-nous-catalog-tier`, 0 models with `headers`, `checkedAt` 2026-11-25T10:58:50Z. +- [x] Mutation check of the six poll-loop tests, run the same day in a scratch copy (temp dir with `index.ts`, `tests/`, `node_modules` symlinked; the repo file was never touched). Six mutations — `slow_down` bump removed, interval fallback 5 → 1, 1 s floor removed, deadline cap removed, non-retryable error swallowed, non-OK device-code check removed — each failed exactly its own test (1 fail / 24 pass, baseline 25/25). +- [x] Committed in the closeout as two atomic commits, each gated on its own tree: `cb5aecf` (carrier move, `refactor:`, 19/19) and `544af1e` (clock seam + tests, `test:`, 25/25). +- [ ] Delete the review report from `$TMPDIR` when no longer needed. + +--- +*Log written by write-log skill* diff --git a/docs/devlog/20261125-finish-audit-architecture-review-unit_log.md b/docs/devlog/20261125-finish-audit-architecture-review-unit_log.md new file mode 100644 index 0000000..fcafec3 --- /dev/null +++ b/docs/devlog/20261125-finish-audit-architecture-review-unit_log.md @@ -0,0 +1,59 @@ +# Finish audit of the architecture-review unit: two rounds to a clean-or-docs-only round + +> **Date:** 2026-11-25 +> **Type:** generic +> **Reference:** procedure `/Users/alex/.pi/agent/prompts/finish_audit.md`; audits the unit recorded in `20261125-architecture-review-tier-property-and-login-clock_log.md` + +## Goal + +Run the finish-audit procedure over this session's uncommitted changes (catalog tier moved to a model property, `login` clock seam with six tests, docs and wiki): fresh-context reviewer fanout, synthesize the three reports, fix accepted findings, and repeat until one full clean-or-docs-only round follows the last code-change finding. + +## What Was Done + +- **Before each round:** five patches re-materialized into `_code_review/` by explicit path list (production / tests / docs / new devlog / agent-wikis), each verified by reverse-apply against the working tree; `after/` snapshots byte-identical; secret scan clean. The morning audit's stale patches were moved to `_code_review/_rounds-1-5-stale/`. Round 2 also materialized README, the ADR and `tsconfig.json` under `after/`, which round-1 reviewers had to skip. +- **Each round:** three fresh-context, read-only reviewers (`ponytail-review`, `security-review`, `review`) in ONE `workflow: true` call with `runs.all` and `worktree: false`; brief at `_code_review/BRIEF.md`; the cumulative "already fixed, do NOT re-report" ledger pasted into every task (17 items carried forward, then 22, then 24). Launched async, armed `goal_wait`, resumed on the native completion wake. +- **Round 1 verdicts:** ponytail code 2 / security CLEAN / general code 1, docs 1, tests 1. Deduplicated: two code-change findings, so round 2 was required. +- **Round 1 fixes:** dead `type ProviderStreams` import deleted; `toModel` writes `catalogTier: tier,` directly instead of a conditional spread; the `driveLogin` fetch mock throws after 100 token polls; the devlog's export wording corrected. +- **Round 2 verdicts:** ponytail CLEAN / security CLEAN / general code 0, docs 2, tests 0. Zero code-change findings in a full round after the last code-change round: stopping rule met, no round 3. +- **Round 2 fixes (docs):** the devlog `index.ts` row says +20 −36 and names the dropped import; "five tests on the fake clock, the sixth on the real clock" in the devlog and `tests/AGENTS.md`; the wiki's injected-clock recipe gained the poll cap, with its INDEX summary and `log.md`. +- **Gates:** `npm run check` after each round: `tsc` clean, 25/25. Wiki lint: 0 errors (its one warning is the unrelated `tea-api-output-flag.md` taxonomy tag). + +## Decisions & Rationale + +| Decision | Rationale | +|----------|-----------| +| Accept the conditional-spread deletion (ponytail) | No reader distinguishes an absent key from `undefined`: `tierOfModel` returns `undefined` both ways and the JSON store drops the key. `exactOptionalPropertyTypes` stays at its default (tsconfig checked), and an explicit property in a literal typed `TieredModel` is better for `tsc` than a spread, where a misspelled key would not be an excess-property error. | +| Reproduce the hang before accepting the test finding | In a scratch copy under a 10 s watchdog, `else throw error;` to `else {}` left the non-retryable test with no result until killed; after the guard the same mutation fails in 273 ms. A plain `Error` from the mock bypasses the `instanceof OAuthError` filter in `login`, so it surfaces even when the loop swallows OAuth errors. | +| Stop after round 2 | It was a full round with zero code-change findings following the last code-change round, the procedure's Goodhart edge. Its two docs findings were counts and wording; fixing them does not reopen the loop. | +| Mutation checks in a scratch copy, not after a commit | The unit is uncommitted and the user has not asked for commits. A temp dir with `node_modules` symlinked exercises the same code with no `git checkout`, so the earlier "checkout discards the fix" trap cannot occur. | +| No commits | Outside the goal's scope and not requested. Both repos are left with uncommitted changes. | + +## Gotchas & Fixes + +| Problem | Root Cause | Fix | +|---------|------------|-----| +| Round-1 reviewers had to skip README, the ADR and `tsconfig.json` | Unchanged files were not materialized | Added under `after/` for round 2; README and ADR confirmed free of header-carrier wording | +| A five-part exact-text edit of the devlog was rejected whole | One target read "a non-OK device-code response" where the file says "non-OK device-code response" | Re-applied the three affected lines by `LINE:HASH` anchor | +| `_code_review/` still held the morning audit's patches | Scratch from the previous loop was never cleared | Moved to `_rounds-1-5-stale/`; the morning's ledger is carried forward in the brief | +| `goal_complete` rejected the first completion summary | Negated phrasing about an out-of-scope leftover ("NOT DONE: commits") is read as incompleteness | Same facts rephrased affirmatively; accepted | + +## Files Changed + +| File | Change Summary | +|------|---------------| +| `index.ts` | `ProviderStreams` import removed; `catalogTier: tier,` written directly. Unit total: +20 −36 | +| `tests/index.test.mjs` | 100-poll runaway guard in the `driveLogin` mock; the untiered assertion is `.catalogTier === undefined` | +| `tests/AGENTS.md` | Five-of-six wording; the 100-poll guard contract and why no test timeout can fire | +| `docs/devlog/20261125-architecture-review-tier-property-and-login-clock_log.md` | Export wording, diff counts, five-vs-six wording, decision row | +| `docs/devlog/20261125-finish-audit-architecture-review-unit_log.md`, `docs/devlog/INDEX.md`, `AGENTS.md` | This log, its index row, the refreshed session-log window | +| agent-wikis: `pi/gotchas/pi-device-code-login-dialog.md`, `pi/INDEX.md`, `pi/log.md` | Poll cap added to the injected-clock recipe; summary and action log | +| `_code_review/` (gitignored) | Round briefs with the cumulative ledger (24 items), patches, snapshots | + +## Open Items & Next Steps + +- [x] Committed in the closeout: `cb5aecf` (carrier move, with the audit's dead-import and explicit-property fixes) and `544af1e` (clock seam and tests, with the runaway guard), each gated on its own tree; this log and its index rows follow in a `docs:` commit. `agent-wikis`: `27b6aa8` (review, audit and distill learnings; that repo has no remote, so nothing to push there). +- [x] The six poll-loop mutations re-run against the final files after the `driveLogin` guard (fresh scratch copy; each mutation asserted to apply exactly once): each fails exactly its own test (1 fail / 24 pass, baseline 25/25); the repo file was untouched. +- [ ] Abort-during-sleep in `login` remains untested (security reviewer, both rounds; not introduced by this unit). + +--- +*Log written by write-log skill* diff --git a/docs/devlog/INDEX.md b/docs/devlog/INDEX.md index 975644b..f240d1e 100644 --- a/docs/devlog/INDEX.md +++ b/docs/devlog/INDEX.md @@ -5,4 +5,6 @@ Complete history of session logs in this directory, newest first. One-line summa | Date | Type | File | Summary | |------|------|------|---------| +| 2026-11-25 | generic | [20261125-finish-audit-architecture-review-unit_log.md](20261125-finish-audit-architecture-review-unit_log.md) | Two-round finish audit of the carrier move and clock seam: two code nits and a test-hang guard fixed, then a docs-only round | +| 2026-11-25 | generic | [20261125-architecture-review-tier-property-and-login-clock_log.md](20261125-architecture-review-tier-property-and-login-clock_log.md) | Architecture review: tier moves from a request header to a model property, `login` gains a clock seam, poll loop now tested | | 2026-11-25 | generic | [20261125-fresh-context-audit-rounds-1-5_log.md](20261125-fresh-context-audit-rounds-1-5_log.md) | Five-round fresh-context audit of the Nous Portal provider: two P1s surfaced in round 3, clean in round 5 |