Skip to content

[BUG] File display_order overflows to float32 MAX, hides all files in workspace #44

@Lucas-Enriquez

Description

@Lucas-Enriquez

Checklist

Description

After many file operations in a workspace (drag-reorder, inserts at end), the workspace becomes
"empty" in the UI: the files panel shows 0 even though the data still exists in SQLite. Creating new
flows/files in that workspace silently fails (clicking "Flow" in the + menu does nothing).

Root cause

files.display_order converges to float32 MAX = 3.4028234663852886e+38.

  • DB schema: display_order REAL (float64) — packages/db/pkg/sqlc/schema/03_files.sql:15
  • Wire spec: order: float32packages/spec/api/file-system.tsp:22

The float32 wire format truncates the float64 DB value. Once display_order approaches float32 MAX
it serializes to +Infinity on the client; the TanStack DB collection then sorts inconsistently and
renders nothing.

The order-generation algorithm seems to use a midpoint between last and MAX_FLOAT when inserting
at the end, which converges to MAX after a handful of inserts.

Expected: the workspace keeps showing files regardless of how many inserts/reorders happen.

Reproduction

  1. Create a workspace with several folders and many files (HTTP requests, flows). My broken
    workspace had ~236 files.
  2. Repeatedly insert/reorder items via drag-and-drop, or insert items "at end" many times.
  3. Close and reopen the app.
  4. The workspace appears in the sidebar but the Files panel shows 0. Right-click → New Flow does
    nothing.

Reproduces consistently once display_order has reached float32 MAX. A freshly created workspace
works fine until the threshold is crossed.

Evidence from my SQLite DB

Affected workspace:

  • MIN display_order: -1.0
  • MAX display_order: 3.4028234663852886e+38 (10 rows pegged exactly at this value)
  • 22 files with display_order >= 2.5e+38

Healthy workspace in the same DB: MAX = 10.0.

Additional context

Workaround

Reset display_order to sequential floats per (workspace_id, parent_id) directly in SQLite:

UPDATE files SET display_order = <seq> WHERE id = <file_id>;
After this, restart the app and all files reappear.


Suggested fix

- Change spec order: float32 → float64 to match the DB type, OR
- Switch to lexorank / string-based fractional indexing.
- Either way, the order-generation algorithm should re-pack values before approaching the type's
MAX, instead of asymptotically converging to it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions