Skip to content

Structured concurrency, and release 0.7.0 - #75

Merged
rmichaelthomas merged 14 commits into
mainfrom
structured-concurrency
Nov 16, 2026
Merged

rmichaelthomas merged 14 commits into
mainfrom
structured-concurrency

Conversation

@rmichaelthomas

Copy link
Copy Markdown
Owner

Builds docs/design-structured-concurrency.md in artifact format 76 (one bump from 75).

What it adds

  • Fan-out is not capped by cores. Worker limit defaults to 64 (raise to 1024 with [runtime] max_parallelism); core_count(); R_PARALLEL_LIMIT says which line to change.
  • try_parallel_map(list, f, Workers(at_once=…, each_ms=…, all_ms=…)): a result per item, with per-item and whole-run deadlines (R_DEADLINE).
  • together: blocks with start, wait, wait_within. Tasks get exactly the parent's grants, budgets are shared, and a task cannot leave its block.
  • Channels (channel, send, receive, close) and first_ready / first_value, which return Ready(index, value) with the value taken in the same step. Ready[T] comes from std:process.
  • Background commands (start_process, process_line, process_write, process_close_input, process_wait): each in its own process group (Unix) or job object (Windows), stopped with everything it started when the block ends, the program ends, or guion is interrupted.
  • Record constructors take named arguments: Box(height=2, width=1); mistakes are named errors.
  • Every timing choice goes on the tape, so replays are deterministic and need no grants.

Also fixed

  • The tape reader could not read any record value (it took the first JSON key as the tag).
  • The python-interop feature had stopped compiling after values moved to shared pointers. It builds again, its tests are updated, and a Python call inside a timed item now ends at the item's deadline.

Checked

  • Full workspace tests: 100 binaries, 1,322 passed, 0 failed. Clippy -D warnings and cargo fmt --check clean; agent reference current; wasm build ok.
  • Windows: one test on a hosted windows-2025 runner (cmd starts ping, the block ends, no ping is left) passes. Ctrl-C on Windows and the rest of the suite were not run there.
  • Speed: release builds of main and this branch measured in the same session with session.py baseline and compare. 26 Guion median ratios between 0.885 and 1.108, most within ±2%; the Python reference runs drifted +1–2% on their own. No clear regression; apps/sqlite-toml read +10.8% on a short benchmark while apps/file-data read −11.5%, which I take to be noise but have not re-run.

Not done / known limits

  • Windows Ctrl-C is untested; a grandchild started in the instant before a command joins its job is not covered.
  • The browser playground reports that these need threads.
  • The self-hosted compiler stays frozen at format 74.
  • python-interop is not built by CI, so it can break again unnoticed.

🤖 Generated with Claude Code

rmichaelthomas and others added 14 commits November 15, 2026 15:19
…re_count(), fix-it R_PARALLEL_LIMIT

parallel_map's worker limit defaults to 64 on every machine and [runtime] max_parallelism
can raise it to 1024; going over names the guion.toml line. std:process gains core_count()
(Process function code 3, artifact format 76). The HTTP client's thread pool follows the
limit up to 64 instead of 8. Also lays the deadline plumbing the next step uses: a policy
deadline that caps every blocking host call (http, process, socket) and stops the VM.

The self-hosted compiler stays frozen at format 74; only its builtin catalog and seed move.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
try_parallel_map(list, f, Workers(at_once, each_ms, all_ms)) returns List[Result[U, TaskError]].
A fault in one item is that item's Err and siblings carry on. An item past each_ms, or running
or unstarted when all_ms passes, is Err with R_DEADLINE; finished items keep their results.
Blocking HTTP, command and socket calls inside an item wait no longer than the time left, so a
hung server cannot hold an item past its deadline. Deadlines use a monotonic timer the program
cannot read, so no clock grant. Timed items run on the interpreter. A recording marks an item
that ran out of time as cut short and a replay makes it R_DEADLINE whatever its speed.
Part of artifact format 76 (HigherOrder kind 11).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
A together: block runs work in the background and ends all of it with the block.
start(f, argument) begins a task on its own thread; wait(task) and wait_within(task, ms)
give Result[T, TaskError], with R_DEADLINE and the task stopped when ms passes. A task not
waited for is stopped when the block ends, and an error that unwinds past a block still
stops its tasks. Tasks have exactly the parent's grants and share its memory and instruction
budgets (the block takes three quarters of what is left and gives back what it did not use).
A task output shows when it is waited for.

Checked at compile time: start outside a block (E_START_OUTSIDE_TOGETHER), return, break,
continue and ? leaving a block (E_TOGETHER_EXIT), and a task returned, printed or stored in
a variable declared outside its block (E_SCOPE_ESCAPE). A recording keeps each task on its
own lane and records each wait_within, so a replay makes the same choices. The browser
playground reports that these need threads. Part of artifact format 76 (tags 211 to 214,
HigherOrder kind 12; the Task type is never written into an artifact).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…rst_ready, first_value

Inside a together: block, let c: Channel[Int] = channel(8) makes a bounded queue. send waits
while it is full, so a fast producer cannot get ahead of a slow consumer by more than the
capacity; receive waits for a value and gives None once the channel is closed and empty;
close closes it, and the block closes every channel it made when it ends. A started function
can take a Channel[T] parameter but nothing can return one (E_SCOPE_ESCAPE).
first_ready(tasks) and first_value(channels), with _within forms, give the position of the
first item that is ready (the earliest in the list when several are). A recording keeps every
send, receive and choice, so a replay makes the same ones whatever the timing (30 replays of
a recorded race in the test). Part of artifact format 76 (tags 215 to 220, type tag 21).

The agent reference is generated from language/spec.md and host-api.md, so the earlier
hand edits to it were being overwritten; the text now lives in those sources.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…e, process_close_input, process_wait

std:process starts a granted command without waiting for it (the same grant, errors and fix-it
text as process_run), reads its output a line at a time, writes to and closes its input, and
waits for it. Each command runs in its own process group, and the whole group is stopped and
reaped when the together: block that started it ends, when the program ends, and when guion is
sent INT, TERM or HUP (a program that polls for signals itself handles them and still stops
its commands when its block ends). Output is bounded per command. A Process cannot be returned
from its block (E_SCOPE_ESCAPE). Recorded sessions replay with no command and no grant.
Part of artifact format 76 (Process function codes 4 to 8).

The design doc is marked built, with notes on where the build differs from it.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…kers(at_once=50, ...)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…e in the same step

A channel value is taken under the channel's lock, so two consumers never get the
same value or lose one. Ready[T] comes from std:process. Tapes can now read records
whatever order their keys come in.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…r block

Compiles for x86_64-pc-windows-gnu; not yet run on Windows.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…lock ends

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…runner

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The python-interop feature had stopped compiling when values moved to shared
pointers and new variants were added. Fixed, tests updated, and a Python call
inside a try_parallel_map item now ends at that item's deadline.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@rmichaelthomas rmichaelthomas changed the title Structured concurrency: together:, channels, background commands, try_parallel_map Structured concurrency, and release 0.7.0 Nov 16, 2026
@rmichaelthomas
rmichaelthomas merged commit 1bc2e92 into main Nov 16, 2026
4 checks passed
@rmichaelthomas
rmichaelthomas deleted the structured-concurrency branch November 16, 2026 02:58
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