Skip to content

feat(folders): position sidebar folders with fractional rank keys - #15041

Open
Pearcekieser wants to merge 1 commit into
kirodotdev:mainfrom
Pearcekieser:feat/folder-fractional-order
Open

Pearcekieser wants to merge 1 commit into
kirodotdev:mainfrom
Pearcekieser:feat/folder-fractional-order

Conversation

@Pearcekieser

@Pearcekieser Pearcekieser commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: moving a sidebar folder writes only that folder, so a drag and an agent's chat_folder_move never renumber siblings.

A folder's place among its siblings is a dense integer order. Every move that has no free integer slot renumbers the siblings. That forced a batch reorder endpoint (POST /api/chat/folders/reorder) with its own entry and byte caps, and it made chat_folder_move refuse an app agent or crew member any position that would renumber a folder the person owns, which in a hand-arranged sidebar is most positions.

Why it matters

An app or crew member that creates a folder cannot put it where it belongs in the person's sidebar; the tool refuses and asks the person to do it. Every sidebar drag also sends a batch of rows computed against a cached tree, so a concurrent move from another tab or an agent can land against a tree that has shifted.

Not a goal

What changed (motivation → approach → change)

Before After
position = integer order, siblings renumbered position = rank string, generated between the two neighbours
drag sends [{id, order}, ...] to /api/chat/folders/reorder drag and chat_folder_move send before / after on PATCH /api/chat/folders/{id}
app positioning refused if it renumbers a foreign row app positions its own folder in any section the person has arranged; it never writes a folder it does not own

A rank is a short base-62 string compared lexicographically, the standard fractional-indexing technique. src/kiro_crew/dashboard/folder_rank.py holds the key generator, the sibling comparator and the placement plan. The PATCH handler resolves the anchor under the folder-store lock and writes the moved folder's rank, so the position is decided against the tree as it is at the write; an anchor that moved to another section is a 409.

Stored folders are not migrated. A folder without a valid rank sorts after its ranked siblings by legacy order, then name, as every earlier build drew it. The first move in a section holding such a folder, a corrupt rank or tied ranks gives every sibling a fresh, evenly spaced rank in its drawn order, then places the moved folder; no other folder's drawn position changes. Only the person's move may spread a section holding folders someone else owns: an app or crew member gets 409 folder_section_unranked there, unless the spread rewrites only its own folders. An app can still place its own folder first or last in such a section without that drag: ranked folders always sort before unranked ones, so first takes a rank and last stays unranked with an order one past the largest (folder_rank.edge_position), and no other row is written. Only a slot between two of the person's unranked folders is refused. A new folder (person, arrival_folders.py import, channel_folders.py, Code Review Sage routes.py) takes a trailing rank when the section is fully ranked. A reparent without an anchor is placed last through the same plan; where an app would need a spread over the person's folders, only the moved folder is written, unranked.

A mate's home folder (#25994) still takes only layout writes from anyone. The layout fields are now collapsed, before, after and expected_parent, so a person can still drag a mate's home among the top-level folders; order stays in the list so an old tab gets order_retired there too. ensure_mate_home gives a new home a trailing rank like the other folder writers.

The sidebar comparator (utils/folderTree.ts) sorts by rank the same way; the crew group that mirrors a connected crew's folders keeps each folder's valid rank too (peerFoldersOf in hooks/useInstanceSessions.ts), so a drag on that crew moves its folders on the hub as well; ChatFolder gains optional rank (types/index.chat.ts); reorderChatFolders is removed from api/client/chatOrganization.ts; utils/folderRank.ts mirrors the key generator for the optimistic draw, and test/fixtures/chat_folder_rank.json pins the keys and sort cases both suites must produce. Undo after a drag-reparent sends the original neighbours as before/after and falls back to the parent alone if they moved. The folder PATCH reads its body through read_bounded_json (1 MiB cap; error-code-baseline.json updated). chat_folder_suggest lists folders in sidebar tree order through folder_rank.tree_order, the same iterative walk chat_folder_tree uses, and the failed-import rollback in arrival_folders.py treats rank like order. docs/architecture/mcp.md, the feature map and the dashboard module spec describe the rank model.

This is a possible shared helper for the pinned-session order in #14233, which stores a dense list today; not changed here.

Backwards compatibility

Breaking: POST /api/chat/folders/reorder is retired to a 410 reorder_retired tombstone that tells an old tab to reload. Its expected_parent precondition, which #15846 added, moves to the folder PATCH: an optional string naming the container the caller saw the folder in ("" is the root lane, and a parent that no longer exists counts as the root). _apply compares it with the folder's container under the store lock and answers a mismatch with 409 folder_parent_changed and no write; a non-string is 400 expected_parent_invalid. Anchors alone cannot stand in for it: when a parent is deleted mid-drag, the dragged folder and its anchor are both promoted to the root and are still siblings there. The sidebar drag sends it on every sibling move, chat_folder_move sends it on every anchored move whose parent its listing shows, and a PATCH without it behaves as before. PATCH /api/chat/folders/{id} answers an order field with 400 order_retired. Writer sweep on origin/main @ 98b7375: the only callers were the sidebar drag (chat-sidebar/dnd/useSidebarDrag.ts via reorderChatFolders, split out of ChatSidebar.tsx by #15094) and chat_folder_move in mcp_dashboard.py; both now send before/after. The one other caller, website/scripts/capture-nested-folder-reorder.mjs (a manual capture harness, not in CI), now stubs and asserts the anchor PATCH. No app manifest writes folder order through the API. A browser tab still running an older build is told to reload on its next folder drag. The member gate does not admit the retired POST: crew members are agent principals with no dashboard bundle to reload, so a member caller on the old contract gets the owner-only refusal rather than the reload hint. When an Undo's original neighbour has moved, the folder lands last in its old section and a status line names it, reveals the folder and clears on the next move; the line shows in Custom folder order only (folder_undo_anchor_gone, added to every file in website/src/i18n/locales/). Downgrading to a build before this one keeps the legacy order values, which this build reads but no longer writes, so folder positions set since the upgrade are lost.

Readers of the removed api_chat_folder_reorder and POST /api/chat/folders/reorder on origin/main:

  • Reader: src/kiro_crew/dashboard/routes/sessions.py:register -- chat -- the path now routes to the 410 api_chat_folder_reorder_retired tombstone; test_chat_folder_rank.py tombstone test
  • Reader: src/kiro_crew/dashboard/chat.py:api_chat_folder_reorder -- chat -- the re-export is replaced by api_chat_folder_reorder_retired
  • Reader: website/src/pages/chat-sidebar/dnd/useSidebarDrag.ts:reorderFolders -- chat -- the drag sends before/after on the folder PATCH; ChatSidebar.folderMoveUndo.test.tsx
  • Reader: website/src/api/client/chatOrganization.ts:reorderChatFolders -- release -- an older bundle still calls it and gets the 410 reload message
  • Reader: src/kiro_crew/mcp_dashboard.py:chat_folder_move -- subagent -- the tool sends before/after on the PATCH instead of renumbering; test_mcp_dashboard_folders.py
  • Reader: src/kiro_crew/dashboard/handlers/_shared.py:_admitted_chat_route_methods -- crew page -- the member admission for the batch POST goes with the route; test_member_chat_folders_gate.py
  • Reader: website/scripts/capture-nested-folder-reorder.mjs:route -- release -- the manual capture harness stubs and asserts the anchor PATCH; not in CI

Other compatible changes:

Deleting a folder still moves its children to the top level; they now land after the top level's ranked folders in their old order (chat_folders.py _remove), instead of keeping a rank from their old section that could collide with a root folder's. In a top level with unranked folders they drop rank and take order values after the root's.

The folder PATCH also accepts before and after together, meaning "between these two adjacent siblings"; a pair that is no longer adjacent is 409 folder_anchor_not_sibling, which Undo uses so a neighbour that moved inside the section cannot drag the folder to a new spot.

The empty-folder cleanup preview (chat_folder_cleanup.py) lists folders in the sidebar's rank order.

Main has since moved chat_folder_move and chat_folder_tree into mcp_dashboard_folder_runs.py and mcp_dashboard_folder_tree.py; the integer-slot code this PR removes is there now. chat_folder_suggest.py and its test are black-clean after this change, so .github/black-baseline.txt drops both.

