Skip to content

Feature/dedup merger#42

Closed
Great-Frosty wants to merge 37 commits into
masterfrom
feature/dedup-merger
Closed

Feature/dedup merger#42
Great-Frosty wants to merge 37 commits into
masterfrom
feature/dedup-merger

Conversation

@Great-Frosty

Copy link
Copy Markdown
Contributor

No description provided.

Great-Frosty and others added 8 commits March 18, 2026 13:29
MergerViewSession with deduplicate=true relied on _dedup_data, which keeps
the first copy of a shared id by POSITION, ignoring dedup_priority. When the
inner MergerPercentage interleaves a low-percentage high-priority source
(recommended, prio 2) with a high-percentage low-priority source (regular,
prio 1), the faster regular stream reaches shared ids first, so the
recommended copy was dropped. Recommended collapsed far below its configured
percentage (35% -> ~21% in prod, near 0 with heavy id overlap).

Root cause: when a view_session runs as a positional owner, its ambient
ctx.dedup is None, so the inner percentage merger ran without the
priority-aware arbitration/refill that already exists in the engine.

Fix: when the session owns deduplication (deduplicate=true + dedup_key) and
there is no ambient dedup policy, build a request-local priority-aware
DeduplicationPolicy + refill settings and pass them inward. This activates
the existing arbitrate_owner_buffers (keeps higher-priority copy) and
_refill_deficits (tops sources back to quota) machinery. No extra backend
calls: dedup runs in-memory over already-fetched data (verified).

Adds a regression test reproducing the collapse and asserting recommended
keeps its share with overlapping ids.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…fig)

The regression test imported fakeredis, which is not a smartfeed dependency,
so CI failed at collection (ModuleNotFoundError). Rewrite it to use the
existing redis_client fixture (sync + async) like the other view_session tests.

Also rebuild the test config to mirror the real feed shape
(dedup -> positional -> view_session -> percentage). The previous standalone
view_session->percentage config did not actually trigger the collapse, so the
test passed even without the fix. The prod-shaped config reproduces it:
recommended share is ~13% without the fix and ~34% with it.
The Test workflow path filter omitted the tests/ directory, so changes that
touch only test files never ran CI. Add tests/** so test-only commits are
validated too.
MergerPercentage interleaved sources proportionally to their ACTUAL lengths,
which smeared a scarce source thinly across the whole feed (e.g. a 35% source
with few items showed up at ~15% on every page instead of 35%). Replace the
proportional block merge with a smooth weighted round-robin keyed on the
configured percentages: each step emits the source most behind its target share
that still has items. This front-loads the target ratio -- a scarce source keeps
its target percentage on the early pages and then drops to zero once exhausted,
instead of being diluted everywhere.

Updates the existing percentage order assertion to the new (front-loaded) output
and adds a front-load regression test.
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.

2 participants