Fix track reordering bugs and replace arrow buttons with drag-to-reorder. Current issues: (1) Moving video tracks above/below audio tracks stalls or doesn't work - there's some kind of contradiction in the reorder logic when crossing track kind boundaries. (2) Audio tracks can't be moved up at all. (3) Replace the up/down arrow buttons in TrackLabel with a drag handle so users can drag tracks to reorder them directly.
The video editor timeline has a track label sidebar where users can reorder tracks using up/down arrow buttons. Three bugs exist, plus a UX improvement request:
Bug: Cross-kind boundary stall — The up button on the first audio track (e.g., index 2 in [V1, V2, A1]) is not disabled (trackIndex !== 0 and sameKindCount > 1 could both be true for A1 at index 2 with 2 audio tracks), but handleReorderTrack silently returns because the adjacent track at index - 1 is visual. The button appears clickable but does nothing.
Bug: Audio tracks can't move up — Same root cause. The disable condition uses trackIndex === 0 (global index), but audio tracks are never at global index 0. The effective first audio track should use its position within its kind group, not the global array.
Feature: Replace arrow buttons with drag handle — Use @dnd-kit/sortable (already installed) to enable drag-to-reorder within each kind group.
Key constraint:sortTracksByKind in timeline-data.ts:320 enforces visual-before-audio ordering on load. The reorder logic must maintain this invariant — tracks can only reorder within their kind group.
Key files:
src/tools/video-editor/components/TimelineEditor/TrackLabel.tsx — UI buttons, will become drag handle
src/tools/video-editor/components/TimelineEditor/TimelineEditor.tsx:217 — track list rendering loop
Assistant
{"flags":[{"id":"FLAG-001","concern":"Track reordering: Replacing the arrow buttons with a drag-only handle removes the current keyboard-accessible reorder path, and the plan's drag setup only mentions PointerSensor.","category":"correctness","severity_hint":"likely-significant","evidence":"Current reorder controls are keyboard-focusable buttons in src/tools/video-editor/components/TimelineEditor/TrackLabel.tsx:196-220. The plan removes them in Step 5, while Step 7 proposes a nested with only, even though the app-level context already wires a in ."},{"id":"FLAG-002","concern":"Track DnD: Over-engineering: the nested is justified as protection from clip-drag conflicts, but the repository's timeline clip dragging is not using dnd-kit, and the app-level dnd handlers already no-op for unrelated drags.","category":"maintainability","severity_hint":"likely-minor","evidence":"Timeline clip dragging is implemented with raw pointer listeners in , not via dnd-kit. The app overlay only renders when drag data contains in , and exits early when drag data is missing or unrelated in ."},{"id":"FLAG-003","concern":"Track reordering: The plan relies on manual validation only and does not add automated tests for the same-kind boundary rules or save/load persistence.","category":"completeness","severity_hint":"likely-significant","evidence":"The current defect is in pure reorder logic at , and persistence also depends on load-time regrouping in . This repo already has vitest coverage for adjacent video-editor serialization logic in , so omitting tests leaves the subtle boundary behavior unguarded."}],"verified_flag_ids":[],"disputed_flag_ids":[]}
Step 1: Fix disabled-state logic in TrackLabel (TrackLabel.tsx)
Scope: Small
Fix the up/down button disabled conditions (TrackLabel.tsx:201,214). Currently they use trackIndex (global) which doesn't account for kind grouping. Replace with kind-relative index:
Up disabled: track is the first of its kind (kind-relative index === 0) OR sameKindCount <= 1
Down disabled: track is the last of its kind (kind-relative index >= sameKindCount - 1) OR sameKindCount <= 1
Approach: Pass a new prop kindIndex (position within same-kind group) from TimelineEditor instead of relying on trackIndex for disable logic. Alternatively, compute it inline: up disabled when trackIndex === 0 || (trackIndex > 0 && /* prev track is different kind */) — but the cleanest fix is passing kindIndex.
Update TimelineEditor (TimelineEditor.tsx:217-234) to compute and pass kindIndex for each track.
Step 2: Fix handleReorderTrack to skip across kind boundaries (useTimelineTrackManagement.ts)
Scope: Small
UpdatehandleReorderTrack (useTimelineTrackManagement.ts:286-308) to find the correct swap target — the next/previous track of the same kind rather than just index + direction. When direction is -1, scan backwards for the previous same-kind track; when +1, scan forwards.
Example: In [V1, V2, A1, A2], moving A1 down should swap with A2 (index 3), and A2 up should swap with A1 (index 2). Moving V2 down should NOT swap with A1 — it's already at the bottom of visual tracks.
Step 3: Validate bug fixes manually
Scope: Small
Test with configurations: [V1, A1] (single of each — buttons should all be disabled), [V1, V2, A1, A2] (both kinds can reorder within group), [V1, V2, V3, A1] (visual reorder works, audio button disabled).
Verify the buttons enable/disable correctly AND clicking them produces the correct swap.
Phase 2: Drag-to-Reorder
Step 4: Add SortableContext wrapper to track list (TimelineEditor.tsx)
Scope: Medium
Wrap the track label list (TimelineEditor.tsx:217-234) with SortableContext from @dnd-kit/sortable using verticalListSortingStrategy.
Separate visual and audio tracks into two SortableContext groups so dragging is constrained within kind. Each group gets its own SortableContext with the IDs of tracks in that group.
AddonDragEnd handler that extracts active.id and over.id, computes the new track order, and calls a new handleReorderTracks (plural) that accepts a full reordered track array. This avoids the directional swap entirely for drag operations.
Note: The app-level DndContext in App.tsx already exists. We may need to ensure the track drag events don't conflict with clip drag events (useClipDrag). Use a unique id prefix (e.g. track-${track.id}) for sortable items to distinguish from clip drags. Check if the app-level onDragEnd needs to be aware of track drags, or if we should use a nested DndContext for track reordering specifically to isolate it.
Step 5: Convert TrackLabel to sortable item (TrackLabel.tsx)
Scope: Medium
AdduseSortable hook to TrackLabel, following the pattern in SortableClip.tsx:86-96.
Replace the up/down arrow buttons (TrackLabel.tsx:196-221) with a GripVertical drag handle that receives {...attributes, ...listeners} from useSortable.
Applytransform and transition styles from useSortable to the root element.
Remove the onReorder prop and related ArrowUp/ArrowDown imports since drag replaces directional buttons.
Keep the drag handle in the hover overlay area where the arrows currently live, maintaining the existing show-on-hover UX pattern.
Step 6: Add handleMoveTrack for drag-end reordering (useTimelineTrackManagement.ts)
Scope: Small
Add a new handleMoveTrack(activeId: string, overId: string) callback that:
Finds both tracks in resolvedConfig.tracks
Validates they're the same kind (should always be true given SortableContext grouping)
Uses arrayMove from @dnd-kit/sortable to reorder
Calls applyResolvedConfigEdit with the new track array
Export this from the hook and wire it into the drag-end handler in TimelineEditor.
Remove the old handleReorderTrack (directional swap) if no longer used.
Decide between using the app-level DndContext or a nested one. Since the app-level DndContext handles shot/clip DnD with closestCenter and overlay, a nested DndContext scoped to the track list is safer — it prevents track drags from triggering clip DnD handlers and vice versa.
Wrap the track label container in its own DndContext with closestCenter collision detection and PointerSensor (with activation constraint of ~5px distance to avoid accidental drags on click).
Ensure the track list scroll container (TimelineEditor.tsx:211-215) still syncs scroll position with the timeline canvas during and after drag.
Test edge cases: single track of a kind (no drag target), dragging first visual track, dragging last audio track, many tracks with scroll.
Execution Order
Fix the bugs first (Steps 1-3) — small, isolated changes that are independently valuable.
Then layer on drag-to-reorder (Steps 4-8) — builds on the corrected reorder logic.
Validation Order
After Steps 1-2: manually test button enable/disable states and swap behavior across various track configurations.
After Steps 4-7: test drag reordering within each kind group, verify kind boundary is respected.
After Step 8: test with scrolling, verify no interference with clip DnD, verify save/load preserves reordered tracks.
code
Plan metadata:
{
"version": 1,
"timestamp": "2026-03-26T17:59:25Z",
"hash": "sha256:363e5aba4b8e5fac86f44ea2583e12dbe0109ca18588657acbd3a966f2c9c1e3",
"questions": [
"Should the drag handle be always visible, or follow the current hover-to-reveal pattern used by the arrow buttons? (Drag handles are typically always visible for discoverability, but this changes the at-rest appearance of the track label.)",
"Is there any keyboard accessibility requirement for track reordering? The arrows provided keyboard-accessible reorder. With drag-only, we'd lose that unless we add keyboard sortable support via @dnd-kit's KeyboardSensor.",
"Should we support dragging a track from one kind to another (e.g., promoting an audio track to visual)? Currently the system treats kind boundaries as hard \u2014 I'm assuming we keep that constraint."
],
"success_criteria": [
"Up/down buttons (or drag) correctly disabled/constrained for tracks at the boundary of their kind group",
"Audio tracks with 2+ tracks can be reordered (currently broken)",
"Reorder across kind boundaries is prevented \u2014 visual tracks stay above audio tracks",
"Drag handle replaces arrow buttons in TrackLabel hover state",
"Dragging a track visually reorders it within its kind group and persists the change",
"No interference between track drag and existing clip drag or external drop functionality",
"Track order survives save/load cycle (sortTracksByKind preserves relative order within kind)"
],
"assumptions": [
"The visual-before-audio track ordering invariant (enforced by sortTracksByKind) should be maintained \u2014 no cross-kind reordering",
"The existing app-level DndContext should NOT be reused for track drags \u2014 a nested DndContext is safer to avoid interference with clip/shot DnD",
"The GripVertical drag handle will live in the hover overlay (same position as current arrow buttons) to keep the at-rest UI clean, unless user says otherwise",
"We'll keep @dnd-kit/sortable (already at v10) \u2014 no new dependencies needed",
"The handleReorderTrack function can be replaced entirely by the drag-based handleMoveTrack \u2014 we don't need to keep the directional API"
],
"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"
]
}
],
"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"
]
}
],
"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"
]
}
],
"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"
]
}
]
}
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`.
“You are an independent reviewer. Critique the plan against the actual repository.….” Conversation with gpt-5.4, from the Peter O’Mallet DataClaw Conversations dataset. The Chat Archive, 2026. https://thechatarchive.com/c/01m80epz4jeb968yhhg3whjyw5