Skip to content

fix(rpi): skip batch-consumed entries in next-work materialize (ag-mjlg #batch-consumed-skip)#652

Merged
boshu2 merged 3 commits into
mainfrom
fix/ag-mjlg-materialize-batch-consumed
May 31, 2026
Merged

fix(rpi): skip batch-consumed entries in next-work materialize (ag-mjlg #batch-consumed-skip)#652
boshu2 merged 3 commits into
mainfrom
fix/ag-mjlg-materialize-batch-consumed

Conversation

@boshu2
Copy link
Copy Markdown
Owner

@boshu2 boshu2 commented May 31, 2026

What

ag-9jle.3 shipped ao next-work materialize with an idempotency gap. isMaterializable() checked only the per-item NextWorkItem.Consumed flag, but the real .agents/rpi/next-work.jsonl records consumption at the batch level (NextWorkEntry.Consumed / consumed_by, set after the items[] array). Every historically-consumed entry therefore looked fresh.

Impact: a dry-run against the live queue planned 44 beads when only 16 items are genuinely available — ~28 stale duplicates for work done months ago (the soc-9xn0 AOP-CLAIM audit, practice-backfill passes 2–12, etc.). Running ao next-work materialize as-is would have flooded the tracker.

Fix

  • Gate enumerateMaterializeCandidates on entry-level consumption via a new isEntryConsumed() helper that mirrors the entry half of the existing rpi.IsFullyConsumed.
  • The per-item isMaterializable checks remain as a second gate.

Why the original test missed it

TestNextWorkMaterialize_SkipsConsumedAndHeld set consumed at the item level — a shape the real queue never uses. Classic test-shape mismatch giving false confidence.

First failing test (regression contract)

Given a next-work.jsonl entry whose batch-level consumed is true with an item that has no item-level consumed flag · When materialize enumerates candidates · Then that entry's items are skipped and produce zero bd-create calls.

TestNextWorkMaterialize_SkipsBatchConsumedEntryfails without the gate (creates 1 stale bead), passes with it. Proven by reverting the gate and re-running.

Evidence

  • Real-queue dry-run: 44 → 16 planned beads.
  • go build ./..., go vet ./cmd/ao/, full materialize suite (6 tests) all green.

Closes-scenario: ag-mjlg#batch-consumed-skip
Bounded-context: BC5-Runtime
Evidence: cli/cmd/ao/next_work_materialize_test.go

…lg #batch-consumed-skip)

ag-9jle.3's `ao next-work materialize` checked only the per-item
NextWorkItem.Consumed flag, but the real next-work.jsonl records
consumption at the BATCH level (NextWorkEntry.Consumed / consumed_by,
set after the items[] array). Every historically-consumed entry therefore
looked fresh: a dry-run against the live queue planned 44 beads when only
16 items are genuinely available — ~28 stale duplicates for work done
months ago (soc-9xn0 AOP-CLAIM audit, practice-backfill passes 2-12, ...).

Gate enumerateMaterializeCandidates on entry-level consumption via a new
isEntryConsumed() helper that mirrors the entry half of rpi.IsFullyConsumed.
Add TestNextWorkMaterialize_SkipsBatchConsumedEntry exercising the real
queue shape (entry.Consumed=true, item-level flag unset) — it fails without
the gate (creates 1 stale bead) and passes with it.

Verified: real-queue dry-run drops 44 -> 16; full materialize suite green.

Closes-scenario: ag-mjlg#batch-consumed-skip
Bounded-context: BC5-Runtime
Evidence: cli/cmd/ao/next_work_materialize_test.go
@github-actions github-actions Bot added the cli label May 31, 2026
@boshu2 boshu2 enabled auto-merge (squash) May 31, 2026 18:54
@boshu2 boshu2 merged commit d543ab9 into main May 31, 2026
13 checks passed
@boshu2 boshu2 deleted the fix/ag-mjlg-materialize-batch-consumed branch May 31, 2026 18:54
boshu2 added a commit that referenced this pull request Jun 6, 2026
…pe (ag-jwtx #test-standard-names-real-shape-requirement) (#776)

## What

Encodes a test standard from **ag-jwtx**:
skip/dedup/consumed/idempotency/regression **guard tests must build
fixtures from the real persisted data shape** — round-trip a real sample
(production writer → reader) or assert against a checked-in real example
— never a hand-built in-memory constructor that sets a marker at a
granularity the on-disk format never emits.

## Why

`ag-mjlg` (PR #652) shipped a next-work materialize over-creation bug
(44 vs 16) green because `TestNextWorkMaterialize_SkipsConsumed` set
`consumed` at the **per-item** level while real `next-work.jsonl` marks
it at the **batch** level. The guard exercised a shape production never
produces → false green. This converts that one-off into a durable
standard + a pre-mortem flag (catch→encode→never-repeat).

## Changes (docs/standards only)

- `skills/standards/references/test-pyramid.md` — new **Fixture
Fidelity** section (the standard + how-to-comply + the pre-mortem flag).
- `skills/standards/references/go.md` + `.claude/rules/go.md` —
Test-Conventions bullet (kept in parity).
- `skills/pre-mortem/references/mandatory-checks.md` — two flags added
to the **Test Pyramid Coverage Check (Mandatory)** table.

## Verification

- `markdownlint --config .markdownlint.json` on all four files: clean.
- `scripts/generate-registry.sh --check`: registry up to date (no new
reference files; existing files edited).
- Docs-only; no code paths touched.

## Scenario

> Given the AI-native test-shape standard doc, when an agent writes a
skip/dedup/consumed guard test, then the standard requires the fixture
to come from a round-tripped real persisted sample, and a
pre-mortem/checklist item flags item-level-only fixtures for batch-level
state.

Closes-scenario: ag-jwtx#test-standard-names-real-shape-requirement
Bounded-context: BC1-Corpus
Evidence: skills/standards/references/test-pyramid.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant