From 98b9431e6eb0ff20b7c42631cd07e8a7bbef3e6c Mon Sep 17 00:00:00 2001 From: Rahul Singh Khokhar Date: Mon, 11 May 2026 08:17:57 -0700 Subject: [PATCH] chore(project): mark STORY-039f done; file STORY-039g; log decisions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - STORY-039f (variant seeding CLI) status → done with merge SHA + summary. - STORY-039g (failureLogger agent wiring) filed at status: backlog with full ACs. Captures the unwired piece of PR #76's squash-rebase. - DECISIONS_LOG: two new 2026-05-11 entries — (1) cycle-break + NOT-NULL ripple + TaskStop reflex, (2) squash-rebase fallback + STORY-NNNg "ship the structure, defer the glue" convention. --- docs/decisions/DECISIONS_LOG.md | 54 +++++++++++++++++ .../stories/STORY-039f-variant-seeding-cli.md | 3 +- ...39g-variant-failure-logger-agent-wiring.md | 58 +++++++++++++++++++ 3 files changed, 114 insertions(+), 1 deletion(-) create mode 100644 project/stories/STORY-039g-variant-failure-logger-agent-wiring.md diff --git a/docs/decisions/DECISIONS_LOG.md b/docs/decisions/DECISIONS_LOG.md index 88e73ab..a555d3c 100644 --- a/docs/decisions/DECISIONS_LOG.md +++ b/docs/decisions/DECISIONS_LOG.md @@ -8,6 +8,60 @@ --- +## 2026-05-11 — Squash-rebase as a fallback when iterative rebase hits too many conflicts; STORY-NNNg follow-up convention for "defer the wiring, ship the structure" + +**Context:** STORY-039e (admin failed-gate surface for LLM-generated variants) was authored against an older `main` and accumulated 12 commits before the orchestrator started merging follow-ups in parallel. By the time PR #76 was ready, `main` had moved through six merges (STORY-038b, 039a, 039c, 039d, 039f, 034a, 045a) — five of which collided with STORY-039e on the same files (`packages/agent/src/{index.ts, problem-variants.ts, problem-variants.test.ts}` and `apps/api/src/problem-variants{.ts, .test.ts}`). The standard rebase loop produced cascade conflicts: every one of the 12 commits re-introduced a conflict on the same chunk, and resolving them one by one was producing inconsistent intermediate states that the next commit's rebase then re-conflicted against. After ~15 minutes the orchestrator gave up on the iterative rebase and switched strategy. + +**Decision:** +1. **When iterative rebase produces a cascade (every commit reconflicts on the same files), switch to squash-rebase.** Procedure: + 1. `git rebase --abort` to bail out. + 2. `git reset --hard origin/main` on the branch worktree. + 3. `git checkout origin/ -- .` to overlay the branch's tip files onto main. + 4. For any file the branch's tip OVERWROTE that main's newer commits had also modified (i.e., files involved in the cascade), `git checkout origin/main -- ` to restore main's version, then re-apply the branch's additive parts via targeted Edit. This concentrates the conflict resolution into ONE pass, not 12. + 5. Stage everything, `pnpm format`, write a single squash commit explaining what was preserved vs. deferred, force-push. +2. **`STORY-NNNg` is reserved for "ship the structure now, wire the cross-cutting glue next."** When a follow-up's runtime integration (the wiring that crosses three packages) collides irreconcilably with a sibling follow-up that landed first, ship the new STRUCTURE (DB tables, migrations, routes, types, UI surfaces) under the original `STORY-NNN` and file the WIRING as `STORY-NNNg` (always the 'g' letter for "glue / generic-followup"). The follow-up commit message must call out exactly what's left unwired, with a concrete one-line description per missing edge. For STORY-039e, that was: "agent-side `failureLogger` wiring (passing failureLogger to `generateProblemVariant` + `safeLogFailure` calls in `tryGenerateOne`) is NOT included in this commit because it conflicted non-trivially with STORY-039d's spec-clarity judge runtime integration that landed on main first. The variant_gate_failures table is set up to receive failure entries; wiring the agent to write to it is filed as a STORY-039g follow-up." + +**Alternatives considered:** +- **Power through the cascade rebase no matter the cost** — would have eaten another 30+ minutes of orchestrator time and produced merge commits with ambiguous resolutions (the same conflict resolved differently across 12 commits). Rejected. +- **Squash the branch's 12 commits into 1 BEFORE rebasing** (`git rebase -i origin/main --autosquash` with `s` markers, or `git reset --soft $(git merge-base origin/main HEAD) && git commit`) — equivalent to the squash-rebase strategy but doesn't help if the squashed diff still conflicts on the same chunks; the file-by-file restoration step in the squash-rebase strategy IS the part that breaks the cascade. Squash-only without file restoration was tried first and didn't help. +- **Drop the conflicting commits from the rebase (`git rebase --skip`)** — would lose the actual work. Rejected. + +**Consequences:** +- (+) Cascade conflicts now have a documented escape hatch. +- (+) The 'g' suffix gives a clean signal in `STORY-NNN[a-z]*.md` globs: anything ending in `g` is a known wiring gap, not just another follow-up. +- (–) Squash-rebase loses per-commit attribution in `git log`. The squash commit's body must summarize what each squashed commit contributed. This session's STORY-039e squash commit follows that pattern. +- (–) Future follow-ups need to know: when picking up STORY-039g, the test file at `apps/api/src/problem-variants.test.ts` won't have the failureLogger expectations the original STORY-039e branch added. STORY-039g picks those up from the structural state, not by cherry-picking. + +**Owner:** user (via standing "merge all and proceed" directive that prompted the strategy switch). +**Related:** STORY-039e (squash-rebased into PR #76 commit `4edd8f1`), STORY-039g (to be filed by work-tracking), the 2026-05-11 cycle-break entry above for the parent agent-dispatch playbook. + +--- + +## 2026-05-11 — Cycle-break for the variant seeding CLI; NOT-NULL column ripple cost; agent TaskStop as a fight-the-edit-loop tool + +**Context:** STORY-039f shipped an operator CLI (`pnpm --filter @learnpro/problems seed:variants`) to top up the `problem_variants` cache. The agent placed the CLI in `packages/problems/src/seed-variants-cli.ts` and added `@learnpro/agent` to `packages/problems`'s `devDependencies` because the CLI imports `seedVariantsForProblem` from `@learnpro/agent`. `@learnpro/agent` already depends on `@learnpro/problems` for the seed bank — so the dev-only back-edge creates a workspace cycle. The agent's `NOTE on the workspace dep cycle:` claimed pnpm only warns and that it's harmless for tooling-only entry points. **Turborepo disagrees:** `turbo run typecheck` errored with `Cyclic dependency detected: @learnpro/problems#build, @learnpro/agent#build` and refused to run any task. Separately, STORY-039e added `users.is_admin boolean NOT NULL default false` and `SessionUser` (the apps/api type) gained `is_admin: boolean` as required — every test factory across `apps/api/src/*.test.ts` (~8 files) and `packages/db/src/data-export.test.ts` then failed typecheck because they constructed a user-shaped object without `is_admin`. CI caught both classes of breakage; neither was visible in the agent's local typecheck which ran scoped to its own package. + +**Decision:** +1. **Workspace cycles, even dev-only, are forbidden in this monorepo.** If package A's CLI consumes a helper that lives in package B, and B already depends on A, the CLI moves to B. Concretely: the variant seeding CLI now lives in `packages/agent/src/seed-variants-cli.ts` next to `seed-variants.ts` (the helper it wraps); operator runs `pnpm --filter @learnpro/agent seed:variants` instead of `--filter @learnpro/problems`. `@learnpro/problems`'s `package.json` is clean of the back-edge dev-dep + the script. Agent prompts that introduce new CLIs now include "if you reach for `@learnpro/X` from `@learnpro/Y` and Y is already in X's deps tree, put the CLI in X." +2. **Adding a NOT-NULL column without a Zod-derived default in the shared user shape ripples to every test factory.** The cheap fix is to add `is_admin: false` (or whatever the new column default is) to every fixture; the structural fix is to derive the test factory type from `typeof users.$inferInsert` (which respects the column default) instead of from `User` (the select-shape). For STORY-039e the cheap fix was the right call (8 occurrences, mechanical). The structural fix is filed mentally but not yet a Story — promote to one only if a third NOT-NULL ripple lands. +3. **`TaskStop` is the right tool when an agent and the orchestrator are editing the same file in opposite directions.** During this run, two agents (STORY-039f's running agent and the orchestrator) were ping-ponging `packages/problems/package.json` — the agent kept re-adding the dev-dep, the orchestrator kept removing it. `TaskStop ` (then orchestrator finishes the resolution + commits + pushes) is faster than waiting for the agent to finish and rebasing afterward. Use it when the agent's last `` snippet shows it's mid-fix on the same file you're editing. +4. **Migration-number contention now has a concrete failure mode.** STORY-039c (per-user seen-seed, merged via PR #77) took migration `0024_episode_variant_of`. STORY-039e (admin failed-gate, in flight as PR #76) also claimed 0024 and 0025. Resolution: renumbered STORY-039e to 0025 and 0026, updated `_journal.json` accordingly, updated the story-file activity log to reference the new numbers, updated the BOARD.md "Last updated" header body text. Total cost ~5 min of careful editing. The discipline from the 2026-05-06 entry (claim numbers up front in the brief) wasn't applied for this batch — re-apply it for the next batch. + +**Alternatives considered:** +- **Suppress the Turborepo cycle check via `turbo.json` config** instead of moving the CLI — would let the dev-only cycle live but defeats the safety property the check provides (real runtime cycles would also slip through). Rejected. +- **Derive `SessionUser` from a Zod schema with `is_admin` defaulting to `false`** — would let test factories omit `is_admin` and still typecheck. Strictly better. Not done in this session because the cheap fix unblocked CI and the structural change touches the auth boundary. Filed as a mental followup; promote to a Story if a third NOT-NULL column ripples through the same test factories. + +**Consequences:** +- (+) Future CLIs in this monorepo follow the "place at the deepest consumer" rule by default. +- (+) Adding NOT-NULL columns is now a known-cost operation: budget ~10 min of test-factory updates per new required column. +- (+) The `TaskStop` reflex shortens the orchestrator-vs-agent edit-loop from "wait + rebase" to "stop + finish." +- (–) `pnpm-lock.yaml` rebuild was required for the cycle-break (the dev-dep removal changed the manifest); CI failed once with `ERR_PNPM_OUTDATED_LOCKFILE` before the orchestrator ran `pnpm install` and committed the lockfile sync. + +**Owner:** user (via standing "keep building, fix as you go" directive). +**Related:** STORY-039f (`story/039f-variant-seeding-cli`), STORY-039e (`story/039e-admin-failed-gate-surface`), STORY-039c (PR #77 merged at `96baa54`), the 2026-05-06 DECISIONS_LOG entry above for the parent agent-dispatch playbook. + +--- + ## 2026-05-06 — STORY-NNNa convention for in-Story deferred follow-ups; agent-dispatch operational lessons from the v1-finishing run **Context:** The session that closed v1 (19 P0/P1/P2 stories merged in one push) routinely landed a primary STORY with one or more deferred ACs — too costly to ship in scope, too small to file as a fresh STORY-NNN. STORY-037 deferred the runtime persistence wiring; STORY-039 deferred 4 ACs around novelty / admin / seeding / Piston-validation; STORY-041 deferred the BullMQ trigger; STORY-043 deferred the multi-file grade-tool harness; STORY-046 deferred the entire weekly view; STORY-038 deferred the tutor route fan-out for the comprehension `kind`; STORY-036 deferred live-model validation; etc. Eight deferred follow-ups landed in this session alone (037a, 037b, 038a, 039a, 041a, 043a, 046b, 046c). The convention crystallized as it was used. diff --git a/project/stories/STORY-039f-variant-seeding-cli.md b/project/stories/STORY-039f-variant-seeding-cli.md index ba7591a..70dfb2a 100644 --- a/project/stories/STORY-039f-variant-seeding-cli.md +++ b/project/stories/STORY-039f-variant-seeding-cli.md @@ -2,7 +2,7 @@ id: STORY-039f title: 100-variant seeding CLI infrastructure (STORY-039 follow-up) type: story -status: in-progress +status: done priority: P2 estimate: S parent: EPIC-007 @@ -82,3 +82,4 @@ ships the *infrastructure* only. ## Activity log - 2026-05-11 — created, picked up +- 2026-05-11 — done. Merged via PR #78 at commit `3e2ded8`. Shipped the operator CLI in `packages/agent/src/seed-variants-cli.ts` (moved from `packages/problems` mid-PR to break a Turborepo workspace cycle; see DECISIONS_LOG 2026-05-11 entry). `pnpm --filter @learnpro/agent seed:variants -- --dry-run --count 3 --all-implement` previews; with `ANTHROPIC_API_KEY` set the real run tops up the `problem_variants` cache. Flags: `--source-slug`, `--all-implement`, `--count` (1-20), `--language`. Tests stub LLM + in-memory DB so CI never spends real money. New `docs/operations/SEED_VARIANTS.md` operator guide. diff --git a/project/stories/STORY-039g-variant-failure-logger-agent-wiring.md b/project/stories/STORY-039g-variant-failure-logger-agent-wiring.md new file mode 100644 index 0000000..5b5d3e1 --- /dev/null +++ b/project/stories/STORY-039g-variant-failure-logger-agent-wiring.md @@ -0,0 +1,58 @@ +--- +id: STORY-039g +title: Wire failureLogger into generateProblemVariant tryGenerateOne (STORY-039e glue) +type: story +status: backlog +priority: P2 +estimate: S +parent: STORY-039 +phase: v1 +tags: [agent, variants, follow-up, glue] +created: 2026-05-11 +updated: 2026-05-11 +--- + +## Description + +Deferred follow-up from STORY-039e. PR #76 squash-rebased STORY-039e onto a `main` that already had STORY-039d's spec-clarity judge integration (merged via PR #75). The two stories both modified `packages/agent/src/problem-variants.ts`, `packages/agent/src/problem-variants.test.ts`, `apps/api/src/problem-variants.ts`, and `apps/api/src/problem-variants.test.ts`. STORY-039d landed first and STORY-039e's agent-side `failureLogger` wiring conflicted non-trivially with the spec-clarity judge runtime flow. + +The structural pieces of STORY-039e all shipped: the `variant_gate_failures` DB table (migration 0025), the `users.is_admin` column (migration 0026), the `@learnpro/db` helpers, the admin Fastify route at `GET /v1/admin/variant-failures`, and the Next.js admin page at `/admin/variant-failures`. The TABLE IS READY TO RECEIVE failure entries — what's missing is the AGENT writing to it. + +This Story wires the agent to write. After this lands, the admin route will show real data; before, it shows an empty table. + +## Acceptance criteria + +- [ ] `packages/agent/src/problem-variants.ts` exports `VariantFailureEntry`, `VariantFailureLogger`, `VariantFailureReason` types (5-member discriminated union: `parse_error | identity_mismatch | spec_clarity_judge | self_validation | retry_exhausted`). +- [ ] `GenerateProblemVariantInput` gains optional `failureLogger?: VariantFailureLogger` and optional `source_problem_id?: string`. Existing callers without these fields keep working (no-op when omitted). +- [ ] `callOnce` returns a richer `CallOnceResult` with `model_id`, `failure_reason`, and `failure_detail` so the retry loop can log the right reason on parse / identity failures. +- [ ] `tryGenerateOne` calls `safeLogFailure(input.failureLogger, ...)` on EVERY failure path: + - parse_error / identity_mismatch (when `callOnce` returns no variant) + - self_validation (when sandbox validation fails — already gated by `if (input.sandbox !== undefined)`) + - spec_clarity_judge (when STORY-039d's judge drops a variant — already gated by `if (input.judge !== undefined)`) + - retry_exhausted (final entry emitted after the retry budget is spent) +- [ ] `apps/api/src/problem-variants.ts` builds a `failureLogger` via `buildDrizzleVariantFailureLogger` (already shipped in this file's STORY-039e contribution) and passes it to `generateProblemVariant`. +- [ ] `packages/agent/src/index.ts` re-exports the new `VariantFailureEntry`, `VariantFailureLogger`, `VariantFailureReason` types from `./problem-variants.js`. +- [ ] Tests in `packages/agent/src/problem-variants.test.ts` assert the logger is called with the right reason on each failure path (parse, identity, self_validation, spec_clarity_judge, retry_exhausted). Use stub loggers — no DB. +- [ ] Tests in `apps/api/src/problem-variants.test.ts` assert that on a failed gate (using a stub `fakeLlm` returning garbage for both attempts), a row is persisted to `variant_gate_failures`. Use the in-memory DB shim already in the file. +- [ ] Forbidden-phrase test on any new prompt copy (the new failure-reason addendum for the retry prompt) lands per repo convention. +- [ ] `pnpm format && pnpm format:check` clean. +- [ ] CI green on the PR. + +## Tasks under this Story + +(To be created when this Story is picked up.) + +## Dependencies + +- Blocked by: STORY-039e (the table + admin route — landed via PR #76) +- Blocked by: STORY-039d (the spec-clarity judge runtime integration — landed via PR #75; STORY-039g must preserve this) + +## Notes + +- The original STORY-039e branch had this wiring written. It's salvageable from the pre-rebase tip `b7c79fb` if needed: `git show b7c79fb:packages/agent/src/problem-variants.ts` (similar for the other 3 files). But it was written against a STORY-039d-less `main`, so applying it raw will revert the spec-clarity judge. The right move when picking this up is to read `b7c79fb`'s diff for guidance and re-write on top of current `main`. +- The squash-rebase commit message for PR #76 (commit `4edd8f1`) calls out this gap explicitly so future-me knows where the missing edge is. +- Cost: S — the structural code already exists, this is "thread the parameter through three call sites and re-add ~10 tests." + +## Activity log + +- 2026-05-11 — created. Deferred from STORY-039e via the squash-rebase fallback documented in `docs/decisions/DECISIONS_LOG.md` (2026-05-11 entry).