Recommended actions
No repository changes recommended.
Failure patterns
Divergent materialized-aggregate reducer implementation (1 task)
- Classification: Model limitation
- Confidence: Low
- What the model wrote:
import { schema, table, t, SenderError, type InferSchema, type ReducerCtx } from 'spacetimedb/server';
function applyDelta(ctx: Ctx, category: string, amountDelta: bigint, countDelta: bigint) {
const existing = ctx.db.categoryTotal.category.find(category);
if (existing) {
const newCount = existing.saleCount + countDelta;
const newTotal = existing.totalAmount + amountDelta;
if (newCount <= 0n) {
ctx.db.categoryTotal.category.delete(category);
} else {
ctx.db.categoryTotal.category.update({
...existing,
totalAmount: newTotal,
saleCount: newCount,
});
}
} else {
if (countDelta <= 0n) {
throw new SenderError('aggregate underflow');
}
ctx.db.categoryTotal.insert({
category,
totalAmount: amountDelta,
saleCount: countDelta,
});
}
}
function insertSale(ctx: Ctx, id: bigint, category: string, amount: bigint) {
ctx.db.sale.insert({ id, category, amount });
applyDelta(ctx, category, amount, 1n);
}
- What was expected:
function addToTotal(ctx: Ctx, category: string, amount: bigint) {
const total = ctx.db.categoryTotal.category.find(category);
if (total) ctx.db.categoryTotal.category.update({ ...total, totalAmount: total.totalAmount + amount, saleCount: total.saleCount + 1n });
else ctx.db.categoryTotal.insert({ category, totalAmount: amount, saleCount: 1n });
}
function removeFromTotal(ctx: Ctx, category: string, amount: bigint) {
const total = ctx.db.categoryTotal.category.find(category);
if (!total) throw new Error('missing category total');
if (total.saleCount === 1n) ctx.db.categoryTotal.category.delete(category);
else ctx.db.categoryTotal.category.update({ ...total, totalAmount: total.totalAmount - amount, saleCount: total.saleCount - 1n });
}
function upsertSale(ctx: Ctx, row: { id: bigint; category: string; amount: bigint }) {
const old = ctx.db.sale.id.find(row.id);
if (old) { removeFromTotal(ctx, old.category, old.amount); ctx.db.s
- What the error says:
schema_parity: failed
- Why this happened: The generated solution diverged from the golden materialized-aggregate pattern. The visible excerpt shows a different maintenance strategy (
applyDelta plus insertSale) instead of the expected upsert-based recomputation flow, and the response is truncated, so the exact mismatch cannot be localized from the supplied evidence.
- Suggested action: None
- Suggested area: None
- Affected tasks: t_065_materialized_aggregate
- AI guidelines gap: Needs manual review