multica-ai/multica · error

stamp watermark: %w

Error message

stamp watermark: %w

What it means

The final UPDATE task_usage_hourly_rollup_state SET watermark_at = now() - INTERVAL '5 minutes' WHERE id = 1 failed at the SQL level. This stamps the cron watermark so scheduled ticks only process events newer than the backfill horizon. A related but distinct case — RowsAffected()==0 — is handled gracefully with a warning (no rollup state row), so an actual error here is a connection/cancellation/permission problem.

Source

Thrown at server/cmd/backfill_task_usage_hourly/main.go:207

	if err := stampWatermark(context.Background(), pool); err != nil {
		return err
	}
	slog.Info("backfill complete", "total_rows_touched", totalRows)
	return nil
}

// stampWatermark moves the hourly rollup state's watermark to
// `now() - 5 min`, mirroring the cron entry's upper bound. The next
// scheduled tick therefore picks up only events newer than the
// backfill horizon and does not redo work the backfill already did.
func stampWatermark(ctx context.Context, pool *pgxpool.Pool) error {
	tag, err := pool.Exec(ctx, `
		UPDATE task_usage_hourly_rollup_state
		   SET watermark_at = now() - INTERVAL '5 minutes'
		 WHERE id = 1
	`)
	if err != nil {
		return fmt.Errorf("stamp watermark: %w", err)
	}
	if tag.RowsAffected() == 0 {
		slog.Warn("no rollup state row to stamp; was the task_usage_hourly schema migration applied?")
		return nil
	}
	fmt.Println("watermark stamped to now() - 5 minutes")
	return nil
}

func monthFloor(t time.Time) time.Time {
	return time.Date(t.Year(), t.Month(), 1, 0, 0, 0, 0, time.UTC)
}

View on GitHub (pinned to 2c0912b6ec)

Solutions

  1. Re-run the backfill: slices are idempotent and the stamp will retry
  2. Confirm task_usage_hourly_rollup_state exists (migration applied); if the 'no rollup state row' warning appears instead, apply the schema migration that creates it
  3. If it recurs, check the wrapped error for auth/permission issues on the table
Defensive patterns

Strategy: try-catch

Validate before calling

var stateExists bool
pool.QueryRow(ctx, `SELECT to_regclass('task_usage_hourly_rollup_state') IS NOT NULL`).Scan(&stateExists)

Try / catch

tag, err := pool.Exec(ctx, `UPDATE task_usage_hourly_rollup_state SET watermark_at = now() - INTERVAL '5 minutes' WHERE id = 1`)
if err != nil {
    return fmt.Errorf("stamp watermark: %w", err)
}

Prevention

When it happens

Trigger: task_usage_hourly_rollup_state table missing (migration 103+ not applied) yields 42P01; ctx cancelled right at the finish; permissions revoked on the table.

Common situations: SIGINT arriving between the last slice and the stamp; running against a partially migrated database. Note: if this fails after slices completed, the data IS rolled up but the watermark is stale — the cron tick will redo recent windows (idempotent) rather than lose data.

Related errors


AI-assisted analysis of multica-ai/multica@2c0912b6ec (2026-08-15). Data as JSON: /api/errors/63851bb69342a6f3. Report an issue: GitHub.