-
Notifications
You must be signed in to change notification settings - Fork 134
fix(actor-kv): fix listing keys #3484
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(actor-kv): fix listing keys #3484
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
3 Skipped Deployments
|
|
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.
How to use the Graphite Merge QueueAdd the label merge-queue to this PR to add it to the merge queue. You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
Code Review: Fix listing keys in actor-kvOverall, this is a solid PR that addresses a critical bug in the KV list operation. The implementation is well-tested and the fix is logical. StrengthsExcellent Test Coverage
Clear Documentation
Correct Bug Fix
Issues and Concerns1. Potential Bug in Prefix Query (lib.rs:336-354)The prefix query assumes tuple encoding adds a trailing 0 byte: if let Some(&0) = start.last() {
start.pop();
}This assumption should be verified with tests that check the encoded bytes directly. 2. 0xFF Byte HandlingTest acknowledges but doesn't fix the issue where keys with 0xFF bytes may not match prefixes correctly. This should either be:
3. Import Style Violation (lib.rs:3)
4. Test AssertionsCould include actual values in assertion messages for easier debugging. RecommendationsMust fix:
Should fix: Nice to have: This is a good PR that fixes an important bug. After addressing the glob import and clarifying the 0xFF behavior, it will be ready to merge! |
4e7d4d5 to
fa4f976
Compare
Code ReviewSummaryThis PR fixes a critical bug in the actor-kv package's key listing functionality and adds comprehensive test coverage. The changes address issues with prefix queries and list limiting behavior. ✅ Positive Aspects
🐛 Potential IssuesCritical: Prefix Query Logic May Be IncorrectIn let mut start = subspace.pack(&ListKeyWrapper(prefix.key.clone()));
// Remove the trailing 0 byte that tuple encoding adds to strings
if let Some(&0) = start.last() {
start.pop();
}
let mut end = start.clone();
end.push(0xFF);Problem: This assumes tuple encoding always adds a trailing 0 byte, but:
Recommendation:
The test at line 253 in Medium: Comment Inconsistency in entry.rsLine 63 in Ok((&input[0..0], v))This returns an empty slice by taking a zero-length slice from the input. While this works, it's unusual and may be confusing. The comment "Parses key in first position, ignores the rest" doesn't clearly explain why we return an empty remaining slice. Consider adding a comment explaining this is intentional to consume all remaining input. 🔍 Security Considerations
⚡ Performance Considerations
🧪 TestingStrengths:
Suggestions:
📝 Style & Convention NotesPer CLAUDE.md:
🎯 RecommendationsMust Fix Before Merge:
Nice to Have:
Overall AssessmentThis is a high-quality PR that fixes an important bug and adds excellent test coverage. The main concern is the prefix query implementation which needs verification/clarification. Once that's addressed, this should be ready to merge. Approval Status: Approve with minor concerns (pending verification of prefix query logic) Review generated by Claude Code |
Code ReviewOverviewThis PR fixes a critical bug in the actor KV store's list operation where the limit was not being enforced correctly, and adds comprehensive test coverage. The changes are well-structured and address real issues with prefix queries and limit handling. ✅ Strengths
🔍 Issues & ConcernsCritical: Potential Prefix Query BugLocation: engine/packages/actor-kv/src/lib.rs:336-355 The prefix query implementation has concerning logic where it attempts to remove a trailing 0 byte from the packed key. This is problematic because:
Recommendation:
Minor Issues
📊 Summary
Overall: Approve with recommendations. The core bug fix is correct and the test coverage is excellent. However, the prefix query implementation should be reviewed carefully before merging. |
fa4f976 to
4630e59
Compare
PR Review: fix(actor-kv): fix listing keysSummaryThis PR fixes issues with key listing in the actor-kv package by addressing limit handling and prefix query range construction. The changes include important bug fixes and comprehensive test coverage. ✅ Strengths
🔍 Code Quality Issues1. Potential Bug: Incorrect Trailing Byte Removal (lib.rs:346-349)let mut start = subspace.pack(&ListKeyWrapper(prefix.key.clone()));
// Remove the trailing 0 byte that tuple encoding adds to strings
if let Some(&0) = start.last() {
start.pop();
}Issue: This assumes tuple encoding always adds a trailing Recommendation:
2. Unnecessary Clone (lib.rs:345)let mut start = subspace.pack(&ListKeyWrapper(prefix.key.clone()));The prefix key is cloned here, but then cloned again in the tuple encoding. Consider if this can be optimized. 3. Magic Number Without Explanation (lib.rs:352)end.push(0xFF);While the comment explains the general approach, it doesn't explain why 🔒 Security ConsiderationsNo security issues identified. The code properly validates inputs through existing ⚡ Performance Considerations
📝 Style & Convention Issues1. Import Style Violation (lib.rs:1)use std::result::Result::Ok;According to CLAUDE.md, glob imports should be avoided, but this is importing a specific variant from 2. Comment Formatting (lib.rs:337-343)The multi-line comment is good, but could be formatted as a doc comment ( 🧪 Test Coverage AnalysisExcellent coverage overall, but consider adding:
🎯 RecommendationsBefore merging:
Future improvements (not blocking):
📊 Overall AssessmentStrong PR with critical bug fixes and exceptional test coverage. The limit handling fix is important and correct. The prefix query fix appears sound, though the trailing byte removal needs verification. Once the minor issues above are addressed, this should be good to merge. The comprehensive test suite is a significant value-add that will prevent regressions. Suggested Action: Request clarification on the trailing byte removal logic, then approve with minor comments. |
4630e59 to
fa4f976
Compare
Code Review for PR #3484: fix(actor-kv): fix listing keysSummaryThis PR fixes a critical bug in the KV listing functionality and adds comprehensive test coverage. The changes address both the limit enforcement logic and prefix query range construction. Positive AspectsExcellent Test Coverage
Clear Documentation
Correct Bug Fixes
Issues & Concerns1. Potential Logic Issue in Prefix Query (Medium Priority)In let mut start = subspace.pack(&ListKeyWrapper(prefix.key.clone()));
// Remove the trailing 0 byte that tuple encoding adds to strings
if let Some(&0) = start.last() {
start.pop();
}Problem: This assumes that tuple encoding always adds a trailing 0 byte to byte strings, but this may not be universally true for all byte sequences. The comment says "tuple encoding adds to strings" but Recommendation:
2. Incomplete Test Coverage for Prefix Edge Case (Low Priority)The test in // Note: 0xFF in byte strings causes issues with prefix matching due to tuple encoding.
// The key "key\xFF" may not match the prefix "key" depending on how the range is constructed.
assert!(
prefix_match.len() >= 3,
"should match at least 3 keys with prefix 'key'",
);Problem: The test accepts this as expected behavior but doesn't verify the actual behavior. If this is a known limitation, it should be:
Recommendation: Either fix the 0xFF handling or add explicit documentation about this limitation. 3. Error Handling: Glob Import from anyhow (Style Violation)In use anyhow::*;Problem: The CLAUDE.md explicitly states:
Recommendation: Change to: use anyhow::{bail, ensure, Context, Result};4. Potential Performance Issue (Low Priority)In the prefix query implementation (
Recommendation: Consider pre-allocating the end vector with capacity or using unsafe operations if this becomes a hot path. 5. Test Dependencies (Question)The test files add several dev dependencies including Question: Are these dependencies already used elsewhere in the workspace, or are they new? Ensure they're added to workspace dependencies per CLAUDE.md guidelines. Minor Issues
Security ConsiderationsNo security issues identified. The changes don't introduce new attack vectors, and the limit enforcement actually improves resource management. RecommendationsBefore Merge:
Future Improvements:
ConclusionThis is a solid bug fix with excellent test coverage. The main concerns are the anyhow glob import (CLAUDE.md violation) and verification of the tuple encoding assumptions. The prefix query fix appears correct but needs verification that the trailing byte removal is safe for all inputs. Overall: Approve with minor changes requested ✅ |
fa4f976 to
4630e59
Compare
PR Review: fix(actor-kv): fix listing keysSummaryThis PR fixes a critical bug in the KV listing functionality and adds comprehensive test coverage. The changes improve the correctness of prefix queries and limit handling. Code Quality & Best Practices✅ Strengths
🔍 Potential Issues1. Prefix Query Implementation Concern (
|
4630e59 to
fa4f976
Compare
Code Review: Fix actor-kv list operationsI've reviewed this PR which fixes key listing functionality in the actor-kv package. Here's my feedback: Overall Assessment✅ LGTM - This is a solid bug fix with excellent test coverage. The changes correctly address prefix query issues and limit handling bugs. Code Quality & Best PracticesStrengths:
Minor suggestions:
Bug FixesCritical fixes identified:
Potential Issuesif let Some(&0) = start.last() {
start.pop();
}This assumes the last byte is 0, but what if
Performance Considerations✅ Good:
Potential optimization: let mut start = subspace.pack(&ListKeyWrapper(prefix.key.clone()));This clones the prefix key. Consider whether the clone is necessary or if you can use a reference. Security Concerns✅ No security issues identified
Test Coverage✅ Excellent test coverage:
Suggestions:
Documentation✅ Well documented:
Suggestion: RecommendationsBefore merging:
After merging:
Summary: This is a high-quality bug fix with excellent tests. The core logic is correct and the fixes address real issues. The minor suggestions above are optional improvements that would enhance code clarity and robustness. |
d34ad3e to
44b3d81
Compare
Pull Request Review: fix(actor-kv): fix listing keysSummaryThis PR fixes critical issues with KV key listing operations, specifically addressing prefix query bugs and limit handling edge cases. The changes include important bug fixes and comprehensive test coverage. Positive Aspects1. Critical Bug Fixes ✅
2. Excellent Documentation 📚
3. Comprehensive Test Coverage 🧪The test suite is exemplary:
This level of testing significantly reduces regression risk. Issues and Concerns1. Potential Prefix Query Bug with 0xFF bytes
|
Code ReviewThis PR fixes a critical bug in the KV listing functionality and adds comprehensive test coverage. Overall, the changes are well-implemented and thoroughly tested. Here's my detailed review: Positive Aspects1. Critical Bug Fix (lib.rs:175-215)
2. Prefix Query Fix (lib.rs:336-354)
3. Excellent Test Coverage
4. Documentation Improvements
Concerns and Suggestions1. Tuple Encoding Edge Case (lib.rs:344-347) // Remove the trailing 0 byte that tuple encoding adds to strings
if let Some(&0) = start.last() {
start.pop();
}This assumes tuple encoding always adds a trailing 0 byte for strings. However:
Recommendation: Add a comment explaining that 2. Test Dependencies (Cargo.toml)
This follows the project's dependency management pattern correctly. 3. Magic Number in Tests (list_edge_cases.rs:261-263) // Note: 0xFF in byte strings causes issues with prefix matching due to tuple encoding.
// The key "key\xFF" may not match the prefix "key" depending on how the range is constructed.This is good documentation, but the assertion then uses assert!(prefix_match.len() >= 3, "should match at least 3 keys...");Recommendation: Make the test deterministic by either:
4. Error Handling Security ConsiderationsNo security issues identified:
Performance ConsiderationsPositive:
No concerns: The changes don't introduce performance regressions. SummaryApproval: ✅ Approved with minor suggestions The core bug fixes are correct and well-tested. The suggestions above are minor improvements for code clarity and test determinism, not blockers. Key strengths:
Minor improvements suggested:
Great work on the comprehensive testing! |
44b3d81 to
d34ad3e
Compare
d4f63d9 to
6d04024
Compare
PR Review: Fix actor-kv key listingThis PR fixes a critical bug in the actor-kv package's key listing functionality and adds comprehensive test coverage. Strengths
Issues and Concerns1. Limit handling logic (lib.rs:175-179, 208-216): When limit is reached, current_entry is set to None and loop breaks. The second check at 208-216 becomes redundant. Document whether discarding the partially-read entry is intended behavior. 2. Security - Prefix query edge cases (lib.rs:345-352): Only removes last 0x00 byte from prefix. No validation for prefixes with only null bytes or other edge cases. Add validation and document behavior with special bytes. 3. Performance - Clone overhead: Multiple unnecessary clones in transactions (list_range, subspace). Consider using Arc for read-heavy operations. 4. Code style (lib.rs:1): 'use std::result::Result::Ok;' shadows prelude Result. Per CLAUDE.md, avoid such imports. Remove or justify. 5. Test reliability: portpicker has race condition - port could be taken between pick and use. Add error handling/retry logic. 6. EntryBuilder::append_chunk: Silently ignores out-of-order chunks. Add comment explaining why. RecommendationsHigh Priority:
Medium Priority:
Low Priority:
AssessmentCode Quality: 4/5 High-quality PR that fixes important bugs with excellent test coverage. Main concerns are prefix query edge cases and minor code style issues. Recommendation: Approve with minor revisions |
Code Review for PR #3484: fix(actor-kv): fix listing keysSummaryThis PR fixes key listing functionality in the actor-kv package by addressing limit handling bugs and correcting prefix query range construction. The changes include implementation fixes and comprehensive test coverage. Positive AspectsExcellent Test Coverage
Clear Documentation
Critical Bug Fixes
Issues & ConcernsCritical: Prefix Query Implementation FlawLocation: The code assumes tuple encoding always adds a trailing 0 byte, but this is implementation-specific and fragile. This breaks the abstraction layer by manually manipulating encoded tuples and may fail with different key encodings or universaldb changes. Recommendation: Use a more robust approach that increments the last non-0xFF byte or extends with 0xFF, rather than assuming internal encoding details. Medium: Import Style ViolationLocation: use anyhow::*;Issue: CLAUDE.md explicitly states not to glob import from anyhow. Fix Required: use anyhow::{Result, Context, bail, ensure};Medium: Test Infrastructure ConcernsIssues:
Medium: Potential Performance IssueAfter breaking at the limit (lib.rs:175-179), partially-built entries with large chunked values may have wasted DB reads. Security & Performance
Recommendations SummaryMust Fix (Blocking)
Should Fix (High Priority)
Nice to Have
ConclusionThis PR makes important correctness fixes, particularly the limit handling bug. Test coverage is exceptional. However, the prefix query implementation needs reconsideration as it relies on fragile assumptions about internal encoding. The glob import also violates project conventions. Recommendation: Request changes to address the prefix query implementation and import style before merging. |
Code ReviewThis PR fixes key listing functionality in the actor-kv package. Overall, the implementation looks solid with comprehensive test coverage. Here are my detailed findings: ✅ Strengths1. Excellent Test Coverage
2. Critical Bug Fix - Limit HandlingThe changes to
3. Improved DocumentationThe added documentation in
4. Prefix Query FixThe prefix query implementation (
🔍 Potential Issues1. Prefix Query Edge Case - 0xFF Handling (Medium Priority)let mut end = start.clone();
end.push(0xFF);If the prefix already ends with 0xFF bytes, this approach may not create the correct upper bound. Consider this scenario:
The test file acknowledges this (
2. Error Handling - Empty Values (Low Priority)In ensure!(!self.value.is_empty(), "empty value at key");This is likely intentional, but:
3. Missing Constants Definition (Low Priority)
4. Potential Performance Issue - Prefix Query (Low Priority)The prefix query implementation ( if let Some(&0) = start.last() {
start.pop();
}This assumes tuple encoding adds a trailing 0. However:
5. Test Dependencies (Low Priority)The new tests add several dev-dependencies:
🔒 Security Considerations✅ No security issues identified
🚀 Performance Considerations1. Prefix Query PerformanceThe manual range construction for prefix queries should perform well, but:
2. Limit Implementation✅ The limit check is efficient (O(1)) and placed correctly to avoid unnecessary processing 📝 Code QualityAdherence to CLAUDE.md Standards:✅ Error Handling: Properly returns
Code Style:✅ Follows existing patterns in the codebase 🧪 Testing Recommendations
✏️ Minor Suggestions
SummaryThis is a well-implemented fix with excellent test coverage. The main concerns are:
The core fix for limit handling is correct and the comprehensive tests give high confidence in the implementation. Recommendation: ✅ Approve with minor suggestions Great work on the thorough testing! The edge case coverage is particularly impressive. |
6d04024 to
d4f63d9
Compare
PR Review: fix(actor-kv): fix listing keysSummaryThis PR fixes key listing functionality in the actor-kv package by addressing limit handling and prefix query range construction. The changes include bug fixes to the core listing logic and comprehensive test coverage. Code Quality & Best PracticesStrengths✅ Excellent documentation - The added comments in key.rs clearly explain the difference between KeyWrapper and ListKeyWrapper and when to use each Areas for Improvement1. Limit Check Logic (Critical Fix ✓) However, there's a subtle issue: the duplicate check at lib.rs:209-216 may be redundant. When keys.len() >= limit at line 176, we set current_entry = None and break. This means current_entry will always be None after the loop if the limit was hit, making the second check unnecessary. 2. Prefix Query Implementation (lib.rs:336-354)
Test coverage note: Your test at list_edge_cases.rs:266-277 acknowledges the 0xFF issue in a comment, which is good awareness. Potential Bugs1. Prefix Query Edge Cases (Medium Priority)
Recommendation: Add validation in utils::validate_list_query or add a comment documenting the limitations. Performance Considerations1. Unnecessary Clone in Prefix Query 2. Stream Processing Security Concerns✅ No security issues identified. The changes:
Test CoverageExcellent - The PR adds 669 lines of comprehensive tests covering:
Minor Issues1. Import Style (lib.rs:3) Current: use anyhow::*;Should be: use anyhow::{Result, bail, Context};2. Test Logging Setup Duplication SummaryThis is a solid PR that fixes real bugs and adds excellent test coverage. Critical Fixes ✅:
Recommended Changes:
The test coverage is exceptional and demonstrates thorough consideration of edge cases. Great work! 🎯 |
44b3d81 to
d34ad3e
Compare
d4f63d9 to
6d04024
Compare
Code Review: fix(actor-kv): fix listing keysSummaryThis PR fixes key listing functionality in the actor-kv package and adds comprehensive test coverage. The changes address issues with prefix queries and limit handling in the Positive Findings ✓Excellent Test Coverage
Bug FixesThe PR correctly fixes two important bugs:
Documentation Improvements
Issues & Concerns🔴 Critical: Potential Security Issue - Incorrect Byte Stripping in Prefix QueryLocation: The prefix query implementation manually strips the trailing 0 byte and appends 0xFF without proper validation: let mut start = subspace.pack(&ListKeyWrapper(prefix.key.clone()));
// Remove the trailing 0 byte that tuple encoding adds to strings
if let Some(&0) = start.last() {
start.pop();
}
let mut end = start.clone();
end.push(0xFF);Problem: If Example scenario:
Recommendation: The comment claims "tuple encoding adds a terminating 0 byte to strings" but 🟡 Code Quality Issues1. Import Anti-Pattern (lib.rs:1)use std::result::Result::Ok;This is unusual and potentially confusing. According to CLAUDE.md, you should not glob import from anyhow and should import individual types. This pattern violates that principle. Recommendation: Remove this import and use 2. Inconsistent Error Handling (lib.rs:203)bail!("unexpected sub key");This does not follow the project's custom error system described in CLAUDE.md. Should use Recommendation: Define proper error types: #[derive(RivetError)]
#[error("actor_kv", "unexpected_sub_key", "Unexpected subkey encountered while listing keys")]
struct UnexpectedSubKey;3. Magic Number (lib.rs:141)let limit = limit.unwrap_or(16384);Should be a named constant like Recommendation: const DEFAULT_LIST_LIMIT: usize = 16384;🟡 Test Issues1. Test Isolation ProblemBoth test files call Recommendation: let _ = tracing_subscriber::fmt()
.with_max_level(tracing::Level::INFO)
.with_target(false)
.try_init();2. Hardcoded Test URLsTests use hardcoded 🔵 Performance Considerations1. Unnecessary Clone (lib.rs:345)let mut start = subspace.pack(&ListKeyWrapper(prefix.key.clone()));Since 2. Stream Buffering Commented Out (lib.rs:71)The 🔵 Documentation Gaps
RecommendationsHigh Priority (Must Fix)
Medium Priority (Should Fix)
Low Priority (Nice to Have)
Test Coverage AssessmentExcellent coverage overall! Tests are thorough and well-structured. Consider adding:
Overall AssessmentStrong PR with important bug fixes and comprehensive tests. Main concern is the potential logic error in prefix query byte handling that could cause incorrect results. The test coverage is exemplary. Recommendation: |
6d04024 to
d4f63d9
Compare
Code Review for PR #3484: fix(actor-kv): fix listing keysSummaryThis PR fixes key listing functionality in the actor-kv package and adds comprehensive test coverage. The changes address issues with prefix queries and limit enforcement in the list() function. ✅ Strengths1. Excellent Test Coverage
2. Clear Documentation
3. Correct Limit Enforcement 🔍 Issues & Concerns1. Potential Bug in Prefix Query Implementation (CRITICAL) In list_query_range() at lines 345-354, the prefix query implementation has a problematic assumption - it removes trailing 0 bytes assuming tuple encoding adds them to strings, but:
Example failure case: A prefix of [0x61, 0x00] would have its trailing 0 removed, searching only for [0x61] and incorrectly matching keys like [0x61, 0x62]. Recommendation: Review the tuple encoding format for Bytes type. If ListKeyWrapper already omits the NIL terminator, you may not need to remove anything. Add a test case specifically for prefixes ending in 0x00. 2. Inconsistent Error Handling Pattern Line 1 uses 'use std::result::Result::Ok' which is a confusing pattern that shadows the Ok variant. While not a glob import from anyhow, it still violates the spirit of the guideline. 3. Test File Missing Error Cases The test files don't verify error conditions like keys/values exceeding MAX_KEY_SIZE/MAX_VALUE_SIZE, too many keys (MAX_KEYS), or payloads exceeding MAX_PUT_PAYLOAD_SIZE. 4. Performance Consideration The test at lines 207-230 (list_edge_cases.rs) has a comment acknowledging that prefix matching with 0xFF may have issues. This should be documented in the main code, not just tests. 🎯 Minor Issues5. Code Duplication: The entry-building logic appears in both get() and list() with very similar patterns. Consider extracting this into a shared helper function. 6. Misleading Comment: Line 347's comment mentions strings but the implementation works with Bytes. 🔒 SecurityNo major security concerns identified. The validation functions prevent oversized keys/values, which is good. 📊 PerformanceThe changes don't introduce obvious performance regressions. The limit check happens at the right time to avoid unnecessary processing. ✨ Recommendations SummaryMust Fix:
Should Fix: Nice to Have: ConclusionThe PR makes important fixes to list limit handling and adds excellent test coverage. However, the prefix query implementation needs careful review as it may have a critical bug with byte sequence handling. Once the prefix query issue is addressed, this will be a solid improvement to the codebase. Overall: Approve with changes requested - fix the prefix query implementation before merging. |
Merge activity
|

No description provided.