Skip to content

feat(streaming): asynchronous byte source driven by its host - #255

Merged
DrunkOnJava merged 2 commits into
mainfrom
feat/streaming-async-source
Oct 26, 2026
Merged

DrunkOnJava merged 2 commits into
mainfrom
feat/streaming-async-source

Conversation

@DrunkOnJava

Copy link
Copy Markdown
Owner

Summary

byte_source::AsyncSource is the asynchronous adapter #206 asks for: a transport that answers later (a worker thread, a browser worker, an HTTP range fetcher, an event loop) satisfies the same ByteSource contract without the library owning a thread, runtime, connection or dependency. Advances #206; the browser worker is #209.

Design

A poll with nothing in flight posts one request of at most one chunk and returns Pending; the host takes it (take_request), fetches it however it likes and answers with complete, complete_eof or fail, then polls again. An answer for another offset, an empty one or one longer than the request is rejected and leaves the request in flight. Bytes the caller's next scratch cannot take are held (at most one chunk) and delivered on the following polls, so nothing is fetched twice. A different request while one is in flight is an error, never a second fetch.

The HTTP/1.1 range worker that drives it in the E2E lives in examples/support/http_range.rs (plain http, one keep-alive connection, std only). Shipping an HTTP or TLS client in the library is a dependency and product decision this PR does not make. The "forward-only transport needs a spool/cache" acceptance item is already documented in docs/streaming/README.md; AsyncSource posts absolute offsets, so its transport must be range-capable.

Test plan

  • python3 tools/streaming/verify_source.py target/debug/examples/stream_walk against an in-process Python range server (206 + Content-Range, 416 past the end), on the canonical R2000 fixture and the pinned line_R14.dwg and line_2000.dwg:
    • output equals the file-backed run under a fixed and a mixed chunk schedule;
    • all 9,206 fetches are answered on a later poll after a Pending (real asynchrony, not the injected flag);
    • the bytes the server sent equal the bytes delivered to the grammar, in order and once; with the fixed schedule every fetch is exactly the grammar's demand;
    • a walk stopped and resumed in a fresh process over HTTP at four points fetches no range twice;
    • a 416 past a short file ends in the walk's typed Truncated; a Content-Range for another offset and a body cut short are source errors; each leaves only a valid output prefix.
  • On a GitHub Linux runner via workflow_dispatch on a stacked head containing this commit (run 40299178744): the step takes 3 s. An earlier run hung because thousands of small keep-alive request/response pairs met Nagle's algorithm and delayed ACKs on Linux loopback; the worker and the test server both set TCP_NODELAY, and the resume runs use 256-byte chunks.
  • verify_walk.py still passes with the modified stream_walk; fmt, clippy (-D warnings, all targets), cargo doc -D warnings.
  • No new unit tests.

Not measured: TLS, a remote host, latency or throughput, a browser worker.

Source-provenance declaration

Clean-room declaration. All code in this PR was written from scratch. The only sources consulted were this repository and the ODA's public Open Design Specification for .dwg files v5.4.1. No Autodesk SDK, ODA SDK (Drawings / Teigha), LibreDWG or other copyleft DWG implementation source, and no decompilation, was consulted. Spec citations are in the diff.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review 🔄 Running since 2026-10-26T10:48:15.551738Z 4fcf37c New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c2e92c9cb2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread examples/support/http_range.rs Resolved
Comment thread examples/stream_walk.rs Resolved
@DrunkOnJava
DrunkOnJava enabled auto-merge (squash) October 26, 2026 10:31
AsyncSource is the adapter for a transport that answers later: a worker
thread, a browser worker, an HTTP range fetcher or an event loop. It
owns no thread, runtime or connection. A poll with nothing in flight
posts one request of at most one chunk and returns Pending; the host
takes it, fetches it however it likes and answers with complete,
complete_eof or fail, then polls again. An answer for another offset,
an empty one or one longer than the request is rejected and the
request stays in flight; bytes the caller's next scratch cannot take
are held, at most one chunk, so nothing is fetched twice.

stream_walk --url drives the R13-R2000 walk through AsyncSource and an
HTTP/1.1 range worker thread kept in the examples (plain http, one
keep-alive connection; no client or TLS dependency in the library).
verify_source.py serves the canonical R2000 fixture and the pinned
line_R14 and line_2000 from a local range server: the output equals the
file-backed run under a fixed and a mixed chunk schedule, all 9,206
fetches are answered on a later poll after a Pending, the bytes served
equal the bytes delivered (in order, once), and with the fixed schedule
every fetch is exactly the grammar's demand. Fresh-process resume over
HTTP fetches no range twice; a 416 past a short file ends in the walk's
typed Truncated, and a Content-Range for another offset and a body cut
short are source errors, each leaving only a valid output prefix. It
runs in the required Streaming E2E job.

Refs #206
…TP bodies

Two findings from the review on #255.

AsyncSource holds bytes it fetched but the caller's scratch has not
taken yet. A checkpoint saved only the walker and the caller's digest,
so a resumed process built a fresh adapter and fetched those bytes again
(--chunks 256,1 --stop-after 1 on the canonical fixture fetched bytes
1-5 twice). AsyncSource now exposes held() and with_held(); stream_walk
saves them beside the checkpoint in <path>.source and restores them on
--resume, and refuses to checkpoint with a fetch in flight. complete()
also rejects an answer whose end would pass u64::MAX.

The example HTTP worker allocated and read a response body before
checking it: a server that ignores Range (200, the whole file) or a 206
claiming more than was asked for was buffered first. It now decides
from the status and Content-Length before allocating; a 416 body is
drained only up to 1 KiB.

verify_source.py resumes over HTTP at fifteen stops under a three-size
chunk schedule, five of them with held bytes, and requires the fetched
and delivered byte sequences of the two processes to concatenate to the
uninterrupted run's; discarding the saved bytes makes that check fail.
It adds the ignored-Range and oversized-206 faults.
@DrunkOnJava
DrunkOnJava force-pushed the feat/streaming-async-source branch from c0c66a4 to 4fcf37c Compare October 26, 2026 10:48
@DrunkOnJava
DrunkOnJava merged commit e4719f3 into main Oct 26, 2026
25 checks passed
@DrunkOnJava
DrunkOnJava deleted the feat/streaming-async-source branch October 26, 2026 11:21
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