Skip to content

feat(kiloclaw): add multi-row-all-destroyed collapse and bulk apply paths#2571

Open
jeanduplessis wants to merge 3 commits intomainfrom
ops-kiloclaw-backfill-run
Open

feat(kiloclaw): add multi-row-all-destroyed collapse and bulk apply paths#2571
jeanduplessis wants to merge 3 commits intomainfrom
ops-kiloclaw-backfill-run

Conversation

@jeanduplessis
Copy link
Copy Markdown
Contributor

@jeanduplessis jeanduplessis commented Apr 18, 2026

Summary

Retroactive PR for changes made to the script to update the database.

…aths

Adds a third remediation mode to the subscription alignment script for
users whose personalCurrentSubscriptionWhere matches >1 rows AND none
point at a live instance, which fails the resolver guard. The mode
collapses the ambiguous rows into one tail row by chaining older rows
to newer ones via transferred_to_subscription_id.

Also introduces an opt-in --bulk flag on apply-missing-personal and
apply-multi-row-all-destroyed for chunked bulk writes (250-row tx
chunks with per-user fallback on chunk failure), batches the
apply-changelog-baseline path into 500-row chunks, and adds progress
logging to long-running apply paths.
Comment thread apps/web/src/scripts/db/kiloclaw-subscription-alignment.ts Outdated
Comment thread apps/web/src/scripts/db/kiloclaw-subscription-alignment.ts Outdated
@kilo-code-bot
Copy link
Copy Markdown
Contributor

kilo-code-bot bot commented Apr 18, 2026

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (1 files)
  • apps/web/src/scripts/db/kiloclaw-subscription-alignment.ts

Reviewed by gpt-5.4-20260305 · 299,454 tokens

- Changelog baseline chunked backfill: return inserted counts from the
  transaction callback and accumulate after commit. Previous in-tx
  counter mutation could over-report on rollback when the second INSERT
  in the chunk threw after the first one ran.
- Multi-row-all-destroyed collapse: detect users whose pre-existing
  partial chain blocks a full collapse (applying the planned pairs
  would still leave >1 ambiguous rows) and surface them as
  skipped_not_collapsible instead of writing a partial chain. A
  partial plan would replace one CurrentPersonalSubscriptionResolutionError
  shape with another and mask the broken state in the change log.
- Extract shared pair planners (planMultiRowAllDestroyedPairsFromSourceRows,
  planMultiRowAllDestroyedPairsFromJoinedRows) used by preview, per-user
  apply, and chunk-bulk apply so the collapsibility invariant is checked
  uniformly. Preview now separately reports collapsible vs
  non-collapsible user counts and shows a sample of non-collapsible users.
Comment thread apps/web/src/scripts/db/kiloclaw-subscription-alignment.ts Outdated
Derive users_skipped_not_collapsible by filtering the skipped list
instead of reading the preview-time candidate count. The bulk path and
per-user path both surface in-tx re-plan races with reason
skipped_not_collapsible, and those were previously excluded from the
metric — users_skipped_total would go up while
users_skipped_not_collapsible stayed flat, hiding how many users
actually ended up requiring manual review.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant