Skip to content

fix(project): do not read a failed enumeration as an empty project store - #783

Merged
Ishaan Gangwani (ishaan1124) merged 1 commit into
synthetic-sciences:mainfrom
aniruddhaadak80:fix/project-list-error-identity
Sep 29, 2026
Merged

Ishaan Gangwani (ishaan1124) merged 1 commit into
synthetic-sciences:mainfrom
aniruddhaadak80:fix/project-list-error-identity

Conversation

@aniruddhaadak80

Copy link
Copy Markdown
Contributor

What does this PR do, and why?

Project.fromDirectory decides whether a worktree already has a project record.
The lookup swallowed any failure and treated the result as authoritative:

const keys = await Storage.list(["project"]).catch(() => [])

Storage.list was deliberately hardened to not do this — it logs and rethrows,
and test/storage/list-errors.test.ts pins that with the name "a permission
error surfaces instead of masquerading as an empty prefix"
. This one call site
took it back.

With found = [], fromDirectory treats the folder as new:

const found = await records(worktree)
const opaque = found.find((record) => record.id.startsWith("prj_"))
const id = opaque?.id ?? createID()          // ← a brand-new prj_<uuid>

and then writes a second project record for a worktree that already has one,
while adoptLegacy(id, worktree, found) is handed an empty list and adopts
nothing. The pre-existing project/<oldId>.json and every
session/<oldId>/*.json are left attached to an id nothing uses any more. The
user opens their folder and their conversation history is simply not there — and
it only self-heals if they open the same folder in a later process, by which
point sessions written under the orphan id are stranded too.

The fix is to let the hardened error reach the caller. The surrounding
FileLease already covers the write, and a retried fromDirectory is strictly
better than a forked identity:

const keys = await Storage.list(["project"])

Linked issue

Self-identified. Happy to file a report if you would rather track it; my issue
budget this turn went to the two apply_patch defects and the localStorage
copies.

How did you verify it?

One case in backend/cli/test/project/project-registration.test.ts:
a failure to enumerate projects is not read as an empty store. It makes the
["project"] read fail, then asserts Project.fromDirectory rejects, and
that no second project record was written.

On unmodified 3e94875c it resolves instead:

Expected promise that rejects
Received promise that resolved: Promise { <resolved> }

Being straight about the test: it stubs the failing read rather than provoking a
real one. A real failure needs a POSIX chmod on the store directory, which is
why the repo's own list-errors.test.ts case is skipIf(process.platform === "win32" || process.getuid?.() === 0) and does not run on this machine. Stubbing
the read is the only portable way to reach this branch here. The stub is
scoped to the ["project"] prefix and restored in a finally, and
Storage.list's own rethrow is covered by the existing test.

Commands run:

  • bun test --timeout 60000 ./test/project/project-registration.test.ts -t "not read as an empty store"
    → 1 pass
  • bun test --timeout 180000 ./test/project/project-registration.test.ts
    → 8 pass, 1 fail — the failure is the (unnamed) teardown from
    test/preload.ts, which cannot rm its temp data dir on Windows (EBUSY) and
    is present on unmodified main in every run I have done in this repo
  • bun run --cwd backend/cli typecheck → exit 0

The rest of that file matters more than the new case: registration boundaries,
the managed-parent relationship and the "no second record" invariant are all
covered there, and none moved.

One consequence worth naming

fromDirectory can now fail where it previously succeeded, for a user whose
project store is transiently unreadable. That is the intended trade — a visible
error the user can retry, instead of a silent fork that loses history — but it is
a behaviour change and I would rather you hear it from me than from a bug report.

Checklist

  • bun run check is green (format, typecheck, backend + frontend/ui + SDK tests) — blocked on this Windows checkout by the CRLF and symlink artifacts in my other pull requests; backend typecheck is clean and project registration adds no new failure
  • bun run --cwd frontend/workspace build succeeds if I touched frontend/workspace or frontend/ui — not touched
  • ./tooling/repo/generate.ts was run and the tooling/sdk output committed if I changed backend/cli/src/server — not touched
  • CHANGELOG.md has an Unreleased entry if the change is user-visible
  • The matching docs page under frontend/docs/src/content/openscience/ is updated if behavior changed — no doc change needed: project identity is internal
  • Screenshots or a short video are attached for UI changes — not a UI change
  • No version bumps (package.json versions and tags are written by the release workflow)
  • install and frontend/landing/public/install are still byte-identical if I touched either — not touched

@vercel

vercel Bot commented Sep 28, 2026

Copy link
Copy Markdown

ANIRUDDHA ADAK (@aniruddhaadak80) is attempting to deploy a commit to the InkVell Team on Vercel.

A member of the Team first needs to authorize it.

Storage.list rethrows on a permission error precisely so a caller cannot mistake
an unreadable store for an empty one, and records() swallowed it. Opening a
folder whose project record already existed then minted a second prj_ id for the
same worktree and adopted no legacy sessions, stranding the folder's history.
Let the error reach the caller.
@ishaan1124
Ishaan Gangwani (ishaan1124) merged commit bf8fc09 into synthetic-sciences:main Sep 29, 2026
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.

2 participants