Skip to content

impl(042): increment 4 part 2, the remote context client - #405

Merged
bartekus merged 1 commit into
mainfrom
impl/042-context-client
Oct 30, 2026
Merged

bartekus merged 1 commit into
mainfrom
impl/042-context-client

Conversation

@bartekus

@bartekus bartekus commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Spec 042 3.10 and 3.12, part 2: the rustev.remote-context/1 client in rustev-remote-http. Builds on part 1 (#403, merged).

  • src/context_client.rs: RemoteContextClient implements ContextSource. It describes the endpoint once at construction (capability failure on an unknown version, an undescribed source or an endpoint class other than host_operated). Every fetch goes through the bounded SeamQueue (immediate remote_seam_queue_full). A fetch sends the budget less the transit margin, the describe digest, the principal reference (spec 020) and the attempt id <escaped decision id>/context/<n>, at most once. An unrequested field or a local-only code is malformed_response. When the caller stops waiting, the client asks the endpoint to cancel; an answer that still arrives is discarded, counted as late and recorded late: true. The exchange records are digest-only, and a failure of the exchange sink is counted, never propagated.
  • cancel and invalidations (poll: baseline, increasing sequences) as public methods for the service.
  • tests/context_client.rs: success with per-decision attempt numbering and exchange records, an unrequested field, an undescribed source, a full queue, abandonment with cancel and late counting, and polling.
  • archive-policy.json: lists the file. The crate's unpacked bound goes from 320 KiB to 384 KiB (it now unpacks to 332.6 KiB), as impl(021): rustev-runtime unpacked bound for the next family version #330 did for rustev-runtime.

Local: cargo test -p rustev-remote-http --test context_client (6 pass), clippy -D warnings clean, cargo test -p rustev-release --test archives passes.

@github-actions

Copy link
Copy Markdown

AI review (no-findings)

Reviewing the five changed paths: the new context_client.rs implementation, its lib.rs registration, the integration test, the spec increment note, and the archive-policy.json update.

context_client.rs — logic and safety review

  • transport_code: mapping is consistent with TransportError variants; PhaseExpired split on bytes_sent is correct.
  • escape: % is encoded first, preventing double-encoding of the percent sign. Correct.
  • connect: describe→select-source→digest chain is clean; unknown version and missing source are properly Capability failures; the host_operated class restriction (parse-fails otherwise) is documented in the module comment.
  • cancel: Stopped from a non-Confirmed source is rejected as MalformedResponse. Correct per spec note.
  • invalidations sequence validation: items must be strictly increasing relative to the running last (initialised from the caller's sequence); the final cursor must not be less than the requested sequence or the last item's sequence. All four boundary cases (baseline/empty, baseline/items, polled/empty, polled/items-or-regression) behave correctly.
  • fetch_once queue-slot-to-task flow: slot is acquired before any early-return path; slot.start deadline check inside the task returns TransportUnsent and releases cleanly; body.len() as u64 cast is lossless on 64-bit targets and safe on 32-bit via the preceding .min(usize::MAX as u64) pattern on the response side.
  • Abandon::drop: fires only when armed (set to false before returning the result) and only when cancellation != None; std::mem::take avoids a double-free of the id; try_current guards against use outside a runtime.
  • Late-response accounting: answered correctly distinguishes transport failure (never sent) from an endpoint answer that arrived after the receiver was dropped; the count_late / record(late=true) path is consistent with the test assertion.
  • judge: is_local_only guard on failure codes, unrequested-field guard on snapshots — both produce MalformedResponse. No silent data laundering.
  • The MAX_COUNTERS eviction (clear the whole map when full and the new key is absent) is documented in the module comment and consistent with the endpoint's attempt_id_conflict refusal being the safety net.

Tests — cover: successful fetch with per-call attempt-id sequencing and exchange records; greedy source returning unrequested fields; undescribed source and zero in-flight at construction; full-queue refusal; abandon-and-cancel with late-answer counting; baseline+incremental invalidation polling. Scenarios match the implementation.

archive-policy.json — context_client.rs added to the file list; max_unpacked_bytes raised from 327 680 to 393 216 (320 KiB → 384 KiB) to accommodate the ~332.6 KiB new actual; max_archive_bytes left at 163 840 (compressed size is unaffected enough not to need raising). The spec note and the JSON change are consistent.

Spec increment — the prose accurately describes the implementation: SeamQueue fail-fast, transit-margin subtraction, attempt-id format, cancel-on-abandon, local-only/unrequested-field rejection, late-discard counting, exchange-record emission, invalidation-sequence validation.

No concrete bugs, security defects, or inconsistencies found.

{"head": "3d4a2496a6a8bf3f0bcf273d45aa6141a96b2e6f", "verdict": "no-findings", "findings": []}

Subject: 6a428f8...3d4a249, diff digest 7ed9dddcb2f840a08109e23997f2323586e5fd5968d94e21152ff70fe3b66e4f, 1 call(s). An AI comment is not an approval.

Base automatically changed from impl/042-callback-server to main October 30, 2026 03:32
@bartekus
bartekus force-pushed the impl/042-context-client branch from 3d4a249 to 30f9934 Compare October 30, 2026 03:34
@github-actions

Copy link
Copy Markdown

AI review (no-findings)

Reviewing the new RemoteContextClient implementation across all five changed files.

context_client.rs

  • next_attempt clears all counters when the map is full and a new decision ID arrives. This can restart counters for previously-seen decisions that were evicted, reusing attempt IDs. The module header comments acknowledge this explicitly ("a reused attempt id with other content is refused by the endpoint"), so this is intentional and specified.
  • fetch_once acquires the queue slot (try_enter) before checking told == 0. On early return, slot drops and frees the slot correctly; the counter (next_attempt) is also not yet incremented at that return point. No leak.
  • Abandon::drop hard-codes the cancel budget at 1,000ms. Not configurable, but fire-and-forget from Drop has no access to a call-time budget, and silently discarding the result is correct for the cancellation path.
  • Response size is bounded by inner.source.terms.max_response_bytes.min(usize::MAX as u64) as usize, preventing overflow on 32-bit targets; server-declared value is used as an upper bound, not a trusted allocation size.
  • judge allows a snapshot with fewer fields than requested (only rejects unrequested fields). This appears intentional — the spec requires rejecting unrequested fields, not requiring all requested fields.
  • invalidations sequence validation: when sequence = None, last starts as None, so the first item's sequence is unconstrained; subsequent items must strictly increase. The final guard on answer.sequence correctly catches regressions relative to both the input sequence and the last item. Logic is correct.
  • cancel correctly rejects a Stopped answer from a source that didn't declare CancelSupport::Confirmed.
  • Exchange records are emitted after tx.send(result) (i.e., after the caller may have received the result). Tests use until(...) polling to handle this, which is the right approach.

lib.rs: pub mod context_client; added cleanly; no issues.

tests/context_client.rs: Integration tests cover the principal paths — normal fetch, unrequested field rejection, undescribed source, queue full, cancellation/late-response counting, and invalidation polling. Coverage matches the spec description.

specs/042-.../spec.md: Increment 4 part 2 note is internally consistent with the implementation and matches the archive policy change.

archive-policy.json: src/context_client.rs added to the file list; max_unpacked_bytes raised from 327,680 (320 KiB) to 393,216 (384 KiB). Spec states measured size is 332.6 KiB, giving ~51 KiB headroom. Consistent.

No concrete defects found.

{"head": "30f9934ff6a37542eae6eb241430499b9e4d4fc8", "verdict": "no-findings", "findings": []}

Subject: 8cd9c0c...30f9934, diff digest 7ed9dddcb2f840a08109e23997f2323586e5fd5968d94e21152ff70fe3b66e4f, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus added this pull request to the merge queue Oct 30, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Oct 30, 2026
@bartekus
bartekus force-pushed the impl/042-context-client branch from 30f9934 to 34a34b0 Compare October 30, 2026 04:28
@github-actions

Copy link
Copy Markdown

AI review (no-findings)

Reviewing the five changed paths for bugs, security issues, and spec inconsistencies.

context_client.rs

  • escape() escapes % first, then / and ,, which is the correct order to avoid double-encoding. Attempt ID format <escaped>/context/<n> matches the test assertion (a%2Fb/context/1).
  • transport_code: PhaseExpired is split on bytes_sent; the Expired variants are matched on the sent field. Pattern exhaustion looks correct.
  • next_attempt: counter map is cleared when at MAX_COUNTERS and the key is new, then the new key is inserted and incremented. Cleared keys restart from 1, which is documented and intentional.
  • fetch_once flow: slot = try_enter() is acquired before the two early returns (told == 0 and body.len() > max_request_bytes). In both cases slot goes out of scope and is dropped by RAII before the spawn; queue accounting depends on SeamQueue::drop, which is not in this diff but is an existing module. next_attempt is called only after the budget check, so a counter is consumed only if the request is actually built — but the body-size check comes after, so a counter is wasted if the body is too large. This is a minor inefficiency (gaps in /context/N IDs for one decision), not a correctness problem because a skipped ID is never sent.
  • Abandon::drop fires the cancel for any CancelSupport other than None (covers Optimistic and Confirmed), which aligns with the spec note "unless the source declares none." The fixed 1,000 ms cancel budget is a design choice not contradicted by visible spec text.
  • invalidations: monotonicity check uses is_some_and, so the first item in a baseline call (sequence = None) has no lower bound — intentional, since there is no prior sequence. The tail check answer.sequence < last is correctly applied.
  • judge: wanted.contains is an O(n·m) linear scan over field names; for the small field lists this protocol expects, it is not a practical problem.
  • No unsafe code; #![forbid(unsafe_code)] is carried forward from lib.rs.

lib.rs — module context_client added as pub mod, matching the new file. No issues.

tests/context_client.rs — Tests cover the described acceptance points (fetch, malformed response, undescribed source, full queue, abandonment/late counting, invalidation polling). The until helper polls at 5 ms intervals for up to 2 seconds; adequate for loopback. No issues.

spec.md — Increment 4 part 2 description matches the implementation: attempt ID format, queue semantics, cancel scope, late counting, exchange records, and the archive bound increase. No contradiction with earlier spec text.

archive-policy.json — src/context_client.rs is inserted in correct alphabetical position; max_unpacked_bytes raised from 327,680 → 393,216 as the spec documents.

No concrete defects found.

{"head": "34a34b0f1bda042e3e2a04723720d70994759d9f", "verdict": "no-findings", "findings": []}

Subject: 0f2440a...34a34b0, diff digest fc0b8a1d00e29986827c32f47a53b4e48657495f5093e1cc01c8947ae76fb0e5, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus added this pull request to the merge queue Oct 30, 2026
Merged via the queue into main with commit f0f3026 Oct 30, 2026
30 checks passed
@bartekus
bartekus deleted the impl/042-context-client branch October 30, 2026 05:43
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