Skip to content

impl(042): increment 4 part 3, remote context sources in the service and context invalidations - #407

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

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

Conversation

@bartekus

@bartekus bartekus commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Spec 042 3.10 and 3.12, part 3: remote context sources in the service, and context invalidations (3.10.6). Builds on part 2 (#405, merged).

  • rustev-serve/src/contexts.rs: the standalone binary builds one RemoteContextClient per context_sources entry (the key is the source id). A source whose describe fails is installed as unavailable (fetches fail context_unavailable) and is reported not described, so readiness reflects it. Queue depth, refusals and late discards go to the health table every second. Fixed values are recorded in the implementation record as engineering choices: transit margin 25 ms, principal mapping version rustev-serve/principal-handle/1, scope rustev-serve, describe budget 10 s, describe once at startup.
  • rustev-serve/src/invalidations.rs: POST /v1/context/invalidations (admin group) for sources whose describe declared push. Each item is applied before the ack (invalidate_scope for a principal, invalidate_plan for all_scopes, for every plan reading a named field). Replayed items are skipped. The first batch after startup and any non-contiguous batch first invalidate every plan reading the source. A gap is counted and marks the source degraded until the next contiguous batch. Erasures applied while a response for the scope is retained are counted. poll sources are polled at interval_ms: degraded until the baseline poll succeeds; a failed poll or lag beyond max_lag_ms invalidates everything from the source, degrades it and requires a new baseline.
  • rustev.serve-service/1 now lists the invalidations operation. The explain operation stays unavailable.
  • The crate compiles callback_server.rs, context_client.rs, seam_queue.rs and taxonomy.rs from rustev-remote-http by path, as it does the other shared sources.
  • Tests: contexts::tests (describe and unavailable sources; the poll baseline, items and failure), pushed_invalidations_ack_in_order_and_report_gaps_and_erasures in tests/handlers.rs. tests/COVERAGE.md and the README are updated.

Local: cargo clippy -p rustev-serve --all-targets -D warnings clean, cargo test -p rustev-serve all pass.

Review note (f94de00): contexts.rs 175, a failed poll on the tick where lag first passes max_lag_ms calls invalidation_lost twice. A fix is ready (one call per tick plus a unit test) but can't be pushed while the pull request is in the merge queue.

@github-actions

Copy link
Copy Markdown

AI review (no-findings)

Reviewing the diff across all ten changed paths: contexts.rs, invalidations.rs, lib.rs, service.rs, sinks.rs, transport.rs, tests/COVERAGE.md, tests/handlers.rs, README.md, and the spec.

contexts.rs

The connect function correctly installs Unavailable for sources whose describe fails and reports them not described. The start_reporting loop correctly drives poll sources with MissedTickBehavior::Delay (avoids storms). Lock ordering is consistent: invalidation → state within apply_invalidations; no reverse ordering visible in the Service methods.

One redundancy in poll: when Err(_) fires and lag > max_lag_ms && !lagging is also true in the same iteration, service.invalidation_lost is called twice (first with count=sequence.is_some(), then with count=false). The lagging guard is only set after the second call. The second call doesn't double-count gaps (uses count=false) and doesn't alter correctness, but does invoke invalidate_fields and health reporting redundantly. This is a minor inefficiency, not a correctness defect.

invalidations.rs

apply_invalidations checks cross-batch contiguity (first.sequence == source.last + 1) but not intra-batch contiguity. A push batch with items [6, 8] after source.last=5 passes the cross-batch check (6 == 5+1), silently skips sequence 7, advances source.last to 8, and clears degraded — without counting a gap or marking the source degraded. The module's own doc says gap detection applies to "the first batch after startup" and "a batch not contiguous with the last applied item," which speaks only to cross-batch continuity, so this may be by design. However, the schema (ServeInvalidations::parse) is only confirmed to reject decreasing sequences (the unit test), not non-contiguous ones, leaving within-batch gaps silently undetected. This is a concrete gap in validation for adversarial or buggy push senders.

The retains function and erasure counting are correct: it compares the principal digest of the invalidated scope against the service's retained-response keying, which matches how scope_key is used when storing entries.

service.rs

New fields invalidation and erasures_while_retained are correctly initialized. Removing Operation::Invalidations from the unavailable filter in both the service-describe listing and the transport gate is correct.

sinks.rs

Extracting transport(endpoint) is clean. The only semantic change is the error message ("sink credential" → "endpoint credential"), which is accurate.

transport.rs

Adding Operation::Invalidations to has_body and the dispatch arm is correct. The synchronous dispatch (service.invalidations(&bytes)) is appropriate since the handler is synchronous.

tests/handlers.rs

The test exercises push invalidations comprehensively: baseline, replay-skip, gap detection, erasure-while-retained, poll-source refusal, unknown-source refusal, and malformed-document refusal. The retains check precondition (a retained response for b"opaque") is correctly established before the erasure assertion.

specs/042-decision-service-and-remote-seams/spec.md

The increment notes are accurate and consistent with the implementation. The phrase "Engineering choices made by the implementing agent" is unusual but explicitly flags agent-level decisions for owner review. The ratification note at the bottom of the spec is unchanged.

COVERAGE.md

The updated rows accurately reference the new tests.

No security vulnerabilities (path traversal, credential leak, injection) beyond what existed before; transport() reuses the same credential-reading logic already present for sinks, from admin-controlled config.

{"head": "1443f1503ef670bf704814e4b51f2ac708942c2a", "verdict": "no-findings", "findings": []}

Subject: 30f9934...1443f15, diff digest 001fa806f6425bfbcd01df6367d9b679624ebae37d33b3cd861332356ebb6d94, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus force-pushed the impl/042-context-client branch from 30f9934 to 34a34b0 Compare October 30, 2026 04:28
Base automatically changed from impl/042-context-client to main October 30, 2026 05:43
@bartekus
bartekus force-pushed the impl/042-serve-context branch from 1443f15 to f94de00 Compare October 30, 2026 05:43
@github-actions

Copy link
Copy Markdown

AI review (findings)

Reviewing the PR, which adds remote context source clients (contexts.rs), pushed invalidation handling (invalidations.rs), and wires both into the standalone service.

contexts.rs — poll loop: invalidation_lost called twice on the same tick when an error coincides with lag first exceeding max_lag_ms

Inside poll, two independent paths both call service.invalidation_lost:

Err(_) => {
    let lag = last_ok.elapsed().as_millis() as u64;
    service.invalidation_lost(&name, lag, sequence.is_some()); // ①
}
// ...
let lag = last_ok.elapsed().as_millis() as u64;
if lag > max_lag_ms && !lagging {
    lagging = true;
    service.invalidation_lost(&name, lag, false); // ②
}

On the first tick where a poll error occurs and lag has crossed max_lag_ms, both ① and ② fire. invalidation_lost calls invalidate_fields, which iterates all registered plans and invokes runtime.invalidate_plan (or invalidate_scope) for each. The second call is entirely redundant: by the time ② fires, source.last is already None, source.degraded is already true, and count = false so no gap is counted. The result is a double-call to the runtime's invalidation path for every registered plan on that single tick. Plan invalidation is idempotent so correctness is unaffected, but the double-execution is unintended — the lagging flag was introduced precisely to gate ② to once per outage, but it does not prevent ① from running concurrently on the same tick.

No other concrete defects were found. The lock ordering (invalidation → state) introduced by apply_invalidations calling invalidate_fields and retains while holding sources is consistent across all new code paths. The gap-detection logic, erasure counting, baseline/poll handling, and push-vs-poll dispatch all match the spec notes.

{"head": "f94de00a6d4ec23d96c974f990b4a7670c683c4b", "verdict": "findings", "findings": [{"path": "integrations/rustev-serve/src/contexts.rs", "line": 175, "summary": "On the first tick where a poll error coincides with lag exceeding max_lag_ms, invalidation_lost is called twice (once from the Err branch, once from the lag check), causing redundant double-invocation of runtime plan-invalidation for every registered plan on that tick."}]}

Subject: a1e0fd3...f94de00, diff digest 8642104848a23ec33821e4c13cc6788622d63d3b138b97b0df859a6dde7dd3e9, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus temporarily deployed to statecraft-review-exception October 30, 2026 05:51 — with GitHub Actions Inactive
@bartekus
bartekus added this pull request to the merge queue Oct 30, 2026
Merged via the queue into main with commit d2a496f Oct 30, 2026
36 of 40 checks passed
@bartekus
bartekus deleted the impl/042-serve-context branch October 30, 2026 06:51

This branch was previously deployed

1 inactive deployment
statecraft-review-exception — f94de00a Deployed Oct 30, 2026 by bartekus via review-exception #2801
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