Text chat 12: core-uploads (#262) #311
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "textchat-12-core-uploads"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What
fluxer-coreattachments and uploads (spec §6.2 "Uploads", §3.3), inchat/uploads.rsandComposers::send_with_files:AddFiles,CoreEvent::Files(Attach;AttachAndSendsends at once),RemoveAttachment,MoveAttachment(clamped),SetAttachmentSpoiler,EditAttachment(blank name keeps the old one; alt text only for images/videos, trimmed, <= 4096; name <= 512),OpenFileDialog(Attach)->Effect::OpenFileDialog.handleFileUpload/canAttachFilesInChannel:NoPermission(ATTACH_FILES, DMs always allowed), thenTooMany { max }(whole batch), thenTooLarge { max }(whole batch), limits from the instance's resolved limits; the next successful add clearsrefusal.SPOILER_file name arrives as a spoiler shown without the prefix; on send the name getsSPOILER_+ flag 8 (title= filename, asMessageAttachmentUtils.ts:29-38).Effect::Upload(UploadCommand::Start(UploadJobSpec)): multipart, or presigned when discovery saysfeatures.presigned_attachment_uploads(newsession.presigned_uploads); payload ids = tray index; presigned payloads carryfile_size/content_type(the runtime addsupload_filename). The draft is emptied (inline edit kept).Messagesunder the job's nonce (nonce allocated with Messages' own provisional-id rule, so it never collides with a plain send).ProgressupdatesUploadJob { sent, total };Doneor the gateway echo replaces the pending record;Failedmarks job + record failed and keeps the files;RetrySend { nonce }starts the same spec again;CancelUploademitsUploadCommand::Cancel(only while uploading) and puts the draft back (files before any added since; text/reply/sticker unless new ones were written).PasteLongTextturns the draft's text intomessage.txt(FileSource::Text,text/plain, ids with the top bit set so they never meet runtime ids), subject to the same checks.selectors::upload_tray(&App, channel) -> Vec<TrayItem { name, size, kind: FileKind, spoiler, description }>(FileKindfollowsgetFileIcon),selectors::upload_progress(&App, nonce) -> Option<f32>.Tests
crates/fluxer-core/tests/chat_uploads.rs: all 13 named in the plan plusfile_dialog_and_picked_files,file_kinds_follow_the_original_icons,logout_forgets_jobs_and_tray. Written first and seen failing, then passing.FLUXER_SCREENSHOT_TESTS=1 cargo xtask cigreen locally (Linux). No desktop tests in this task.Deviations / for the reviewer
PasteLongTextshould carry the pasted text), #336 (cancel/Donerace).session.rs(presigned_uploadsfrom discovery),chat/state.rs(resolve_limits(session, guilds, channels, channel)so reducers can resolve limits for the target channel),messages.rs(provisional,show_upload, and upload Done/Failed/Cancel/Retry on the pending record),app.rs(hands the started job's message toMessagesafterchat::reduce),chat/mod.rs(uploads reducer gets&mut Composers),selectors/mod.rs(re-exports),tests/chat_ports.rs(the stub test skips the actions this task fills in).UploadJobgainsspecanddraft(for retry and cancel) and losesEq(SendMessageRequestis notEq).size_limit_from_resolved_limits_and_premiumchecks the instance's resolved limit and that a premium rule does NOT apply:UserPrivatehas no traits/premium yet (follow-up #185).PasteLongText { channel_id }carries no text, so it files the whole draft text (both cases). The original files only the pasted part on a long paste; with iced the UI can let the paste land first, then emit it.SendDraftreachessend_with_filesfrom the composer's stubreduce(Text chat 11's function), not from the uploads reducer (review fix,4705987). Text chat 11 (PR #309) replaces that function, so the merge conflicts textually there and itssend(after the inline-edit, slowmode,@everyoneand length checks) becomes the onlySendDraftcaller.CoreEvent::FileswithAttachAndSendstill callssend_with_filesfrom the uploads reducer; with #309 it should go through the composer's send checks too. Merging with #309: content here is the trimmed draft text; it should become Text chat 11's convertedwirecontent (andallowed_mentions), and the two limits helpers (limits_ofthere,resolve_limitshere) should become one. Both use the same 'started this event, drained in app.rs' pattern.DismissUploadRefusal).Closes #262
🤖 Generated with Claude Code
Independent review: Text chat 12 (core-uploads)
I reviewed
git diff 53fbd6f..origin/textchat-12-core-uploads(commit19baf68) without reading the implementer's notes first.Checks
tests/chat_uploads.rs, and each asserts what the plan says. The values match the spec: 25 MiB default, 10 files,SPOILER_with flag 8,attachments[i].id = i, presignedfile_size/content_type, andmessage.txtastext/plain. There are 3 extra tests.size_limit_from_resolved_limits_and_premiumasserts that the premium rule does not apply, becauseUserPrivatehas no traits yet. Task 10 already documents this gap; see minor finding 3.UploadRefusal::{TooLarge{max}, TooMany{max}, NoPermission}is inchat.uploads.refusal.selectors::upload_tray(&App, channel) -> Vec<TrayItem{name,size,kind: FileKind,spoiler,description}>andselectors::upload_progress(&App, &str) -> Option<f32>exist as written.UploadPathcomes fromfeatures.presigned_attachment_uploads, which is in the server'sInstanceController.ts:109. Cancel emitsUploadCommand::Cancel.UploadJoblosesEq; nothing downstream needs it.FileRefs, andFileSource::Textis the sanctioned Task 10 form. Logs carry no paths, URLs or text: the only tracing isdebug!lines that name channel ids. There are no new fixtures; the tests use the existing server-shapedwell_known/ready/message_attachmentsfixtures. Out-of-range indexes, unknown nonces and unknown channels are no-ops; the tests cover them.resolve_limitswith the target channel's guild features. Payloadid= tray index. The presigned fields are left for the runtime, as Task 5 expects.Findings
[blocking] The
SendDraftarm inuploads.rs(on_user) bypasses Text chat 11's send checks once #309 merges. The plan says Task 12 coordinates with Task 11 "by touching only thesend_with_filesfunction it leaves as a stub". This PR also makes the uploads reducer callcomposers.send_with_fileson everyUserAction::SendDraft. Onorigin/textchat-11-core-composer,Composers::sendreturns early in four cases and leaves the files in the draft:@everyone/@hereconfirm is pending (Confirm::Everyone);chat::reducerunscomposer.reduceand thenuploads.reducein the same event. So after the merge, the uploads arm sends the files in every one of those cases. That means an upload during slowmode, a draft sent while the user is editing another message, and an@everyonemessage sent with no confirm and with raw content instead ofto_wirecontent. This sits in uploads.rs, which #309 does not touch, so it will merge without a textual conflict and nobody will notice it.Fix: drop the
SendDraftarm, or gate it on the legacy path, e.g. only whenctx.legacy_send, which #309 introduces. MakeComposers::sendthe only caller ofsend_with_files, and have the tests reach it through theSendDraftpath that remains. At minimum, the PR body and a follow-up issue must say that the integrator has to remove this arm when #309 lands. A note aboutresolve_limits/limits_ofalone is not enough.[minor]
PasteLongTextfiles the whole draft, not just the pasted text. The action carries no text, so the draft text the user already wrote moves intomessage.txtas well. The original converts only the pasted part. No text is lost, because it ends up in the file, but this differs from the original. A follow-up should givePasteLongTextthe pasted text, which is a Task 10 port change.[minor] Before #309 lands, one
SendDraftcan send two messages. Foundation'sMessages::send_draftsends theui.draftstext and the uploads job sends the files. This is transitional; the PR body already notes it.[minor] Premium-aware size limit not applied. The spec says "premium aware" for this rule, so it needs a
follow-upissue linked from this PR if none exists yet: the user's traits are not modelled, so a premium user is refused above the default rule's limit.[minor] Cancel/Done race. If the runtime's
Donearrives afterCancelUploadhas restored the draft, the message exists on the server and the files are back in the tray, so the user may resend them. Ignoring aDonefor a cancelled nonce, or dropping the restored files onDone, would avoid a duplicate. This is low priority.CI:
FLUXER_SCREENSHOT_TESTS=1 cargo xtask ciwas green locally on19baf68("all steps passed"; livekit-interop was skipped, as by default).Verdict: Changes requested. One blocking finding: the
SendDraftarm inuploads.rsbypasses Text chat 11's send checks. Everything else is minor.Review addressed in
4705987(plus a merge of currentorigin/textchat):SendDraftarm is gone fromuploads.rs. The composer's stubreduce(the function Text chat 11 replaces) now callssend_with_filesonSendDraft, so merging #309 conflicts textually there and #309'ssendis the only caller after its checks. Tests still reach it throughSendDraft.AttachAndSendstill calls it from the uploads reducer; noted in the PR body for the #309 merge.PasteLongTextwhole draft: follow-up #335.FLUXER_SCREENSHOT_TESTS=1 cargo xtask cigreen locally on4705987.Independent review: Text chat 12 (core-uploads)
Scope:
git diff 9fcc13d..origin/textchat-12-core-uploads(head2c32af2), read cold.(1) Plan tests. All 13 named tests exist in
crates/fluxer-core/tests/chat_uploads.rs. They assert what the plan asks, using the spec's values: 25 MiB default, a whole batch refused when one file is over the limit, 10 files, count checked before size,SPOILER_prefix plus flag 8,id= tray index inpayload_json, presigned mode fromfeatures.presigned_attachment_uploads, progress 0.25 and 1.0, Done and gateway echo, Failed then Retry with the same spec, Cancel,message.txt/text/plain. There are also 3 extra tests (dialog, file kinds, logout).size_limit_..._premiumchecks that the premium rule does not apply, becauseUserPrivatehas no traits yet. That is deferred to #185 and fine.(2) Interfaces.
UploadRefusal::{TooLarge { max }, TooMany { max }, NoPermission}is inapp.chat.uploads.refusal.selectors::upload_tray(&App, channel) -> Vec<TrayItem { name, size, kind: FileKind, spoiler, description }>andselectors::upload_progress(&App, nonce) -> Option<f32>exist exactly as written.UploadPathcomes from discovery. Cancel emitsUploadCommand::Cancel.UploadJobgainsspec/draftand losesEq. No consumer exists yet, so this breaks nothing.(3) Invariants. fluxer-core gains no dependency. It holds only
FileRefs, andFileSource::Textis the sanctioned port shape. No bytes, upload URLs or paths are in logs: thetracing::debug!calls print only channel ids. No new fixture (the tests reusemessage_attachments.json). Server-provided data cannot cause a panic: indices are bounds-checked, moves are clamped, progress is clamped, and an unknown nonce or channel is ignored. The presigned payload carriesfile_size/content_type, and the platform falls back toapplication/octet-stream, so it is never empty (the server'screateStringType(1,255)would reject an empty string).(4) Review Focus 4. In the payload,
attachments[i].id = ifollows the order offiles[n]. The presigned path is chosen byfeatures.presigned_attachment_uploads. Limits come from the instance's resolved limits viaresolve_limitsfor the target channel's guild. OK for the core side.Findings
SendDraftis handled twice:Messages::send_draft(text fromui.drafts) andComposers::send_with_files(files fromchat.composer). With text inui.draftsand files in the tray, the user gets two messages: the text alone, then the files with empty content. Nothing is lost, there is no UI path yet, and #309 replaces the stub. Recording it so the #309 merge removes the Foundation path for this case.FilePurpose::AttachAndSendcallssend_with_filesdirectly and skips Text chat 11's send checks (slowmode, inline edit,@everyoneconfirm). The PR body already notes this. Fold it into the #309 merge, together with mergingresolve_limitsandlimits_of.uploads.refusal. Two identical refusals in a row (e.g. twoNoPermissiondrops) leave the value unchanged, so a UI that opens the modal when the value changes cannot see the second one. Text chat 26 will wantDismissUploadRefusal. Already noted in the PR body. Suggest filing it as a follow-up linked here.ChannelDeleteand logout drop jobs that are still uploading without emittingUploadCommand::Cancel, so the runtime may finish a transfer nobody tracks. Logout probably tears the runtime down anyway. The runtime side (Text chat 21) should cancel on channel delete, or core should emit the cancel.No blocking findings.
(5) CI.
FLUXER_SCREENSHOT_TESTS=1 cargo xtask ciin a fresh review worktree at2c32af2: green (all steps passed, exit 0; livekit-interop skipped as usual).Verdict: approve (0 blocking, 4 minor; the minor items belong to the #309 merge and Text chat 21/26).
Independent review, Task 12 (core-uploads), reviewed after merge (PR already merged into textchat as
eaafba9). Diff reviewed: 79af1e1...origin/textchat-12-core-uploads (fluxer-core only; the two-dot diff also shows textchat commits the branch predates, which are not this task).Findings:
Verdict: APPROVED (no blocking findings, local CI green).