Tests

  • test/test_chat_folder_rank.py: key generation (random insert property check, cap refusal, determinism), comparator (ranked before unranked, UTF-16 id tie-break, corrupt rank), placement plan, and the real PATCH handler through the real folder repository: first move spreads then later moves write one row, corrupt rank falls back to the spread, an app is refused (409, no write) where the spread would touch the person's folders and allowed once the section is ranked or the spread touches only its own, an app reparent into a legacy section writes only the moved folder, a duplicate or unranked row anywhere in the section forces a spread, app refused on the person's folder and on a folder holding the person's, anchor in another section is 409, reparent plus position in one write, reparent without anchor lands at the end of ranked and legacy sections, concurrent moves both land, malformed bodies are 400 with no write, create in a ranked section gets a trailing rank, deleting a folder appends its children after the root's ranked rows in their old order (in a legacy root, unranked with order values after the root's), a spread whose store write fails restores every rank.
  • website/src/test/folderRank.test.ts and reorderFolders.test.ts: shared fixture parity, drag direction to anchor, optimistic ranks match the gateway's plan, cross-container drop moves nothing.
  • website/src/test/crewSpaces.test.ts: a connected crew's valid rank is kept and a malformed one dropped; its folders draw in rank order over a conflicting legacy order; an older crew's unranked folders still sort by order.
  • website/src/test/ChatSidebar.folderMoveUndo.test.tsx: Undo of a folder drag-reparent sends the original neighbour as the anchor, and a failed parent-only fallback restores the cached parent and rank.
  • test_chat_folder_suggest.py: a ranked nested section stays under its parent in the suggestion list instead of pushing top-level folders past the cap; orphans and parent_id loops are listed once.
  • test_mcp_dashboard_folders.py: the tool sends one PATCH with the anchor and surfaces endpoint refusals. test_chat_folder_reorder_atomic.py is deleted with its endpoint.

Manual verification

N/A: the endpoint tests drive the real handler and repository transaction, and the sidebar path is covered by the drag tests; the drawn order for an existing store is unchanged by construction (unranked rows keep the legacy comparator).

Screenshots / video

A drag lands where it did before; the new surface is the Undo fallback status line (folder-undo-anchor-gone). Captured from this revision's built SPA by website/scripts/capture-folder-undo-anchor-gone.mjs (real pointer drag, then Undo against a stubbed 409 folder_anchor_not_sibling; 28/28 assertions pass), committed under temp-screenshots/15041-folder-undo-anchor-gone/:

  • nested-dark.png, nested-light.png: a folder with a long name goes back under Archive; the line wraps at sidebar width above the tree and the folder is revealed and outlined below it.
  • top-dark.png, top-light.png: a root folder goes back to the top level.

The line uses the neutral status surface with a dismiss ✕, not the red "Folder update failed" notice, which is absent in every capture.

The three folder-move refusals reach the existing "Folder update failed" line through errMessage(e). That notice now sets actionPlacement="below", as the sidebar's other notices do. Since #37263 a block notice always draws Ask the agent in its action row under the copy, and a test pins that layout for this notice. These six captures come from the built SPA on 25d95bcb9b: a real pointer drag of Inbox above Archive, with the folder PATCH stubbed to answer the gateway's exact body. All 6 checks that the line shows the server text pass, and each of the 6 image URLs answers 200.

409 folder_parent_changed, the folder's parent was deleted or it was moved by another tab during the drag:

409 folder_parent_changed in the Folder update failed line, dark
409 folder_parent_changed in the Folder update failed line, light

409 folder_anchor_not_sibling, the neighbour the drag named moved or was deleted before the write:

409 folder_anchor_not_sibling in the Folder update failed line, dark
409 folder_anchor_not_sibling in the Folder update failed line, light

410 reorder_retired (and the 400 order_retired PATCH, which carries the same text), a tab still on an older build:

Stale-tab reload message in the Folder update failed line, dark
Stale-tab reload message in the Folder update failed line, light

Related Issues

Supersedes the renumber race fixed in #12278, since there is no batch renumber left to race.

Fixes #15040

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

Follow-ups

Deferred review items, one issue each:

@Pearcekieser
Pearcekieser marked this pull request as ready for review September 29, 2026 15:39
@Pearcekieser

Copy link
Copy Markdown
Contributor Author

Intent: A sidebar folder move writes only the moved folder, because its position is a rank string the gateway generates between the two neighbours, so drags and chat_folder_move no longer renumber siblings and an app can position its own folder among the person's.
Not a goal: pinned-session order (#14233), a manual order for unpinned sessions, or rewriting stored folders' legacy order values.

@Pearcekieser
Pearcekieser requested a review from a team September 29, 2026 15:39
@Pearcekieser
Pearcekieser requested a review from a team as a code owner September 29, 2026 15:39
@github-actions github-actions Bot added fork Pull request from a fork (external contributor) readiness: checking Automated validation is still running labels Sep 29, 2026
@github-actions

github-actions Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review (fork) — ✅ no blocking findings

Reviewed ebf7e14445e6a4cacb6a119c26cbba2fd3c61f23 via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] ebf7e14

@github-actions

github-actions Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5, fork) — ✅ PASS

Design-level review of ebf7e14445e6a4cacb6a119c26cbba2fd3c61f23 via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks: fractional ranks remove sibling renumbering at its source, the spread and the move happen in one locked mutate, and the retired endpoint is listed as Breaking.

Notes

  • Downgrading is a one-way door the author accepts: ranks written after the upgrade are lost on an older build. The rollback plan in the release notes should say so.
  • The description was cut off inside ## Backwards compatibility, so this review did not judge the rest of the reader list.

[DESIGN-REVIEWED] ebf7e14

Description read

[DESCRIPTION-READ] a0580bd1b0768ceffc90da64e85b46dd9095da0be377a66d37360ed87208f686

That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5, fork) — ✅ PASS

Premise-level review of ebf7e14445e6a4cacb6a119c26cbba2fd3c61f23 via the fork AI-review pipeline — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

First-Principles-Verdict: PASS

Nothing blocks. Rank keys address the cause (dense integer order forced sibling renumbers) and delete the batch endpoint, the tool-side renumber planner and _free_slot_order.

Notes

  • Item 9 — oversized: the generator mirror in website/src/utils/folderRank.ts (rankBetween, spreadRanks, planPosition) exists "only to draw a drag before the server answers". That is a second spelling of folder_rank.py, kept in lockstep by a fixture of about 400 lines. Subtraction: keep validRank/compareRanks for sorting and delete the three generators. Draw the optimistic drop from the locally spliced sibling sequence, then take ranks from the refetch.

What this change ships

Inventory (10 items) — 7 justified

Intent: let a person's drag and an agent's chat_folder_move place a folder by writing only that folder. This is an ADDITION (a new position model).

  1. A folder's position is stored as a rank string between its neighbours; siblings are no longer renumbered — justified
  2. POST /api/chat/folders/reorder is retired; it answers 410 and tells an old tab to reload — justified
  3. A PATCH carrying order is refused with 400 order_retired — justified
  4. The PATCH accepts before/after/expected_parent, checked under the store lock (409 when an anchor or parent moved) — justified
  5. An app or crew member can place its own folder among the person's folders once that section is ranked, or at either end of it — justified
  6. The first move in a legacy section gives every sibling an evenly spaced rank; an app gets 409 folder_section_unranked there — justified
  7. When an Undo's original neighbour has moved, a status line names the folder (new i18n key) — justified
  8. Deleting a folder now puts its children last in the top level — undeclared
  9. The sidebar carries its own copy of the key generator for the optimistic draw — oversized
  10. The folder PATCH body is now capped at 1 MiB — rides along

[FIRST-PRINCIPLES-REVIEWED] ebf7e14

Description read

[DESCRIPTION-READ] acf84b58ed4ff50a0976f21063689af4832e276e581727bb0565fb22ab41f3f9

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

github-actions Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5, fork) — ✅ PASS

UX-level review of ebf7e14445e6a4cacb6a119c26cbba2fd3c61f23 via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

UX-Verdict: PASS

The attached and committed screenshots show every control this diff adds: the Undo "went back… at the end" status line (nested and top level, both themes) and the folder-error notices with the action moved below. No first-time reader has looked at them, because this fork lane has no blind read. Pushing the branch to this repository adds that read.

Notes

  • "This page is out of date; reload it to move folders." asks the user to reload but only offers "Ask the agent". Add a "Reload page" action to that notice so the next step is one click.

[UX-REVIEWED] ebf7e14

Description read

[DESCRIPTION-READ] a2d8ad83f0d39f403655934f85d656432f733774426ce9e60ca2295368bd18dd

That sha256 names everything this verdict read: the PR description, plus the 13 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review (fork) — 🔴 changes requested (blocking)

Reviewed ebf7e14445e6a4cacb6a119c26cbba2fd3c61f23 via the fork AI-review pipeline; updated in place on each push.

One folder writer still adds unranked rows: install-archive import. After an import, an app can't place a folder between two siblings until the person drags a folder by hand. This PR fixes and tests that same outcome for every other folder writer.

BLOCKING — src/kiro_crew/dashboard/folder_portability.py:261
row["order"] = order + offset / current.append(row)
Trigger: The person imports an install archive whose folders.json holds new folder ids into a section that is already fully ranked. read_archive_folders → _clean_row drops rank, and add_missing_folders appends rows that carry only order. Next, an app's chat_folder_move sends a before/after anchor between two siblings in that section. The request goes PATCH → _apply → plan_position, whose respread names the person-owned imported rows → edge_position returns None for a middle slot.
Outcome: The app's anchored move gets 409 folder_section_unranked in a section the person had already arranged. It keeps failing until the person drags a folder by hand. The PR adds assign_append_rank to every other writer to prevent exactly this: create, arrival, channel, mate home and code_review_sage, the last pinned by test_the_folder_keeps_a_ranked_section_ranked.
Anchor: defect
Fix: In add_missing_folders, after setting each row's order, call assign_append_rank(row, current) before current.append(row), in archive order.

[BLOCK-MERGE] ebf7e14
[OPUS-REVIEWED] ebf7e14

@Pearcekieser
Pearcekieser force-pushed the feat/folder-fractional-order branch from 6693e55 to 8e3a35f Compare September 29, 2026 16:43
@Pearcekieser

Pearcekieser commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor Author

span=44792a8fa23a
self-added: yes
fixed in 8e3a35f

  • module docstring overstated single-row writes

The folder_rank.py docstring now says the common path writes one row and a section needing normalization is re-ranked in place in its current order, which is what plan_position does.

@Pearcekieser

Pearcekieser commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor Author

span=65f81eb341a2
self-added: yes
mechanism: no-anchor reparent now places the folder via plan_position(siblings, len(siblings))
fixed in 8e3a35f

  • legacy order+1 ties after clamping

The legacy order write is gone. A no-anchor reparent calls plan_position(siblings, len(siblings)): a fully ranked destination gets one trailing rank, anything else is re-ranked in its drawn order with the moved folder last, so ORDER_LIMIT clamping can no longer tie.
test_a_reparent_without_anchor_handles_a_clamped_legacy_order covers a sibling at 2**53-1.

@Pearcekieser

Pearcekieser commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor Author

span=340683d4ba46
fixed in 8e3a35f

  • module spec still listed order as writable

docs/system-specs/modules/learn-cron-dashboard.md now drops order from the PATCH field list and documents before/after, the server-computed rank, legacy ordering, 409 folder_anchor_not_sibling and 400 order_retired.

@Pearcekieser

Pearcekieser commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor Author

span=96abd459e241
fixed in 8e3a35f

  • capture harness still asserted the removed reorder POST

website/scripts/capture-nested-folder-reorder.mjs now stubs PATCH /api/chat/folders/{id}, asserts exactly one anchored PATCH naming the dragged folder with before= and no parent_id, and keeps the re-parent assertion. The Backwards compatibility sweep names it.

@Pearcekieser

Pearcekieser commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor Author

span=b7d7ccc155aa
fixed in 8e3a35f

  • 409 text used API vocabulary

The folder_anchor_not_sibling error now reads "That folder moved before the drop landed. Try the move again." The code is unchanged.

@Pearcekieser

Pearcekieser commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor Author

span=b093ded56bb2
rebutted

  • stale tab shows a bare 404 on drag

A stale tab does not outlive the upgrade that removes the route: useWebSocket.ts reloads the page when the dashboard frame's version or bundle_id changes (the 'dashboard' case, window.location.reload()).
The window is a drag between the new gateway starting and the tab's first status frame; a 410 stub route for a retired endpoint would be permanent code for that gap.

@Pearcekieser

Pearcekieser commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor Author

span=472852ca8399
acknowledged

  • order_retired wording

Agreed: order_retired only reaches API callers (the UI never sends order), so its developer wording stays.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Sep 29, 2026
@Pearcekieser
Pearcekieser force-pushed the feat/folder-fractional-order branch 2 times, most recently from 7208c92 to d3b842b Compare September 29, 2026 18:00
@Pearcekieser

Pearcekieser commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor Author

span=14713081046c
self-added: yes
mechanism: app positioning refused (409 folder_section_unranked) when the respread would touch a folder the caller does not own
fixed in d3b842b

  • rank normalization wrote foreign-owned folders

_apply now checks every respread row's owner before any mutation: a principal whose positioning would re-rank a folder it does not own gets 409 folder_section_unranked (SEL-audited, no write). A respread over only its own folders, or any positioning once the person has ranked the section, is still allowed.
A no-anchor app reparent that would need such a respread writes only the moved folder (no rank, order past the section max). Create only ever writes the new folder.
Tests: app refused in a legacy section with the person's folders, allowed after the person ranks it, allowed when the respread is its own, app reparent writes only the moved row.

@Pearcekieser

Pearcekieser commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor Author

span=2d121c59e4ca
rebutted

  • enforce order preservation of the respread

With d3b842b an app or member never writes another owner's folder, so the person's arrangement no longer rests on plan_position's order preservation; a respread now runs only for the person or over the caller's own rows.
plan_position assigns spread_ranks in the section's existing custom_sort_key order by construction, and TestPlanPosition plus the endpoint spread tests pin that order.

@Pearcekieser

Pearcekieser commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor Author

span=7f50c78d70d4
fixed in d3b842b

  • 409 anchor copy named the wrong folder

folder_anchor_not_sibling now reads "The folder you dropped next to just moved. Try the move again."

@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Sep 29, 2026
@Pearcekieser

Copy link
Copy Markdown
Contributor Author

chore (non-blocking): rebased on main, no behaviour change

Head 2410fba, a clean rebase of c109358 with no conflicts. Main now includes #26180, which fixes the boot-smoke failure (test_a_second_boot_touches_only_known_module_globals on admission_gate._last_config_at) that made Integration (in-process gateway) red on c109358. With #26078 already on main, both flakes this PR kept hitting are fixed. Locally, the folder stability command with 4 workers (633 tests), the integration boot-smoke file (16 tests) and the pre-push gate (24 of 24) pass.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

span=be85a2d5c148
self-added: yes
acknowledged (follow-up) tracked in Pearcekieser#51

  • a background refetch silently cancels the Undo fallback

issue (non-blocking): adjudication downgraded this one, and it is the mechanism Pearcekieser#51 tracks. Both anchored Undo requests skip updateFolderMutation, so a refetch landing before the 409 can make the superseded check misread the cache. #51 routes them through the keyed mutation lifecycle with a mid-Undo refetch test. The folder stays where the server has it; only the "Undo didn't apply" line is missing.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

chore (non-blocking): rebased on main, no behaviour change

Head 6919493. The only conflict was the lucide-react import line in website/src/pages/chat-sidebar/SearchDock.tsx: main added ZapOff and this PR adds CornerDownRight, so both are kept. tsc, eslint on the sidebar, 1,591 sidebar vitest tests, 690 backend tests and the pre-push gate (24 of 24) pass locally.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

chore (non-blocking): rebased on main, no behaviour change

Head d1fe31e, a clean rebase of 6919493 with no conflicts. Backend Lint & Type Check failed on 6919493 with flake8 F401 on an unused DASHBOARD_PORT import in src/kiro_crew/cli_parser_agent.py, a file this PR does not touch; main fixed it in #26336, which this head includes. The full flake8 src/kiro_crew test conftest.py xdist_budget.py run is clean locally, and 690 folder and error-code tests and the pre-push gate (24 of 24) pass.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

chore (non-blocking): rebased on main

Head 3814c81. Main had moved four days since d1fe31e, and the rebase conflicted in nine files. Most were import or doc lines where both sides are kept. Two changes go beyond a plain merge, both caused by main's mate home folders (#25994):

  • A mate's home takes only layout writes from anyone, and main's layout fields were collapsed and the integer order. This PR retires order writes, so a person could no longer drag a mate's home at all. LAYOUT_ONLY_FIELDS in chat_folders_records.py now also lists before, after and expected_parent. An anchor alone keeps a folder in its own section, and main's separate parent_id check still refuses any move into or out of a home. test_collapse_and_reposition_still_apply fails with 403 without this and passes with it, and an old tab's order write to a home gets order_retired like anywhere else.
  • ensure_mate_home in mate_folders.py gives a new home a trailing rank, as the other folder writers do.

The arrival and channel folder writers use main's next_folder_order plus this PR's assign_append_rank. The mcp.md conflict drops the chat_folder_file_self paragraph, which main deleted in #28917. The description now names these.

Locally, flake8, mypy on the touched modules, 746 folder, mate and error-code tests with 4 workers, 1,782 sidebar and folder vitest tests, tsc, the full frontend lint and the pre-push gate (24 of 24) pass. Local GPT and Opus reviews found nothing.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

note (non-blocking): Internal Content Scan on 3814c81 needs a re-run (run 41763408225); its runner could not reach github.com:443 during "Checkout base (trusted)", so it scanned nothing and reports no verdict.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

note (non-blocking): 289aac6 is the same tree as 3814c81, re-run for Internal Content Scan (run 41763408225, no verdict after a runner network failure) and Backend Tests (3.12, 5) (job 126358548050, two test_decisions_end_to_end.py cases that pass locally).

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

note (non-blocking): Security Scope Review (fork lane) on 289aac6 needs a re-run (check run 126415705934); it reports scope-floor:unsettled because its generate job did not finish, so no leg ran and it has no findings. Every other check on this head has passed, and readiness is waiting only on this lane.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

chore (non-blocking): rebased on main, no behaviour change

Head 5f1ccd2. Main's #27427 added the folder icon preview (POST /api/chat/folders/{id}/icon-preview) right beside the batch reorder this PR retires, so eight files conflicted. Each keeps both sides: main's api_chat_folder_icon_preview and previewChatFolderIcon, and this PR's 410 api_chat_folder_reorder_retired with reorderChatFolders removed. The feature map and the dashboard module spec take main's icon-preview text inside this PR's rank text. No _MAX_REORDER_* or reorderChatFolders reference remains.

Locally, flake8, mypy on the touched modules, 765 folder, mate, icon and error-code tests with 4 workers, 3,072 sidebar, folder and API client vitest tests, tsc, the full frontend lint and the pre-push gate (24 of 24) pass. This push also gives Security Scope Review, which never finished on 289aac6, a fresh run.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

chore (non-blocking): rebased on main, no behaviour change

Head 2f29255. The only conflict was test/test_mcp_dashboard_folders_position.py, where main's #29599 shortened comments and docstrings, including on the integer-order and batch-reorder tests this PR deletes or rewrites. Every block keeps this PR's side, so the file has the same 45 tests as before and main's shorter docstrings on the tests both sides keep. Locally, those 47 cases, 765 folder, mate, icon and error-code tests with 4 workers and the pre-push gate (24 of 24) pass.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

Re-run with no code change: be216fb has the same tree as 2f29255. Frontend Tests (4) job 126650733345 crashed a worker after all tests passed, and Backend Tests (3.12, 5) job 126650732226 hit the open flake #29457.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

Re-run with no code change: 36146ce has the same tree as 2d21d9f. Frontend Tests (1) job 126908222918 hit the open flake #29597, and Frontend Coverage Merge and Coverage Gate failed only because of it.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

Re-run with no code change: 35c8834 has the same tree as f32d788. On f32d788, nine lanes failed between 19:01Z and 19:08Z on the CI app's API rate limit before they judged anything: Fork PR Description, PR Policy, Publish readiness signal, Sensitive Change Review, Dependency License Gate, Internal Content Scan, GPT 6.1 Review, Opus 5.5 Review and Security Scope Review. Frontend Tests (2) job 127469072592 timed out at 15 s in notificationsSlice.test.ts:649, a test this PR does not touch that passes locally in 2.5 s.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

self-added: yes
mechanism: folder names reached the Trans markup parser through interpolated values

fixed in e9115df: the Undo anchor-gone line no longer passes folder names through <Trans values>.

GPT 6.1 blocked e2d9e86 at website/src/pages/chat-sidebar/SearchDock.tsx:1311 (lane run 42435707913). The rate limit kept its PR comment from posting, so this records the finding and the fix here.

i18n runs with escapeValue: false, so interpolation ran before <Trans> parsed the line for its <name> and <parent> slots. A folder named <br/> was read as a line break and dropped from the line that reports its move.

The names now render as React text through a small FolderNameSlot component placed in self-closing <name/> and <parent/> slots. The two catalog entries use those slots in English, the 11 translated locales and Bengali, and en-XA is regenerated. FolderNameSlot takes the name as a prop, so <Trans> keeps the element as it is and does not remount the names on each render inside the role="status" line.

The new test in website/src/test/ChatSidebar.folderMoveUndo.test.tsx, "shows folder names in the fallback notice as literal text, never as markup", renders the names Kids <br/> & <name>x</name> and <i>Old</i> <parent/>. It failed on e2d9e86 and passes now. The file passes 24 of 24, and the catalog tests pass 174 of 174.

@bolichen97 bolichen97 left a comment

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.

Requesting changes at e9115df for one point. CI is green.

website/src/utils/folderRank.ts adds a regex in product code. This repository asks new code not to use one:

out.push(digits.replace(/0+$/, ''))

It strips trailing 0 characters from the rank digits. The same thing needs no regex: walk back from the end while the character is '0', then slice. For example:

let end = digits.length
while (end > 0 && digits[end - 1] === '0') end--
out.push(digits.slice(0, end))

A test with no trailing zeros, some, and all zeros would pin it.

Separately, this PR retires POST /api/chat/folders/reorder to a 410 tombstone and changes how apps may position folders. iamwhatever's open review also asks for a maintainer on that, so it is not settled by this review.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

@bolichen97 issue: the regex in website/src/utils/folderRank.ts is gone, fixed in 26142e1.

spreadRanks now calls a new exported helper, stripTrailingZeros(digits). It walks back from the end while the character is '0' and then slices, as you suggested. It removes the same characters as the old /0+$/ and as rstrip("0") in spread_ranks on the gateway side, so the two sides still produce the same ranks. The shared fixture in test/fixtures/chat_folder_rank.json still passes on both sides.

website/src/test/folderRank.test.ts has a new table test with six cases: no trailing zeros (V, a0b), some (V0, 0a00), all zeros (000) and the empty string. I searched the product code this PR adds under website/src, tests excluded, and it adds no other regex.

