Skip to content

[bug] JSON import: a stale preview can authorize committing a different file than the one the user reviewed #72

Closed

Description

@timacek

What happens

The import modal's dry-run preview is not tied to the file that produced it, so the classification
list the user approves can describe a different file than the one Run commits.

src/client/board/ImportModal.tsx:43-63 (onFile):

setParsed(value)
setFileName(file.name)
void controller.importPreview(value).then(p => {
  if (p !== undefined) setPlan(p)
})

There is no request token or cancellation. parsed switches to the newly picked file immediately,
while plan is whatever preview resolves last. The Run button only checks that a plan exists
(:173), and commits parsed (:73):

void controller.importCommit(mode, parsed)

Pick ledger A, then ledger B before A's /import/preview round-trip returns. If B resolves
first and A lands second, the modal shows B's filename with A's create/overwrite/invalid rows,
and Run commits B. In replace mode that is a whole-ledger swap justified by a preview the
reviewer never saw; the host writes a backup first, but the dry-run check — the entire point of the
preview step — is bypassed.

The same missing guard exists on file.text() (line 51): two quickly picked files can also be
parsed out of order and overwrite parsed/fileName.

How to reproduce

  1. Open ⬆ Import and pick a ledger file A (a large file, or a LAN host where the preview takes
    a moment).
  2. Immediately pick ledger file B.
  3. B's preview resolves first, A's resolves last → the stats/lists describe A while the filename
    says B.
  4. Press Run: importCommit receives B's payload.

This was reproduced with a jsdom render: two file picks, deferred importPreview promises resolved
B then A; the modal displayed b.json with A's plan rows and Run called importCommit with B.

Environment

  • dsh-taskboard 0.9.7 / dev @ fb97e7f (originally reproduced on 0.9.6 @ 3054eba)
  • DSH 0.2.1-rc.5, Windows 11, Node 26.13.0

Suggested fix

Capture a monotonic sequence in onFile (const seq = ++seqRef.current) and check it in both
async continuations (file.text() and importPreview), e.g. if (seq !== seqRef.current) return.
That is enough to drop every late response; the reset block at :44-50 already clears plan, so
the UI stays on "previewing" until the current file's preview lands. A regression test with two
deferred previews resolving out of order is cheap.

Dedupe

Nearest issues are #17 (import existing sessions) and #29 (bulk delete); neither covers the import
preview lifecycle. No open PR touches ImportModal.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions