feat(usage): dispatch-reviews per idee en fase, jobtabel in de idee-focus (IDEA-251, T-254) #163

Merged
janpeter merged 1 commit from claude/idea-251-usage-jobs into main 2026-10-13 00:52:14 +02:00
Owner

IDEA-251, task T-254 (sprint S-2026-10-12-4, story ST-078). Plan: docs/superpowers/plans/2026-10-12-idea-251-dispatch-idea-work-item.md (branch claude/idea-251-spec), section T4.

What changes

  • usageFactsCte job branch: LEFT JOIN dispatch_idea_links dil ON dil.request_id = cj.dispatch_request_id.
    • With a link, idea and phase come from the link (dil.idea_id, dil.idea_phase).
    • Without one, cj.idea_id and kind stay as they are.
    • New columns job_id, job_kind, job_status; the session branch selects NULL for them.
  • PHASE_RULES: job rules GRILL/SPEC/PLAN/CEREMONY. phaseCaseSql itself is unchanged.
  • fetchIdeaJobs: one row per job, newest first, max 200. total comes from count(*) OVER (), so it counts before the LIMIT. It uses the same attribution and phase as pie 2.
  • IdeaJobsTable: columns date/time (Amsterdam), phase, kind, model with runtime dot, status, tokens, USD ("—" when there is no price). Shows "200 van N getoond" when total exceeds 200. Vis tokens only.
  • Page: the idea focus loads the jobs table as its own snapshot next to the phases pie.
  • Submodule: scrum4me-shared → f1e78df (S1).

Deviation from the plan, with reason

  • Real-DB cleanup: the plan's chain of plain DELETEs cannot run. queue_dispatch_requests, queue_dispatch_candidates and queue_dispatch_profiles carry queue_dispatch_guard_immutable, which raises DISPATCH_IMMUTABLE on every DELETE, for every user. The job guard also refuses an admin delete of a bound job (DISPATCH_MANAGED_ROW).
    • Fix: the test cleans up in one transaction with SET LOCAL session_replication_role = replica. Afterwards it asserts that no prefixed or orphaned dispatch rows remain, because replica mode also skips the FK checks.
    • Seeding follows the web harness: the dispatch-bound rows are written as scrum4me_dispatch via SET LOCAL ROLE.
    • So the test URL must be a superuser. The header comment says so.
  • Existing fixture seg-e (sprint overhead) violated the real usage_segments_scope_check: a sprint requires an anchor_task_id. The earlier Prisma-derived schema had no such CHECK. It now gets an anchor, and task_id stays NULL, so it still counts as overhead.

Verification

  • npm run verify: green. 211 files passed and 4 skipped; 2733 tests passed and 56 skipped. One lint warning, already present, in components/jobs/job-card.tsx.
  • Real-DB: USAGE_TEST_DATABASE_URL=… npx vitest run __tests__/lib/usage/scrum/queries-realdb.test.ts gives 13/13 green, twice in a row (it can be re-run). It ran against a disposable Postgres 17.9 s4m_dispatch_test, provisioned from the T2 web branch (test-db.mjs provision --stage chain, which includes dispatch_idea_links). Covered:
    • phase per fixture row: linked review A/PLAN → plan, B/SPEC on an idea with a build sprint → spec (Review Focus 4), unlinked IDEA_GRILL → grill;
    • the source filter: a session on A appears in pie 2 but not in the jobs table or the job-only pie;
    • Σ jobs table = Σ job-only pie, in tokens and USD.
  • Palette rg on idea-jobs-table.tsx: exit 1 (nothing found).
  • Component test: columns, "—" for NULL USD, "200 van 250 getoond" (Review Focus 5), empty state.
  • Browser preview: not run, because there is no dev DB with the full schema plus an admin login. Moved to T6 step 4, as the plan allows.

Deploy conditions (not part of this PR)

  • Deploy only after T2 (Scrum4Me#369, merged) has passed apply/check in production. The join sits in usageFactsCte, so every Scrum Usage query fails without the table.
  • In the test DB, the roles that read claude_jobs (scrum4me_web_runtime, scrum4me_app, ops_readonly) also have SELECT on dispatch_idea_links. Before deploy, check which role production workers uses for DATABASE_URL, and confirm that role has has_table_privilege(…, 'dispatch_idea_links', 'SELECT').

🤖 Generated with Claude Code

IDEA-251, task T-254 (sprint S-2026-10-12-4, story ST-078). Plan: `docs/superpowers/plans/2026-10-12-idea-251-dispatch-idea-work-item.md` (branch `claude/idea-251-spec`), section T4. ## What changes - **`usageFactsCte` job branch:** `LEFT JOIN dispatch_idea_links dil ON dil.request_id = cj.dispatch_request_id`. - With a link, idea and phase come from the link (`dil.idea_id`, `dil.idea_phase`). - Without one, `cj.idea_id` and `kind` stay as they are. - New columns `job_id`, `job_kind`, `job_status`; the session branch selects NULL for them. - **`PHASE_RULES`:** job rules `GRILL`/`SPEC`/`PLAN`/`CEREMONY`. `phaseCaseSql` itself is unchanged. - **`fetchIdeaJobs`:** one row per job, newest first, max 200. `total` comes from `count(*) OVER ()`, so it counts before the LIMIT. It uses the same attribution and phase as pie 2. - **`IdeaJobsTable`:** columns date/time (Amsterdam), phase, kind, model with runtime dot, status, tokens, USD ("—" when there is no price). Shows "200 van N getoond" when `total` exceeds 200. Vis tokens only. - **Page:** the idea focus loads the jobs table as its own snapshot next to the phases pie. - **Submodule:** `scrum4me-shared` → `f1e78df` (S1). ## Deviation from the plan, with reason - **Real-DB cleanup:** the plan's chain of plain DELETEs cannot run. `queue_dispatch_requests`, `queue_dispatch_candidates` and `queue_dispatch_profiles` carry `queue_dispatch_guard_immutable`, which raises `DISPATCH_IMMUTABLE` on every DELETE, for every user. The job guard also refuses an admin delete of a bound job (`DISPATCH_MANAGED_ROW`). - Fix: the test cleans up in one transaction with `SET LOCAL session_replication_role = replica`. Afterwards it asserts that no prefixed or orphaned dispatch rows remain, because replica mode also skips the FK checks. - Seeding follows the web harness: the dispatch-bound rows are written as `scrum4me_dispatch` via `SET LOCAL ROLE`. - So the test URL must be a superuser. The header comment says so. - **Existing fixture `seg-e`** (sprint overhead) violated the real `usage_segments_scope_check`: a sprint requires an `anchor_task_id`. The earlier Prisma-derived schema had no such CHECK. It now gets an anchor, and `task_id` stays NULL, so it still counts as overhead. ## Verification - `npm run verify`: green. 211 files passed and 4 skipped; 2733 tests passed and 56 skipped. One lint warning, already present, in `components/jobs/job-card.tsx`. - Real-DB: `USAGE_TEST_DATABASE_URL=… npx vitest run __tests__/lib/usage/scrum/queries-realdb.test.ts` gives **13/13 green**, twice in a row (it can be re-run). It ran against a disposable Postgres 17.9 `s4m_dispatch_test`, provisioned from the T2 web branch (`test-db.mjs provision --stage chain`, which includes `dispatch_idea_links`). Covered: - phase per fixture row: linked review A/PLAN → `plan`, B/SPEC on an idea with a build sprint → `spec` (Review Focus 4), unlinked IDEA_GRILL → `grill`; - the source filter: a session on A appears in pie 2 but not in the jobs table or the job-only pie; - Σ jobs table = Σ job-only pie, in tokens and USD. - Palette `rg` on `idea-jobs-table.tsx`: exit 1 (nothing found). - Component test: columns, "—" for NULL USD, "200 van 250 getoond" (Review Focus 5), empty state. - **Browser preview:** not run, because there is no dev DB with the full schema plus an admin login. **Moved to T6 step 4**, as the plan allows. ## Deploy conditions (not part of this PR) - Deploy only after T2 (Scrum4Me#369, merged) has passed apply/check in production. The join sits in `usageFactsCte`, so every Scrum Usage query fails without the table. - In the test DB, the roles that read `claude_jobs` (`scrum4me_web_runtime`, `scrum4me_app`, `ops_readonly`) also have SELECT on `dispatch_idea_links`. **Before deploy, check which role production workers uses** for `DATABASE_URL`, and confirm that role has `has_table_privilege(…, 'dispatch_idea_links', 'SELECT')`. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
feat(usage): dispatch-reviews per idee en fase, jobtabel in de idee-focus (IDEA-251, T-254)
All checks were successful
CI / Verify (pull_request) Successful in 2m26s
6335609eb5
De job-tak van usageFactsCte leest dispatch_idea_links: een gekoppelde
dispatch-review telt onder het idee en de fase uit de koppeling, anders
blijven claude_jobs.idea_id en kind. PHASE_RULES krijgt de job-regels
GRILL/SPEC/PLAN/CEREMONY. Nieuw fetchIdeaJobs (één rij per job, max 200,
total vóór de LIMIT) met IdeaJobsTable onder de taart van een idee.

Real-DB-test seedt dispatch-rijen als scrum4me_dispatch en ruimt op met
session_replication_role = replica: de dispatch-tabellen zijn
onveranderlijk (DISPATCH_IMMUTABLE), dus een gewone DELETE kan niet.
Sessie E krijgt een anker-taak omdat usage_segments_scope_check dat eist.

Submodule scrum4me-shared → f1e78df (S1, DispatchIdeaLink).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
s4m-codex-reviewer left a comment

APPROVED

Beoordeeld op commit 6335609eb544dca2d58934b6e2df02c73212bd57.

Findings

  • Geen blokkerende of overige bevindingen gevonden.

Plan en productafspraken

plan gekoppeld via pr_refs; references: T-254, ST-078. Geen onderdelen omitted.

De diff rondt het Workers-deel T-254 af conform het plan en IDEA-251-specificatie §6: idee en fase komen samen uit de dispatch-koppeling, de PK-join behoudt één feit per job, de jobtabel gebruikt dezelfde toerekening en prijsberekening als de taart, en toont maximaal 200 rijen met het volledige aantal. Bestaande read-only snapshots, tabelprimitive en Vis-tokens worden hergebruikt. MANUAL page-usage-scrum is bijgewerkt.

De afwijkende testopruiming met SET LOCAL session_replication_role = replica is verklaard door de immutable dispatch-guards en wordt gevolgd door controles op achtergebleven rijen. De shared-bump bevat uitsluitend de bedoelde schema-uitbreiding; de overige wijzigingen betreffen de bestaande ST-074-prijshelperopruiming. Geen conflicten met de gebruikte helpers gevonden.

Andere onderdelen van ST-078, de productieproef en de browsercontrole op 375px vallen buiten deze PR en blijven bij T-256. De beschreven voorwaarde voor deploy — migratie en db-access apply/check plus SELECT voor de Workers-databaserol — volgt de productspecificatie.

Verificatie

  • Zelf uitgevoerd op de exacte PR-commit: npm run verify, exit 0; 211 testbestanden en 2733 tests geslaagd, 4 bestanden en 56 tests overgeslagen. Eén bestaande lintwaarschuwing in components/jobs/job-card.tsx.
  • Apart uitgevoerd: queries-realdb.test.ts, 13/13 geslaagd op een exclusieve lokale PostgreSQL 17.11-wegwerpcluster, geprovisiond vanuit de web-migratieketen inclusief additieve contracten en echte dispatch-guards. Dit bewijst onder meer fase-toerekening en Σ jobtabel = Σ job-only-taart voor tokens en USD.
  • Forgejo CI / Verify: success voor dezelfde commit. Geen browsercontrole uitgevoerd.
# APPROVED Beoordeeld op commit `6335609eb544dca2d58934b6e2df02c73212bd57`. ## Findings - Geen blokkerende of overige bevindingen gevonden. ## Plan en productafspraken plan gekoppeld via pr_refs; references: `T-254`, `ST-078`. Geen onderdelen omitted. De diff rondt het Workers-deel T-254 af conform het plan en IDEA-251-specificatie §6: idee en fase komen samen uit de dispatch-koppeling, de PK-join behoudt één feit per job, de jobtabel gebruikt dezelfde toerekening en prijsberekening als de taart, en toont maximaal 200 rijen met het volledige aantal. Bestaande read-only snapshots, tabelprimitive en Vis-tokens worden hergebruikt. MANUAL `page-usage-scrum` is bijgewerkt. De afwijkende testopruiming met `SET LOCAL session_replication_role = replica` is verklaard door de immutable dispatch-guards en wordt gevolgd door controles op achtergebleven rijen. De shared-bump bevat uitsluitend de bedoelde schema-uitbreiding; de overige wijzigingen betreffen de bestaande ST-074-prijshelperopruiming. Geen conflicten met de gebruikte helpers gevonden. Andere onderdelen van ST-078, de productieproef en de browsercontrole op 375px vallen buiten deze PR en blijven bij T-256. De beschreven voorwaarde voor deploy — migratie en db-access apply/check plus SELECT voor de Workers-databaserol — volgt de productspecificatie. ## Verificatie - Zelf uitgevoerd op de exacte PR-commit: `npm run verify`, exit 0; 211 testbestanden en 2733 tests geslaagd, 4 bestanden en 56 tests overgeslagen. Eén bestaande lintwaarschuwing in `components/jobs/job-card.tsx`. - Apart uitgevoerd: `queries-realdb.test.ts`, 13/13 geslaagd op een exclusieve lokale PostgreSQL 17.11-wegwerpcluster, geprovisiond vanuit de web-migratieketen inclusief additieve contracten en echte dispatch-guards. Dit bewijst onder meer fase-toerekening en Σ jobtabel = Σ job-only-taart voor tokens en USD. - Forgejo CI / Verify: success voor dezelfde commit. Geen browsercontrole uitgevoerd.
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
janpeter/scrum4me-workers!163
No description provided.