Skip to content

fix(projections): reject oversized definitions#422

Merged
yordis merged 1 commit into
masterfrom
yordis/fix-projection-definition-size
Jul 6, 2026
Merged

fix(projections): reject oversized definitions#422
yordis merged 1 commit into
masterfrom
yordis/fix-projection-definition-size

Conversation

@yordis

@yordis yordis commented Jul 6, 2026

Copy link
Copy Markdown
Member
  • Projection management requests should fail promptly when the persisted definition cannot fit in a log record.
  • Callers need a deterministic validation error instead of waiting for a deadline after the management queue loses the reply path.
  • Related projection operations should preserve their specific gRPC failure semantics instead of collapsing expected failures into unknown responses.

@cursor

cursor Bot commented Jul 6, 2026

Copy link
Copy Markdown

PR Summary

Medium Risk
Changes projection create/update persistence and gRPC error handling on management paths; behavior is more correct but alters failure modes clients may have relied on.

Overview
Projection management now rejects definitions whose serialized ProjectionUpdated record would exceed TFConsts.EffectiveMaxLogRecordSize, instead of attempting a log write and leaving callers without a reply.

ManagedProjection uses TryCreatePersistedStateEvent before persisting state (create/update/config paths). On failure it skips the write, faults the projection, disposes the core projection when already created, and replies with a new RecordTooLarge management message.

gRPC projection operations handle OperationFailed (including RecordTooLarge) via MapFailure, mapping oversized definitions to InvalidArgument and preserving distinct status codes for conflict and authorization failures. Tests cover post and update with oversized queries.

Reviewed by Cursor Bugbot for commit 75b79a7. Bugbot is set up for automated code reviews on this repo. Configure here.

@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@yordis, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 40 seconds

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 394df997-f5c8-4691-a729-48bad955bd52

📥 Commits

Reviewing files that changed from the base of the PR and between 68e6848 and 75b79a7.

📒 Files selected for processing (12)
  • src/EventStore.Projections.Core.Tests/Services/projections_manager/when_posting_a_projection_with_oversized_definition.cs
  • src/EventStore.Projections.Core.Tests/Services/projections_manager/when_updating_a_projection_with_oversized_definition.cs
  • src/EventStore.Projections.Core/Messages/ProjectionManagementMessage.cs
  • src/EventStore.Projections.Core/Services/Grpc/ProjectionManagement.Abort.cs
  • src/EventStore.Projections.Core/Services/Grpc/ProjectionManagement.Create.cs
  • src/EventStore.Projections.Core/Services/Grpc/ProjectionManagement.Delete.cs
  • src/EventStore.Projections.Core/Services/Grpc/ProjectionManagement.Disable.cs
  • src/EventStore.Projections.Core/Services/Grpc/ProjectionManagement.Enable.cs
  • src/EventStore.Projections.Core/Services/Grpc/ProjectionManagement.Reset.cs
  • src/EventStore.Projections.Core/Services/Grpc/ProjectionManagement.Update.cs
  • src/EventStore.Projections.Core/Services/Grpc/ProjectionManagement.cs
  • src/EventStore.Projections.Core/Services/Management/ManagedProjection.cs

Walkthrough

This PR adds a RecordTooLarge projection management message and enforces size validation of persisted projection definitions in ManagedProjection against TFConsts.EffectiveMaxLogRecordSize. gRPC handlers now map OperationFailed variants to appropriate RpcException status codes. Tests cover oversized post/update scenarios.

Changes

Oversized projection definition handling

Layer / File(s) Summary
RecordTooLarge message contract
src/EventStore.Projections.Core/Messages/ProjectionManagementMessage.cs
Adds RecordTooLarge message type deriving from OperationFailed, carrying a failure reason.
Persisted state size validation
src/EventStore.Projections.Core/Services/Management/ManagedProjection.cs
Introduces TryCreatePersistedStateEvent size check and FailPersistedStateWrite failure/fault path used in UpdateConfig handling and WriteStartOrLoadStopped, replacing the old unconditional event creator.
gRPC failure mapping and propagation
src/EventStore.Projections.Core/Services/Grpc/ProjectionManagement.cs, ProjectionManagement.Abort.cs, ...Create.cs, ...Delete.cs, ...Disable.cs, ...Enable.cs, ...Reset.cs, ...Update.cs
Adds MapFailure helper translating OperationFailed variants (RecordTooLarge, Conflict, NotAuthorized, others) into RpcException status codes, and wires OperationFailed handling into all projection management gRPC operations.
Tests for oversized post/update flows
src/EventStore.Projections.Core.Tests/Services/projections_manager/when_posting_a_projection_with_oversized_definition.cs, when_updating_a_projection_with_oversized_definition.cs
Adds fixtures asserting RecordTooLarge failures, absence of unwanted ProjectionUpdated writes, and projection faulting for both post and update scenarios.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant ProjectionManagement
  participant ManagedProjection
  participant Stream as ProjectionsStateStream

  Client->>ProjectionManagement: Post/Update projection with oversized query
  ProjectionManagement->>ManagedProjection: forward command
  ManagedProjection->>ManagedProjection: TryCreatePersistedStateEvent (check size)
  alt size exceeds EffectiveMaxLogRecordSize
    ManagedProjection->>ManagedProjection: FailPersistedStateWrite (fault projection)
    ManagedProjection-->>ProjectionManagement: OperationFailed(RecordTooLarge)
    ProjectionManagement-->>Client: RpcException(InvalidArgument)
  else size within limit
    ManagedProjection->>Stream: WriteEvents(ProjectionUpdated)
    ManagedProjection-->>ProjectionManagement: Updated
    ProjectionManagement-->>Client: success
  end
Loading

Poem

A rabbit typed a query grand,
too big for logs to understand,
"Too Large!" the record cried out loud,
faulted gently, no more proud.
Now gRPC wraps it neat and small — 🐇
tests confirm it, one and all!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title matches the main change: rejecting oversized projection definitions.
Description check ✅ Passed The description directly matches the changes: immediate failure for oversized definitions and preserved gRPC failure semantics.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch yordis/fix-projection-definition-size

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.

❤️ Share

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/EventStore.Projections.Core.Tests/Services/projections_manager/when_updating_a_projection_with_oversized_definition.cs (1)

18-30: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Duplicated setup across both oversized-definition test files.

Given(), the _oversizedQuery field, and the faulted-status test are identical to when_posting_a_projection_with_oversized_definition.cs. Consider extracting a shared base fixture for the common setup/assertions to avoid drift between the two scenarios.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@src/EventStore.Projections.Core.Tests/Services/projections_manager/when_updating_a_projection_with_oversized_definition.cs`
around lines 18 - 30, The oversized-definition projection tests duplicate the
same setup and assertion logic across this fixture and
when_posting_a_projection_with_oversized_definition, so extract the shared
Given(), _oversizedQuery, and faulted-status assertion into a common base
fixture or shared helper. Move the repeated projection setup around
when_updating_a_projection_with_oversized_definition and its sibling into a
reusable base class, then let each test class keep only the scenario-specific
action while inheriting the common assertions.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/EventStore.Projections.Core/Services/Management/ManagedProjection.cs`:
- Around line 895-906: The oversized persisted-state write path in
FailPersistedStateWrite only faults ManagedProjection and leaves an already
running core projection alive. Update this method to call
DisposeCoreProjection() when Created is true, before or alongside Fault(reason),
so a Created/Prepared projection is actually torn down when the management layer
marks it faulted. Keep the existing reply envelope handling unchanged.

---

Nitpick comments:
In
`@src/EventStore.Projections.Core.Tests/Services/projections_manager/when_updating_a_projection_with_oversized_definition.cs`:
- Around line 18-30: The oversized-definition projection tests duplicate the
same setup and assertion logic across this fixture and
when_posting_a_projection_with_oversized_definition, so extract the shared
Given(), _oversizedQuery, and faulted-status assertion into a common base
fixture or shared helper. Move the repeated projection setup around
when_updating_a_projection_with_oversized_definition and its sibling into a
reusable base class, then let each test class keep only the scenario-specific
action while inheriting the common assertions.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: cc0ff9a0-637b-470c-b18d-d4d6da1ecb5d

📥 Commits

Reviewing files that changed from the base of the PR and between 4934657 and 68e6848.

📒 Files selected for processing (12)
  • src/EventStore.Projections.Core.Tests/Services/projections_manager/when_posting_a_projection_with_oversized_definition.cs
  • src/EventStore.Projections.Core.Tests/Services/projections_manager/when_updating_a_projection_with_oversized_definition.cs
  • src/EventStore.Projections.Core/Messages/ProjectionManagementMessage.cs
  • src/EventStore.Projections.Core/Services/Grpc/ProjectionManagement.Abort.cs
  • src/EventStore.Projections.Core/Services/Grpc/ProjectionManagement.Create.cs
  • src/EventStore.Projections.Core/Services/Grpc/ProjectionManagement.Delete.cs
  • src/EventStore.Projections.Core/Services/Grpc/ProjectionManagement.Disable.cs
  • src/EventStore.Projections.Core/Services/Grpc/ProjectionManagement.Enable.cs
  • src/EventStore.Projections.Core/Services/Grpc/ProjectionManagement.Reset.cs
  • src/EventStore.Projections.Core/Services/Grpc/ProjectionManagement.Update.cs
  • src/EventStore.Projections.Core/Services/Grpc/ProjectionManagement.cs
  • src/EventStore.Projections.Core/Services/Management/ManagedProjection.cs

Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
@yordis yordis force-pushed the yordis/fix-projection-definition-size branch from 68e6848 to 75b79a7 Compare July 6, 2026 21:34
@yordis yordis merged commit 35e09cd into master Jul 6, 2026
21 checks passed
@yordis yordis deleted the yordis/fix-projection-definition-size branch July 6, 2026 21:58
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