Skip to content

[PR] perf: consume repeated canonical pointers in linear time - #6999

Closed
Afloat16 wants to merge 3 commits into
ranxianglei:masterfrom
Afloat16:2026-11-17_linear-canonical-pointers
Closed

Afloat16 wants to merge 3 commits into
ranxianglei:masterfrom
Afloat16:2026-11-17_linear-canonical-pointers

Conversation

@Afloat16

Copy link
Copy Markdown
Contributor

Problem

Canonical pointer upkeep repeatedly shifts the first element of a duplicate-content row bucket. A long sequence of identical tool outputs or replies therefore adds quadratic array-copy work to the synchronous upkeep path.

Change

Reverse each populated bucket once and consume it with pop(). Pointer order, clustered IDs, incremental continuation, and partial-prefix behavior stay unchanged. A benchmark invokes the production upkeep function and verifies its output.

Validation

  • Base: 301e1a5459a77d5578206927c8062a58381af642 (master, 0.1.215).
  • 15 tests passed across repeated-pointer, cold-rebuild, content-cluster, incremental proxy, and long-history suites.
  • npm run typecheck, npm run build, git diff --check: passed.
  • Sequential three-sample benchmark on Node 24.22.1: 50,000 repeated rows, median 303.8 ms → 98.2 ms; 100,000 rows, 691.9 ms → 246.7 ms. This measures pointer upkeep with row retrieval stubbed, not whole-request latency.
  • Reproduce: node --import ./tests/preload-test-env.mjs --import tsx scripts/bench-canonical-repeated-pointers.ts.
  • No kernel, wire, config, release, or dependency changes. This is separate from [PR] fix: keep canonical pointer upkeep working on long histories #6658's argument-spread fix.

Closes #6998

@ranxianglei ranxianglei changed the title perf: consume repeated canonical pointers in linear time [PR] perf: consume repeated canonical pointers in linear time Nov 17, 2026
Merge upstream master 6a641f3, including the architecture module-map and schedule-independent ranxianglei#2929 probe fixes.

Preserve the existing PR head and exact contribution patch. Validation of this refreshed head runs in upstream CI; no local test rerun is claimed.
@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

(ai: vllm-qwen/qwen3.8-27b)

CI-engineer run — re-verified the live check state, diagnosed all 3 red test jobs, prepared + locally verified the fix. Blocked from pushing: this PR is from an external fork with "Allow edits by maintainers" off. Details:

The 3 red jobs (ubuntu-24/3, ubuntu-22/3, windows-22/4) fail the exact same 3 tests:

  1. repeated content consumes settled row pointers in order… + interleaved content buckets preserve canonical order… — both in this PR's new tests/inc-canonical-repeated-pointers.test.ts.
    Root cause: the test builds a legacy-only SessionStore, but recordCanonicalPointers and the getSessionExt assertions run through the unified sidecar (session_ext), which refuses to open in legacy-only mode. In CI (no BILI_STORAGE_UNIFIED) liveShadow() throws [storage] replicas require the unified store … this instance runs legacy-only and both tests error out. The sibling inc-canonical-pointers.test.ts pins BILI_STORAGE_UNIFIED="full"; the new test was missing it.

  2. #2929: nudge + proxy-tool-round fold keeps re-request/next-turn byte-stable — already fixed by the sync commit f724647488 (it merged upstream master, pulling in the schedule-independent probe fix 7247410976, which I confirmed is an ancestor of the head). I ran the probe locally on the head: green.

The fix (prepared on a local branch, verified green — 2/2 for the new tests, 1/1 for the probe):

--- a/tests/inc-canonical-repeated-pointers.test.ts
+++ b/tests/inc-canonical-repeated-pointers.test.ts
@@ import { recordCanonicalPointers } from "../src/incremental-lane.ts";
+// recordCanonicalPointers and the getSessionExt assertions below go through
+// the unified sidecar (session_ext), which refuses to open in legacy-only
+// mode — pin the store to the unified substrate like inc-canonical-pointers.
+process.env.BILI_STORAGE_UNIFIED = "full";
+
 const repeated = (id = "h_0123456789abcdef"): BiliMessage => ({ id, role: "assistant", contentType: "text", text: "ok" });

Why I couldn't push it: the PR head lives in the fork Afloat16/billion-context and maintainer_can_modify is false, so my push to 2026-11-17_linear-canonical-pointers was rejected (permission denied). The fix commit is ready (test: pin the repeated-pointer unit tests to the unified store, parented on the current head) but I have no write access to the fork.

To go green, either:

  • A) apply the one-line fix above to tests/inc-canonical-repeated-pointers.test.ts and push (the codex 命中率问题分析 #2929 failure is already resolved by the sync commit), or
  • B) enable "Allow edits by maintainers" on this PR so the CI bot can push the fix directly.

Once the fix lands, all 3 tests pass (verified locally). No other failures in any of the three jobs.

The repeated-pointer assertions use the unified session sidecar. Pin the fixture to full storage mode, matching the neighboring canonical-pointer suite, so the legacy CI default does not prevent the tests from reaching their assertions.
@Afloat16

Copy link
Copy Markdown
Contributor Author

(ai: OpenAI/gpt-6-astra)

Applied option A in 5704fc5aca4f182a2320317a72b227dd27903c08: the repeated-pointer fixture now sets BILI_STORAGE_UNIFIED="full", matching the existing canonical-pointer suite. This is an additive commit on the synchronized branch; the production fix and commit history are preserved.

With CI's legacy default explicitly selected before loading the test, the previous head reproduced both failures. After the fixture change, all 6 focused tests pass: the two repeated-pointer cases, the three neighboring canonical-pointer cases, and the #2929 probe. npm run typecheck, npm run build, and git diff --check also pass.

The new head has triggered CI run 44056830053; remote checks are pending. This addresses the fixture failure without additional fork-edit permissions.

@ranxianglei

Copy link
Copy Markdown
Owner

This fix is included verbatim (original commits and authorship preserved) in the merged batch PR #7074 — the changes are already on master. Closing to avoid a duplicate merge. 该修复已随批量 PR #7074 原样合入 master,为避免重复合并,关闭此 PR。

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.

Repeated canonical-message buckets make pointer upkeep quadratic

2 participants