Skip to content

fix(intelligence): replace unsafe number-grabbing fallback in _parse_importance_response - #1075

Merged
lightzt99 merged 1 commit into
oceanbase:mainfrom
knqiufan:fix/importance-parse-fallback-unsafe-number
Jun 23, 2026
Merged

fix(intelligence): replace unsafe number-grabbing fallback in _parse_importance_response#1075
lightzt99 merged 1 commit into
oceanbase:mainfrom
knqiufan:fix/importance-parse-fallback-unsafe-number

Conversation

@knqiufan

@knqiufan knqiufan commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Summary

Closed #1074

The second-level fallback in _parse_importance_response() blindly grabbed the first number from the entire LLM response text via re.findall(r'\d+\.?\d*'). This could misinterpret dimension counts (6 → clamped to 1.0), percentages (85%1.0), or unrelated config references as the importance_score, causing incorrect memory classification and review scheduling downstream.

Changes

  • L1 (JSON parsing): Replace hand-rolled find("{")/rfind("}") with parse_json_from_text() (existing utility); support both importance_score and overall_score field names; when only criteria_scores is present, compute weighted sum using criteria_weights
  • L2 (field-name regex): Only extract numbers anchored to recognized field names (importance_score, overall_score, score); reject values outside [0.0, 1.0] instead of clamping
  • L3 (safe failure): Return None instead of fixed 0.5; caller _llm_based_evaluation falls back to _rule_based_evaluation (consistent with LLM exception path)
  • Tests: Add 17 unit tests covering all parsing paths, rejection of invalid numbers, and fallback behavior

Why

importance_score directly determines:

  • Memory type classification (working / short_term / long_term)
  • Initial retention rate (initial_retention * importance_score)
  • Review schedule intervals (interval * (1 - importance_score * 0.3))

A silently wrong score cascades through the entire memory lifecycle and is nearly impossible to diagnose from external behavior.

Test plan

  • All 17 new unit tests pass (tests/unit/intelligence/test_importance_evaluator.py)
  • All 63 existing intelligence unit tests pass with no regression
  • CI regression suite passes

…importance_response (oceanbase#1074)

The second-level fallback in _parse_importance_response() used
re.findall(r'\d+\.?\d*') to blindly grab the first number from
the entire LLM response text. This could misinterpret dimension
counts (6), percentages (85), or unrelated numbers as the
importance_score, causing incorrect memory classification and
review scheduling.

Changes:
- L1: Use parse_json_from_text() for robust JSON extraction;
  support both importance_score and overall_score fields; synthesize
  from criteria_scores via weighted sum when no total is present
- L2: Only extract numbers anchored to recognized field names
  (importance_score, overall_score, score); reject values outside
  [0.0, 1.0] instead of clamping
- L3: Return None instead of fixed 0.5; caller falls back to
  _rule_based_evaluation (consistent with LLM exception path)
- Add 17 unit tests covering parsing and fallback behavior

Closes oceanbase#1074
@lightzt99

Copy link
Copy Markdown
Collaborator

LGTM

@lightzt99
lightzt99 merged commit 74f2f36 into oceanbase:main Jun 23, 2026
21 checks passed
@knqiufan
knqiufan deleted the fix/importance-parse-fallback-unsafe-number branch July 5, 2026 16:50
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.

fix(intelligence): _parse_importance_response second-level fallback blindly grabs first number

2 participants