Skip to content

fix(rpc): update StateSearchMsg to return null instead of error when not found#6817

Merged
hanabi1224 merged 3 commits intomainfrom
hm/fix-StateSearchMsg
Mar 30, 2026
Merged

fix(rpc): update StateSearchMsg to return null instead of error when not found#6817
hanabi1224 merged 3 commits intomainfrom
hm/fix-StateSearchMsg

Conversation

@hanabi1224
Copy link
Copy Markdown
Contributor

@hanabi1224 hanabi1224 commented Mar 30, 2026

Summary of changes

To match Lotus logic: filecoin-project/lotus#13562 (comment)

Changes introduced in this pull request:

Reference issue to close (if applicable)

Closes

Other information and links

Change checklist

  • I have performed a self-review of my own code,
  • I have made corresponding changes to the documentation. All new code adheres to the team's documentation standards,
  • I have added tests that prove my fix is effective or that my feature works (if possible),
  • I have made sure the CHANGELOG is up-to-date. All user-facing changes should be reflected in this document.

Outside contributions

  • I have read and agree to the CONTRIBUTING document.
  • I have read and agree to the AI Policy document. I understand that failure to comply with the guidelines will lead to rejection of the pull request.

Summary by CodeRabbit

  • Bug Fixes

    • State search RPC now returns null when a message isn't found instead of treating it as an error.
  • Tests

    • Snapshot acceptance now only runs when tests fail.
    • Validation helpers updated to correctly compare nullable/optional message lookup responses.
  • Documentation

    • Changelog updated to note the RPC behavior change.

@hanabi1224 hanabi1224 added the RPC requires calibnet RPC checks to run on CI label Mar 30, 2026
@hanabi1224 hanabi1224 marked this pull request as ready for review March 30, 2026 06:04
@hanabi1224 hanabi1224 requested a review from a team as a code owner March 30, 2026 06:04
@hanabi1224 hanabi1224 requested review from LesnyRumcajs and sudo-shashank and removed request for a team March 30, 2026 06:04
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 30, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: e092f423-981c-4780-8ec8-01acfda377a0

📥 Commits

Reviewing files that changed from the base of the PR and between 3c60922 and e002338.

📒 Files selected for processing (1)
  • CHANGELOG.md
✅ Files skipped from review due to trivial changes (1)
  • CHANGELOG.md

Walkthrough

State search RPC handlers now return nullable results (Option) when a message is not found; test validators were updated to handle optional lookups; build tooling (mise.toml) now conditionally runs cargo insta accept only if snapshot tests fail.

Changes

Cohort / File(s) Summary
RPC Method Signature Changes
src/rpc/methods/state.rs
StateSearchMsg and StateSearchMsgLimited change type Ok from MessageLookup to Option<MessageLookup>. Handlers return Ok(None) when a message is not found and Ok(Some(...)) when found; DESCRIPTION strings updated to indicate null on miss.
Test Validation Helpers
src/tool/subcommands/api_cmd/api_compare_tests.rs
Replaced test usage of validate_message_lookup with validate_message_wait; added an overloaded validate_message_lookup for rpc::Request<Option<MessageLookup>> that conditionally sets return_dec to Ipld::Null only when payload is Some, adjusting comparison semantics for nullable payloads.
Build Tooling
mise.toml
tasks.insta run command changed to use short-circuit `
Changelog
CHANGELOG.md
Added unreleased entry documenting that StateSearchMsg returns null when a message is not found.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • sudo-shashank
  • LesnyRumcajs
  • akaladarshi
🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 14.29% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and specifically describes the main change: updating StateSearchMsg RPC handler to return null instead of error when message not found.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch hm/fix-StateSearchMsg
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch hm/fix-StateSearchMsg

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

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/tool/subcommands/api_cmd/api_compare_tests.rs (1)

1237-1249: ⚠️ Potential issue | 🟡 Minor

Add an explicit not-found StateSearchMsg case.

Every request here is built from sampled on-chain message CIDs, so this change still only verifies the Some(MessageLookup) path. Please add at least one case where the message exists in the snapshot but falls outside the selected lookback/tipset window, so the new null behavior is actually covered.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/tool/subcommands/api_cmd/api_compare_tests.rs` around lines 1237 - 1249,
Add a test invocation that exercises the "not-found / null" path by creating a
StateSearchMsg request whose lookback/tipset window excludes the sampled msg_cid
and then validate that the response is null; for example, add a
validate_message_lookup(StateSearchMsg::request((None.into(), msg_cid, /* very
small lookback or older tipset */ 0, true))?) (or a similar
StateSearchMsg::request with parameters that put the message outside the window)
alongside the existing validate_message_lookup calls so the code that handles
the None/null result for StateSearchMsg is exercised.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/rpc/methods/state.rs`:
- Line 1274: The RPC docs still claim a lookup is always returned but the actual
return type is Option<MessageLookup> (type Ok = Option<MessageLookup>), so
update the inline RPC descriptions for the methods that use MessageLookup to
state they return either a MessageLookup or null when the item is missing;
locate the doc comments adjacent to the declaration using MessageLookup (the
block containing "type Ok = Option<MessageLookup>;") and the other similar
occurrence around the second use (near the other Option<MessageLookup>
declaration) and change phrasing to explicitly mention "null on misses" or
equivalent nullable wording.

---

Outside diff comments:
In `@src/tool/subcommands/api_cmd/api_compare_tests.rs`:
- Around line 1237-1249: Add a test invocation that exercises the "not-found /
null" path by creating a StateSearchMsg request whose lookback/tipset window
excludes the sampled msg_cid and then validate that the response is null; for
example, add a validate_message_lookup(StateSearchMsg::request((None.into(),
msg_cid, /* very small lookback or older tipset */ 0, true))?) (or a similar
StateSearchMsg::request with parameters that put the message outside the window)
alongside the existing validate_message_lookup calls so the code that handles
the None/null result for StateSearchMsg is exercised.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 1abfe056-ebc8-4a9e-a695-faee020714ce

📥 Commits

Reviewing files that changed from the base of the PR and between 533def4 and 7d56c35.

⛔ Files ignored due to path filters (2)
  • src/rpc/snapshots/forest__rpc__tests__rpc__v0.snap is excluded by !**/*.snap
  • src/rpc/snapshots/forest__rpc__tests__rpc__v1.snap is excluded by !**/*.snap
📒 Files selected for processing (3)
  • mise.toml
  • src/rpc/methods/state.rs
  • src/tool/subcommands/api_cmd/api_compare_tests.rs

Comment thread src/rpc/methods/state.rs
@hanabi1224 hanabi1224 force-pushed the hm/fix-StateSearchMsg branch from 7d56c35 to 3c60922 Compare March 30, 2026 06:20
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 30, 2026

Codecov Report

❌ Patch coverage is 75.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 63.82%. Comparing base (b074d6f) to head (e002338).
⚠️ Report is 2 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/rpc/methods/state.rs 75.00% 2 Missing ⚠️
Additional details and impacted files
Files with missing lines Coverage Δ
src/rpc/methods/state.rs 46.25% <75.00%> (+0.05%) ⬆️

... and 8 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b074d6f...e002338. Read the comment docs.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Member

@LesnyRumcajs LesnyRumcajs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a changelog entry, it's a user-facing change.

@hanabi1224 hanabi1224 requested a review from LesnyRumcajs March 30, 2026 08:28
@hanabi1224
Copy link
Copy Markdown
Contributor Author

Let's add a changelog entry, it's a user-facing change.

@LesnyRumcajs changelog updated

@hanabi1224 hanabi1224 enabled auto-merge March 30, 2026 08:30
@hanabi1224 hanabi1224 added this pull request to the merge queue Mar 30, 2026
Merged via the queue into main with commit f0673df Mar 30, 2026
45 checks passed
@hanabi1224 hanabi1224 deleted the hm/fix-StateSearchMsg branch March 30, 2026 10:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

RPC requires calibnet RPC checks to run on CI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants