Skip to content

feat(sqlite): wire preload hints through envoy#4890

Draft
NathanFlurry wants to merge 1 commit intomock-agentic-loop/envoy-protocol-v5-preload-hintsfrom
mock-agentic-loop/wire-sqlite-preload-hints
Draft

feat(sqlite): wire preload hints through envoy#4890
NathanFlurry wants to merge 1 commit intomock-agentic-loop/envoy-protocol-v5-preload-hintsfrom
mock-agentic-loop/wire-sqlite-preload-hints

Conversation

@NathanFlurry
Copy link
Copy Markdown
Member

Description

Please include a summary of the changes and the related issue. Please also include relevant motivation and context.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Copy link
Copy Markdown
Member Author

NathanFlurry commented May 3, 2026

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@claude
Copy link
Copy Markdown
Contributor

claude Bot commented May 3, 2026

Code Review: feat(sqlite): wire preload hints through envoy

Overview

This PR wires up the SQLite preload hints round-trip through the envoy protocol layer: rivetkit-core already sends hints (fire-and-forget and periodic flush), envoy-client now routes them as SqliteRequest::PersistPreloadHints, and pegboard-envoy now receives and acknowledges them. The wire-up is clean and follows existing patterns.

The engine-side handler is intentionally a stub — it validates the actor and returns Ok without persisting the hints data. That's fine for a draft, but it means hints are currently received and silently discarded.


Issues

1. Stub discards hints data (expected for draft, but worth noting)

// engine/packages/pegboard-envoy/src/ws_to_tunnel_task.rs
async fn handle_sqlite_persist_preload_hints(
    ctx: &StandaloneCtx,
    conn: &Conn,
    request: protocol::SqlitePersistPreloadHintsRequest,
) -> Result<protocol::SqlitePersistPreloadHintsResponse> {
    validate_sqlite_actor(ctx, conn, &request.actor_id).await?;
    Ok(protocol::SqlitePersistPreloadHintsResponse::SqlitePersistPreloadHintsOk)
}

request.hints (the SqlitePreloadHints struct with pgnos and ranges) is never read or stored. Per CLAUDE.md and SQLITE_OPTIMIZATIONS.md, the intended path is to persist to a /PRELOAD_HINTS KV key so it can be fed into OpenConfig on the next actor start. There should be a follow-up task or TODO comment since this is a deliberate stub.

2. SqliteFenceMismatch is unreachable

The protocol response union includes SqliteFenceMismatch for generation mismatch, but the handler never validates request.generation. The rivetkit-core client handles SqliteFenceMismatch specifically — but it can never receive it with the current implementation. Once the real persistence lands, generation validation will need to be wired in.

3. Missing tracing span on the hot path

The commit request handler wraps its call with a tracing::debug_span!:

let timed_response = async { handle_sqlite_commit_response(...).await }
    .instrument(tracing::debug_span!(
        "handle_sqlite_commit",
        actor_id = %actor_id,
        request_id = ?request_id,
    ))
    .await;

The preload hints handler omits this. Even though the current stub does no real work, adding the span now (matching the commit pattern) avoids a future omission once real logic is added:

protocol::ToRivet::ToRivetSqlitePersistPreloadHintsRequest(req) => {
    let actor_id = req.data.actor_id.clone();
    let request_id = req.request_id;
    let response = async { handle_sqlite_persist_preload_hints_response(ctx, &conn, req.data).await }
        .instrument(tracing::debug_span!(
            "handle_sqlite_persist_preload_hints",
            actor_id = %actor_id,
            request_id = ?request_id,
        ))
        .await;
    send_sqlite_persist_preload_hints_response(&conn, request_id, response).await?;
}

Minor Observations

  • fire_and_forget receiver drop is correct. let (tx, _rx) = oneshot::channel() intentionally drops _rx. When the response arrives and tx.send() fails, the error is silently discarded — the desired semantic. Cleanup via fail_sqlite_requests_with_shutdown and cleanup_old_sqlite_requests handles the in-flight entry correctly.

  • async fn handle_sqlite_persist_preload_hints_response in sqlite.rs is async unnecessarily (it only calls a sync handle_sqlite_response), but this matches the existing pattern for other handlers so it's consistent.

  • stringify.rs is complete — both ToRivet and ToEnvoy arms are covered.

  • Enum variants are exhaustively matched throughout — no _ => fallthrough in new code, consistent with CLAUDE.md requirements.


Summary

The protocol plumbing is clean and follows established patterns. The main gap (expected for a draft) is that the engine-side handler is a stub: it needs actual KV persistence of the hints data and generation validation before this feature does anything useful. Recommend adding a // TODO: persist request.hints to actor KV comment in the stub so it does not get shipped silently incomplete, and adding the tracing span to match the commit handler pattern.

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