Repository navigation
fix(platform): serialize saved task attachment changes - #4339
Conversation
Independent exact-head review: REQUEST CHANGESHead: What holds
B1 (blocking): the queue serializes the upload itself, not only drain → read → replace
Fix sketch (tested): keep the queue, but serialize only the drain/read/replace step. // Uploads overlap, so the hook's reservations keep the duplicate, count and
// size gates across batches; only drain + read + replace is serialized.
const onUploadAttachments = async (files: File[]) => {
await uploadFiles(files).catch(onMutationError);
await enqueueAttachmentChange(async () => {
const added = clearAttachments();
if (added.length === 0) return;
const current = await savedAttachments();
await updateTask.mutateAsync({
taskId: task._id,
attachments: stripPreviews([...current, ...added]),
});
});
};
Closure proof I'd accept: Q1–Q3 pass on a new exact head, and the PR's 7 cases stay green there while still failing on main's sources. Non-blocking
Expected conflicts (local
|
| Check | Result |
|---|---|
| The PR's targeted files at this head | 22/22 pass |
| Main's 2 sources swapped in, PR tests plus probe | 5 failed / 20 passed (both PR controls and Q1–Q3 pass on main) |
| The probe at this head | Q1–Q3 fail |
| The probe with the sketch and the save-level test 4 | 25/25 pass |
Scoped oxlint --type-aware on the 4 changed TS files |
exit 0 |
oxfmt --check |
exit 0 |
Scoped tsc --noEmit (the 4 files, ambient types, app/router.tsx) |
exit 0 |
commitlint --from a73fab7af --to 5029cfa9f |
exit 0 |
git diff --check |
clean |
bun run lint:manual |
exit 0 (5 trees, 1459 boxes) |
| CI snapshot at 11:17Z | 50 pass, 28 skipping, 0 failing or pending |
Unrun
- No install, browser, E2E, backend stack, live task or blob write, or full suite.
- Q1–Q3 run in jsdom against synthetic upload, query and write seams, as the PR's tests do.
- Real-browser feedback for queued files and N1 are unobserved.
- N2 and the count/size caps come from reading the source.
- No CI rerun.
Root's rule (08:15Z) applies: B1 overrides ACCEPT until it is independently closed on an exact head, with proof. This review makes no push, merge, CI action or card move, and no decision on the human-captured native review.
Probe: append to the PR test file's harness (everything above its describe) and run with PROBE_LOG=<file> bunx vitest run <probe> --project client --maxWorkers=1
// Review probe (TALE-814, reviewer agent #6): behaviours main has and the
// queued-upload design changes. Not part of the PR.
import { appendFileSync } from 'node:fs';
const log = (line: string) => {
if (process.env.PROBE_LOG) appendFileSync(process.env.PROBE_LOG, `${line}\n`);
};
describe('review probe: overlapping selections keep main behaviour', () => {
it('Q1 rejects the same file re-selected while its upload is in flight', async () => {
const slow = deferred<Response>();
let calls = 0;
vi.stubGlobal(
'fetch',
vi.fn(() => {
calls += 1;
return calls === 1
? slow.promise
: Promise.resolve(Response.json({ storageId: `slow-ref-${calls}` }));
}),
);
const view = openTask();
await view.user.upload(view.input, file('slow'));
await waitFor(() => expect(fetch).toHaveBeenCalledTimes(1));
await view.user.upload(view.input, file('slow'));
await act(async () => {
slow.resolve(Response.json({ storageId: 'slow-ref-1' }));
});
await waitFor(() => expect(seams.update).toHaveBeenCalled());
await new Promise((resolve) => setTimeout(resolve, 300));
const saved = seams.task?.attachments?.map((entry) => entry.fileId);
const dupToast = vi
.mocked(toast)
.mock.calls.some(([arg]) => /duplicate/i.test(String(arg?.title)));
log(`Q1 saved=${JSON.stringify(saved)} uploads=${calls} duplicateToast=${dupToast}`);
expect(saved?.filter((id) => id.startsWith('slow-ref'))).toHaveLength(1);
expect(dupToast).toBe(true);
});
it('Q2 shows an uploading row for a second selection right away', async () => {
const pending = deferred<Response>();
vi.stubGlobal(
'fetch',
vi.fn(() => pending.promise),
);
const view = openTask();
await view.user.upload(view.input, file('slow'));
await waitFor(() => expect(screen.getAllByText('Uploading…')).toHaveLength(1));
await view.user.upload(view.input, file('other'));
await new Promise((resolve) => setTimeout(resolve, 200));
const rows = screen.queryAllByText('Uploading…').length;
log(`Q2 uploadingRows=${rows}`);
expect(rows).toBe(2);
});
it('Q3 sends a removal without waiting for an unrelated upload', async () => {
const slow = deferred<Response>();
vi.stubGlobal(
'fetch',
vi.fn(() => slow.promise),
);
const view = openTask();
await view.user.upload(view.input, file('slow'));
await waitFor(() => expect(fetch).toHaveBeenCalledTimes(1));
await view.user.click(
screen.getByRole('button', { name: 'Remove attachment' }),
);
await new Promise((resolve) => setTimeout(resolve, 200));
const writesBeforeUpload = seams.update.mock.calls.length;
log(`Q3 writesWhileUploadPending=${writesBeforeUpload}`);
expect(writesBeforeUpload).toBe(1);
});
});|
ACCEPT — exact-head B1 re-review Head reviewed: B1 is closed at this head. Q1 (duplicate re-selection produces one attachment and a duplicate toast), Q2 (each overlapping selection gets an Uploading row), and Q3 (removal proceeds without waiting for an unrelated upload) all pass in
The main-source comparison still has the pre-repair upload-in-the-queue serialization, so the #3904 regressions remain reproducible on main's sources. The relocation commit Read-only CI observation: checks were still settling when reviewed; completed checks observed were green (including Build, Lint, Format, Browser, Unit and Playwright), with Type check/UI/Validate images still pending. I did not push, merge, rerun, or change status. |
Changes
Verification
a73fab7afconfirmed the defect remains./opt/node/bin/node.git diff --check, manual-reference gate and commitlint: passed.Closes #3904