The same push rebases the PR onto current main, so CI runs fresh on this head. I agree the 410 for POST /api/chat/folders/reorder and the app positioning rules still need a maintainer's call. That is the open point in iamwhatever's review, and I have asked them to look again.

@bolichen97

Copy link
Copy Markdown
Contributor

Thanks. My point from e9115df is fixed at 751091b. spreadRanks now calls stripTrailingZeros, which walks back from the end while the character is '0' and slices. The new table test covers no, some and all trailing zeros and the empty string, and a second search of the product code finds no regex. All 91 checks are green.

I'm not approving yet. Retiring POST /api/chat/folders/reorder to a 410 and changing how apps may position folders is a maintainer decision, and iamwhatever's open review asks for the same. I'll follow up once that call is made.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

@iamwhatever @bolichen97 question (blocking): this PR now waits on two maintainer calls, and both of your reviews point at them.

  1. Retire POST /api/chat/folders/reorder to a 410 reorder_retired tombstone, and answer an order field on the folder PATCH with 400 order_retired. The writer sweep in Backwards compatibility found two callers, the sidebar drag and chat_folder_move, and both now send before/after anchors. A tab on an older build is told to reload on its next folder drag.
  2. Let an app or crew member place a folder it owns in any section the person has arranged, through those anchors. It still never writes a folder it does not own. Before this PR, chat_folder_move refused any app move that had to renumber a folder the app does not own.

If either call should go the other way, say which one and I will change the PR to match.

@KiroCrewCaptain

KiroCrewCaptain commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

Code change approver recommendation: A person should decide

Why: the decider thinks the change is probably fine but estimates a 22% chance that this change introduces a defect, above the 12% limit for approving on its own.

Approve. Folder positions move from dense integer order values to fractional base-62 rank keys. The rank math (rank_between, spread_ranks, plan_position, edge_position) is correct and the browser copy matches the Python. The PATCH handler decides placement under the folder-store lock. It keeps the existing ownership rules (moved folder owned, destination owned, no foreign folders in its subtree) and adds one: an app never rewrites the rank of a folder it doesn't own. Where a re-spread would touch the person's folders, the app can only take a first or last slot, and a slot between them is refused with 409 folder_section_unranked. The MCP tool's removed ownership check is covered by the PATCH's not_owned check. Every chat-folder creator gives a new folder a trailing rank, deleting a folder places its children last, and other readers (cleanup preview, suggestions, MCP tree) use the shared comparator. The retired reorder POST answers 410 and its known callers are updated. Undo sends the original neighbours and falls back to a parent-only move guarded by expected_parent. test_chat_folder_rank.py covers the risky paths against the real handler and store. Some CI jobs

An automated recommendation, not a review: a maintainer still decides. It approves on its own only when the estimated chance of a defect is at most 12% and the change has at most 400 changed lines. Decider v3c (217fe607) · commit ce410a1d7a · 6454 changed lines. If this recommendation is wrong, reply here: replies are how the approver is evaluated.

A sidebar folder's place among its siblings is now a short rank string that
the gateway picks between the two neighbours, so a move writes the moved
folder only. PATCH /api/chat/folders/{id} takes before/after naming a sibling;
the sidebar drag and chat_folder_move both send that anchor, and the atomic
multi-row reorder endpoint they used to renumber siblings through is removed.

Folders written before ranks sort after ranked siblings by their legacy order,
so nothing changes on disk until someone moves a folder. The first move in such
a section spreads fresh ranks over it in its current order; since that changes
no other folder's position, an app may position its own folder among the
person's without owning them.
@Pearcekieser

Copy link
Copy Markdown
Contributor Author

span=6662a031f2c4

fixed in ebf7e14

fixed in ebf7e14: PeerFolder now has an optional rank. peerFoldersOf in website/src/hooks/useInstanceSessions.ts keeps the rank of a peer folder when validRank accepts it and drops it otherwise, so a rank that the proxy redaction changed falls back to order. The crew group sorts by rank first, then by the legacy order, then by name, so a peer on an older build that sends no rank still draws in order. Three new tests in website/src/test/crewSpaces.test.ts cover a kept and a refused rank, ranked peer folders drawn in rank order when order disagrees, and unranked folders from an older peer sorted by order. Two of them fail on the old hook.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fork Pull request from a fork (external contributor) merge conflict Branch has merge conflicts with its base — author must resolve before merge needs-author-decision PR blocked on author input readiness: action required A blocking check or review needs attention

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Position sidebar folders with fractional rank keys instead of renumbering siblings

5 participants