Light megaplan: Consolidate all TimelineData construction into a single canonical builder function. Currently there are multiple code paths that build TimelineData objects (buildDataFromCurrentRegistry, buildTimelineData, patchRegistry hand-assembly) and they don't all go through migration/deduplication. The fix is to make one function that guarantees consistent tracks/clips/config, and route all construction through it. This will eliminate the duplicate key bugs (V3 tracks, cascading -dup- clip IDs) at the structural level.
Goal: Consolidate all TimelineData construction into a single canonical builder so that migration, deduplication, and signature computation are guaranteed by construction — eliminating structural bugs (duplicate tracks, cascading -dup- clip IDs) at the source.
Current state: There are three places that assemble a TimelineData object:
buildTimelineData() (timeline-data.ts:330) — async, full rebuild with URL resolution
All three do call migration, but they do it independently (and configToRows re-migrates internally, so some paths migrate 2x). The inline literal in patchRegistry is the most fragile — it manually assembles 12 fields and mutates signature after construction.
Key insight from audit: Migration is not actually being skipped today — all paths call migrateToFlatTracks. The real problems are: (a) redundant double-migration, (b) the inline assembly in patchRegistry is brittle and doesn't match the other two builders, (c) no single function guarantees all fields are consistently derived.
Constraints:
buildTimelineData must stay async (URL resolution)
Assistant
User
Assistant
I’m re-checking the revised plan against the repository and the earlier findings. I’ll verify the new assumptions and look for any remaining execution gaps rather than re-flagging issues the revision already covered.
Assistant
{"flags":[{"id":"timeline-builder-missing-regression-tests","concern":"Timeline data validation: The revised plan still leaves the highest-risk path, patchRegistry(), without automated regression coverage. The new pure-function tests cover assembleTimelineData and buildDataFromCurrentRegistry, but the duplicate-ID bug is explicitly expected to reproduce through the registry-patch flow, and that path still relies on manual smoke testing only.","category":"completeness","severity_hint":"likely-significant","evidence":"patchRegistry() contains distinct behavior beyond plain assembly in [/Users/user_c042661f/Documents/reigh-workspace/reigh-app/src/tools/video-editor/hooks/useTimelineSave.ts:303], including rebuilding nextResolvedRegistry, preserving src, and committing with { save: false } through [/Users/user_c042661f/Documents/reigh-workspace/reigh-app/src/tools/video-editor/hooks/useTimelineSave.ts:358]. A repo-wide test search still shows no tests invoking patchRegistry() or useTimelineSave(), so Step 7 does not cover the exact path called out in Step 9."}],"verified_flag_ids":["timeline-builder-double-migration","timeline-builder-not-canonical"],"disputed_flag_ids":[]}
buildDataFromCurrentRegistry and patchRegistry must stay sync (called in React callbacks)
patchRegistry needs to update registry + resolved registry without re-resolving URLs
Test helpers also construct TimelineData manually
Phase 1: Create the canonical builder
Step 1: Extract a sync assembleTimelineData function (timeline-data.ts)
Scope: Medium
Create a new exported function assembleTimelineData in timeline-data.ts (~line 330) that takes all pre-computed parts and returns TimelineData. This is the single place that stamps out the object shape and computes the signature.
Key invariant:config passed in must already be migrated. The function calls configToRows (which will migrate again — idempotent — but we'll fix the double-migration in Step 3).
No callers yet — this step just adds the function and its types.
Step 2: Remove migration from configToRows (timeline-data.ts:160-163)
Scope: Small
ChangeconfigToRows to accept config as-is instead of calling migrateToFlatTracks internally. Currently line 163 does const migratedConfig = migrateToFlatTracks(config) — change to just use config directly.
Rationale: Migration should happen once at the entry point, not re-applied by every internal helper. configToRows is only called by buildTimelineData, buildDataFromCurrentRegistry, patchRegistry, and assembleTimelineData — all of which already migrate before calling it.
Risk: If any caller was relying on configToRows to do migration for them, this would break. Audit shows all callers pre-migrate, so this is safe. The getUniqueClipId fallback at line 177 will still catch any stray duplicates as a defense-in-depth measure.
Phase 2: Route all construction through the builder
Step 3: Refactor buildTimelineData to use assembleTimelineData (timeline-data.ts:330-356)
Step 5: Refactor patchRegistry to use assembleTimelineData (useTimelineSave.ts:303-359)
Scope: Medium — this is the most impactful change
Replace the inline TimelineData literal (lines 331-352) with a call to assembleTimelineData.
The tricky part: patchRegistry patches the registry and resolved registry without changing config. The refactored version needs to build the resolved config with the updated registry, then pass everything to the assembler.
Remove the manual nextData.signature = getConfigSignature(...) line — the assembler handles it.
Step 6: Update test helpers (useTimelineHistory.test.ts:49-76)
Scope: Small
RefactormakeTimelineData() in the test to use assembleTimelineData instead of hand-building the object.
Checkrender-bounds.validation.test.ts and useTimelineTrackManagement.test.ts — these use configToRows or buildTimelineData directly, which should continue to work after the refactor.
Phase 3: Validation
Step 7: Verify existing tests pass
Scope: Small
Runnpx vitest run --reporter=verbose scoped to video-editor tests:
useTimelineHistory.test.ts
useTimelineTrackManagement.test.ts
render-bounds.validation.test.ts
Any other timeline-related tests
Fix any breakage from the configToRows migration removal (Step 2).
Step 8: Manual smoke test — duplicate key scenarios
Scope: Small
Load a timeline with known duplicate tracks (V3 data) and confirm no duplicate key warnings in console.
Add an asset via patchRegistry path and confirm no -dup- cascading in clip IDs.
Undo/redo several times and confirm data roundtrips cleanly.
Execution Order
Steps 1-2 first (add assembler, remove double-migration) — foundation with no caller changes.
Steps 3-5 in sequence (refactor each caller one at a time, testing after each).
Step 6 (test helpers) can happen anytime after Step 1.
Steps 7-8 last (validation).
Validation Order
After Step 2: run existing tests to confirm removing migration from configToRows doesn't break anything.
After each of Steps 3-5: run tests to catch regressions incrementally.
Step 7: full test suite.
Step 8: manual smoke test for the specific bugs this fixes.
code
Plan metadata:
{
"version": 1,
"timestamp": "2026-03-26T23:25:45Z",
"hash": "sha256:ab33643bfd50f5f0b8bc4c976157c6f06d2e7ca1e0cf0b6570039158c64f95b5",
"questions": [
"patchRegistry currently preserves current.resolvedConfig.clips (the resolved clips from the existing data) and only updates the registry entries. After routing through the assembler, configToRows will rebuild rows/meta/effects from scratch based on nextConfig. Is it acceptable that clip ordering and derived row data might shift slightly, or does patchRegistry need to preserve exact row identity across the patch?",
"The test helper makeTimelineData in useTimelineHistory.test.ts constructs TimelineData with minimal/mock data. Should it use the real assembleTimelineData (tighter coupling to implementation) or remain a standalone mock factory (looser coupling but won't validate the assembler)?",
"Are there any other consumers of TimelineData outside the video-editor tool (e.g., edge functions, workers) that might construct the object independently? The audit only found browser-side construction but server-side code wasn't checked."
],
"success_criteria": [
"Only one function (assembleTimelineData) stamps out TimelineData objects \u2014 all other construction paths delegate to it",
"No TimelineData object literal { config: ..., rows: ..., ... } exists outside assembleTimelineData (except test mocks if deliberately excluded)",
"migrateToFlatTracks is called exactly once per construction path (no double-migration)",
"configToRows no longer calls migrateToFlatTracks internally",
"All existing video-editor tests pass without modification (other than test helper updates)",
"No duplicate-key React warnings when loading V3 timeline data",
"No cascading -dup- clip ID suffixes after registry patches"
],
"assumptions": [
"Migration (migrateToFlatTracks) is idempotent \u2014 running it twice on already-migrated data produces identical output. This is assumed true based on the implementation (dedup is stable, track/clip transforms are no-ops on clean data) and is what makes removing the double-migration safe.",
"The patchRegistry path can safely rebuild rows/meta/effects from config via configToRows rather than preserving them from current. This is what it already does today (line 329 calls configToRows(nextConfig)).",
"TimelineData is only constructed in browser-side code within the video-editor tool. No edge functions or workers build TimelineData objects.",
"The getUniqueClipId fallback inside configToRows (line 177) is kept as defense-in-depth even after migration handles dedup \u2014 it logs a warning if it ever fires, which means migration missed something.",
"Test helpers may optionally continue to construct TimelineData manually if routing through the real assembler would make tests too brittle or slow. The key invariant is that production code uses the assembler."
],
"structure_warnings": []
}
code
Plan structure warnings from validator:
[]
Existing flags:
[]
Known accepted debt grouped by subsystem:
{
"agent-chat-rendering": [
{
"id": "DEBT-007",
"concern": "removing the duplicate assistant turn may hide message_user text if the frontend only renders assistant-role turns as chat bubbles.",
"occurrence_count": 1,
"plan_ids": [
"refactor-ai-timeline-agent-20260326-0157"
]
}
],
"agent-chat-undo-integration": [
{
"id": "DEBT-018",
"concern": "agent chat edits arrive via query invalidation/realtime polling and will bypass the undo stack because those paths are marked skiphistory.",
"occurrence_count": 1,
"plan_ids": [
"implement-undo-redo-history-20260326-2240"
]
}
],
"bulk-panel-tabs": [
{
"id": "DEBT-010",
"concern": "text clip multi-selections would miss the position tab under the plan's stated rule.",
"occurrence_count": 1,
"plan_ids": [
"multi-select-feature-parity-20260326-0548"
]
}
],
"bulk-properties-panel": [
{
"id": "DEBT-016",
"concern": "bulkclippanel still imports customeffecteditor; removing it without updating bulk mode would break the build.",
"occurrence_count": 1,
"plan_ids": [
"build-an-llm-powered-custom-20260326-2230"
]
}
],
"clip-drag-scroll-sync": [
{
"id": "DEBT-015",
"concern": "the plan's step 3 ontick callback only shows coordinator.update() but the full clip-drag state path (snap, lateststart, ghost positions) also needs re-running during stationary-pointer scroll.",
"occurrence_count": 1,
"plan_ids": [
"add-auto-scroll-to-the-20260326-2119"
]
}
],
"clip-param-schema-evolution": [
{
"id": "DEBT-019",
"concern": "clips with stale or partial params from a previous schema version will not be automatically normalized/backfilled when the effect schema changes.",
"occurrence_count": 1,
"plan_ids": [
"add-tuneable-parameters-to-20260326-2332"
]
}
],
"conflict-resolution": [
{
"id": "DEBT-004",
"concern": "silently reloading agent-originated timeline updates would discard dirty local edits.",
"occurrence_count": 1,
"plan_ids": [
"build-a-turn-based-timeline-20260326-0005"
]
}
],
"context-menu-scope": [
{
"id": "DEBT-012",
"concern": "multi-clip copy is not included despite being mentioned in the original idea.",
"occurrence_count": 1,
"plan_ids": [
"multi-select-feature-parity-20260326-0548"
]
}
],
"issue-detection": [
{
"id": "DEBT-006",
"concern": "mid-sentence-cut detection is not implementable without transcript/profile data that the current provider doesn't expose.",
"occurrence_count": 1,
"plan_ids": [
"build-a-turn-based-timeline-20260326-0005"
]
}
],
"legacy-effect-lifecycle": [
{
"id": "DEBT-017",
"concern": "removing customeffecteditor makes effects-table entries read-only \u2014 users can no longer edit legacy custom effects.",
"occurrence_count": 1,
"plan_ids": [
"build-an-llm-powered-custom-20260326-2230"
]
}
],
"optimistic-locking": [
{
"id": "DEBT-002",
"concern": "plan only specifies version checking at the db write layer; the ui load/state/save path doesn't carry config_version yet.",
"occurrence_count": 1,
"plan_ids": [
"build-a-turn-based-timeline-20260326-0005"
]
}
],
"properties-panel-scope": [
{
"id": "DEBT-011",
"concern": "crop and transition controls are not included in the bulk panel, narrowing the original idea's scope.",
"occurrence_count": 1,
"plan_ids": [
"multi-select-feature-parity-20260326-0548"
]
}
],
"realtime-subscriptions": [
{
"id": "DEBT-003",
"concern": "the shared realtime system doesn't know about timeline_agent_sessions; step 7 hooks need their own channel subscription.",
"occurrence_count": 1,
"plan_ids": [
"build-a-turn-based-timeline-20260326-0005"
]
}
],
"selection-save-bridge": [
{
"id": "DEBT-009",
"concern": "the plan specifies passing pruneselection into usetimelinesave but doesn't detail the hook-layer bridge needed because usetimelinesave is instantiated inside usetimelinedata before usetimelinestate runs.",
"occurrence_count": 1,
"plan_ids": [
"multi-select-timeline-clips-20260326-0415"
]
}
],
"task-deduplication": [
{
"id": "DEBT-001",
"concern": "server-generated idempotency keys would break retry deduplication because retried requests get fresh keys.",
"occurrence_count": 1,
"plan_ids": [
"migrate-all-task-creation-20260325-2354"
]
}
],
"task-system-integration": [
{
"id": "DEBT-005",
"concern": "create_generation_task is underspecified against the actual task family system.",
"occurrence_count": 1,
"plan_ids": [
"build-a-turn-based-timeline-20260326-0005"
]
}
],
"tool-error-propagation": [
{
"id": "DEBT-008",
"concern": "a blanket catch in executetool would silently downgrade db/persistence failures into ordinary tool results, changing the session error/http 500 behavior.",
"occurrence_count": 1,
"plan_ids": [
"refactor-ai-timeline-agent-20260326-0157"
]
}
],
"track-reorder-accessibility": [
{
"id": "DEBT-013",
"concern": "replacing arrow buttons with drag-only handle removes keyboard-accessible reorder; plan only specifies pointersensor.",
"occurrence_count": 1,
"plan_ids": [
"fix-track-reordering-bugs-and-20260326-1856"
]
}
],
"track-reorder-testing": [
{
"id": "DEBT-014",
"concern": "no automated tests specified for same-kind boundary rules or save/load persistence of reordered tracks.",
"occurrence_count": 1,
"plan_ids": [
"fix-track-reordering-bugs-and-20260326-1856"
]
}
]
}
code
Escalated debt subsystems:
[]
Debt guidance:
- These are known accepted limitations. Do not re-flag them unless the current plan makes them worse, broadens them, or fails to contain them.
- Prefix every new concern with a subsystem tag followed by a colon, for example `Timeout recovery: retry backoff remains brittle`.
- When a concern is recurring debt that still needs to be flagged, prefix it with `Recurring debt:` after the subsystem tag, for example `Timeout recovery: Recurring debt: retry backoff remains brittle`.
Requirements:
- Consider whether the plan is at the right level of abstraction.
- Reuse existing flag IDs when the same concern is still open.
- `verified_flag_ids` should list previously addressed flags that now appear resolved.
- Focus on concrete issues that would cause real problems.
- Robustness level: standard. Use balanced judgment. Flag significant risks, but do not spend flags on minor polish or executor-obvious boilerplate.
- Verify that the plan remains aligned with the user's original intent.
- Verify that the plan follows the expected structure: one H1 title, `## Overview`, numbered step sections (`### Step N:` under `## Phase` headers, or flat `## Step N:`) with file references and numbered substeps, plus `## Execution Order` or `## Validation Order`.
- Missing required sections or step coverage (for example: no H1, no `## Overview`, or no step sections at all) should be flagged as category `completeness` with severity_hint `likely-significant`.
- Structural formatting within steps (for example: prose instead of numbered substeps, or a missing file reference inside an otherwise actionable step) should usually be category `completeness` with severity_hint `likely-minor` because the executor can still follow the instructions.
- Ask whether the plan is the simplest approach that solves the stated problem, whether it could use fewer steps or less machinery, and whether it introduces unnecessary complexity.
- Over-engineering concerns should use category `maintainability`, should usually prefix the concern with "Over-engineering:", and should scale severity_hint to the practical impact.
- Flag scope creep explicitly when the plan grows beyond the original idea or recorded user notes. Use the phrase "Scope creep:" in the concern.
- Assign severity_hint carefully. Implementation details the executor will naturally resolve should usually be `likely-minor`.
{"flags":[{"id":"timeline-builder-double-migration","concern":"Timeline data migration: The plan does not actually achieve its stated "migrate exactly once" invariant on the async load path. buildTimelineData() already migrates before resolving, but the shared resolveTimelineConfig() helper migrates again internally, and the plan never updates that helper.","category":"correctness","severity_hint":"likely-significant","evidence":"buildTimelineData() calls migrateToFlatTracks(config) before resolveTimelineConfig(...) in [/Users/user_c042661f/Documents/reigh-workspace/reigh-app/src/tools/video-editor/lib/timeline-data.ts:336] and [/Users/user_c042661f/Documents/reigh-workspace/reigh-app/src/tools/video-editor/lib/timeline-data.ts:339]. The shared resolver then re-runs migrateToFlatTracks(config) in [/Users/user_c042661f/Documents/reigh-workspace/reigh-app/src/tools/video-editor/lib/config-utils.ts:77] and [/Users/user_c042661f/Documents/reigh-workspace/reigh-app/src/tools/video-editor/lib/config-utils.ts:82]."},{"id":"timeline-builder-not-canonical","concern":"Timeline data assembly: The proposed assembleTimelineData() centralizes the outer TimelineData object literal, but it still leaves resolvedConfig and assetMap derivation split across multiple callers. That means the plan does not fully deliver on the stated goal of one canonical construction path that guarantees consistent tracks/clips/config by construction.","category":"maintainability","severity_hint":"likely-significant","evidence":"Today the sync paths each hand-build resolvedConfig and related derived fields in [/Users/user_c042661f/Documents/reigh-workspace/reigh-app/src/tools/video-editor/lib/timeline-save-utils.ts:30] and [/Users/user_c042661f/Documents/reigh-workspace/reigh-app/src/tools/video-editor/hooks/useTimelineSave.ts:335]. The plan's Step 4 and Step 5 examples keep that manual assembly pattern and only swap the final return object for assembleTimelineData(...). That reduces duplication, but it does not make derivation canonical."},{"id":"timeline-builder-missing-regression-tests","concern":"Timeline data validation: The plan refactors the two sync construction paths most closely tied to the duplicate-ID bug (buildDataFromCurrentRegistry and patchRegistry), but it only proposes existing tests plus manual smoke checks. There is no automated regression coverage for the exact paths being changed.","category":"completeness","severity_hint":"likely-significant","evidence":"The repository has production logic in [/Users/user_c042661f/Documents/reigh-workspace/reigh-app/src/tools/video-editor/lib/timeline-save-utils.ts:19] and [/Users/user_c042661f/Documents/reigh-workspace/reigh-app/src/tools/video-editor/hooks/useTimelineSave.ts:303], but a repo-wide test search found no tests invoking buildDataFromCurrentRegistry(...), patchRegistry(...), or useTimelineSave(...). Existing tests only cover configToRows, buildTimelineData, and history/track helpers."}],"verified_flag_ids":[],"disputed_flag_ids":[]}
You are an independent reviewer. Critique the plan against the actual repository.
Light megaplan: Consolidate all TimelineData construction into a single canonical builder function. Currently there are multiple code paths that build TimelineData objects (buildDataFromCurrentRegistry, buildTimelineData, patchRegistry hand-assembly) and they don't all go through migration/deduplication. The fix is to make one function that guarantees consistent tracks/clips/config, and route all construction through it. This will eliminate the duplicate key bugs (V3 tracks, cascading -dup- clip IDs) at the structural level.
Goal: Consolidate all TimelineData construction into a single canonical builder so that migration, deduplication, and signature computation are guaranteed by construction — eliminating structural bugs (duplicate tracks, cascading -dup- clip IDs) at the source.
Current state: There are three places that assemble a TimelineData object:
buildTimelineData() (timeline-data.ts:330) — async, full rebuild with URL resolution
All three do call migration, but they do it independently. Additionally, configToRows (line 163) and resolveTimelineConfig in config-utils.ts (line 82) each call migrateToFlatTracks internally, so the async path migrates 3 times (caller → resolver → configToRows) and sync paths migrate 2 times (caller → configToRows). The inline literal in patchRegistry is the most fragile — it manually assembles 12 fields and mutates signature after construction.
Key insight from audit: Migration is not actually being skipped today — all paths call migrateToFlatTracks. The real problems are: (a) redundant multi-migration across configToRows and resolveTimelineConfig, (b) the inline assembly in patchRegistry is brittle and doesn't match the other two builders, (c) no single function guarantees all fields are consistently derived.
Constraints:
buildTimelineData must stay async (URL resolution)
buildDataFromCurrentRegistry and patchRegistry must stay sync (called in React callbacks)
patchRegistry needs to update registry + resolved registry without re-resolving URLs
Design boundary (DECISION-003):resolvedConfig derivation remains caller-specific because of the sync/async split. The async path (buildTimelineData) resolves URLs via the network; the sync paths (buildDataFromCurrentRegistry, patchRegistry) reuse existing resolved data from current. The assembler centralizes the object shape and derived fields (rows, meta, effects, tracks, clipOrder, signature) but does not own resolvedConfig construction. This is an inherent constraint, not a gap.
Migration call sites being updated (all 4):
Call site
File
Line
Action
configToRows
timeline-data.ts
163
Remove internal migration (Step 2)
resolveTimelineConfig
config-utils.ts
82
Remove internal migration (Step 2)
buildTimelineData
timeline-data.ts
336
Keep — this is the entry-point migration
buildDataFromCurrentRegistry
timeline-save-utils.ts
27
Keep — this is the entry-point migration
patchRegistry (implicit via configToRows)
useTimelineSave.ts
329
Replace with explicit migration before assembler call (Step 5)
After this change, migration happens exactly once per construction path: at the entry-point caller, never inside helpers.
Phase 1: Foundation — builder + migration cleanup
Step 1: Extract a sync assembleTimelineData function (timeline-data.ts)
Scope: Medium
Create a new exported function assembleTimelineData in timeline-data.ts (~line 330) that takes all pre-computed parts and returns TimelineData. This is the single place that stamps out the object shape and computes the signature.
Key invariant:config passed in must already be migrated. Add a JSDoc comment making this contract explicit.
No callers yet — this step just adds the function and its types.
Step 2: Remove migration from internal helpers (timeline-data.ts:163, config-utils.ts:82)
Scope: Small
In configToRows (timeline-data.ts:160): Remove line 163 (const migratedConfig = migrateToFlatTracks(config)) and use config directly. Rename the local variable references from migratedConfig to config.
In resolveTimelineConfig (config-utils.ts:77): Remove line 82 (const migratedConfig = migrateToFlatTracks(config)) and use config directly. Rename the local variable references from migratedConfig to config. Remove the migrateToFlatTracks import if now unused.
Rationale: Migration should happen exactly once at the entry point, not re-applied by every internal helper. After this change:
configToRows converts config→rows (no migration)
resolveTimelineConfig resolves asset URLs (no migration)
Entry-point callers own migration
Risk: If any caller was relying on these helpers to migrate for them, this would break. Audit confirms: configToRows is called by buildTimelineData (pre-migrates at line 336), buildDataFromCurrentRegistry (pre-migrates at line 27), and patchRegistry (will pre-migrate after Step 5). resolveTimelineConfig is only called by buildTimelineData (pre-migrates at line 336). All callers pre-migrate.
Defense-in-depth: The getUniqueClipId fallback inside configToRows (line 177) is kept — it logs a warning if a duplicate clip ID somehow survives, catching bugs upstream.
Step 3: Run tests after migration removal
Scope: Small
Runnpx vitest run scoped to video-editor tests to confirm the migration removal didn't break anything.
This is the cheapest validation checkpoint — catches any caller that was depending on internal migration.
Phase 2: Route all construction through the builder
Replace the inline TimelineData literal (lines 331-352) with a call to assembleTimelineData. Add explicit migration at the entry point (previously handled implicitly by configToRows).
Remove the manual nextData.signature = getConfigSignature(...) mutation — the assembler handles it.
Note on resolvedConfig.clips: The old code used current.resolvedConfig.clips (pre-existing resolved clips). The new code rebuilds from nextConfig.clips (migrated config clips) with assetEntry lookups. This is more correct — it ensures resolved clips reflect the migrated config, not stale resolved state. The old configToRows(nextConfig) call already rebuilt rows from scratch, so clip identity was already not preserved across patches.
Phase 3: Tests
Step 7: Add regression tests for assembleTimelineData and buildDataFromCurrentRegistry (timeline-save-utils.test.ts)
Test: assembleTimelineData produces consistent output — pass a known config with 2 tracks and 3 clips, verify all 12 fields are present and signature matches getConfigSignature(resolvedConfig).
Test: duplicate track IDs are deduplicated — pass config with duplicate track IDs through migrateToFlatTracks → assembleTimelineData, verify tracks are unique.
Test: cascading -dup- clip IDs are cleaned — pass config with clip IDs like clip-1-dup-1-dup-2, verify output clips have clean IDs.
Test: buildDataFromCurrentRegistry preserves registry from current — pass a new config and a mock current TimelineData, verify the output uses current.registry and current.resolvedConfig.registry.
Test: buildDataFromCurrentRegistry migrates config — pass config with duplicate tracks, verify output config has deduplicated tracks.
These are pure function tests — no React hooks or DOM needed, so they run fast and don't need renderHook.
Step 8: Update test helper and run full suite
Scope: Small
UpdatemakeTimelineData() in useTimelineHistory.test.ts (lines 49-76) — can either use assembleTimelineData or remain a standalone mock. Per DECISION-002, keeping it standalone is fine since it's test code. No change required unless it breaks.
Runnpx vitest run --reporter=verbose for all video-editor tests:
useTimelineHistory.test.ts
useTimelineTrackManagement.test.ts
render-bounds.validation.test.ts
New timeline-save-utils.test.ts
Fix any breakage.
Step 9: Manual smoke test
Scope: Small
Load a timeline with known V3 data (duplicate tracks) — confirm no duplicate key warnings in console.
Upload an asset (triggers patchRegistry path) — confirm no -dup- cascading in clip IDs.
Undo/redo several times — confirm data roundtrips cleanly through buildDataFromCurrentRegistry.
Execution Order
Steps 1-2 (add assembler, remove migration from helpers) — foundation with no caller changes.
Step 3 (test checkpoint) — validate migration removal is safe before proceeding.
Steps 4-6 in sequence (refactor each caller one at a time).
Steps 7-8 (tests) — after all callers are routed through assembler.
Step 9 (manual smoke test) — final validation.
Validation Order
After Step 2: run existing tests to confirm removing migration from configToRows and resolveTimelineConfig doesn't break anything.
After each of Steps 4-6: run existing tests to catch regressions incrementally.
After Step 7: run new regression tests for the assembler and sync construction paths.
Step 8: full test suite.
Step 9: manual smoke test for the specific bugs this addresses.
code
Plan metadata:
{
"version": 2,
"timestamp": "2026-03-26T23:31:33Z",
"hash": "sha256:ac213774a3a8bc9e64e1347f5939818e20066eac5e37776bee4b2e6fd02b379c",
"changes_summary": "Flag timeline-builder-double-migration: Added resolveTimelineConfig in config-utils.ts:82 as a fourth migration call site to be cleaned up in Step 2. The plan now enumerates all 4 internal migration calls (configToRows, resolveTimelineConfig, plus the 2 entry-point callers that are kept) in a table in the Overview. Step 2 now explicitly removes migration from both configToRows AND resolveTimelineConfig.\n\nFlag timeline-builder-not-canonical: Added an explicit "Design boundary (DECISION-003)" paragraph in the Overview explaining why resolvedConfig derivation remains caller-specific (sync/async split is inherent) and what the assembler does vs doesn't centralize. This is now a stated design choice, not an unstated gap.\n\nFlag timeline-builder-missing-regression-tests: Added Step 7 with 5 specific test cases for assembleTimelineData and buildDataFromCurrentRegistry in a new timeline-save-utils.test.ts file. These are pure function tests that cover: consistent output shape, duplicate track dedup, cascading dup-ID cleanup, registry preservation, and config migration. Updated success criteria to include the new tests.",
"flags_addressed": [
"timeline-builder-double-migration",
"timeline-builder-not-canonical",
"timeline-builder-missing-regression-tests"
],
"questions": [
"Are there any other internal helpers (beyond configToRows and resolveTimelineConfig) that call migrateToFlatTracks? The audit found these two plus the entry-point callers, but if there are others (e.g., in serialization or export paths), they would also need updating."
],
"success_criteria": [
"Only one function (assembleTimelineData) stamps out TimelineData objects \u2014 all other construction paths delegate to it",
"No TimelineData object literal { config: ..., rows: ..., ... } exists outside assembleTimelineData (except test mocks per DECISION-002)",
"migrateToFlatTracks is called exactly once per construction path \u2014 removed from configToRows (timeline-data.ts:163) and resolveTimelineConfig (config-utils.ts:82), kept only at entry-point callers",
"All existing video-editor tests pass without modification (other than test helper updates)",
"New regression tests in timeline-save-utils.test.ts cover: assembler output consistency, duplicate track dedup, cascading dup-ID cleanup, registry preservation, and config migration",
"No duplicate-key React warnings when loading V3 timeline data",
"No cascading clip ID suffixes after registry patches"
],
"assumptions": [
"Migration () is idempotent \u2014 running it twice on already-migrated data produces identical output. This is assumed true based on the implementation (dedup is stable, track/clip transforms are no-ops on clean data) and is what makes removing the multi-migration safe.",
"The path can safely rebuild rows/meta/effects from config via rather than preserving them from . This is what it already does today (line 329 calls ).",
"TimelineData is only constructed in browser-side code within the video-editor tool. No edge functions or workers build TimelineData objects.",
"The fallback inside (line 177) is kept as defense-in-depth even after migration handles dedup \u2014 it logs a warning if it ever fires, which means migration missed something.",
"Test helpers may continue to construct TimelineData manually (DECISION-002). The key invariant is that production code uses the assembler.",
" in is only called via the wrapper in , which is only called by . No other code path calls the config-utils version directly."
],
"structure_warnings": [],
"delta_from_previous_percent": 40.5
}
code
Plan structure warnings from validator:
[]
Existing flags:
[
{
"id": "timeline-builder-double-migration",
"concern": "Timeline data migration: The plan does not actually achieve its stated "migrate exactly once" invariant on the async load path. buildTimelineData() already migrates before resolving, but the shared resolveTimelineConfig() helper migrates again internally, and the plan never updates that helper.",
"status": "addressed",
"severity": "significant"
},
{
"id": "timeline-builder-not-canonical",
"concern": "Timeline data assembly: The proposed assembleTimelineData() centralizes the outer TimelineData object literal, but it still leaves resolvedConfig and assetMap derivation split across multiple callers. That means the plan does not fully deliver on the stated goal of one canonical construction path that guarantees consistent tracks/clips/config by construction.",
"status": "addressed",
"severity": "significant"
},
{
"id": "timeline-builder-missing-regression-tests",
"concern": "Timeline data validation: The plan refactors the two sync construction paths most closely tied to the duplicate-ID bug (buildDataFromCurrentRegistry and patchRegistry), but it only proposes existing tests plus manual smoke checks. There is no automated regression coverage for the exact paths being changed.",
"status": "addressed",
"severity": "significant"
}
]
code
Known accepted debt grouped by subsystem:
{
"agent-chat-rendering": [
{
"id": "DEBT-007",
"concern": "removing the duplicate assistant turn may hide message_user text if the frontend only renders assistant-role turns as chat bubbles.",
"occurrence_count": 1,
"plan_ids": [
"refactor-ai-timeline-agent-20260326-0157"
]
}
],
"agent-chat-undo-integration": [
{
"id": "DEBT-018",
"concern": "agent chat edits arrive via query invalidation/realtime polling and will bypass the undo stack because those paths are marked skiphistory.",
"occurrence_count": 1,
"plan_ids": [
"implement-undo-redo-history-20260326-2240"
]
}
],
"bulk-panel-tabs": [
{
"id": "DEBT-010",
"concern": "text clip multi-selections would miss the position tab under the plan's stated rule.",
"occurrence_count": 1,
"plan_ids": [
"multi-select-feature-parity-20260326-0548"
]
}
],
"bulk-properties-panel": [
{
"id": "DEBT-016",
"concern": "bulkclippanel still imports customeffecteditor; removing it without updating bulk mode would break the build.",
"occurrence_count": 1,
"plan_ids": [
"build-an-llm-powered-custom-20260326-2230"
]
}
],
"clip-drag-scroll-sync": [
{
"id": "DEBT-015",
"concern": "the plan's step 3 ontick callback only shows coordinator.update() but the full clip-drag state path (snap, lateststart, ghost positions) also needs re-running during stationary-pointer scroll.",
"occurrence_count": 1,
"plan_ids": [
"add-auto-scroll-to-the-20260326-2119"
]
}
],
"clip-param-schema-evolution": [
{
"id": "DEBT-019",
"concern": "clips with stale or partial params from a previous schema version will not be automatically normalized/backfilled when the effect schema changes.",
"occurrence_count": 1,
"plan_ids": [
"add-tuneable-parameters-to-20260326-2332"
]
}
],
"conflict-resolution": [
{
"id": "DEBT-004",
"concern": "silently reloading agent-originated timeline updates would discard dirty local edits.",
"occurrence_count": 1,
"plan_ids": [
"build-a-turn-based-timeline-20260326-0005"
]
}
],
"context-menu-scope": [
{
"id": "DEBT-012",
"concern": "multi-clip copy is not included despite being mentioned in the original idea.",
"occurrence_count": 1,
"plan_ids": [
"multi-select-feature-parity-20260326-0548"
]
}
],
"issue-detection": [
{
"id": "DEBT-006",
"concern": "mid-sentence-cut detection is not implementable without transcript/profile data that the current provider doesn't expose.",
"occurrence_count": 1,
"plan_ids": [
"build-a-turn-based-timeline-20260326-0005"
]
}
],
"legacy-effect-lifecycle": [
{
"id": "DEBT-017",
"concern": "removing customeffecteditor makes effects-table entries read-only \u2014 users can no longer edit legacy custom effects.",
"occurrence_count": 1,
"plan_ids": [
"build-an-llm-powered-custom-20260326-2230"
]
}
],
"optimistic-locking": [
{
"id": "DEBT-002",
"concern": "plan only specifies version checking at the db write layer; the ui load/state/save path doesn't carry config_version yet.",
"occurrence_count": 1,
"plan_ids": [
"build-a-turn-based-timeline-20260326-0005"
]
}
],
"properties-panel-scope": [
{
"id": "DEBT-011",
"concern": "crop and transition controls are not included in the bulk panel, narrowing the original idea's scope.",
"occurrence_count": 1,
"plan_ids": [
"multi-select-feature-parity-20260326-0548"
]
}
],
"realtime-subscriptions": [
{
"id": "DEBT-003",
"concern": "the shared realtime system doesn't know about timeline_agent_sessions; step 7 hooks need their own channel subscription.",
"occurrence_count": 1,
"plan_ids": [
"build-a-turn-based-timeline-20260326-0005"
]
}
],
"selection-save-bridge": [
{
"id": "DEBT-009",
"concern": "the plan specifies passing pruneselection into usetimelinesave but doesn't detail the hook-layer bridge needed because usetimelinesave is instantiated inside usetimelinedata before usetimelinestate runs.",
"occurrence_count": 1,
"plan_ids": [
"multi-select-timeline-clips-20260326-0415"
]
}
],
"task-deduplication": [
{
"id": "DEBT-001",
"concern": "server-generated idempotency keys would break retry deduplication because retried requests get fresh keys.",
"occurrence_count": 1,
"plan_ids": [
"migrate-all-task-creation-20260325-2354"
]
}
],
"task-system-integration": [
{
"id": "DEBT-005",
"concern": "create_generation_task is underspecified against the actual task family system.",
"occurrence_count": 1,
"plan_ids": [
"build-a-turn-based-timeline-20260326-0005"
]
}
],
"tool-error-propagation": [
{
"id": "DEBT-008",
"concern": "a blanket catch in executetool would silently downgrade db/persistence failures into ordinary tool results, changing the session error/http 500 behavior.",
"occurrence_count": 1,
"plan_ids": [
"refactor-ai-timeline-agent-20260326-0157"
]
}
],
"track-reorder-accessibility": [
{
"id": "DEBT-013",
"concern": "replacing arrow buttons with drag-only handle removes keyboard-accessible reorder; plan only specifies pointersensor.",
"occurrence_count": 1,
"plan_ids": [
"fix-track-reordering-bugs-and-20260326-1856"
]
}
],
"track-reorder-testing": [
{
"id": "DEBT-014",
"concern": "no automated tests specified for same-kind boundary rules or save/load persistence of reordered tracks.",
"occurrence_count": 1,
"plan_ids": [
"fix-track-reordering-bugs-and-20260326-1856"
]
}
]
}
code
Escalated debt subsystems:
[]
Debt guidance:
- These are known accepted limitations. Do not re-flag them unless the current plan makes them worse, broadens them, or fails to contain them.
- Prefix every new concern with a subsystem tag followed by a colon, for example `Timeout recovery: retry backoff remains brittle`.
- When a concern is recurring debt that still needs to be flagged, prefix it with `Recurring debt:` after the subsystem tag, for example `Timeout recovery: Recurring debt: retry backoff remains brittle`.
Requirements:
- Consider whether the plan is at the right level of abstraction.
- Reuse existing flag IDs when the same concern is still open.
- `verified_flag_ids` should list previously addressed flags that now appear resolved.
- Focus on concrete issues that would cause real problems.
- Robustness level: standard. Use balanced judgment. Flag significant risks, but do not spend flags on minor polish or executor-obvious boilerplate.
- Verify that the plan remains aligned with the user's original intent.
- Verify that the plan follows the expected structure: one H1 title, `## Overview`, numbered step sections (`### Step N:` under `## Phase` headers, or flat `## Step N:`) with file references and numbered substeps, plus `## Execution Order` or `## Validation Order`.
- Missing required sections or step coverage (for example: no H1, no `## Overview`, or no step sections at all) should be flagged as category `completeness` with severity_hint `likely-significant`.
- Structural formatting within steps (for example: prose instead of numbered substeps, or a missing file reference inside an otherwise actionable step) should usually be category `completeness` with severity_hint `likely-minor` because the executor can still follow the instructions.
- Ask whether the plan is the simplest approach that solves the stated problem, whether it could use fewer steps or less machinery, and whether it introduces unnecessary complexity.
- Over-engineering concerns should use category `maintainability`, should usually prefix the concern with "Over-engineering:", and should scale severity_hint to the practical impact.
- Flag scope creep explicitly when the plan grows beyond the original idea or recorded user notes. Use the phrase "Scope creep:" in the concern.
- Assign severity_hint carefully. Implementation details the executor will naturally resolve should usually be `likely-minor`.