P4b: invert non-row bounded tokens to sync TdsCore step_token driver - #199
Draft
Saurabh Singh (saurabh500) wants to merge 2 commits into
Draft
Conversation
Mirror P4a's row inversion for the non-row receive path: parse the bounded category-(a) tokens (DONE/DONEINPROC/DONEPROC, RETURNSTATUS, ORDER, ERROR, INFO, ENVCHANGE) with a pure-sync body over PacketBuffer and drive them from one async shell that owns the sole refill .await. - Add TokenStep + TdsCore::step_token (tds_core.rs) and the sync parse leaf sync_token.rs (one production parse body per (a) token). - Add drive_token_over_buffer + resolve_header_token (token_stream.rs); rewire the three production receive_token call sites in network_transport.rs. - Retain receive_token_internal as a #[cfg(any(test, fuzzing))] oracle; the value-carrying (b) tokens (COLMETADATA/RETURNVALUE/SESSIONSTATE/ FEATUREEXTACK) and login tokens stay on the AsyncToken async seam; their pure-sync inversion is deferred to a later parent-gated TokenPauseState layer. - Fold two P4a-hardening items: strengthen the RowStep::AsyncColumn doc with the load-bearing bounded-residency rationale, and add a strict production-path eager-PLP residency-ceiling test on drive_row_over_buffer (cfg(test) peak_length hook on PacketBuffer, off the public surface). - Add refill-boundary differential tests: DONE family, ERROR/INFO, ORDER, ENVCHANGE swept at every split vs the oracle, COLMETADATA across a refill via the seam, and a COLMETADATA -> ROW handoff. Public API frozen (all new symbols pub(crate)/cfg(test)). Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: e2c378f8-3ba1-4b48-9ebe-5a4ea2bd2761
Replace the magic 8192 constant with the working buffer's real capacity read from the production reader, so the eager-PLP residency ceiling asserts against the actual in-test 2 x negotiated-packet cap. Regress-on-flip verified: forcing whole-value residency at the eager-PLP path fails the test (guard trip on the fixed cap; the explicit peak <= buffer_capacity assertion on a growable cap). Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: e2c378f8-3ba1-4b48-9ebe-5a4ea2bd2761
Saurabh Singh (saurabh500)
marked this pull request as ready for review
August 10, 2026 06:38
Copilot started reviewing on behalf of
Saurabh Singh (saurabh500)
August 10, 2026 06:39
View session
Contributor
There was a problem hiding this comment.
Pull request overview
Moves bounded non-row token parsing into the synchronous TdsCore path while retaining async seams for value-carrying tokens.
Changes:
- Adds synchronous token classification and parsing.
- Rewires production token reception through one async refill driver.
- Adds differential and PLP residency tests.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
mssql-tds/src/io/token_stream.rs |
Adds token drivers and boundary tests. |
mssql-tds/src/io/tds_core.rs |
Adds synchronous token stepping. |
mssql-tds/src/io/sync_token.rs |
Implements synchronous token parsers. |
mssql-tds/src/io/packet_buffer.rs |
Adds test-only residency tracking. |
mssql-tds/src/io.rs |
Registers the new module. |
mssql-tds/src/connection/transport/network_transport.rs |
Uses the new production driver. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+260
to
+261
| if let Err(need) = buf.ensure(total) { | ||
| return Ok(TokenStep::NeedBytes(need)); |
Comment on lines
+105
to
+108
| TokenType::Order => parse_order_body(buf), | ||
| TokenType::Error => parse_error_body(buf), | ||
| TokenType::Info => parse_info_body(buf), | ||
| TokenType::EnvChange => parse_envchange_body(buf), |
Saurabh Singh (saurabh500)
marked this pull request as draft
August 10, 2026 06:49
Saurabh Singh (saurabh500)
marked this pull request as ready for review
August 10, 2026 07:39
Saurabh Singh (saurabh500)
marked this pull request as draft
August 10, 2026 13:28
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
P4b — Invert the non-row RECEIVE / token-consume paths to a sans-I/O sync core
Base:
dev/saurabh/sans-io-p4a-tdscore-row-driver(frozen P4a tip07099e0c). Draft; do not merge — coordinator will verify from git ground truth + a real nextest and append to stack #192.Mirrors P4a's row inversion for the non-row receive path. Every guaranteed-bounded category-(a) non-row token is now parsed by a pure-sync body over
PacketBuffer, driven by one async shell that owns the sole refill.await. Value-carrying / login tokens stay on an explicit async seam. Zero behavior change; public API frozen async-only.What changed
TokenStep+TdsCore::step_token(io/tds_core.rs) — peeks the token byte, ensures the length-bounded body, and parses in place; returnsNeedByteson entry underflow (nothing consumed, restartable) orAsyncToken(tt)for seamed tokens.io/sync_token.rs(new) — the pure-sync parse leaf: one production parse body per category-(a) token (DONE/DONEINPROC/DONEPROC, RETURNSTATUS, ORDER, ERROR, INFO, ENVCHANGE), byte-for-byte mirroring the async parsers.drive_token_over_buffer+resolve_header_token(io/token_stream.rs) — the single async shell; rewires the three productionreceive_tokensites innetwork_transport.rs.receive_token_internalis gated#[cfg(any(test, fuzzing))]as a differential byte-identity oracle; grep-proven no production path reaches it (its only non-test callers are#[cfg(fuzzing)]).Scope honesty (deferred work)
COLMETADATA / RETURNVALUE / SESSIONSTATE / FEATUREEXTACK (category-(b), value/PLP-carrying) and the login/handshake tokens (LOGINACK/TABNAME/COLINFO/SSPI/FEDAUTHINFO) remain on the
AsyncTokenasync seam. Their pure-sync inversion is deferred to a later, parent-gated layer that would introduce a sanctioned mid-tokenTokenPauseStatecursor. The receive path is not fully sync after P4b — this is stated in thetds_core.rsmodule doc and enforced by leaving those tokens on the seam. No new resumable machine is introduced here.Two folded P4a-hardening items (carried here, not in #198)
RowStep::AsyncColumnload-bearing doc comment (io/tds_core.rs) — bakes in the exact rationale that yielding an unbounded PLP column preserves L4b bounded residency and must never be collapsed intoNeedBytes{shortfall}.tdscore_step_row_eager_plp_residency_ceiling_on_production_driver) — decodes a >8192 B eager-PLP LOB throughdrive_row_over_buffer(production) and asserts peakPacketBufferresidency stays ≲ one buffer/chunk via a#[cfg(test)]peak_lengthhigh-water hook (off the public surface). It FAILS ifAsyncColumnis ever collapsed to a collect-whole /NeedBytes(full-len)path.Tests (through the new sync driver)
AsyncTokenseam handles a token spanning a refill.Gate (from this worktree)
cargo nextest run -p mssql-tds --lib --no-fail-fast→ fail-set == exactly the 7 known cert fixtures (Compare-Object of sorted fail-name sets == EMPTY), no hang.cargo bfmt+cargo bclippy(-D warnings) clean;scripts/bfmt.ps1+scripts/bclippy.ps1clean incl.mssql-py-core;cargo build --all-featuresinmssql-py-coreOK.pub(crate)/cfg(test)).