Skip to content

refactor: consolidate five percentile implementations into core.stats (#2878) - #2886

Closed
Sinity wants to merge 1 commit into
masterfrom
worktree-wf_54d4fb2e-841-17
Closed

Sinity wants to merge 1 commit into
masterfrom
worktree-wf_54d4fb2e-841-17

Conversation

@Sinity

@Sinity Sinity commented Jul 14, 2026

Copy link
Copy Markdown
Owner

Summary

Consolidate duplicate percentile algorithms across daemon, insights, and archive subsystems into a single implementation in core/stats.py that supports both linear and nearest-rank methods.

Problem

Five separate implementations existed (three using linear interpolation, two using nearest-rank) with different behaviors and scaling conventions (q vs p). This caused divergent p50/p95 results across operator-facing surfaces when displaying metrics side by side.

Solution

Created polylogue.core.stats.percentile() with:

  • Support for both 'linear' (default, numpy.percentile compatible) and 'nearest' methods
  • Consistent quantile scale (q in [0, 1])
  • Single source of truth for all percentile computations

Updated call sites to use the new function:

  • daemon/status.py, cursor_lag_baseline.py, live_ingest_attempt_progress.py → linear method
  • insights/portfolio.py → nearest method
  • archive/semantic/timing.py → nearest method with p→q conversion
  • insights/archive_rollups.py → nearest method

Verification

  • devtools verify --quick: all gates pass
  • devtools test -k percentile: 1 passed
  • No remaining duplicate _percentile implementations in codebase

Ref polylogue-a7xr.4

Consolidate duplicate percentile algorithms across daemon, insights, and
archive subsystems. Five implementations existed (three linear interpolation,
two nearest-rank) with different behaviors and scaling (q vs p). This caused
divergent p50/p95 results across operator-facing surfaces.

New single implementation in core.stats.percentile() supports both 'linear'
(default, numpy-compatible) and 'nearest' methods, with q in [0,1] quantile
scale. Call sites updated:
- daemon/status.py, cursor_lag_baseline.py, live_ingest_attempt_progress.py
  → percentile(..., method='linear')
- insights/portfolio.py → percentile(..., method='nearest')
- archive/semantic/timing.py → percentile(..., method='nearest') with p→q conversion
- insights/archive_rollups.py → percentile(..., method='nearest')

Ref polylogue-a7xr.4

Co-Authored-By: Claude <[email protected]>
@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown

Warning

Review limit reached

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

Next review available in: 21 minutes

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: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: c66f7398-2931-4fe3-a1fc-3be7a412f790

📥 Commits

Reviewing files that changed from the base of the PR and between 3796f54 and 296517e.

📒 Files selected for processing (9)
  • docs/plans/topology-target.yaml
  • docs/topology-status.md
  • polylogue/archive/semantic/timing.py
  • polylogue/core/stats.py
  • polylogue/daemon/cursor_lag_baseline.py
  • polylogue/daemon/live_ingest_attempt_progress.py
  • polylogue/daemon/status.py
  • polylogue/insights/archive_rollups.py
  • polylogue/insights/portfolio.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch worktree-wf_54d4fb2e-841-17

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.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 296517ee80

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread polylogue/core/stats.py Resolved
@Sinity

Sinity commented Jul 14, 2026

Copy link
Copy Markdown
Owner Author

Duplicate of #2896 (same diff targeting the same bead, polylogue-a7xr.4, plus one extra test file — a resume-after-pause artifact that re-ran an already-completed Haiku item). Closing without merge.

@Sinity Sinity closed this Jul 14, 2026
@Sinity
Sinity deleted the worktree-wf_54d4fb2e-841-17 branch July 14, 2026 17:19
@Sinity

Sinity commented Oct 1, 2026

Copy link
Copy Markdown
Owner Author

Historical Codex triage: evidence checked at 5ebcfe5. This records that source revision; it does not claim a fresh review of current master.

  • 63.F022 / P2: fixed-already at the checked revision: The nearest-rank implementation now uses math.ceil(q * len(sorted_values)) at polylogue/core/stats.py:74. Its p90 rank for 16 observations is 15, preserving the documented nearest-rank definition.

Only the rows listed above are dispositioned. Held findings remain open.

Sinity added a commit that referenced this pull request Oct 24, 2026
Move all three Sinex wire dependency pins directly from `f2951e51` to
qualified merged `c8a5e4b1` (Sinex PR #2886), including its
source-retirement and sealed-repair fixes and immutable common `v0.5.20`
pin. Update the four corresponding lock sources together. Polylogue's
Nix package consumes this Cargo lock; there is no separate Sinex flake
input.

The preserved formatting/boundaries push hook passed (devkit 2450).
Locked metadata resolution passed (job 1520), verifying
model/macros/protocol/transport all resolve exactly to
`c8a5e4b1eb7f9f6724d7d1da4ea8fe4c73722687`. Their complete crate trees,
including manifests, are byte-identical at the old pin, prior native
witness `99cbdf3c`, and this merged revision. Registry dependency
constraints are unchanged; Polylogue already pins common `v0.5.20`.

The existing ordinary producer/wire witness is job 1478 on SX `99cbdf3c`
and PL `199659e682`. It predates the sealed-store repair, so this update
does not claim a new native daemon/store replay. Upstream PR #2885 owns
its daemon/store repair controls; PR #2886 owns the locked API masking
controls. Root's coalesced paired qualification follows these pins. No
Rust source, harness, schema, or package build is added here.
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