Skip to content

Drop server item cap for bounded chunk queries - #1490

Merged
DZakh merged 2 commits into
mainfrom
claude/max-number-logs-chunk-queries-pnmwvx
Jul 24, 2026
Merged

Drop server item cap for bounded chunk queries#1490
DZakh merged 2 commits into
mainfrom
claude/max-number-logs-chunk-queries-pnmwvx

Conversation

@DZakh

@DZakh DZakh commented Jul 24, 2026

Copy link
Copy Markdown
Member

What

Stop sending a server-side item cap (maxNumLogs / maxNumInstructions) for chunk queries that have a specific end block.

Why

A bounded chunk query already has its toBlock as a hard bound on the response range, so the itemsTarget cap only ever existed to guard against a denser-than-expected range. With the recently added client-side address filtering (#1483), the server counts filtered-out items toward that cap, so it can truncate the range short — returning fewer blocks than toBlock — and open a gap that then needs an extra gap-fill roundtrip. For bounded chunks the cap buys nothing and actively causes gaps.

How

  • SourceManager forwards None as the item target to the source when the query is a chunk with a set toBlock; everything else keeps its cap.
  • itemsTarget at the Source.getItemsOrThrow boundary becomes option<int> (None = no cap).
  • maxNumLogs (EVM) and maxNumInstructions (SVM) become optional through the HyperSync ReScript clients and the Rust napi boundary (Option<i64>), mapping to the underlying HyperSync query's already-optional field.
  • FetchState capacity heuristic: a bounded chunk's partial response is now always treated as genuine source-capacity evidence, since no self-inflicted cap could have truncated it. The old "cap hit preserves capacity" protection still applies to non-chunk bounded queries.

query.itemsTarget stays int in FetchState, so query sizing, budget reservation (itemsEst), and the cross-chain headroom accounting are unchanged — only the decision to forward it as a server cap moved to the dispatch boundary.

Testing

  • cargo check (EVM + SVM napi)
  • pnpm rescript compiles envio, envio-tests, test_codegen
  • FetchState_test 99/99, SourceManager_test 56/56, SvmHyperSyncSource_test 3/3
  • Updated the capacity-heuristic test to cover both the new bounded-chunk behavior (partial response = capacity evidence) and the retained cap-hit protection on non-chunk bounded queries.

🤖 Generated with Claude Code


Generated by Claude Code

Summary by CodeRabbit

  • New Features

    • HyperSync log and instruction limits can now be omitted, allowing uncapped server responses.
    • Bounded data-fetch requests no longer apply an unnecessary server-side cap.
    • Query sizing now distinguishes estimated work from optional server limits for more accurate fetch planning.
  • Bug Fixes

    • Partial responses from bounded requests are now used more reliably to determine source capacity.

A chunk query with a specific end block already has its toBlock as a hard
bound on the response range, so the itemsTarget/maxNumLogs cap only exists to
guard against a denser-than-expected range. With client-side address
filtering the server counts filtered-out items toward that cap, so it can
truncate the range short and open a gap that then needs a gap-fill roundtrip.

Stop sending a server cap for bounded chunk queries: SourceManager forwards
None to the source when the query is a chunk with a set toBlock, and the
maxNumLogs / maxNumInstructions inputs become optional through the HyperSync
clients and the napi boundary. A bounded chunk's partial response is now
always treated as genuine source-capacity evidence.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GqyCTGE239bpYGZ9UvfJDn
@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 64a02a4f-10da-4cf3-bee6-8a1d6e35ce95

📥 Commits

Reviewing files that changed from the base of the PR and between eac1946 and 10cead7.

📒 Files selected for processing (9)
  • packages/envio/src/ChainState.res
  • packages/envio/src/ChainState.resi
  • packages/envio/src/CrossChainState.res
  • packages/envio/src/FetchState.res
  • scenarios/test_codegen/test/IndexerState_test.res
  • scenarios/test_codegen/test/lib_tests/CrossChainState_test.res
  • scenarios/test_codegen/test/lib_tests/FetchState_onBlock_test.res
  • scenarios/test_codegen/test/lib_tests/FetchState_test.res
  • scenarios/test_codegen/test/lib_tests/SourceManager_test.res

📝 Walkthrough

Walkthrough

HyperSync log, instruction, and source item caps now accept optional values. Bounded fetch queries omit server-side caps, open-ended probes retain caps, and partial chunk responses update capacity evidence. Query sizing and related tests now use estimated item counts.

Changes

Optional cap contracts and payloads

Layer / File(s) Summary
Query contracts and request construction
packages/envio/src/sources/*, packages/cli/src/*hypersync_source/*
Log, instruction, and source item caps use optional values; absent caps are omitted from outgoing HyperSync requests.
Optional-cap call sites
packages/envio-tests/test/*, scenarios/test_codegen/test/RpcSource*, scenarios/test_codegen/test/SourceBlockHashes_test.res
Updated source and HyperSync test calls pass Some(...) cap values.

Fetch scheduling and dispatch

Layer / File(s) Summary
Bounded and open-ended query sizing
packages/envio/src/FetchState.res
Bounded chunks and gap fills use itemsTarget: None; open-ended probes use Some(itemsEst), and obsolete sizing parameters were removed.
Capacity and cross-chain accounting
packages/envio/src/ChainState.res, packages/envio/src/ChainState.resi, packages/envio/src/CrossChainState.res
Chain query sizing signatures were simplified, and dispatch accounting now records itemsEst.

Validation updates

Layer / File(s) Summary
Scheduling and response behavior tests
scenarios/test_codegen/test/lib_tests/FetchState_test.res, CrossChainState_test.res, SourceManager_test.res
Assertions cover optional targets, capless chunks, estimated-item totals, and partial-response capacity handling.
Query fixture migrations
scenarios/test_codegen/test/IndexerState_test.res, FetchState_onBlock_test.res
Fetch query fixtures use optional itemsTarget values throughout.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CrossChainState
  participant FetchState
  participant HyperSyncSource
  participant HyperSyncClient

  CrossChainState->>FetchState: request next query
  FetchState->>HyperSyncSource: getItemsOrThrow(itemsTarget)
  HyperSyncSource->>HyperSyncClient: send optional max cap
  HyperSyncClient-->>HyperSyncSource: items response
  HyperSyncSource-->>FetchState: query response
  FetchState->>FetchState: update capacity from bounded partial response
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: removing the server-side item cap for bounded chunk queries.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Comment @coderabbitai help to get the list of available commands.

Follow-up to dropping the server cap for bounded chunk queries. Every
chunk/gap-fill query is bounded (its toBlock is sized to the source's range
capacity), so it now carries itemsTarget None and sends no server cap; only
open-ended probes, whose range isn't otherwise bounded, keep a cap
(itemsTarget Some(itemsEst)). query.itemsTarget becomes option<int> and
SourceManager forwards it straight through.

itemsEst is now the sole query-sizing and budget-reservation unit. This
retires the chunkItemsMultiplier headroom and the itemsTargetFloor: both only
ever sized a bounded query's server cap, never the itemsEst-based reservation,
so with bounded queries uncapped they no longer do anything. Drops the params
from FetchState.getNextQuery, ChainState.getNextQuery, and CrossChainState's
1.5x/3x realtime headroom.

Tests updated to the option representation and to assert itemsEst where they
previously asserted the (now-absent) cap.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GqyCTGE239bpYGZ9UvfJDn
@DZakh
DZakh merged commit 7782ce2 into main Jul 24, 2026
9 of 11 checks passed
@DZakh
DZakh deleted the claude/max-number-logs-chunk-queries-pnmwvx branch July 24, 2026 18:22
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.

2 participants