Skip to content

Checker: tuple call as scalar argument, return value count; std.os sandbox checks; two flaky tests - #3880

Merged
paul-hammant merged 7 commits into
mainfrom
batch/nov26
Nov 26, 2026
Merged

paul-hammant merged 7 commits into
mainfrom
batch/nov26

Conversation

@paul-hammant

@paul-hammant paul-hammant commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

Commits: two checker holes where a wrong program reached the C compiler (or compiled and returned the wrong value), a sandbox gap in std.os, and flaky tests fixed at the root. Each fix has a regression test that was run against main and failed there before it passed with the fix.

Commits

1a0d7eb checker: refuse a tuple-returning call passed as a scalar argument

  • Wrong: a call that returns several values, written straight into an argument that takes one value, passed ae check and then failed in the C compiler: passing '_tuple_ptr_string' to parameter of incompatible type 'const char *'. reject_tuple_argument caught a name bound to the tuple, but skipped calls.
  • Repro: spec.expect_str(list_get(av, 0)), takes(list.get(xs, 0)), takes(pair()), pair().takes() (UFCS).
  • Fix: a multi-value return is never spread over parameters (f(pair()) for a two-parameter f is already an arity error), so the call form is now E0200 at the argument. The message names the call and says to destructure it first. fn and wildcard parameters are not affected.
  • Test: tests/integration/tuple_argument_reject adds the user-function, module-function and UFCS cases, plus a destructured list.get_string that still runs. On main, aetherc accepted all three cases.

a6a32d7 checker: a multi-value return must match the result's count

  • Wrong: check_return_values accepted a multi-value return whose count differed from the result type, and codegen then used the shape of the first return. return 0 followed by return 41, 1 failed in C. return 0, "" followed by return 41, "", 3 silently dropped the third value (only a C warning about excess initializers). return 0, 0, 0 followed by return 41, 1 filled the missing value with zero. The value-type side of a differently shaped early return was already the narrowing error (A return value that does not fit the written result type is accepted and fails in C #2782); nothing checked the count.
  • Fix: E0200 at the return, e.g. "'pick' returns (int, string) (inferred from its first return), but this return gives 3 values". This covers inferred and written result types. For an optional tuple result (-> (int, int)?) it counts the tuple's values, so test_optional_tuple_return still passes.
  • Test: tests/integration/return_type_check adds five cases: one-then-two, two-then-three, three-then-two, a written (int, string) returning three, and an optional (int, int)? returning three. On main all five were accepted.

a380286 std.os: check os.which candidates and os.getcwd against the sandbox

  • Wrong: os_which checked only env PATH, then called access(2) on every <dir>/<name> without a sandbox check. So code in a sandbox with no file-system grant could find out where any program on PATH was installed. os_getcwd_raw checked nothing.
  • Fix: each candidate is now an fs_read of its path (POSIX and Windows/PATHEXT). A refused candidate is skipped as if absent, the same as fs.exists. os.getcwd needs fs_read on the directory and returns "" when refused, the same as fs.realpath("."). docs/containment-sandbox.md lists both.
  • Behaviour change: sandboxed code that calls os.which now needs fs_read on the program's directory (e.g. grant_fs_read("/usr/bin/*")), not just env PATH.
  • Test: tests/regression/test_os_which_getcwd_sandbox.ae. On main it fails with "os.which found '/bin/sh' with no fs_read grant".

e828732 tests: tcp_deadline_cancel accepts a decoy dial the broken canceller hit

  • The demonstration run (BROKEN_CANCELLER=1) has to show that the race check catches a canceller that closes a descriptor by number. On a loaded host, the broken close can land on a decoy while it is still dialling, so the round fails as "decoy dial: [connect failed]" instead of "a decoy was disturbed". The check did catch it, but the shell test reported that it had not. This happened in a 12-way parallel make test-ae on macOS. The demonstration run now accepts both forms; the plain run is unchanged.

68cd10e tests: external_psk lets openssl s_server pick its own port

  • The s_server cases computed a port from the pid. In a parallel make test-ae on FreeBSD, one case failed: the client reported "connect failed" while s_server had printed ACCEPT and saw no connection. The likely cause is a collision with a port another test held on 127.0.0.1, which s_server's SO_REUSEADDR wildcard bind does not refuse on FreeBSD. The test now passes -accept 0 and reads the kernel's chosen port from the ACCEPT line. Checked on macOS (OpenSSL 4.1) and FreeBSD (3.5).

b1854d9 std.os: getcwd checked under fs_read on Windows too; test frees its sandboxes

  • The Windows os_getcwd_raw is a separate function and had not been given the fs_read check that a380286 added on POSIX, so a sandbox with no fs_read grant was still told the working directory (Windows UCRT64, MSYS2 and Wine). It now checks it too.
  • test_os_which_getcwd_sandbox freed neither of its two grant lists (LSan exit 23; macOS leaks 6 leaks, 192 bytes). It frees both now.
  • Checked: macOS leaks 6 to 0; the Windows build under Wine fails as CI did before the fix and passes after.

02b47ec tests: http_server_slow_clients per-IP round waits for the server to see the close

  • Failing: Windows / GCC (MSYS2) [2/2], intermittently, on main too (runs 45703887868, 45466082014) and on this PR (45825237241): round[per ip ...]: ... after one closed 503 FAILED.
  • Cause: the round closed one of two held connections, slept a fixed 300 ms, and expected a new connection to be served. The server gives the address's slot back in conn_close on a pool worker, after the parking lot's poller sees the FIN and hands the connection over: two thread hand-offs with no promised bound. On the Windows 11 VM under load (probe 8-way beside 16 busy loops) close-to-release took median 47-62 ms, p99 250-282 ms, max 344 and 516 ms. A connection arriving before that is correctly refused, so the server is not wrong; the test's timing was.
  • Fix (test only): wait for the observable condition, bounded at 5 s: the server's on_conn_close hook on the worker path (it runs after the count goes down), the event loop's live connection count on the loop round. The round still fails if the close is never seen.
  • Windows rate: under that load, 4 of 1200 per-IP rounds failed before (0.33%), 0 of 1200 after.

Lane results

  • ae-x64 (Ubuntu 22.04 x86_64, gcc): CC=gcc make ci green: C unit tests 788/788, its .ae sweep 2396 passed / 0 failed / 20 skipped. Then make test-ae: 2397 passed / 0 failed / 19 skipped.
  • ghostbsd (FreeBSD 15.1, native): gmake test 786/786. gmake test-ae: 2381 passed / 1 failed / 34 skipped. The one failure was crypto_tls13_external_psk (the s_server port collision above). It passed when run alone, and with 68cd10e it passed twice more there.
  • macOS (arm64): make test-ae 2360 passed / 0 failed / 56 skipped (all commits except 68cd10e, which only touches that test; passes alone on macOS).
  • make check-docs, make check-changelog and ae fmt are clean. There is one changelog fragment for each of the three fixes.
  • 02b47ec, http_server_slow_clients: win11 (Windows 11 VM, MSYS2 MINGW64) whole test 30/30 rounds and the loaded per-IP loop above; macOS 40/40 rounds; ghostbsd (FreeBSD 15.1) 40/40 rounds, both including the event-loop per-IP round.

🤖 Generated with Claude Code

paul-hammant and others added 7 commits November 26, 2026 07:15
A call that returns several values, written straight into an argument
whose parameter takes one value (`takes(list.get(xs, 0))`,
`spec.expect_str(pair())`, or as a UFCS receiver, `pair().takes()`),
passed the checker and failed in the C compiler: "passing
'_tuple_ptr_string' to parameter of incompatible type 'const char *'".
reject_tuple_argument already refused a NAME bound to the tuple, but
left a call to "the callee's own rules", and nothing else looked.

A multi-value return is never spread over parameters (`f(pair())` for a
two-parameter `f` is an arity error), so the call form is the same
mistake. It is now E0200 at the argument, naming the call and the fix
(destructure it first), for user functions, module functions and
externs alike. A `fn`/wildcard parameter is left alone.

Test: tuple_argument_reject gains the call, module-call and UFCS cases,
and a destructured list.get_string that still runs; the new cases fail
on main (aetherc accepted the program).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
check_return_values let a multi-value `return` through whenever its
count differed from the result type's (`rt->tuple_count !=
ret->child_count`, or a result that is not a tuple at all), and codegen
then built the value in the shape of the first `return`:

    pick(ok: int) -> {
        if ok == 0 { return 0, "" }
        return 41, "", 3          // third value dropped, C warning only
    }

`return 0` followed by `return 41, 1` returned a tuple from an int
function (a C compiler error); `return 0, 0, 0` followed by
`return 41, 1` zero-filled the last value. The value-type side of a
differently shaped early return (an early `return 0, 0, 0` ahead of a
return of 64-bit values) was already the narrowing error (#2782); the
count side was not checked at all.

Now E0200 at the `return`: "'pick' returns (int, string) (inferred from
its first `return`), but this `return` gives 3 values", with a hint to
give every `return` the same number of values or write the result type.
The same for a written result type.

Test: return_type_check gains one-then-two, two-then-three,
three-then-two and a written (int, string) returning three; all four
were accepted on main.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
os_which checked `env PATH` and then access(2)'d each `<dir>/<name>`
on it unchecked, so code in a sandbox with no file-system grant learned
where any program on PATH was installed. os_getcwd_raw checked nothing
and gave the path of a directory the caller may not read. Every other
std call that tells what is at a path is an fs_read (fs.exists,
file_stat, realpath, ...; docs/containment-sandbox.md).

Each candidate os.which tries (POSIX: the name with a slash, `./name`
for an empty PATH entry, `<dir>/name`; Windows: every PATH and PATHEXT
combination) is now an fs_read of that path, a refused one skipped as
if absent. os.getcwd checks fs_read on the directory getcwd(3) gives
and returns "" when refused. The containment doc lists both.

Behaviour change for sandboxed code: os.which needs fs_read on the
directory that holds the program (grant_fs_read("/usr/bin/*")), not
only `env PATH`.

Test: tests/regression/test_os_which_getcwd_sandbox.ae, which on main
fails with "os.which found '/bin/sh' with no fs_read grant".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The demonstration run (BROKEN_CANCELLER=1, a canceller that closes the
connection's descriptor by number) must show the race check catching
it, and grepped only for "a decoy was disturbed". On a loaded host the
broken close lands on a decoy while it is still dialling, the number
already the decoy's, and the round fails as "decoy dial: [connect
failed]" first: the check caught it, and the test reported that it had
not ("the race check did not catch a canceller that closes by number").
Seen in a 12-way parallel `make test-ae` on macOS; it passes alone.

Both forms now count as caught in the demonstration run. The plain run,
where any decoy failure is a real one, is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The s_server cases computed a port from the shell's pid and the case
name and retried on a bind failure. In a parallel `make test-ae` on
FreeBSD one case (-ciphersuites TLS_CHACHA20_POLY1305_SHA256) failed
with the client's "connect failed" while s_server had printed ACCEPT
and saw no connection; alone it passes. A computed port can be one
another test is using: s_server binds the wildcard with SO_REUSEADDR,
which FreeBSD lets coexist with another socket's 127.0.0.1 bind of the
same port, so the client can reach the other listener instead.

s_server now gets `-accept 0`, and the port is read from its
"ACCEPT 0.0.0.0:<port>" line: the kernel's choice, free by
construction. Checked on macOS (OpenSSL 4.1) and FreeBSD (3.5).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…andboxes

The Windows os_getcwd_raw is a function of its own and had not been given
the fs_read check the POSIX one got in this batch, so a sandbox with no
fs_read grant was still told the working directory (Windows/UCRT64,
MSYS2, and Wine: "os.getcwd told 'Z:\...' with no fs_read grant").

test_os_which_getcwd_sandbox never freed its two grant lists; the env-only
one was reported (LSan exit 23, macOS leaks: 6 leaks, 192 bytes).

Checked: macOS leaks 6 -> 0; the Windows build under Wine fails as CI did
before and passes after.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…see the close

The per-IP round holds two connections against a limit of two, closes
the first, slept a fixed 300 ms, and then expected a fourth connection
to be served. It failed now and then on the Windows / GCC (MSYS2) job
("after one closed 503"), on main as well as on PRs.

The server is not wrong. The address's slot is given back in conn_close,
on a worker: the parking lot's poller sees the client's FIN, hands the
connection to a pool worker, the worker reads the end and closes. That
is two thread hand-offs, and the server never promised them within any
time. Measured on the Windows 11 lab VM with the probe run 8 at a time
beside 16 busy loops (a loaded runner), the time from the client's close
to the server's close was median 47-62 ms, p99 250-282 ms, max 344 and
516 ms: past 300 ms now and then, which is exactly the 503 CI saw. A
fourth connection arriving before then is correctly refused.

So the round now waits for the observable condition instead of a sleep:
on a worker-path server, the on_conn_close hook (which runs after the
address's count has gone down); on the proxy event loop, which has no
such hook, its live connection count down to the one still held. The
wait is bounded at 5 s and the round fails if the close is never seen,
so a server that stopped giving slots back still fails it. The note
reports how long the close took to be seen.

Windows 11 VM, SLOW_PROBE_ONLY=perip under that load: before, 4 of
1200 per-IP rounds failed (0.33%); after, 0 of 1200. Unloaded, 0 of 200
either way. The whole test passes on Windows 11, macOS and FreeBSD 15.1
(ghostbsd), the last two including the event-loop round.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@paul-hammant
paul-hammant merged commit 63fbb0f into main Nov 26, 2026
54 checks passed
@paul-hammant
paul-hammant deleted the batch/nov26 branch November 26, 2026 20:39
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