Skip to content

fix(site): persist workspace upload drafts - #32221

Merged
jakehwll merged 4 commits into
mainfrom
jakehwll/CODAGT-1172-persist-workspace-upload-drafts
Nov 17, 2026
Merged

jakehwll merged 4 commits into
mainfrom
jakehwll/CODAGT-1172-persist-workspace-upload-drafts

Conversation

@jakehwll

@jakehwll jakehwll commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

🤖 This PR was modified by Coder Agents on behalf of Jake Howell.

Completed but unsent workspace-upload chips disappeared when leaving a chat or when an optimistic workspace rebind rolled back, even though the files remained in the workspace. Persist compose-draft metadata by chat and workspace, restore completed references when returning, and clear them on successful send or explicit removal.

PNGs use the normal image-attachment path, which already persists drafts, so they do not reproduce this issue. To reproduce the original bug, upload a .zip or .tar in an existing chat with a running workspace, wait for completion, do not send the message, then switch chats and return. Check whether the unsent composer chip survives, not whether the file remains in the workspace.

Refs CODAGT-1172 and #27080.

Implementation decisions
  • Store metadata only in browser localStorage. File bytes stay in the workspace; there is no backend change or cross-device synchronization.
  • Enable persistence only for the existing-chat composer, keeping message edits and deferred new-chat uploads separate.
  • Preserve previous scopes for navigation and rebind rollback, cancel unfinished uploads, and ignore stale worker completions.
  • Warn on storage failures without blocking the current draft. Keep previously saved references when they are still current; otherwise attempt to clear stale metadata so removed files do not return.

@jakehwll
jakehwll temporarily deployed to main November 16, 2026 01:51 — with GitHub Actions Inactive
@jakehwll
jakehwll temporarily deployed to main November 16, 2026 01:51 — with GitHub Actions Inactive
@linear-code

linear-code Bot commented Nov 16, 2026

Copy link
Copy Markdown

CODAGT-1172

@jakehwll
jakehwll temporarily deployed to main November 16, 2026 04:34 — with GitHub Actions Inactive
@jakehwll
jakehwll temporarily deployed to main November 16, 2026 04:34 — with GitHub Actions Inactive
Flatten failure handling and replace field-by-field comparisons with the existing equality helper. Compare reference counts so failed removals cannot restore duplicate chips while failed additions preserve saved references.
@jakehwll
jakehwll temporarily deployed to main November 16, 2026 05:47 — with GitHub Actions Inactive
@jakehwll
jakehwll temporarily deployed to main November 17, 2026 00:46 — with GitHub Actions Inactive
@jakehwll
jakehwll temporarily deployed to main November 17, 2026 00:47 — with GitHub Actions Inactive
@jakehwll
jakehwll marked this pull request as ready for review November 17, 2026 00:50
@jakehwll
jakehwll requested a review from a team as a code owner November 17, 2026 00:50
@jakehwll
jakehwll temporarily deployed to main November 17, 2026 00:50 — with GitHub Actions Inactive
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-17T00:52:40.842646Z 06c29c0 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Comment on lines +60 to +145
const workspaceUploadSchema: Yup.ObjectSchema<UploadChatWorkspaceFileResponse> =
Yup.object({
path: Yup.string().required(),
name: Yup.string().required(),
size: Yup.number().min(0).max(Number.MAX_VALUE).required(),
media_type: Yup.string().defined(),
workspace_id: Yup.string().defined(),
}).required();

const readWorkspaceUploadDraft = (
storageKey: string | undefined,
): readonly UploadChatWorkspaceFileResponse[] | undefined => {
if (!storageKey) {
return [];
}
try {
const stored: unknown = JSON.parse(
localStorage.getItem(storageKey) ?? "[]",
);
if (!Array.isArray(stored)) {
return undefined;
}
return stored.filter((value: unknown) =>
workspaceUploadSchema.isValidSync(value, { strict: true }),
);
} catch {
// Unavailable or invalid storage must not prevent composing a message.
return undefined;
}
};

const restoreWorkspaceUploadDraft = (
storageKey: string | undefined,
workspaceId: string | undefined,
): readonly WorkspaceFileUpload[] =>
(readWorkspaceUploadDraft(storageKey) ?? [])
.filter((response) => response.workspace_id === workspaceId)
.map((response) => ({
id: createUploadId(),
file: new File([], response.name, { type: response.media_type }),
status: "uploaded",
response,
}));

const persistWorkspaceUploadDraft = (
storageKey: string | undefined,
uploads: readonly WorkspaceFileUpload[],
) => {
if (!storageKey) {
return;
}
const responses = uploads.flatMap((upload) =>
upload.status === "uploaded" && upload.response ? [upload.response] : [],
);
try {
if (responses.length === 0) {
localStorage.removeItem(storageKey);
} else {
localStorage.setItem(storageKey, JSON.stringify(responses));
}
return;
} catch {
toast.warning(
"Could not save workspace upload changes. Your draft may be outdated when you return to this chat.",
{ id: storageKey },
);
}

// A failed save can leave removed uploads in storage.
const savedResponses = readWorkspaceUploadDraft(storageKey);
if (
savedResponses?.every(
(saved) =>
responses.filter((response) => isEqual(response, saved)).length >=
savedResponses.filter((response) => isEqual(response, saved)).length,
)
) {
return;
}

try {
localStorage.removeItem(storageKey);
} catch {
// The in-memory draft remains usable if storage is unavailable.
}
};

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still pained by our lack of an actual abstraction for this localStorage stuff. I might tackle this myself using a proper slow burn approach instead of trying to migrate everything at once and introduce a 10k LoC PR stack

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Zustand's developer just decided this was dead to him. 🥲 I hate it with a burning passion too, but now I don't know what I want to use.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Damn, I've got some ideas that don't require their projects anyways

@jakehwll
jakehwll merged commit f1c5983 into main Nov 17, 2026
36 of 37 checks passed
@jakehwll
jakehwll deleted the jakehwll/CODAGT-1172-persist-workspace-upload-drafts branch November 17, 2026 09:07
@jakehwll
jakehwll temporarily deployed to main November 17, 2026 09:07 — with GitHub Actions Inactive
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 17, 2026

This branch had an error being deployed

1 failed and 1 inactive deployments
main — 06c29c0d Deployed Nov 17, 2026 by jakehwll via cla #258471
docs-preview — 06c29c0d Deployed Nov 17, 2026 by jakehwll via cleanup #155
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants