Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -210,3 +210,29 @@ jobs:
run: python -m pip install maturin==1.14.1
- name: Build, install, smoke, and test wheel
run: bash scripts/test-python-wheel.sh

python-free-threaded:
# Plan 326: a separate job so a free-threaded failure is unambiguous and
# never masks (or is masked by) the GIL wheel lane.
name: python-free-threaded
runs-on: ubuntu-latest
timeout-minutes: 30
env:
PYTHONNOUSERSITE: "1"
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
- uses: dtolnay/rust-toolchain@fa04a1451ff1842e2626ccb99004d0195b455a88 # master
with:
toolchain: stable
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
with:
python-version: "3.14t"
- uses: Swatinem/rust-cache@23869a5bd66c73db3c0ac40331f3206eb23791dc # v2.9.1
- name: Release metadata sync (fail cheaply before wheel build)
run: python3 scripts/check-python-release-metadata.py
- name: Install Maturin
run: python -m pip install maturin==1.14.1
- name: Free-threaded compile check
run: PYTHON=python3.14t bash scripts/check-python-free-threaded-compile.sh
- name: Build, install, smoke, and test free-threaded wheel
run: PYTHON=python3.14t bash scripts/test-python-wheel.sh
23 changes: 20 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ jobs:
platforms: ${{ matrix.qemu_platform }}
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
with:
python-version: "3.11"
# Plan 326: the matrix owns the interpreter for each ABI family
# (3.11 for cp311, 3.14t for the free-threaded targets).
python-version: ${{ matrix.setup_python }}
- name: Build wheel
uses: PyO3/maturin-action@e83996d129638aa358a18fbd1dfb82f0b0fb5d3b # v1
with:
Expand All @@ -114,7 +116,10 @@ jobs:
manylinux: ${{ matrix.manylinux }}
# `compatibility` carries the maturin `--compatibility` PyPI policy
# separately (pypi for all release targets).
args: "--profile dist --locked --interpreter python3.11 --compatibility ${{ matrix.compatibility }} --out dist"
# Plan 326: the interpreter comes from the matrix authority, never
# a hard-coded python3.11. Linux free-threaded targets use the pypa
# image path; native runners use python3.14t.
args: "--profile dist --locked --interpreter ${{ matrix.interpreter }} --compatibility ${{ matrix.compatibility }} --out dist"
working-directory: crates/eggserve-python
- name: Verify wheel composition
shell: bash
Expand All @@ -133,6 +138,15 @@ jobs:
${{ matrix.venv_python }} -m eggserve --help >/dev/null
${{ matrix.venv_python }} "$GITHUB_WORKSPACE/scripts/release_smoke.py"
${{ matrix.venv_python }} "$GITHUB_WORKSPACE/scripts/abi_smoke.py"
- name: Free-threaded import stays GIL-free
# Plan 326: the installed 3.14t wheel must leave the GIL disabled.
# -W error::RuntimeWarning turns PyO3's re-enable warning into a
# failure instead of a silent GIL fallback.
if: matrix.abi_family == 'cp314t'
shell: bash
run: |
${{ matrix.venv_python }} -X gil=0 -W error::RuntimeWarning -c \
"import sys, eggserve._native; assert sys._is_gil_enabled() is False"
- name: Smoke test wheel (QEMU)
# Plan 268 Track D: matching ARM userspace via QEMU. Alpine/musl
# images are minimal and may not contain bash, so invoke `sh -c`.
Expand Down Expand Up @@ -161,6 +175,8 @@ jobs:
# Plan 264 Track B: build-once, test-many. The exact Linux x86_64
# cp311-abi3 artifact from the build matrix is installed with
# binary-only resolution on every supported CPython minor.
# Plan 326: this lane stays GIL-only; the free-threaded family has its own
# install/import assertion in the build job and never enters this proof.
# Plan 268 Track F: until final CPython 3.15 is available through the
# pinned setup-python action, 3.15 lanes resolve 3.15 RC builds via
# allow-prereleases. Remove once final 3.15 resolves without it, and
Expand Down Expand Up @@ -473,8 +489,9 @@ jobs:
os: ubuntu-latest
mode: qemu-musl-armv7
python-version: "3.11"
# Plan 327: macos-14 no longer provisions; match the wheel matrix.
- name: "macOS arm64"
os: macos-14
os: macos-latest
mode: native
python-version: "3.11"
- name: "Windows x86_64"
Expand Down
2 changes: 1 addition & 1 deletion .opencode/skills/eggserve-dev/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ requirements and bans
- **Python server façade** — `eggserve.server` is the supported six-class API, including rustls-backed `HTTPSServer` and `ThreadingHTTPSServer` with HTTP/1.1 ALPN only. The exact fast-path eligibility and intentional incompatibility contract is maintained in `docs/python-http-server-compatibility.md`. Stock static handlers also support `default_content_type` and ordered safe `extra_response_headers`; those headers are limited to final 200 responses. Handler `protocol_version` must remain HTTP/1.1. Subprocess helpers are canonically owned by `eggserve.subprocess` (`eggserve.server` keeps compatibility re-exports without expanding `__all__`; top-level `serve_directory` re-exports the subprocess implementation).
- **Python lowlevel substrate (Plan 166)** — `eggserve.lowlevel` exposes handler-only `Server(config, handler)` (no static root, same native runtime, no second accept loop), frozen `RuntimeConfig` (Plan 164 controls + safe privacy subset: `server_header`/`date_policy` system|suppress/`stripped_response_headers`/`error_policy` minimal|empty; Plan 202 trusted-proxy subset: `trusted_proxies`/`trust_unix_local`/`proxy_protocol`/`forwarded_standard`/`forwarded_legacy`, all default nothing trusted; `None` disables, `0` never unlimited; projected via the single `_native_kwargs()` helper, Plan 182), bounded `Response.stream(status, iterable, headers, content_length)` over a 16-chunk bridge (HEAD/body-forbidden never advance the iterator; sync iterables only — async via `AsyncResponse.stream`; non-bytes/iterator errors truncate with sanitized type-only logs; no `Transfer-Encoding` from services), and caller-owned `StaticResponder` composition (no routing in EggServe). `Request` exposes `remote_addr` unchanged plus `effective_addr`/`effective_scheme`/`effective_authority`/`proxy_provenance`/`forwarded_provenance` (absent without explicit trust). Plan 204 adds experimental `AsyncServer(config, async_handler, max_async_tasks)` (H1-only, same runtime, manual asyncio bridge, no new deps; `AsyncRequest` byte-fidelity + `read_chunk`/`trailers`/`send_interim`/`take_tunnel`, `AsyncResponse.stream` over async iterables via bounded 16-queue + `stream_with_trailers`, one-shot `Tunnel` duplex; ASGI fixture in `crates/eggserve-python/tests/asgi_fixture.py` only, not a product).
- **CLI compatibility polish** — Manual parsing accepts hostname `--bind` values, repeatable `-H/--header` and `--content-type` static metadata, and a combined certificate/key PEM when `--tls-key` is omitted. Header metadata is validated against runtime-owned and hop-by-hop fields. Production admission/lifecycle CLI flags: `--max-in-flight-requests`, `--keep-alive-idle-timeout`, `--max-requests-per-connection` (`0` = unlimited), `--response-write-timeout`, `--max-buf-size`, `--max-headers`, `--max-header-bytes`, `--max-request-target-bytes`.
- **Python wheel support** — GIL-enabled CPython 3.11–3.15 via one `cp311-abi3` wheel per platform (build-once/test-many ABI proof on 3.11–3.15; no per-minor wheels; free-threaded owned by Plan 267). Routine CI builds and tests the Linux wheel; release targets 10 required platforms from `release/wheel-matrix.toml` (manylinux x86_64/aarch64/armv7, musllinux x86_64/aarch64/armv7, macOS x86_64/arm64, Windows x86_64/arm64) plus declared i686/win32 candidates. Plan 268: `manylinux` baseline vs `--compatibility pypi` are separate controls; cross-built AArch64 glibc/musl + Windows ARM64 are deferred to native qualifiers gating aggregation (AArch64 musl via Alpine container); ARMv7 via matching QEMU userspace with `sh`; 3.15 lanes use prerelease until final. `scripts/test-python-wheel.sh` has `MODE=full` (primary interpreter suite) and `MODE=abi-smoke` (cross-interpreter lane) with `WHEEL_PATH` reuse; `scripts/qualify-python-wheel-target.sh` is the rootless real-device path.
- **Python wheel support** — GIL-enabled CPython 3.11–3.15 via one `cp311-abi3` wheel per platform (build-once/test-many ABI proof on 3.11–3.15; no per-minor wheels) plus a **Stable** free-threaded CPython 3.14t family (promoted by Plan 327) (`cp314-cp314t`) on Linux x86_64 glibc, macOS arm64, and Windows x86_64 only (Plan 326; explicit `gil_used = false`; 3.13t/3.15t/`abi3t`/PyPy/ARMv7/Windows arm64/musl are not supported; `max_python_callbacks=1` is the serialized mode and handlers own their thread safety). Routine CI builds and tests the GIL Linux wheel plus a separate `python-free-threaded` lane; release targets 13 required entries on 10 platform tags from `release/wheel-matrix.toml` (manylinux x86_64/aarch64/armv7, musllinux x86_64/aarch64/armv7, macOS x86_64/arm64, Windows x86_64/arm64, plus the three cp314t entries) with matrix-owned interpreters, plus declared i686/win32 candidates. Plan 268: `manylinux` baseline vs `--compatibility pypi` are separate controls; cross-built AArch64 glibc/musl + Windows ARM64 are deferred to native qualifiers gating aggregation (AArch64 musl via Alpine container); ARMv7 via matching QEMU userspace with `sh`; 3.15 lanes use prerelease until final. `scripts/test-python-wheel.sh` has `MODE=full` (primary interpreter suite) and `MODE=abi-smoke` (cross-interpreter lane) with `WHEEL_PATH` reuse; `scripts/qualify-python-wheel-target.sh` is the rootless real-device path.
- **Semaphore bounds** — `max_connections`, `max_file_streams`, and `max_in_flight_requests` are validated once in the Plan 179 kernel (`crate::runtime_limits`) against `tokio::sync::Semaphore::MAX_PERMITS`. Values above this bound are rejected with a controlled error.
- **Plan 164 admission/lifecycle fields** — `RuntimeConfig`/`Limits` own `max_buf_size` (65536, Hyper min 8192), `max_headers` (100, pinned explicitly; Hyper answers excess with 431), `max_header_bytes` (32 KiB, 431 pre-service), `max_request_target_bytes` (8192, 414 pre-service), `max_in_flight_requests` (64, 503 on exhaustion, held across `Service::call`), `keep_alive_idle_timeout` (60s, resets on activity), `max_requests_per_connection` (`Option<u64>`, `None` = unlimited; CLI `0` = unlimited), `response_write_timeout` (30s, no-progress via `ProgressIo` + `TrackedBody`). Idle/write timeouts are NOT cross-checked against `connection_total_timeout`. `ConnectionOutcome` adds `IdleTimeout` (clean) and `WriteTimeout`. Hyper is 1.11.1: lone TE+CL normalizes to TE-wins (200), only duplicate/conflicting CLs still fail; Hyper also applies `header_read_timeout` while keep-alive idle, so set idle shorter for distinct accounting or raise both for long-lived keep-alive. Per-profile defaults live in `docs/deployment.md`; full semantics in `docs/timeout-reference.md`.
- **Plan 179 canonical runtime authority** — shared runtime defaults/validation live once in `eggserve-server::runtime_limits` (`SharedRuntimeValues` + `Violation`, public; `eggserve_core::runtime_limits` re-exports with `From` adapters next to `Limits`/`RuntimeConfig`). `Limits::validate()` delegates shared checks + static listing budgets; `RuntimeConfigBuilder::build()` validates the shared group + `ResponsePolicy`; `try_from_serve_config()` projects via `RuntimeConfig::from_shared_runtime`. Static listing/extra-header budgets stay service-owned; frontend-only controls stay in their surfaces. Services may lower `max_request_body_bytes` but never raise the hard ceiling.
Expand Down
17 changes: 16 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
# Changelog

## Unreleased — post-audit maintenance (Plans 320–325)
## Unreleased — post-audit maintenance (Plans 320–326)

No version has been published from this work; the Rust line stays on `0.5.x`
and the wheel on `0.2.5` until a maintainer chooses a release.

- **Free-threaded CPython 3.14t (Plan 326, Stable; promoted by Plan 327).** The extension now states
`#[pymodule(gil_used = false)]` explicitly and ships an additive
`cp314-cp314t` wheel family on Linux x86_64 (glibc), macOS arm64, and
Windows x86_64 only. The wheel matrix, release-set validator, release
metadata gate, and release workflow understand the ABI-family dimension
(13 required entries on 10 platform tags) and take interpreters from the
matrix. A separate `python-free-threaded` CI lane builds and tests the
wheel with `python3.14t`, and `test_free_threaded.py` covers parallel
callbacks, serialized mode, concurrent stream producers, one-shot body and
iterator contention, tunnel-receive contention, and restart. The tunnel
receive path now reports `concurrent Tunnel.recv is not supported` instead
of a misleading closed state. The GIL `cp311-abi3` contract is unchanged;
there is no Rust crate API, HTTP, TLS, or security behavior change, and no
release is cut.

- **Compatible dependency refresh (Plan 325).** The root, Python-wheel, and
fuzz lockfiles now resolve the newest semver-compatible dependency set
available at implementation time, with shared packages aligned. The pinned
Expand Down
5 changes: 4 additions & 1 deletion SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ minimal reproduction when safe to share.

The release wheel targets the CPython 3.11 stable ABI (abi3) and supports
GIL-enabled CPython 3.11–3.15 through one `cp311-abi3` wheel per platform
(build-once/test-many ABI proof; PyPy and free-threaded CPython unsupported).
(build-once/test-many ABI proof). An additive **Stable** family supports
free-threaded CPython 3.14t (`cp314-cp314t`) on Linux x86_64 (glibc), macOS
arm64, and Windows x86_64 only; PyPy, free-threaded CPython 3.13t/3.15t,
`abi3t`, ARMv7, Windows arm64, and musl free-threaded builds are unsupported.
Routine CI verifies the Linux wheel on the primary interpreter plus the
matrix authority gates; macOS and Windows wheels are built and tested in the
release/platform workflows, with the Windows ARM64 artifact executed natively
Expand Down
3 changes: 2 additions & 1 deletion crates/eggserve-python/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[build-system]
requires = ["maturin>=1.0,<2.0"]
requires = ["maturin>=1.14.1,<2.0"]
build-backend = "maturin"

[project]
Expand All @@ -22,6 +22,7 @@ classifiers = [
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: 3.14",
"Programming Language :: Python :: 3.15",
"Programming Language :: Python :: Free Threading :: 3 - Stable",
"Programming Language :: Rust",
"Topic :: Internet :: WWW/HTTP :: HTTP Servers",
"Topic :: System :: Filesystems",
Expand Down
9 changes: 8 additions & 1 deletion crates/eggserve-python/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1667,7 +1667,14 @@ fn run_cli_fn(py: Python<'_>, argv: Vec<String>) -> i32 {
py.detach(|| eggserve_bin::run_cli(argv))
}

#[pymodule]
/// Native extension module (`eggserve._native`).
///
/// The free-threading declaration is explicit. PyO3 >= 0.28 emits
/// `Py_MOD_GIL_NOT_USED` for a `#[pymodule]` without `gil_used`, and Plan 326
/// qualifies that promise for CPython 3.14t on Linux x86_64 (glibc), macOS
/// arm64, and Windows x86_64 only. On a GIL-enabled interpreter the attribute
/// is a no-op; it never re-enables a disabled GIL.
#[pymodule(gil_used = false)]
fn _native(m: &Bound<'_, PyModule>) -> PyResult<()> {
registration::register(m)
}
14 changes: 13 additions & 1 deletion crates/eggserve-python/src/server/body_bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,13 @@ pub(super) fn spawn_python_stream_producer(
// Python RequestBody — wraps Rust RequestBody
// ---------------------------------------------------------------------------

/// Python-facing one-shot request body.
///
/// `read()`, `read_chunk()`, and `iter_chunks()` are mutually exclusive
/// consumption modes; concurrent callers race the same one-shot state and the
/// losers receive the existing typed consumption errors. This holds on
/// free-threaded builds too: the mutex is structural, not a sharing API, and
/// thread safety is never inferred from the GIL.
#[pyclass(frozen, from_py_object, name = "RequestBody")]
#[derive(Debug, Clone)]
#[allow(dead_code)]
Expand Down Expand Up @@ -581,7 +588,12 @@ impl PyRequestBody {
// Python BodyChunkIterator — synchronous iterator over body chunks
// ---------------------------------------------------------------------------

/// PyBodyChunkIterator is not thread-safe; concurrent __next__ calls are not supported.
/// Synchronous iterator over request-body chunks.
///
/// Not thread-safe: `__next__` takes `&mut self`, so a concurrent call from
/// another Python thread raises `Already borrowed` rather than corrupting the
/// channel. One consumer per iterator; on a free-threaded interpreter the
/// guard stays structural (the GIL is not involved).
#[pyclass(name = "BodyChunkIterator")]
#[allow(dead_code)]
pub struct PyBodyChunkIterator {
Expand Down
5 changes: 5 additions & 0 deletions crates/eggserve-python/src/server/response_bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ use eggserve_primitives::body::BodySource;
use super::*;
use super::static_responder::validate_response_status;

/// Python-facing response with one-shot body ownership.
///
/// Reusing or concurrently taking the body raises the existing one-shot
/// errors on GIL-enabled and free-threaded interpreters alike; the interior
/// mutex is structural and is not a cross-thread sharing contract.
#[pyclass(frozen, name = "Response")]
pub struct PyResponse {
#[pyo3(get)]
Expand Down
Loading
Loading