Medlar/docs/PROGRESS.md
astar76 59e921762d S005: dynamic parts and adaptive connections
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 01:18:06 -06:00

12 KiB

Progress

One entry per session, newest last, ≤ 15 lines: done, verified how, not done, later.

S001 — Workspace, store, settings and strings (2026-11-24)

Done: four crates; core has paths, model, store, settings, strings, logging, redact. No egui dependency yet: the first UI plan adds it to crates/app. Verified: nice cargo test -j 2 green (34 tests; kill test run 5 times, 5 kills each), build without warnings, --version prints 0.1.0, a made-up tr! key fails the test.

  • Store (store::Store, share in Arc): open, add_task/save_task/set_state/delete_task/task/tasks, save_parts (waits) / post_parts (journal, doesn't), parts, save_queue/queues/delete_queue, tags, save_host/host. Calls block briefly: use spawn_blocking from async. State and error change only through set_state (model::State::moves). Migration number 1 (store/001.sql); add 002.sql to MIGRATIONS, never edit 001.
  • Secrets: secret columns hold a keyring item name. The store refuses cookie/authorization headers and user:password@ links. A token inside a link's query is stored (it is the link) but never logged.
  • Settings: Settings::load(path) -> (Settings, Option<Damage>), save, limits(). Speed-mode numbers and the own colour are placeholders. Bad single values fall back alone.
  • Strings: add the key to crates/core/lang/en.json, use tr!("key", name = value); plurals are objects chosen by n; run-time keys use strings::text and need their own test. User files: <config>/languages/<code>.json.
  • Logging: logging::init(&paths.log(), level); every line is redacted. Nothing calls it, Paths::create or Store::open from the binary yet: whoever starts the engine does.
  • ErrorKind is empty (S007): add variants and error.<name> texts. Not done: statistics and quota tables (their plans add a migration).

S002 — Test server with faults (2026-11-24)

Done: crates/testserver (hand-made HTTP/1.1 on tokio, 127.0.0.1 only), binary medlar-testserver [--port N] [--tls] [--media] [--proxies]. Verified: nice cargo test -j 2 -p medlar-testserver green (44 tests, ~1 s, one per fault and fixture); clippy clean; zip/tar checked with unzip/bsdtar.

  • API: TestServer::start()/start_tls() (async, port 0), url(path), log()/requests_for(path)/clear_log(), set_faults(path, Faults) (exact, prefix*, or *), clear_faults, open_connections(), build_media() (ffmpeg → /media/), cert_der() for HTTPS clients. Content: expected(seed, start, len).
  • Files: /data/<seed>/<len>[/name] (len takes k m g t; 100g ok). Query: disp=attachment|bare|star|both|inline|evil|dotfile, chunked=1, nolen=1, etag=0, lm=0, weak=1. Also /redirect/<n>?to=&code=, /redirect/loop, /status/<code>, /basic|digest/<u>/<p>/…, /cookie/<tok>/login, /referrer/<needle>/…, /dir/, /site/, /archive.zip|tar, /sum/<algo>/<seed>/<len>, /meta/v4.meta4|v3.metalink|header.bin.
  • Faults (field of Faults, or same name in the query): throttle_conn, throttle_total (bytes/s), latency_ms, stall_after (+stall_ms), cut_after (clean close), reset_after (RST), status (+retry_after, status_count), wrong_length (added to Content-Length), ignore_range, change_after (bytes switch), version_after_requests (new ETag, date, bytes), gzip (header only, body stays plain), expire_secs / expire_requests (+expire_status, default 403), max_conns (open connections per client; over it → 429).
  • Proxies: proxy::Proxy::start_http(auth) / start_socks5(auth); seen() lists kind, target, credentials, allowed; they connect only to loopback or names set with map_host. Not done: BLAKE3 sidecar, HTTP/2, a real gzip body, FTP/SFTP servers (their plans).

S003 — App shell, theme, motion and tools (2026-11-25)

Done: crates/app is a library medlar_app plus the medlar binary (no arguments: window; else the command line). Verified: nice cargo test -j 2 -p medlar -p medlar-core green (19 here; 432 themes for contrast); shots seen in light and dark, hover and press tints change; hidden release run: window drawn, idle 5 s = 0.00 % CPU twice (also after input), click and keys arrive, scheme.json change re-colours it live, 700×500 remembered, 480×360 is the least.

  • Tokens (tokens.rs): space XS–XXL, radius XS–XL, FULL, inner(), text LABEL BODY TITLE HEADLINE DISPLAY, icon S M L XL HERO, size, state (hover, press, drag, disabled), elevation::floating, spring FAST DEFAULT SLOW EFFECT.
  • Colour: app.theme.<role> (theme.rs); faint text is on_variant, outline only reaches 3:1. New settings scheme and contrast; own_color default is #b5622b. Changing app.settings re-themes by itself.
  • Motion: motion::spring(id, target, preset) inside App::frame; it asks for frames by itself. Non-spring motion calls motion::keep_alive() only while something changes. Colours use EFFECT.
  • Text: fonts::{ui, med, semi}(size); digits are tabular. Icons: icons::paint(painter, centre, tokens::icon::M, "name", colour); add one through tools/icons.txt, then python3 tools/gen_assets.py icons (draft, queue don't exist there).
  • Shots: add ("name", |app, ui| app.frame(ui, draw)) to SCENES in tests/shots.rs. Interface tests: tests/shell.rs shows a harness without a window.
  • Icon: at the user's wish an orange disc with the five-pointed star and arrow, not a fruit. Not done: run() logs settings damage but shows no message; the store is not opened.

S004 — HTTP core with resume and crash-safe files (2026-11-24)

Done: core::http (client, probe, names, fetch, download), core::disk (PartialFile), core::part (LivePart, split). Choices: D-017 to D-019. Verified: nice cargo test -j 2 -p medlar-core green (47 unit, 16 http, on tmpfs and btrfs); 50 kills at random moments × 4 runs, SHA-256 equal; clippy clean for the new code.

  • http::download(client, store, id, source, options, stop): start or continue a task in fixed ranges, returns the finished path. It never sets the task's state. S005 replaces its scheduling; start/resume/checkpoint/finish in download.rs are the pieces to keep.
  • http::fetch(link, part, file, body, stop): one part, one connection. stop is a watch of bool; stop it, don't drop it (it writes its 512 KiB buffer first). On resume it reloads 4096 bytes and compares. http::compare checks any finished range (for S008).
  • LivePart: get(), remaining(), set_end(x) (false if it would cut bytes written or on their way): a split is set_end(mid) on the old part, then a new part mid..end.
  • http::probe gives size, proven ranges, validators, safe name, final link, and the live reply when there are no ranges (pass it to fetch, or drop it).
  • disk::PartialFile: create (free name, locked), reopen, reserve, write_at, read_at, sync, finish (never replaces a file). It is Busy for a second process.
  • http::Error has no user text: S007 maps it. Error::Status carries Retry-After for S006. Build Source with cookies and logins from the keyring; they are dropped on another origin. Not done: a Content-Length smaller than the real body, on a server without ranges, can't be seen (HTTP ends the body there). A body without any length over plain HTTP can be cut unseen. The power-cut order is by construction, not tested.

S013 — Controls, dialogs and toasts (2026-11-25)

Done: crates/app/src/ui/{widgets/,field,menu,dialog,toast,gallery}; medlar --gallery shows every control. Verified: nice cargo test -j 2 -p medlar --test widgets green (23: hover, press, keyboard, focus return, popups inside the window); shots of every control seen in light or dark, hovered, and at 480×360; press seen on buttons, group, chips. All take (ui, &Theme, …); the theme is app.theme.clone(). The caller keeps every value.

  • widgets: Button::new(text) / Button::icon(icon, name) .with_icon .kind(Kind) .size(Size) .danger .enabled .busy .toggle(on) .tip .keys .width .show; group(name, [(icon, text)], &mut chosen), segmented(…same…), tabs(name, &[Tab], &mut chosen), split(icon, text, more, open) -> (main, arrow), Fab{icon,text,name,keys}, fab_menu(ctx, t, id, corner, (name, close), &mut open, items), toolbar(ctx, t, id, bottom middle, open, add).
  • Choice::new(label) .enabled .busy .error .mixed then .switch/.checkbox(&mut on) or .radio(on); Chip::new(text).icon .filter(on) .closable .error; Slider::new(name, range, step).show_value(&fn), range(slider, &mut low, &mut high); tip, waiting, spinner, ring, feel, line.
  • field: Field::new(label) .hint .icon .unit .help .error(Option) .busy .password .clear .rows, search(name, &mut text, width), Number{..}, Combo::new(label, &options, width). .error(…) keeps the line below free; always call it on a field that can fail.
  • menu: Item::new(text, action) .icon .keys .checked .danger .enabled, Item::sub, Item::line; menu::below(ui, t, &response, || items), menu::context(…) give back the action. menu::is_open, any_open.
  • dialog: Dialog::new(id, title, main) .body .width(size::DIALOG_*) .enabled .busy, Dialog::confirm(…, danger); .show(ctx, t, open, content) -> Option<Answer> every frame, the caller sets open. sheet(ctx, t, id, title, open, content) -> close?. View shortcuts wait while dialog::any_open or menu::any_open.
  • toast: Toasts<A> .info .error .action .undo, .show(ctx, t, bottom) -> Option<A>. Not done: menus close without a fade; tooltips show on hover only, not on keyboard focus; screen readers untested. Gallery words are not in the catalogue (builders only). Hidden release run of --gallery: 4 pages and a menu by real clicks, idle 5 s = 0.00 % CPU. The debug build opened no window in tools/hidden.sh (nested niri drops the connection, no panic; also without --gallery); the release build does. Cause not found.

S005 — Dynamic parts and adaptive connections (2026-11-25)

Done: core::segment (what a free connection takes), core::adapt (how many), core::host (caps, pace, memory), http::parts (the run), http::monitor. Choices: D-020 to D-022. Verified: nice cargo test -j 2 -p medlar-core green (62 unit, 16 http with 50 kills, 9 parts, the last two 3 more times, under load too); clippy clean for the new code. Numbers (debug build, test timing 0.2 s + 0.6 s): 512 KiB/s per connection, cap 1, 2, 4, 8, 16 → ×1, 2.0, 3.7, 6.9, 12.8 with the ramp counted, settled at the cap; 2 MiB/s in total → 1.99 MiB/s, settled at 2, never over 4. One crawling connection of two (20 kB/s against 2 MiB/s, 6 MiB): 4.5 s and 8 ranges, instead of minutes.

  • http::download(&Shared { client, store, hosts }, id, source, &Options, &Monitor, stop): one Shared per program, one Monitor per task, which outlives runs. Errors of one part stay inside until it was tried tries times and nothing else delivers; a longer Retry-After than max_wait comes out as Error::Status.
  • Caps, live: monitor.set_cap(n), hosts.set_caps(Caps { total, per_host, burst, per_second }), hosts.set_host_cap(host::key(&url), n). Task::max_parts and HostProfile::max_connections are read at the start. S006 maps settings::Limits to them.
  • Events, monitor.subscribe() (broadcast of 1024; on Lagged take a snapshot): PartEvent::{Born{id,start,end}, Split{from,id,at,end}, Stolen{id}, Done{id}, Merged{into,gone}}. Stolen: what is left of a part goes to another connection. Ids are new in each run.
  • monitor.snapshot(): Snapshot { size, parts, connections, wanted, received, speed }, parts in file order as PartView { id, start, end, done, state, speed, fails }, PartState::{Waiting, Connecting, Running, Done}. done is of this moment; the rest of the last tick (250 ms).
  • LivePart: new pos() and received() (bytes from the network, what S006 limits); part::split is gone. Not done: a lone connection that crawls is replaced only when a second one is wanted (tried after each hold, 30 s to 4 min). Servers without ranges still fail at the first error. Not tried on the real line. In an early build the crawling test ran over 60 s three times while all tests shared the CPU; not seen in 64 runs since, half of them under full load.

Later