Repository navigation
perf(schemas): add bounded __bool__ to replay membership views - #3565
Conversation
|
Warning Review limit reached
Next review available in: 8 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the 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 configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (7)
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. Comment |
Ref polylogue-5svw0 Co-Authored-By: Claude <[email protected]>
Ref polylogue-5svw0 Co-Authored-By: Claude <[email protected]>
98afe01 to
e95ab96
Compare
Problem polylogue-5svw0 (Fable perf audit F1+F2): ArtifactMemberships, MembershipSamples, MembershipSessionIds, and MembershipObservedAts (polylogue/schemas/generation/replay.py) all had O(n) __len__ with no __bool__, so `if view:` / `bool(view)` fell back to Sequence/Collection's default truthiness protocol -- a full rescan of the filtered membership source just to answer "is this empty?". Same defect class as PR #3546 (ReplayableRecordSamples.__bool__), currently latent (no live call site does implicit truthiness on these views yet) but "one wrong future call site from recreating #3546" per the audit finding. ArtifactMemberships.__getitem__ also fully materialized via list(self) for a single bounded index/slice access. Separately, ReplayableRecordSamples.__getitem__'s slice path (sampling_extract.py) still called index.indices(len(self)) -- forcing a full file decode -- even for the common forward-bounded shape (samples[:5]); no current caller slices it, but observation_runtime.py already had to route around it with islice + a warning comment. Solution - polylogue/core/common.py: two new shared helpers. peek_truthy() answers truthiness from a bounded single-item peek instead of __len__. forward_bounded_slice() resolves a slice's (start, stop, step) via itertools.islice without needing the sequence's true length, for the common non-negative start/stop + positive-step shape; returns None (fall back to len()-based resolution) for a slice that genuinely needs true length (negative bound, non-positive step). - replay.py: all four membership views get __bool__ via peek_truthy(). ArtifactMemberships.__getitem__ now uses forward_bounded_slice() for slices and a bounded islice for non-negative int indices, only falling back to full materialization for negative indices. - sampling_extract.py: ReplayableRecordSamples.__getitem__'s slice path now tries forward_bounded_slice() first, avoiding len(self) (a full file decode) for the common samples[:N] shape. Verification - New tests: tests/unit/core/test_common.py (peek_truthy, forward_bounded_slice unit coverage), tests/unit/core/ test_schema_replay_memberships.py (bounded-access assertions for all four replay.py views, using an instrumented counting membership source), tests/unit/core/test_sampling.py (bounded-slice/bool coverage for ReplayableRecordSamples with instrumented JSON-decode counting). Confirmed each new test genuinely fails without the fix (git stash of the three production files reproduced 7 failures + 1 import error; only test_bool_still_does_not_decode_full_file stayed green, since ReplayableRecordSamples.__bool__ already existed from PR #3546). - `devtools test tests/unit/core/test_common.py tests/unit/core/test_schema_replay_memberships.py tests/unit/core/test_sampling.py tests/unit/core/test_schema_workload_profiles.py tests/unit/core/test_schema_observation_journal.py tests/unit/core/test_schema_generation.py` -- 129 passed, 1 skipped, 1 pre-existing unrelated failure (confirmed via git stash against the unmodified checkout: TestLoadSamplesFromDb::test_schema_observation_records_included_and_decode_failed_raws). - `devtools verify --quick` -- clean, exit 0. Ref polylogue-5svw0 Co-Authored-By: Claude <[email protected]>
Ref polylogue-5svw0 Co-Authored-By: Claude <[email protected]>
e95ab96 to
654038d
Compare
Summary
Adds bounded
__bool__to the four lazy membership views inpolylogue/schemas/generation/replay.py, fixesArtifactMemberships.__getitem__'s full-materialization on bounded access, and closes the last "loaded gun" from PR #3546 by makingReplayableRecordSamples.__getitem__'s slice path bounded too.Problem
polylogue-5svw0 (Fable perf audit findings F1+F2, 2026-08-02):
ArtifactMemberships,MembershipSamples,MembershipSessionIds, andMembershipObservedAtsall had O(n)__len__with no__bool__, soif view:/bool(view)fell back toSequence/Collection's default truthiness protocol — a full rescan of the filtered membership source just to answer "is this empty?". Same defect class as PR #3546 (ReplayableRecordSamples.__bool__), currently latent in this repo (no live call site does implicit truthiness on these views yet) but "one wrong future call site from recreating #3546" per the audit finding.ArtifactMemberships.__getitem__also fully materialized vialist(self)for a single bounded index/slice access.Separately:
ReplayableRecordSamples.__getitem__'s slice path (sampling_extract.py) still calledindex.indices(len(self))— forcing a full file decode — even for the common forward-bounded shape (samples[:5]), after PR #3546 had already added__bool__but left the slice path alone. No current caller slices it, butobservation_runtime.pyalready had to route around this exact shape withislice+ a warning comment.Solution
polylogue/core/common.py: two new shared helpers.peek_truthy(iterable)answers truthiness from a bounded single-item peek instead of falling back to__len__.forward_bounded_slice(index)resolves a slice's(start, stop, step)viaitertools.islicewithout needing the sequence's true length, for the common non-negative start/stop + positive-step shape; returnsNone(caller falls back tolen()-based resolution) for a slice that genuinely needs true length (negative bound, non-positive step).polylogue/schemas/generation/replay.py: all four membership views get__bool__viapeek_truthy().ArtifactMemberships.__getitem__now usesforward_bounded_slice()for slices and a boundedislicefor non-negative int indices, only falling back to full materialization for negative indices (which genuinely need the true length to normalize).polylogue/archive/raw_payload/sampling_extract.py:ReplayableRecordSamples.__getitem__'s slice path now triesforward_bounded_slice()first, avoidinglen(self)(a full file decode) for the commonsamples[:N]shape.No current call site suffers from the membership-view gap yet (grepped for implicit truthiness on these classes across the repo — none found), so this is a preventive fix per the audit's own framing, not a live perf regression fix.
Verification
tests/unit/core/test_common.py— unit coverage forpeek_truthy/forward_bounded_slice.tests/unit/core/test_schema_replay_memberships.py— bounded-access assertions for all fourreplay.pyviews, using an instrumented counting membership source that records how many items were actually touched.tests/unit/core/test_sampling.py— bounded-slice/bool coverage forReplayableRecordSampleswith instrumented JSON-decode counting.git stash'd the three production files and reran the new tests — 7 failures + 1 import error (onlytest_bool_still_does_not_decode_full_filestayed green, sinceReplayableRecordSamples.__bool__already existed from PR perf(schemas): stop full-corpus schema inference rescanning raw files #3546). Restored the fix and reran green.devtools test tests/unit/core/test_common.py tests/unit/core/test_schema_replay_memberships.py tests/unit/core/test_sampling.py tests/unit/core/test_schema_workload_profiles.py tests/unit/core/test_schema_observation_journal.py tests/unit/core/test_schema_generation.py— 129 passed, 1 skipped, 1 pre-existing unrelated failure (TestLoadSamplesFromDb::test_schema_observation_records_included_and_decode_failed_raws, confirmed viagit stashagainst the unmodified checkout).devtools verify --quick— clean, exit 0.Ref polylogue-5svw0
Co-Authored-By: Claude [email protected]