Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
e8e182f
fix(web): identify failed composer attachments
Adamulek123 Oct 31, 2026
76275bd
fix(web): reveal failed attachments in composer
Adamulek123 Oct 31, 2026
ac52ff3
fix(web): reveal failed composer attachments with a brief glow
Adamulek123 Nov 8, 2026
2bee003
fix(web): reveal failed file and video attachments
Adamulek123 Nov 8, 2026
4ec7eda
fix(web): show failure treatment on file and video attachments
Adamulek123 Nov 8, 2026
d53a381
Merge remote-tracking branch 'github/main' into pr-32909
maria-rcks Nov 10, 2026
aca77cd
Merge remote-tracking branch 'origin/main' into fix/composer-attachme…
juliusmarminge Nov 15, 2026
85db113
fix(web): keep the failed-attachment fix, drop new visual treatment
juliusmarminge Nov 15, 2026
a53e51d
Merge remote-tracking branch 'origin/main' into fix/composer-attachme…
juliusmarminge Nov 15, 2026
c33c28a
test(github): give the failing thread-read stub the new truncated field
juliusmarminge Nov 15, 2026
b012a9b
Merge main and repair rejected attachment retries
Adamulek123 Nov 15, 2026
46b93d1
fix(web): retry restored rejected attachments
Adamulek123 Nov 15, 2026
20ddb97
fix(web): add retry to failed inline documents
Adamulek123 Nov 15, 2026
c7a064f
fix(web): delay failed document glow
Adamulek123 Nov 15, 2026
7dbcad1
Merge remote-tracking branch 'origin/main' into fix/composer-attachme…
juliusmarminge Nov 16, 2026
fd78665
fix(web): keep the claim-failure fix, drop the inline retry and glow
juliusmarminge Nov 16, 2026
3465cbf
fix(mobile): a server-rejected upload restores without its ID
juliusmarminge Nov 16, 2026
5ce9e16
fix(mobile): a server-rejected attachment shows as failed in the comp…
juliusmarminge Nov 16, 2026
6b8b338
Merge main into fix/composer-attachment-highlighting
Adamulek123 Nov 17, 2026
ec5f4d6
Merge remote-tracking branch 'origin/main' into fix/composer-attachme…
Adamulek123 Nov 17, 2026
8106c7f
Merge commit 'd085ee5d155064d98a27e4e936f0316b1d92e70e' into fix/comp…
Adamulek123 Nov 17, 2026
fcba6e4
fix(web): highlight rejected composer attachments
Adamulek123 Nov 17, 2026
0e400f7
Merge remote-tracking branch 'origin/main' into fix/composer-attachme…
Adamulek123 Nov 18, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions apps/mobile/src/state/composer-attachment-uploads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,17 @@ export function retryComposerAttachmentUpload(environmentId: EnvironmentId, atta
uploadQueue?.retry(composerAttachmentUploadKey(environmentId, attachmentId));
}

export function markComposerAttachmentUploadFailed(
environmentId: EnvironmentId,
attachmentId: string,
reason: string,
) {
composerAttachmentUploads().markFailed(
composerAttachmentUploadKey(environmentId, attachmentId),
reason,
);
}

type ComposerAttachmentUploadRequest = {
readonly environmentId: EnvironmentId;
readonly attachment: DraftComposerAttachment;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ vi.mock("./session", async () => {
sessionHasScope(appAtomRegistry.get(sessionStateAtom(environmentId)), scope),
};
});

vi.mock("./projects", async () => {
const { Atom } = await import("effect/reactivity");
return { environmentProjects: { projectsAtom: Atom.make([]) } };
Expand Down Expand Up @@ -109,7 +110,10 @@ vi.mock("./git", () => ({ gitEnvironment: { preparePullRequestThread: state.chec
vi.mock("../lib/modelOptions", () => ({ isModelSelectionUnavailable: state.modelUnavailable }));
vi.mock("../lib/uuid", () => ({ uuidv4: () => "uuid", randomHex: () => "abcd" }));
vi.mock("../lib/attachmentUpload", () => ({ prepareTurnAttachments: state.prepare }));
vi.mock("./composer-attachment-uploads", () => ({ uploadComposerAttachmentShared: vi.fn() }));
vi.mock("./composer-attachment-uploads", () => ({
uploadComposerAttachmentShared: vi.fn(),
markComposerAttachmentUploadFailed: vi.fn(),
}));
vi.mock("./thread-outbox", async () => {
const { createThreadOutboxManager } = await import("./thread-outbox-manager");
const { appAtomRegistry } = await import("./atom-registry");
Expand Down
45 changes: 44 additions & 1 deletion apps/mobile/src/state/threadOutboxDelivery.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const harness = vi.hoisted(() => ({
typeof import("./thread-outbox-manager").createThreadOutboxManager
>,
removePersistedFile: vi.fn(async () => undefined),
markAttachmentUploadFailed: vi.fn(),
removeOutboxMessage: vi.fn(async (_message: QueuedThreadMessage) => undefined),
prepareTurnAttachments: vi.fn<typeof import("../lib/attachmentUpload").prepareTurnAttachments>(),
draftFile: (() => {
Expand Down Expand Up @@ -88,7 +89,10 @@ vi.mock("../lib/uuid", () => ({
vi.mock("../lib/attachmentUpload", () => ({
prepareTurnAttachments: harness.prepareTurnAttachments,
}));
vi.mock("./composer-attachment-uploads", () => ({ uploadComposerAttachmentShared: vi.fn() }));
vi.mock("./composer-attachment-uploads", () => ({
uploadComposerAttachmentShared: vi.fn(),
markComposerAttachmentUploadFailed: harness.markAttachmentUploadFailed,
}));

vi.mock("./projects", () => ({ environmentProjects: {} }));

Expand Down Expand Up @@ -236,6 +240,7 @@ afterEach(() => {
appAtomRegistry.set(threadComposerErrorsAtom, {});
harness.draftFile.setWriteError(null);
harness.removePersistedFile.mockClear();
harness.markAttachmentUploadFailed.mockClear();
harness.removeOutboxMessage.mockClear();
harness.prepareTurnAttachments.mockReset();
});
Expand Down Expand Up @@ -955,6 +960,44 @@ describe("thread outbox recovery rollback", () => {
}),
);

it.effect(
"restores a server-rejected upload as failed and without its ID so retry uploads fresh",
() =>
Effect.gen(function* () {
const base = withReusedFileUpload(
queuedMessage({
messageId: "message-claim-rejected",
text: "two reports",
fileUri: "file:///a.pdf",
}),
"pending-kept",
);
const rejected = {
...base.attachments[0]!,
id: "file-rejected",
fileUri: "file:///b.pdf",
uploadedAttachmentId: "pending-rejected",
};
const message = { ...base, attachments: [base.attachments[0]!, rejected] };
yield* Effect.promise(() => harness.manager.enqueue(message));

expect(yield* restoreRejectedQueuedMessage(message, "rejected", "pending-rejected")).toBe(
"restored",
);

const restored = composerDrafts.getComposerDraftSnapshot(
`${message.environmentId}:${message.threadId}`,
).attachments;
expect(restored.map((attachment) => attachment.uploadedAttachmentId)).toEqual([
"pending-kept",
undefined,
]);
expect(harness.markAttachmentUploadFailed.mock.calls).toEqual([
[message.environmentId, "file-rejected", "rejected"],
]);
}),
);

it.effect("leaves no error when the restored text is resent before recovery finishes", () =>
Effect.gen(function* () {
const message = queuedMessage({ messageId: "message-resent", text: "resend me" });
Expand Down
76 changes: 68 additions & 8 deletions apps/mobile/src/state/threadOutboxDelivery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ import {
} from "./pending-thread-creation";
import { environmentProjects } from "./projects";
import { environmentServerConfigsAtom, serverEnvironment } from "./server";
import { uploadComposerAttachmentShared } from "./composer-attachment-uploads";
import {
markComposerAttachmentUploadFailed,
uploadComposerAttachmentShared,
} from "./composer-attachment-uploads";
import { gitEnvironment } from "./git";
import { environmentSession, readEnvironmentScope, sessionHasScope } from "./session";
import {
Expand Down Expand Up @@ -457,12 +460,30 @@ export const recoverEditedCreationAfterDelivery = Effect.fn("ThreadOutbox.recove
},
);

/** A server claim rejected this upload; restore with local bytes so the next send uploads fresh. */
function withoutRejectedUpload(
attachments: QueuedThreadMessage["attachments"],
rejectedAttachmentId: string | undefined,
): QueuedThreadMessage["attachments"] {
if (rejectedAttachmentId === undefined) return attachments;
return attachments.map((attachment) => {
const hasLocalBytes =
attachment.fileUri !== undefined ||
(attachment.type === "image" && attachment.dataUrl !== undefined);
if (attachment.uploadedAttachmentId !== rejectedAttachmentId || !hasLocalBytes) {
return attachment;
}
const { uploadedAttachmentId: _id, uploadEnvironmentId: _environmentId, ...rest } = attachment;
return rest;
});
}

/**
* Hands an undeliverable message back to its draft with the reason. "blocked" means the draft
* cannot take it yet (attachment cap); "deferred" means an editor or newer write owns it.
*/
export const restoreRejectedQueuedMessage = Effect.fn("ThreadOutbox.restoreRejectedMessage")(
function* (queuedMessage: QueuedThreadMessage, message: string) {
function* (queuedMessage: QueuedThreadMessage, message: string, rejectedAttachmentId?: string) {
const draftKey = recoveryDraftKey(queuedMessage);
const threadKey = scopedThreadKey(queuedMessage.environmentId, queuedMessage.threadId);
const editing = () => isEditingQueuedMessage(queuedMessage.messageId);
Expand Down Expand Up @@ -515,7 +536,7 @@ export const restoreRejectedQueuedMessage = Effect.fn("ThreadOutbox.restoreRejec
mergeComposerDraftContent(draftKey, {
text: queuedMessage.text,
context: queuedMessage.context,
attachments: queuedMessage.attachments,
attachments: withoutRejectedUpload(queuedMessage.attachments, rejectedAttachmentId),
}),
).pipe(
Effect.ensuring(
Expand Down Expand Up @@ -558,6 +579,18 @@ export const restoreRejectedQueuedMessage = Effect.fn("ThreadOutbox.restoreRejec
if (!removed) return yield* withdraw(restoredDraft);
// After queue removal, the draft owns content and must never roll back.
rollback = null;
const rejectedAttachment = queuedMessage.attachments.find(
(attachment) =>
rejectedAttachmentId !== undefined &&
attachment.uploadedAttachmentId === rejectedAttachmentId,
);
if (rejectedAttachment) {
markComposerAttachmentUploadFailed(
queuedMessage.environmentId,
rejectedAttachment.id,
message,
);
}
if (queuedMessage.creation) {
clearThreadComposerError(threadKey, queuedMessage.messageId);
recordPendingThreadCreationOutcome({
Expand Down Expand Up @@ -714,7 +747,11 @@ function reportCommandFailure(
queuedMessage: QueuedThreadMessage,
commandResult: AtomCommandResult<unknown, unknown>,
stage: ThreadOutboxCommandStage,
): { readonly action: "retry" | "restore"; readonly message: string } | null {
): {
readonly action: "retry" | "restore";
readonly message: string;
readonly rejectedAttachmentId?: string;
} | null {
if (!AsyncResult.isFailure(commandResult)) {
return null;
}
Expand All @@ -733,6 +770,12 @@ function reportCommandFailure(
return {
action,
message: errorDisplayMessage(error, m) ?? m(msg("The message could not be sent.")),
...(typeof error === "object" &&
error !== null &&
"attachmentId" in error &&
typeof error.attachmentId === "string"
? { rejectedAttachmentId: error.attachmentId }
: {}),
};
}

Expand Down Expand Up @@ -813,8 +856,13 @@ export function createThreadOutboxDelivery(): {
const restoreQueuedMessage = Effect.fn("ThreadOutbox.restoreQueuedMessage")(function* (
queuedMessage: QueuedThreadMessage,
message: string,
rejectedAttachmentId?: string,
) {
const result = yield* restoreRejectedQueuedMessage(queuedMessage, message);
const result = yield* restoreRejectedQueuedMessage(
queuedMessage,
message,
rejectedAttachmentId,
);
if (result === "retry") return yield* retryDelivery;
if (result !== "blocked" || disposed || blockedRecoveries.has(queuedMessage.messageId)) {
return;
Expand Down Expand Up @@ -1024,7 +1072,11 @@ export function createThreadOutboxDelivery(): {
return yield* retryDelivery;
}
if (failure?.action === "restore") {
return yield* restoreQueuedMessage(persistedMessage, failure.message);
return yield* restoreQueuedMessage(
persistedMessage,
failure.message,
failure.rejectedAttachmentId,
);
}
acknowledgedExistingThreadMessageIds.add(persistedMessage.messageId);
const outcome = yield* completeQueuedMessageDelivery(
Expand Down Expand Up @@ -1135,7 +1187,11 @@ export function createThreadOutboxDelivery(): {
const failure = reportCommandFailure(queuedMessage, checkout, "start-turn");
if (failure?.action === "retry") return yield* retryDelivery;
if (failure?.action === "restore")
return yield* restoreQueuedMessage(persistedMessage, failure.message);
return yield* restoreQueuedMessage(
persistedMessage,
failure.message,
failure.rejectedAttachmentId,
);
if (!AsyncResult.isSuccess(checkout)) return yield* retryDelivery;
if (!checkout.value.worktreePath || !checkout.value.isOnPullRequestHead) {
const term = changeRequestTermKind(
Expand Down Expand Up @@ -1198,7 +1254,11 @@ export function createThreadOutboxDelivery(): {
return yield* retryDelivery;
}
if (failure?.action === "restore") {
return yield* restoreQueuedMessage(persistedMessage, failure.message);
return yield* restoreQueuedMessage(
persistedMessage,
failure.message,
failure.rejectedAttachmentId,
);
}
recordPendingThreadCreationOutcome({ kind: "delivered", message: persistedMessage });
const outcome = yield* completeQueuedMessageDelivery(
Expand Down
10 changes: 3 additions & 7 deletions apps/server/src/orchestration-v2/AttachmentClaims.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,18 +149,14 @@ describe("AttachmentClaims", () => {
const mismatched = { ...staged, sizeBytes: 999 };
const config = yield* ServerConfig.ServerConfig;

const result = yield* Effect.exit(
const failure = yield* Effect.flip(
claimPendingAttachments({
threadId: "thread-claims-4",
attachments: [good, mismatched],
}),
);

expect(result._tag).toBe("Failure");
if (result._tag === "Failure") {
const error = result.cause;
expect(String(error)).toContain("stored size does not match");
}
expect(failure.message).toContain("stored size does not match");
expect(failure.attachmentId).toBe(mismatched.id);
const claimedFiles = NodeFS.readdirSync(config.attachmentsDir).filter((entry) =>
entry.startsWith("thread-claims-4-"),
);
Expand Down
6 changes: 6 additions & 0 deletions apps/server/src/orchestration-v2/AttachmentClaims.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export class AttachmentClaimError extends Schema.TaggedError<AttachmentClaimErro
"AttachmentClaimError",
{
message: Schema.String,
attachmentId: Schema.optional(Schema.String),
cause: Schema.optional(Schema.Defect()),
},
) {}
Expand Down Expand Up @@ -99,20 +100,23 @@ export const claimPendingAttachments = Effect.fn("AttachmentClaims.claimPendingA
});
if (!claim.ok) {
return yield* new AttachmentClaimError({
attachmentId: attachment.id,
message: `Attachment '${attachment.name}' cannot be sent: ${claim.reason}.`,
});
}
const info = yield* fileSystem.stat(claim.currentPath).pipe(
Effect.mapError(
(cause) =>
new AttachmentClaimError({
attachmentId: attachment.id,
message: `Attachment '${attachment.name}' cannot be sent: attachment not found.`,
cause,
}),
),
);
if (Number(info.size) !== attachment.sizeBytes) {
return yield* new AttachmentClaimError({
attachmentId: attachment.id,
message: `Attachment '${attachment.name}' cannot be sent: stored size does not match.`,
});
}
Expand All @@ -133,6 +137,7 @@ export const claimPendingAttachments = Effect.fn("AttachmentClaims.claimPendingA
});
if (expectedPath !== claim.finalPath) {
return yield* new AttachmentClaimError({
attachmentId: attachment.id,
message: `Attachment '${attachment.name}' cannot be sent: attachment type does not match the upload.`,
});
}
Expand All @@ -142,6 +147,7 @@ export const claimPendingAttachments = Effect.fn("AttachmentClaims.claimPendingA
Effect.mapError(
(cause) =>
new AttachmentClaimError({
attachmentId: attachment.id,
message: `Failed to claim attachment '${attachment.name}' for this thread.`,
cause,
}),
Expand Down
6 changes: 6 additions & 0 deletions apps/server/src/ws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2030,6 +2030,9 @@ export const layerWsRpc = (
commandType: command.type,
message: detail ?? "Failed to dispatch orchestration V2 command",
...(detail === undefined ? {} : { detail }),
...(cause._tag === "AttachmentClaimError" && cause.attachmentId !== undefined
? { attachmentId: cause.attachmentId }
: {}),
cause,
});
}),
Expand Down Expand Up @@ -2253,6 +2256,9 @@ export const layerWsRpc = (
commandId: input.commandId,
projectId: input.projectId,
message: cause.message,
...(cause.attachmentId !== undefined
? { attachmentId: cause.attachmentId }
: {}),
cause,
}),
ThreadLaunchError: (cause) =>
Expand Down
14 changes: 12 additions & 2 deletions apps/web/src/components/chat/ComposerAttachmentStrip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ export function ComposerAttachmentMediaRow({
<SnapShotAttachmentFrame
key={image.id}
data-chat-composer-expanded-image="true"
data-failed-attachment-id={upload?.status === "failed" ? image.id : undefined}
aria-hidden={snapShotAnimationPending || undefined}
inert={snapShotAnimationPending || undefined}
arrival={snapShotArrival}
Expand All @@ -224,6 +225,7 @@ export function ComposerAttachmentMediaRow({
? SNAP_SHOT_ATTACHMENT_FRAME_CLASS
: "relative h-16 w-16 overflow-hidden rounded-lg border border-border/80",
snapShotAnimationPending && "invisible",
upload?.status === "failed" && "composer-attachment-failure",
)}
>
{!ready || ready.previewUrl ? (
Expand Down Expand Up @@ -372,7 +374,11 @@ export function ComposerAttachmentMediaRow({
return (
<div
key={file.id}
className="relative h-16 w-16 shrink-0 snap-start overflow-hidden rounded-lg border border-border/80 bg-black"
data-failed-attachment-id={upload?.status === "failed" ? file.id : undefined}
className={cn(
"relative h-16 w-16 shrink-0 snap-start overflow-hidden rounded-lg border border-border/80 bg-black",
upload?.status === "failed" && "composer-attachment-failure",
)}
>
<button
type="button"
Expand Down Expand Up @@ -484,7 +490,11 @@ export function ComposerAttachmentFileList({
return (
<div
key={file.id}
className="flex min-w-0 items-center gap-2 py-1 text-sm text-foreground"
data-failed-attachment-id={upload?.status === "failed" ? file.id : undefined}
className={cn(
"flex min-w-0 items-center gap-2 rounded-sm py-1 text-sm text-foreground",
upload?.status === "failed" && "composer-attachment-failure",
)}
>
<PierreEntryIcon pathValue={file.name} kind="file" theme={resolvedTheme} />
<button
Expand Down
Loading
Loading