Skip to content

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

Open
jeanduplessis wants to merge 1 commit intomainfrom
ops-kiloclaw-backfill-run
Open

feat(kiloclaw): add multi-row-all-destroyed collapse and bulk apply paths#2571
jeanduplessis wants to merge 1 commit 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.
after_state: serializeKiloClawSubscriptionSnapshot(row),
}))
);
insertedFromCurrent += currentStateRows.length;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WARNING: This counter can over-report successful backfills after a chunk rollback

insertedFromCurrent is mutated before the transaction commits. If the later mutationStateRows insert throws, the whole chunk rolls back but this JS counter stays incremented, so the results table can claim rows were backfilled when none of them committed. Returning the per-chunk counts from db.transaction(...) and accumulating them after it resolves would keep operator output in sync with the database.

const next = joinedRows[index + 1]?.subscription;
if (!source || !next) continue;
if (source.transferred_to_subscription_id !== null) continue;
if (existingPredecessorTargets.has(next.id)) continue;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WARNING: Skipping a claimed successor can leave the user still ambiguous

If next.id already has a predecessor from an older partial chain, this continue drops the current source row from the collapse plan entirely. A history like D->B, A, B, C then only writes B->C, leaving both A and C current and resolveCurrentPersonalSubscriptionRow still throwing afterward. These cases need to be surfaced as manual review / skipped-not-collapsible instead of being counted as a successful collapse.

@kilo-code-bot
Copy link
Copy Markdown
Contributor

kilo-code-bot bot commented Apr 18, 2026

Code Review Summary

Status: 2 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 2
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
apps/web/src/scripts/db/kiloclaw-subscription-alignment.ts 1055 applyChangelogBaselineBackfill increments success counters before the chunk transaction commits, so a later rollback can make the results table report backfills that never persisted.
apps/web/src/scripts/db/kiloclaw-subscription-alignment.ts 2557 applyMultiRowAllDestroyedCollapseRow skips rows whose successor already has a predecessor, which can leave multiple current rows and keep resolveCurrentPersonalSubscriptionRow throwing after the script runs.
Other Observations (not in diff)

None.

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

Fix these issues in Kilo Cloud


Reviewed by gpt-5.4-20260305 · 815,632 tokens

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