Skip to content

fix(platform): keep appended task ranks short - #4594

Merged
yannickmonney merged 2 commits into
mainfrom
fix/task-rank-growth
Oct 9, 2026
Merged

yannickmonney merged 2 commits into
mainfrom
fix/task-rank-growth

Conversation

@yannickmonney

@yannickmonney yannickmonney commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

What

Task ranks grew by one character every five or six appends to a column. The load harness (#4589) found this: after a task burst, the Backlog column of one project held 44,000 tasks with ranks up to 7,319 characters (3,658 on average).

Every row carries its rank, and so does every entry of the (project_id, status, rank) index and every board read. A B-tree entry may not exceed about 2.7 KB once compression stops helping. Task creation also slowed down run after run as the column grew.

Cause: an append to the end of a column took the midpoint between the last key and the end of the base-36 alphabet. That reaches z within a few steps, after which every further append adds a digit. Appends are the hot path: every created task, every status change and every drop at the bottom of a column.

Fix: rankBetween(last, undefined) now counts. It increments the key as a base-36 number of the same length, carrying to the left, with the last digit running 1–z so no key ends in 0 (the between-insert relies on that). Only an all-z key is extended, and then by a block as long as the key itself.

  • Key length is now O(log n): a million appends stay within 16 characters.
  • Same-length keys order numerically, so counted keys interleave with every key already stored.
  • A column that already holds long keys stops growing: the next append keeps its length.
  • Between-inserts and prepends are unchanged.

Rank order (review finding): counted keys run through every letter pair, and the board (use-task-board-dnd.ts), the subtask list (subtasks.ts) and the server's board read sorted ranks with localeCompare. A browser whose collation treats a pair as one letter — Hungarian zs, Croatian lj, Danish/Norwegian aa, Czech/Slovak ch — would order a column differently from the server and compute drops from the wrong neighbours. Ranks are now compared by code unit everywhere (lib/shared/task-rank-order.ts), the order rankBetween and the (project_id, status, rank) index use (the database collation is en_US.utf8, code-unit order for [0-9a-z]). A long legacy all-z key is extended by at most 8 digits instead of doubling.

Testing

New tests in rank.test.ts (16 tests in the file):

  • a million appends stay ordered, within 16 characters, and none ends in 0;
  • an append after a 5,001-character stored key keeps its length;
  • the exact carry and extension steps (iz → j1, a0z → a11, z → zi, zz → zzi1, zzzz → zzzzi001);
  • appended keys interleave with keys placed between them.

The task, core/tasks, projects and REST suites pass: 1,351 tests.

Follow-up (not in this PR)

Shortening ranks already stored in very large columns would be a data migration that renumbers a column while keeping its order. It's optional now that those keys no longer grow.

@yannickmonney
yannickmonney added this pull request to the merge queue Oct 9, 2026
@yannickmonney
yannickmonney removed this pull request from the merge queue due to a manual request Oct 9, 2026
Appending to a column took the midpoint between the last key and the
end of the alphabet, which reaches z within a few steps and then adds a
digit: one digit every five or six appends. A project with 44,000 tasks
in Backlog carried ranks up to 7,319 characters, in every row, every
entry of the (project, status, rank) index and every board read, and a
B-tree entry may not grow past about 2.7 KB once compression stops
helping. Appends now count up within the key's length and extend only
past an all-z key, by a block as long as the key: a million appends
stay within 16 characters, and counted keys interleave with every key
already stored.
The board, the subtask list and the board read sorted ranks with
localeCompare, so a browser whose collation joins a letter pair
(Hungarian zs, Croatian lj, Danish aa, Czech ch) ordered a column
differently from the server and computed drops from the wrong
neighbours; counted ranks contain every pair. One comparator now
orders ranks the way rankBetween and the index do. A long legacy
all-z key is extended by at most 8 digits instead of doubling.
@yannickmonney
yannickmonney merged commit b29a781 into main Oct 9, 2026
@yannickmonney
yannickmonney deleted the fix/task-rank-growth branch October 9, 2026 06:23
tale-review-bot pushed a commit that referenced this pull request Oct 30, 2026
Until #4594 an append took the midpoint towards the alphabet's end, so a
column's keys grew a digit every six appends: a load run's board reached
7,319 characters after 44k appends. #4594 counts appends within a key's
length, so such a column kept handing out keys that long.

Migration 0220, a TypeScript data migration, gives every task of a board
that holds a rank over 64 characters (LONG_RANK_LENGTH) a short rank, in
the order the board stands: by rank in code-unit order across all of its
columns, archived tasks and subtasks, with ties parted by id. The keys
come from the rank module's new spacedRanks(): evenly spaced, all of one
length (44k tasks get 4 digits), none ending in 0 or all z. Each board's
rows are locked before its order is read, the ranks are written 5,000
rows at a time, updated_at_ms is left alone, and each rewritten board
gets one org-wide task hint. A board whose ranks are all at most 64
characters is untouched, and a second run finds nothing to do.

rank.test.ts pins spacedRanks (order, spacing, length, and drops before,
between and after its keys); data-migrations.test.ts pins 0220's decision
table and admits rank.ts as a pure rule; checkTaskShortRanks proves the
migration on real Postgres with a board holding 7,319-character ranks.

Closes #4713
Task: TALE-122
tale-code-bot added a commit that referenced this pull request Oct 30, 2026
Until #4594 an append took the midpoint towards the alphabet's end, so a
column's keys grew a digit every six appends: a load run's board reached
7,319 characters after 44k appends. #4594 counts appends within a key's
length, so such a column kept handing out keys that long.

Migration 0220, a TypeScript data migration, gives every task of a board
that holds a rank over 64 characters (LONG_RANK_LENGTH) a short rank, in
the order the board stands: by rank in code-unit order across all of its
columns, archived tasks and subtasks, with ties parted by id. The keys
come from the rank module's new spacedRanks(): evenly spaced, all of one
length (44k tasks get 4 digits), none ending in 0 or all z. Each board's
rows are locked before its order is read, the ranks are written 5,000
rows at a time, updated_at_ms is left alone, and each rewritten board
gets one org-wide task hint. A board whose ranks are all at most 64
characters is untouched, and a second run finds nothing to do.

rank.test.ts pins spacedRanks (order, spacing, length, and drops before,
between and after its keys); data-migrations.test.ts pins 0220's decision
table and admits rank.ts as a pure rule; checkTaskShortRanks proves the
migration on real Postgres with a board holding 7,319-character ranks.

Closes #4713
Task: TALE-122
tale-code-bot added a commit that referenced this pull request Oct 30, 2026
Until #4594 an append took the midpoint towards the alphabet's end, so a
column's keys grew a digit every six appends: a load run's board reached
7,319 characters after 44k appends. #4594 counts appends within a key's
length, so such a column kept handing out keys that long.

Migration 0220, a TypeScript data migration, gives every task of a board
that holds a rank over 64 characters (LONG_RANK_LENGTH) a short rank, in
the order the board stands: by rank in code-unit order across all of its
columns, archived tasks and subtasks, with ties parted by id. The keys
come from the rank module's new spacedRanks(): evenly spaced, all of one
length (44k tasks get 4 digits), none ending in 0 or all z. Each board's
rows are locked before its order is read, the ranks are written 5,000
rows at a time, updated_at_ms is left alone, and each rewritten board
gets one org-wide task hint. A board whose ranks are all at most 64
characters is untouched, and a second run finds nothing to do.

rank.test.ts pins spacedRanks (order, spacing, length, and drops before,
between and after its keys); data-migrations.test.ts pins 0220's decision
table and admits rank.ts as a pure rule; checkTaskShortRanks proves the
migration on real Postgres with a board holding 7,319-character ranks.

Closes #4713
Task: TALE-122
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant