feat(entities): log console.error when realtime broadcast is oversize#167
Conversation
Server-side BASE-40236 slims oversize entity broadcasts to fit under the
Redis pubsub cap, signaling the slim with `_truncated: true` on the event
data. Customer apps that render the truncated fields would otherwise
display placeholder text until refresh.
The SDK now detects `_truncated` in `entities.X.subscribe` and transparently
refetches the full record over HTTP before invoking the user callback, so
deployed customer code keeps working without changes. Concurrent subscribers
in the same browser fan out to a single HTTP call via an in-flight
debounce keyed by `${entityName}:${id}:${timestamp}`. On refetch failure
the SDK falls through with the partial payload and logs a warning, so the
failure mode is no worse than today's drop-and-stale.
Delete events skip refetch — the record no longer exists.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
The wire flag is set only when the server falls back to a stub payload
because the original record was too big for realtime transport. Calling
it "truncated" was misleading — we don't truncate fields in that path,
we replace the whole payload with `{id, _oversize: true}`. `_oversize`
names the actual cause and tells the SDK why a refetch is needed.
Coordinated with the matching backend rename.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
|
Claude finished @theunreal's task —— View job Code Review for PR #167: Auto-refetch when realtime broadcast is truncatedI've reviewed the implementation and tests for the auto-refetch feature. Overall, this is a well-designed solution to handle oversized realtime broadcasts. Here's my feedback: ✅ Code Quality & Best PracticesStrengths:
Minor suggestions:
✅ Bug AnalysisThe implementation appears solid with no critical bugs identified. Key defensive programming practices observed:
✅ Performance ConsiderationsExcellent optimizations:
Potential enhancement:
✅ Security AssessmentNo security concerns identified:
✅ Test CoverageComprehensive test suite covering:
Test quality highlights:
🔍 Additional Observations
📋 SummaryThis PR implements a robust solution for handling oversized realtime broadcasts. The code is production-ready with excellent test coverage and thoughtful design decisions. The debouncing mechanism is particularly well-implemented, avoiding unnecessary network calls while ensuring data freshness. The only minor suggestion is to extract the cache timeout constant for better configurability, but this is not blocking. Great work on this implementation! 👍 |
🚀 Package Preview Available!Install this PR's preview build with npm: npm i @base44-preview/sdk@0.8.26-pr.167.fdb48d8Prefer not to change any import paths? Install using npm alias so your code still imports npm i "@base44/sdk@npm:@base44-preview/sdk@0.8.26-pr.167.fdb48d8"Or add it to your {
"dependencies": {
"@base44/sdk": "npm:@base44-preview/sdk@0.8.26-pr.167.fdb48d8"
}
}
Preview published to npm registry — try new features instantly! |
Per PM pushback, drop the HTTP auto-refetch path on oversize broadcasts — even with debouncing, an entity that tens of subscribers all refetch on every broadcast (e.g. a popular Truck record updated every 30 s in a fleet app) shifts realtime load to HTTP at potentially uncapped fan-out. New behavior: when `_oversize: true` is seen, log a single console.error naming the entity, id, and the recommended `entities.X.get(id)` call so the developer is notified at debug time. The user callback still fires with the slimmed payload (big string fields are empty, rest of the record may be the stub) — caller decides what to do. Removed the inflightRefetches debounce map and refetchTruncated helper since they're no longer needed. Tests collapse from 5 refetch scenarios to 3 logging scenarios: - logs and passes the stub through when _oversize is true - does NOT log on delete events even if _oversize is set - does NOT log when _oversize is absent 156/156 pass; lint + build clean.
|
Claude encountered an error —— View job Code Review for PR #167: Auto-refetch when realtime broadcast is truncatedI've reviewed the implementation and tests for handling oversized realtime broadcasts. Here's my comprehensive feedback: ✅ Code Quality & Best PracticesStrengths:
Observations on the evolution:
✅ Potential Bugs or IssuesNo critical bugs identified. The implementation is solid with proper safeguards:
✅ Performance ConsiderationsCurrent approach (console.error) is performant:
Previous approach (auto-refetch) had good optimizations:
The shift to console.error eliminates any performance concerns about HTTP fan-out. ✅ Security ConcernsNo security issues identified:
✅ Test CoverageExcellent test coverage:
Test quality:
🔍 Additional Observations
📋 SummaryThis is a well-implemented solution that balances functionality with performance concerns. The final approach of using console.error to notify developers about oversized broadcasts is pragmatic and gives applications control over how to handle these scenarios. The code is production-ready with comprehensive test coverage. The only minor suggestion would be to consider adding a configuration option in the future to allow developers to customize the behavior (e.g., provide a callback for handling oversized events), but this is not necessary for the current implementation. Great work on this PR! 👍 |
|
Claude finished @theunreal's task —— View job Code Review for PR #167: log console.error when realtime broadcast is oversizeI've thoroughly reviewed the implementation and tests for handling oversized realtime broadcasts. Here's my comprehensive feedback: ✅ Code Quality & Best PracticesStrengths:
Observations:
✅ Potential Bugs or IssuesNo critical bugs identified. The implementation is solid with proper safeguards:
✅ Performance ConsiderationsCurrent implementation is performant:
✅ Security ConcernsNo security issues identified:
✅ Test CoverageExcellent test coverage in the new test suite:
The tests are well-structured, focused, and cover all edge cases. 🔍 Additional Observations
📋 SummaryThis is a well-implemented, pragmatic solution that balances functionality with performance concerns. The shift from auto-refetch to console.error notification gives applications control over handling oversized broadcasts while preventing backend overload. The code is production-ready with comprehensive test coverage. Minor suggestion for future enhancement: Consider adding a configuration option to allow developers to provide a custom handler for oversized events, but this is not necessary for the current implementation. Excellent work on this PR! 👍 Tasks
|
Why
Realtime entity broadcasts have a transport size limit. Records with very large fields (e.g. base64-encoded media, long markdown) can exceed the limit and get dropped — subscribers see stale state until refresh.
The Base44 backend now slims oversize broadcasts to fit under the limit and signals it with
_oversize: trueon the eventdata. Without this SDK change, customer apps that read the slimmed fields would get an empty string with no signal that anything happened — devs writing the app have no idea their >10 KB field was just blanked at the wire.What
In
entities.X.subscribe(callback):event.type !== "delete"andevent.data._oversize, log a singleconsole.errornaming the entity, id, and the recommended fetch call.entities.X.get(id), or render the partial data.Why not auto-refetch? An earlier draft of this PR did transparent HTTP refetch behind the scenes (with debouncing across concurrent subscribers). PM pushback: a popular entity in a fleet/logistics app could have tens of subscribed components per browser, hundreds of users online, and updates every few seconds. Auto-refetching on every oversize broadcast — even with per-browser debounce — multiplies backend HTTP load by the active-user count of the affected app. Surfacing the issue to developers and letting them decide is the safer default.
Wire contract is preserved: the server always emits
dataas an object containing at minimumid, so older SDK clients that don't know about_oversizecontinue to receive a structurally valid event. They render the empty/stub fields without the warning — same UX as a brand-new install today, just no debug signal.Tests
tests/unit/entities-subscribe.test.ts— 3 new tests underoversize broadcast handling, all 9 pass:console.errorand passes the stub through whendata._oversizeis true_oversizeis set_oversizeis absentFull suite: 156 / 156 pass.
npm run lintandnpm run buildclean.Backward compatibility
_oversize. Pure passthrough._oversizeflag never appears, so this code path is dormant.Versioning
Recommend a minor bump (
0.8.x → 0.9.0) since this is additive observability behavior.Reopened from #165 to run from base repo (fork PRs lack secrets/OIDC).