Skip to content

Ariadne: file-pick and http-upload, a file the user picks sent in chunks that resume - #1190

Merged
transfix merged 13 commits into
masterfrom
feat/ariadne-file-pick-upload
Nov 14, 2026
Merged

transfix merged 13 commits into
masterfrom
feat/ariadne-file-pick-upload

Conversation

@transfix

@transfix transfix commented Nov 12, 2026 •

Copy link
Copy Markdown
Owner

A document can attach a file now. This is nicotina's roadmap item L18: Attach in the compose view, built on two generic verbs, with no host of its own. Docs are in docs/ARIADNE.md §10.8.

(file-pick [OPTS])

An async verb: the program parks until the user picks or cancels.

  • It returns a list of {handle name size type}, empty on cancel.
  • A handle ("file:N") names a FileSource the app keeps (app.slot<PickedFiles>(); no process-wide state). The program never holds the file's bytes or its path, so a document can send only what the user chose.
  • (file-info H) and (file-forget H) go with it.
  • Options: accept (.ext, type/sub, type/*), multiple, title, dir.

Who asks the user:

host picker
arigl (native) Backend::pick_files: SDL3's SDL_ShowOpenFileDialog, the system's dialog. SDL's answer is handed over at the next frame
any browser build (arigl-web, ari.html) the page's <input type=file>. The File objects stay on the page, and reads slice them
ari's FTXUI and tvision, a GL window without SDL, a mock an Open file window the Runtime draws with the backend's own widgets: the folder, a name field (type a name or a path, then Enter), the listing filtered by accept, Open and Cancel. tvision shows it as one of its windows. Each opening is a new window id, so a backend places it afresh over the document

(http-upload URL FILE [OPTS])

It sends a picked file with the http verbs' rules. prepare/complete are reused, so it gets the policy, auth: and credential values in headers, the renewal after a 401, and an echo blanked.

  • as: multipart (the default): one request of multipart/form-data, with field, filename, content_type and the other parts in form.
  • as: body: the file as it is, e.g. a PUT.
  • as: chunks:
    • each chunk is a PATCH carrying Upload-Offset (offset_header), optionally with Content-Range;
    • the next chunk starts at the offset the server says it has (its header, or a JSON offset), after a 2xx or a 409;
    • a dropped connection, a 408, 425 or 429, or a 5xx is retried with a back-off (retries), asking status_url how far the server got;
    • offset resumes a failed upload.
  • progress names a state path that the sent fraction is written to, for a progress: bar.
  • The reply is http-request's dict plus done, offset and size.

Threading:

  • Native: a kernel on the background pool.
  • Single-threaded browser: each read of the page's File and each request is started, never waited on (StartedRequest now hands its outcome to a caller), so frames go on. A killed program aborts the request in flight.
  • Threaded browser (wasm-mt): the pool's reads of the page's File are proxied to the main thread.

txwtf's own protocol, read from its SPA:

  • POST /social/files (multipart).
  • The resumable flow: POST /social/files/resumable, then PATCH chunks with Upload-Offset (409 resync), then .../complete.

Both are document-level http-requests around this verb. The same verb serves tus and the like.

Also

  • FTXUI's radio no longer prints an ImGui-style ##id caption.
  • The arigl-web job's path filter includes files.h/files.cpp.

Tests

  • ariadne_files_test (new, 15 cases):
    • picker: the host's own picker; one picker at a time; the composed window over a mock (listing, accept, refusals, Cancel, the close box), in a real FTXUI terminal driven by keys (opened twice), and in tvision's hosted layout;
    • files: a file that changed size after it was picked is not read;
    • uploads: multipart byte for byte; a body; chunks resuming through a 409, a 503 and a lost reply (with status_url); a failed upload resumed from its offset; only a picked file and only an allowed origin; the credential in each chunk and never in state; the started path keeping frames going, a torn-down document aborting.
  • ari_run_file_pick_upload_{ftxui,tvision} (tmux, Linux): ari run presses Attach, picks a file in the Open file window and sends it in 1 KiB chunks to a probe server, whose sha256 must match.
  • arigl_web_smoke.mjs: two new cases. On arigl-web and on ari's page, a File handed to the page's input is picked, and it reaches the page's origin in chunks, every byte.

Run locally on Windows:

  • ariadne_files_test 15/15;
  • the full ariadne_runtime_test 262/262, ariadne_ftxui_test 91/91, ariadne_host_test 57/57;
  • clang-format clean;
  • files.cpp, file_picker.cpp, net_intrinsics.cpp and ariadne.cpp compile under Emscripten, single-threaded and -pthread;
  • the browser: a lean single-threaded arigl-web built here, in headless Chrome. arigl_web_smoke.mjs passed all six arigl-web cases. In the new one, the page's input got a File, and the upload went out in five PATCH chunks at offsets 0…4096, the server holding all 5000 bytes. ari's page wasn't in that build, so its case is CI's.

nicotina's Attach (cy-pca/nicotina#26) ran end to end against its stub with this build: a small file as multipart and a 9 MiB one in resumable chunks, then the post, with the server's sha256 matching both files. tvision isn't buildable here, so its tmux run is CI's.

Base: master a5fbd47. #925 is not merged yet. This touches net_intrinsics.cpp away from its hunks (the upload code goes after uri_fetch_work, and its registration is a provider of its own), and a trial merge with #925's branch is clean.

…nks that resume

A document can attach a file now (nicotina's roadmap L18, the compose view's Attach).
(file-pick [OPTS]) asks the user and parks the program until they pick or cancel. It returns
{handle name size type} per file. The handle, "file:N", names a FileSource the app keeps
(app.slot<PickedFiles>(), no process-wide state). The program never holds the file's bytes or its
path, so a document sends only what the user chose. (file-info H) and (file-forget H) go with it.

Who asks:
- the backend's own picker: Backend::pick_files, arigl's being SDL3's system file dialog;
- in a browser build, the page's <input type=file> (files.cpp, its File objects kept on the
  page);
- anywhere else, an "Open file" window the Runtime draws with the backend's own widgets: the
  folder's listing, a name field, Open and Cancel. That covers ari's FTXUI and tvision (a hosted
  window there), a GL window without SDL, and a test's mock. Each opening is a new window id, so
  a backend places it afresh over the document.

(http-upload URL FILE [OPTS]) sends a picked file with the http verbs' rules (prepare/complete:
the policy, auth: and credential values, a renewal after a 401):
- as multipart (default), as a raw body, or in chunks;
- chunks carry Upload-Offset (or Content-Range), go on from the server's offset after a 2xx or a
  409, and retry a dropped one or a 5xx with a back-off, asking status_url how far it got;
- `offset` resumes a failed upload;
- `progress` names a state path the fraction sent goes to;
- the reply adds done, offset and size.

Natively the upload is a kernel on the background pool. In a browser build without threads each
read and request is started (StartedRequest now hands its outcome to a caller), so frames go on.
In a threaded browser build the pool's reads of the page's File are proxied to the main thread.

Also:
- FTXUI's radio no longer shows an ImGui-style "##id" caption.
- ariadne_files_test covers the picker over a mock, a real FTXUI terminal and tvision's hosted
  layout (twice, the second opening too), and uploads blocking and started, with a 409, a 503,
  a lost reply, the policy and a credential.
- ari_run_file_pick_upload_{ftxui,tvision} pick and send a file in tmux.
- arigl_web_smoke picks (a File handed to the page's input) and uploads on both pages.
- docs/ARIADNE.md §10.8.
…d document's guard set in init

The page's globals may share a name with what the test injects, so the stub runs in an IIFE.
An unset state key reads nil, not "", so upload.ari's first tick never started: init sets
up.started. (str #t) prints #t, which the check now takes. Run locally against a lean
single-threaded arigl-web in headless Chrome: all six cases pass, the upload in five chunks.
…s Enter on its own

ari_run_file_pick_upload_tvision failed on package-linux: the name typed into the Open file
window stayed there, and Enter never picked it. tvision reads keys that come in a burst (three
or more in one read, its minPasteEventCount) as a paste. A paste's Enter reaches the view as the
text "\n", not as kbEnter. tmux sent "photo.bin" and Enter at once, so the field took a line
break, and the window never got its Enter.

- input_text, and message_input with multiline: false, now take typed text without its line
  breaks, as a browser's <input> does. A pasted path or line is left whole and on one line.
  A multi-line message field still takes them.
- file_pick_upload_test.sh waits 0.3 s before Enter, as nicotina's type_text does, so Enter
  comes as a key a person presses.
- ariadne_ftxui_test: a one-line message field and a text field each take "...\n" without the
  line break.
transfix added a commit to cy-pca/nicotina that referenced this pull request Nov 13, 2026
…b app uploads them (#26)

The compose view gets Attach (ROADMAP L18), where the host can pick and upload a file:
file-pick and http-upload, transfix/libcvc#1190. The picked files are listed, each with a
Remove. Post uploads each one first, with a progress bar:
- one of 8 MiB or less as a multipart POST /social/files;
- a bigger one by txwtf's resumable upload: POST /social/files/resumable, a PATCH per chunk at
  its Upload-Offset (the host resyncs on a 409 and retries a dropped chunk, asking GET .../{id}
  how far it got), then POST .../complete.
Then it posts with attachment_ids, with or without text.

The document holds handles only. The host reads and sends the files, so their bytes never pass
through the document's state. Who asks the user: arigl's system dialog, a browser page's
picker, or in ari (FTXUI, tvision) an Open file window in the terminal. After Attach or Remove,
the focus is back in the text, as the reply box takes it. On a host without the verbs (all three
are optional in requires:), the view says a post is text only.

The stub learns POST /social/files, the resumable endpoints (409 and Upload-Offset on a
mismatch), attachment_ids, serving uploads back, and a log line per file with its sha256. In
run.sh, ari snapshot checks Attach (or "Text only") by host. In tmux (FTXUI and tvision), a post
gets a picture and a 9 MiB file through the Open file window, and the stub must get both whole.
local.sh posts a picture to a real txwtf. Both skip on a host without file-pick.
package-linux / libcvc-release-grpc failed only in tools/singleton_scan, on
cvc::ocean::sea_surface::source's thread_local. The run tested a merge with master b745ea6,
from before #1181 (29ff406) took that thread_local out, and a rerun would test the same
merge. Master since then: #1156, #1153, #1166, #1181, #1165. No conflicts.
…w shows it

recipe / macos-latest / Debug failed TheOpenFileWindowTakesTheKeysInAnFtxuiTerminal. macOS's
temp folder (/private/var/folders/.../T/cvcpkg-libcvc-.../) is wider than the 90-column
window, whose frame cuts the Folder: line, so the whole path was never on the screen. The test
now checks that what the window shows is the path's start; the listing (sub/, notes.txt)
already says which folder it is. Checked here with TMP set to a 200-character folder.
The one conflict was arigl_web_smoke.mjs. Both sides are kept:
- the /apps/up endpoint, with #1200's ISOLATION headers on its replies as on every response;
- the settle probe reads out and isolated/sab;
- each case runs its before/inject and #1200's isolation check.
The headless-Chrome smoke passes 6/6 here, the picked-file upload included.
Master since then: #1179, #1174, #1196, #1198, #1178, #1157, #1172, #1200.
@transfix
transfix enabled auto-merge (squash) November 14, 2026 06:18
…k-upload

Conflict in src/cvc/CMakeLists.txt, both kept: Ariadne's source list has this branch's
files.cpp and file_picker.cpp and master's rich_text.cpp.
@transfix
transfix disabled auto-merge November 14, 2026 06:27
@transfix
transfix enabled auto-merge (squash) November 14, 2026 06:27
…le-pick-upload

Conflicts, each side kept:
- ImGuiBackend.h: master's set_clipboard on the document's app, then this branch's pick_files
  and begin_frame.
- net_intrinsics.cpp: master's net verbs on the app with its OpenUrlLimit, then this branch's
  http-upload provider.

The upload follows #1203: perform() and http_starts_async() take the app, and the started
upload's StartedRequest gets the app it starts on (its go() calls cvc::net::start(*app, ...)).

Master's ariadne_runtime_test doesn't build: #1180's three rich-text cases call load_string
with one argument, and #1203 made it take the app. They pass their test's app now.
The upload tests' guard turns off its test's app's network and drops that app's fake transport;
each test installs its transport on its own app.
@transfix
transfix disabled auto-merge November 14, 2026 08:22
@transfix
transfix enabled auto-merge (squash) November 14, 2026 08:22
cmd_trace (#1168) still had the old command signature and called cvc_app(), which #1203
removed, so cvc-cli did not build on master. It now takes the app like the other commands
and replays the trace in it. The same change as #1225's, so either can land first.
@transfix
transfix disabled auto-merge November 14, 2026 10:42
@transfix
transfix enabled auto-merge (squash) November 14, 2026 10:42
@transfix
transfix disabled auto-merge November 14, 2026 14:33
@transfix
transfix enabled auto-merge (squash) November 14, 2026 14:33
Two conflicts, both resolved by keeping both sides: src/cvc/CMakeLists.txt keeps chart_emit.cpp
next to files.cpp and file_picker.cpp, and ariadne.cpp includes both chart_emit.h and
file_picker.h.

#1169's tests still called load_string without an app, as before #1203, so master's
ariadne_loader_test and ariadne_chart_test do not build. ChartWidget now uses the file's
fresh_load, and FromADocument loads into the app it renders with.
@transfix
transfix disabled auto-merge November 14, 2026 14:55
@transfix
transfix enabled auto-merge (squash) November 14, 2026 14:55
@transfix
transfix merged commit f8863fd into master Nov 14, 2026
49 of 50 checks passed
@transfix
transfix deleted the feat/ariadne-file-pick-upload branch November 14, 2026 18:49
transfix added a commit that referenced this pull request Nov 14, 2026
CI at 9d002d1 built it on master as of 09:28, after #1197 added
ariadne_wasm_browser_test.cpp with register_script_engine calls that
predate #1203 (all three package-linux lanes and wasm-guests failed to
compile it). Master fixed that in #1229, and the load_string calls
#1169 left in the loader and chart tests in #1190. This merge takes
master as it is now, so CI builds on those fixes. No conflicts.

Master's new natives (#1190's file-pick and http-upload, #1195's
py_console, #1169's chart) build against this branch's call_args
context as they are.

Checked on Windows (MSVC Release): full build; the Ariadne, net, HTTP,
state_exec, groups, slices, async-call, cycle-registry and multi-app
ctests, 1336/1336. ariadne_wasm_browser_test is not built here (it needs
wasmtime or Emscripten); master's CI builds it.
transfix added a commit that referenced this pull request Nov 14, 2026
…#1222-#1225, #1229)

Master's #1190 (file-pick and http-upload) was written for a single async host; this branch runs
an isolated document's programs on its own group's host, on a pool worker in an `any` group.

- net_intrinsics.cpp: StartedRequest takes master's deliver()/on_outcome, settling through the
  host's finisher. http-upload is its own provider, `any` as the requests are: it parks on the
  calling program's host (ictx.host), takes its progress path from ictx.root_path (no tree walk
  on a worker), and a started upload (a browser page) keeps the host's finisher, not the host.
- ariadne.cpp: file-pick, file-info and file-forget bind into the program's env as they are, in
  every group (install_backend_verbs), not through the backend verbs' host_proxied wrapper, which
  cannot park an async verb. file-pick parks on the program's own host, claims the Runtime's
  picker hub under its lock where it is called, and opens the picker on the host thread
  (exec_pool::run_on_host; inline when called there). Its answer goes through the host's
  finisher, as the host may be gone by then.
- ci.yml: the sanitizer list keeps this branch's tests and master's point_classes_test.
- STATE_EXEC_THREADED.md: rows for http-upload, the file verbs, and the contours and
  point-classes providers. The last two are registered without a kind, so they are host_only, and
  an isolated document in an app that installs them goes to a host-affinity group.
- New test: AriadneIsolatedDocs.FilePickOpensItsPickerOnTheFramesThread.
transfix added a commit that referenced this pull request Nov 16, 2026
…ialog's title and folder (#1274)

Three gaps in #1190's file picker, found by trying it by hand on Windows and in Chrome.

A browser page's picks and reads polled a timer until the page answered. A hidden tab runs
timers about once a second, so an upload in a background tab crawled (70,000 B in 1 KiB chunks
took 35 s). Now the page calls back (cvc_files_settled, an EMSCRIPTEN_KEEPALIVE export, as
browser_runtime.cpp does) from the browser's own events: the input's change/cancel and the
slice's promise. The same upload hidden takes 0.8 s, 1 MiB 12.2 s. A read settles exactly once,
even if the copy into the heap throws (before, that hung). A wasm-mt pool thread's read still
waits as before.

arigl's system dialog now goes through SDL_ShowFileDialogWithProperties, so file-pick's title
reaches it; without one it keeps the system's own. dir gets a trailing separator: SDL took a
folder without one as a file, and Windows opened its parent with the folder's name typed in.

docs/ARIADNE.md section 10.8 says what title and dir do in each picker. With no dir, the system
dialog starts where the system chooses (usually the folder last used).

Checked by hand: arigl's dialog on Windows (title, no title, dir with the filter, a 70,000 B
pick sent byte-exact, cancel) and Chrome 157 (a trusted click opens the dialog, pick, cancel,
the hidden-tab timings). arigl_web_smoke.mjs 6/6, ariadne_files_test 15/15.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant