Skip to content

perf(experience): reuse FTS projection admission and narrow recurrence reads - #2846

Merged
hidb4ai merged 1 commit into
oceanbase:masterfrom
Junkrat77:perf/experience-recall-and-recurrence
Nov 26, 2026
Merged

hidb4ai merged 1 commit into
oceanbase:masterfrom
Junkrat77:perf/experience-recall-and-recurrence

Conversation

@Junkrat77

Copy link
Copy Markdown
Contributor

Which issue or RFC does this PR close?

N/A (performance improvement on Experience search and recurrence read paths; no schema or public API changes).

Rationale for this change

Two read-heavy paths in the built-in Experience pipeline performed avoidable repeated work:

  1. Experience FTS search (search_approved_artifact_rows / experience_search_hits): Even after the database query had already checked lexical admission against the stored searchable_text projection, experience_search_hits re-ran admits_fts_text (including full text analysis/tokenization) on every returned Experience row during decoding.
  2. Recurrence ledger window processing (RelationalRecurrenceLedger / RecurrenceRepository):
    • record_window eagerly loaded all active Experience heads for a scope whenever any unlinked TaskOutcome appeared, even if the outcome had no unrecorded failure items with available evidence (e.g., passing outcomes or replayed windows).
    • _revision_proposal scanned and decoded every pc_recurrence_observation row in the scope in Python to filter one (artifact_ref, cue_key) verdict bucket, and re-fetched the target artifact revision via artifacts.latest after already loading it via artifacts.get.

What changes are included in this PR?

  • Reuse projection-level FTS admission for Experience search (src/powercontext/builtin/persistence/experience_index.py):
    • Added a projection_admitted column to the bounded final SELECT in search_approved_artifact_rows (with the SQLite rejected sentinel UNION ALL column list updated to match):
      • On SQLite (family == "experience"), sets projection_admitted via EXISTS verifying pc_artifact_heads.searchable_text = pc_artifact_fts.searchable_text for the exact (scope_id, family, artifact_id, revision) so drifted FTS rows still fall back to full decoding validation.
      • On OceanBase (family == "experience"), sets projection_admitted = 1 when required > 1 (both fast probe and full-query fallback) and evaluates exact oceanbase_fts_coverage_sql >= :required on the bounded candidate rows when required == 1.
      • Leaves non-Experience families (projection_admitted = 0) unchanged.
    • Updated experience_search_hits to skip redundant admits_fts_text(...) re-analysis when row.get("projection_admitted") is truthy.
  • Narrow recurrence reads (src/powercontext/builtin/persistence/recurrence.py, src/powercontext/builtin/runtime/recurrence.py):
    • Added RecurrenceRepository.verdicts_for_target, which filters one (artifact_ref, signature_key) bucket using existing _bucket_conditions (revision index + signature hash + plaintext) and event != 'selected', ordered by (task_outcome_position, observation_id).
    • Updated RelationalRecurrenceLedger.record_window to return early when no TaskOutcome is present and lazily load scope_heads() at most once per window only when an unlinked outcome actually reaches an unrecorded failure item with available evidence.
    • Updated _revision_proposal to check repair_surface before calling artifacts.latest(..., known=target) and to read bucket verdicts through verdicts_for_target instead of scanning all scope observations.
  • Release gate metadata (release/upgrade-support.json):
    • Refreshed schema_review.persistence_sha256 and appended the read-only query rationale. No database schema, table layout, index, migration resource, frozen revision checksum, or persisted encoding is changed.
  • Tests:
    • tests/builtin/persistence/test_experience_index.py: verifies drifted SQLite pc_artifact_fts rows cannot bypass lexical admission.
    • tests/builtin/persistence/test_recurrence_repository.py: covers verdicts_for_target bucket filtering, selected exclusion, journal ordering, and unnormalized key rejection.
    • tests/builtin/runtime/test_recurrence_ledger.py: verifies passing unlinked windows and replayed windows skip pc_artifact_heads / pc_artifacts reads.

Are there any user-facing changes?

No user-facing API, configuration, documentation, or persistence format changes. Existing search admission semantics and recurrence ledger behavior are preserved.

How was this change tested?

  • Static checks (ruff check, ruff format --check, ty check) passed on all modified files.
  • Unit & release-gate tests:
    pytest -q \
      tests/builtin/persistence/test_experience_index.py \
      tests/builtin/persistence/test_recurrence_repository.py \
      tests/builtin/runtime/test_recurrence_ledger.py \
      tests/test_upgrade_release_gate.py
    Result: 180 passed, 1 skipped.
  • Local end-to-end benchmark (file-backed SQLite, origin/master b0f5eadea vs this PR 078f7c2d8, 2 interleaved rounds):
    • HTTP POST /v1/scopes/{scope_id}/artifacts/experience/search (40 bilingual Experiences, limit=8):
      • Short query p50: 71.2 ms -> 22.7 ms (-68.1%)
      • Multi-term query p50: 76.8 ms -> 23.7 ms (-69.1%)
    • RecurrenceLedger.record_window (150 active Experience heads, 600 historical observations):
      • Passing unlinked window p50: 25.1 ms -> 1.58 ms (-93.7%, SQL statements 5 -> 0)
      • Replayed failing window p50: 54.9 ms -> 28.1 ms (-48.9%, SQL statements 21 -> 16)
      • Streak proposal p50: 83.8 ms -> 53.9 ms (-35.8%; mean 99.9 ms -> 56.8 ms, -43.1%)
  • Validation scope note: Local tests and benchmarks exercised SQLite only; the OceanBase/seekdb SQL branch was verified by code review and unit tests, not against a live OceanBase/seekdb instance.

AI usage statement

AI coding assistant (Antigravity / Gemini) was used to help review the diff, refine the SQL/runtime changes, add targeted regression tests, and run local SQLite benchmarks.

@hidb4ai hidb4ai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Validation note: the current harness-validation / Acceptance (sqlite) check and aggregate CI result are failing. The uploaded acceptance reports identify AgentSetupTimeoutError: Agent setup timed out after 360.0 seconds, before the business scenarios ran; this is not evidence of a regression in the changed search or recurrence code. Please resolve the harness setup failure and rerun acceptance before merging. See https://github.com/oceanbase/powercontext/actions/runs/45776011633/job/139767673418.

No reproducible correctness defect was found in the reviewed changes. There are no schema changes or new HTTP/MCP endpoints, but the exported RecurrenceRepository gains the callable verdicts_for_target interface.

@hidb4ai
hidb4ai merged commit 69c28d4 into oceanbase:master Nov 26, 2026
77 of 79 checks passed
xixi-box added a commit to xixi-box/powercontext that referenced this pull request Nov 26, 2026
Brings in oceanbase#2859/oceanbase#2846 and the Harbor shared-download CI fix (oceanbase#2827) so the
next acceptance run exercises the updated install path.

Signed-off-by: wangshun <96341168+xixi-box@users.noreply.github.com>
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.

3 participants