-
-
Notifications
You must be signed in to change notification settings - Fork 711
Improve metadata flushing efficiency by collapsing operations (fix #2104) #2106
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
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: 3779960 The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
WalkthroughThe changes introduce a new Note ⚡️ AI Code Reviews for VS Code, Cursor, WindsurfCodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback. 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
⏰ Context from checks skipped due to timeout of 90000ms (25)
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🧹 Nitpick comments (1)
packages/core/test/standardMetadataManager.test.ts (1)
284-1087
: Exceptional test suite for operation collapsing!This test suite demonstrates excellent software engineering practices:
- Comprehensive coverage of both common scenarios and edge cases
- Property-based testing approach ensuring collapsed operations maintain correctness
- Clear test names and structure
- Thorough validation of the fix for issue Metadata flushing can fail if there are too many operations #2104
Consider breaking this large test suite into separate files for better organization (e.g.,
collapseOperations.test.ts
for the pure logic tests and keeping integration tests here).
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
apps/webapp/app/routes/api.v1.runs.$runId.metadata.ts
(1 hunks)apps/webapp/app/services/metadata/updateMetadata.server.ts
(1 hunks)packages/core/src/v3/runMetadata/manager.ts
(6 hunks)packages/core/src/v3/runMetadata/operations.ts
(1 hunks)packages/core/test/standardMetadataManager.test.ts
(2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (3)
packages/core/src/v3/runMetadata/operations.ts (1)
packages/core/src/v3/schemas/common.ts (2)
RunMetadataChangeOperation
(53-60)RunMetadataChangeOperation
(62-62)
packages/core/src/v3/runMetadata/manager.ts (2)
packages/core/src/v3/runMetadata/types.ts (1)
RunMetadataUpdater
(5-18)packages/core/src/v3/runMetadata/operations.ts (1)
collapseOperations
(169-236)
packages/core/test/standardMetadataManager.test.ts (1)
packages/core/src/v3/runMetadata/operations.ts (2)
applyMetadataOperations
(10-130)collapseOperations
(169-236)
🪛 Biome (1.9.4)
packages/core/src/v3/runMetadata/operations.ts
[error] 186-187: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.
The declaration is defined in this switch clause:
Unsafe fix: Wrap the declaration in a block.
(lint/correctness/noSwitchDeclarations)
packages/core/src/v3/runMetadata/manager.ts
[error] 75-75: This aliasing of this is unnecessary.
Arrow functions inherits this
from their enclosing scope.
Safe fix: Use this instead of an alias.
(lint/complexity/noUselessThisAlias)
⏰ Context from checks skipped due to timeout of 90000ms (25)
- GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (10, 10)
- GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (9, 10)
- GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (8, 10)
- GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (7, 10)
- GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (6, 10)
- GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (5, 10)
- GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (4, 10)
- GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (3, 10)
- GitHub Check: units / internal / 🧪 Unit Tests: Internal (8, 8)
- GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (2, 10)
- GitHub Check: units / internal / 🧪 Unit Tests: Internal (7, 8)
- GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (1, 10)
- GitHub Check: units / internal / 🧪 Unit Tests: Internal (6, 8)
- GitHub Check: units / internal / 🧪 Unit Tests: Internal (5, 8)
- GitHub Check: units / internal / 🧪 Unit Tests: Internal (4, 8)
- GitHub Check: units / packages / 🧪 Unit Tests: Packages (1, 1)
- GitHub Check: units / internal / 🧪 Unit Tests: Internal (3, 8)
- GitHub Check: units / internal / 🧪 Unit Tests: Internal (2, 8)
- GitHub Check: units / internal / 🧪 Unit Tests: Internal (1, 8)
- GitHub Check: e2e / 🧪 CLI v3 tests (windows-latest - pnpm)
- GitHub Check: e2e / 🧪 CLI v3 tests (windows-latest - npm)
- GitHub Check: e2e / 🧪 CLI v3 tests (ubuntu-latest - pnpm)
- GitHub Check: e2e / 🧪 CLI v3 tests (ubuntu-latest - npm)
- GitHub Check: typecheck / typecheck
- GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (13)
packages/core/src/v3/runMetadata/operations.ts (1)
132-236
: LGTM! Well-designed function with comprehensive documentation.The
collapseOperations
function effectively addresses the payload size optimization goal by intelligently merging operations while preserving semantic correctness. The documentation is excellent and provides clear examples.🧰 Tools
🪛 Biome (1.9.4)
[error] 186-187: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.The declaration is defined in this switch clause:
Unsafe fix: Wrap the declaration in a block.
(lint/correctness/noSwitchDeclarations)
apps/webapp/app/services/metadata/updateMetadata.server.ts (1)
384-384
: Great addition for debugging and observability.Including the operations array in the debug logs provides valuable insight into the specific metadata changes being applied, which will be helpful for troubleshooting and monitoring.
packages/core/src/v3/runMetadata/manager.ts (4)
7-7
: LGTM! Proper import of the collapseOperations function.The import correctly brings in the new
collapseOperations
function alongside the existingapplyMetadataOperations
import.
356-366
: Excellent integration of operation collapsing in flush method.The implementation correctly applies
collapseOperations
to all three operation arrays before sending them to the API, which will significantly reduce payload sizes and improve performance.
422-425
: Consistent application of operation collapsing in stopAndReturnLastFlush.Good consistency in applying
collapseOperations
to all operation arrays when returning the last flush data, ensuring the same optimization benefits.
75-75
: Static analysis false positive -this
aliasing is necessary here.The static analysis tool suggests removing the
this
aliasing, but this is actually necessary because theself
variable is used within closure functions wherethis
context could change. The current implementation is correct.🧰 Tools
🪛 Biome (1.9.4)
[error] 75-75: This aliasing of this is unnecessary.
Arrow functions inherits
this
from their enclosing scope.
Safe fix: Use this instead of an alias.(lint/complexity/noUselessThisAlias)
packages/core/test/standardMetadataManager.test.ts (7)
6-6
: LGTM!The import correctly brings in the necessary functions for testing operation collapsing functionality.
285-304
: Well-structured test for increment collapsing!The test correctly verifies that multiple increment operations are collapsed into a single operation with the summed value.
306-324
: Good test for set operation collapsing!The test correctly verifies that only the last set operation is retained when multiple sets target the same key.
350-378
: Excellent test for append operation preservation!The test correctly verifies that append operations are not collapsed, maintaining their order which is crucial for list operations.
380-430
: Comprehensive test for mixed operations!The test effectively covers the interaction between different operation types. The comment correctly explains why delete operations on non-existent keys are not queued.
591-815
: Excellent comprehensive sanity checks!These tests provide crucial verification that collapsed operations produce identical results to the original operations. The large-scale test (lines 756-814) effectively simulates the original issue scenario with 1000 operations, ensuring the solution scales properly.
817-1086
: Outstanding edge case coverage!This comprehensive suite of edge case tests demonstrates exceptional attention to detail. The tests cover:
- Numeric edge cases (zero, negative, MAX_SAFE_INTEGER)
- String edge cases (special characters, unicode, very long keys)
- Type handling (null, undefined, mixed types, type changes)
- Complex data structures (deeply nested paths, empty collections)
- Conflicting operations
This level of testing significantly reduces the risk of bugs in production.
This PR implements "operation collapsing" client-side to prevent run metadata flush failures because of too-large of a request body. Many operations, especially increment and decrement on a single key, can easily be "collapsed" into a single operation.