Skip to content

Fix/skill tool memory#514

Merged
MaojiaSheng merged 7 commits intomainfrom
fix/skill_tool_memory
Mar 10, 2026
Merged

Fix/skill tool memory#514
MaojiaSheng merged 7 commits intomainfrom
fix/skill_tool_memory

Conversation

@BytedanceFu
Copy link
Collaborator

Description

Related Issue

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)
  • Performance improvement
  • Test update

Changes Made

Testing

  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have tested this on the following platforms:
    • Linux
    • macOS
    • Windows

Checklist

  • My code follows the project's coding style
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

Screenshots (if applicable)

Additional Notes

@github-actions
Copy link

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Inconsistent Threshold

Skill name calibration threshold differs between _get_tool_skill_info (0.9) and calibrate_skill_name (0.8). This could lead to inconsistent behavior in different code paths.

if best_ratio >= 0.9 and best_skill_name:
Redundant Code

The limited variable in _merge_kv_field is assigned the same value as merged before truncating to 1000 characters; this redundancy can be simplified.

limited = "; ".join(parts).strip()[:1000]
return limited

@github-actions
Copy link

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
Possible issue
Align skill calibration threshold

Align the skill calibration threshold with the value used in compressor.py to ensure
consistent behavior across code paths. The compressor uses 0.9 for skills, so update
the utils function to match.

openviking/session/tool_skill_utils.py [74-80]

 def calibrate_skill_name(candidate_skill_name: str, tool_parts: Iterable[Any]) -> Tuple[str, str]:
     return _calibrate_name(
         candidate_name=candidate_skill_name,
         parts=tool_parts,
         name_getter=lambda p: extract_skill_name_from_uri(getattr(p, "skill_uri", "") or ""),
-        threshold=0.8,
+        threshold=0.9,
     )
Suggestion importance[1-10]: 6

__

Why: The suggestion correctly identifies an inconsistency between the skill name calibration threshold in tool_skill_utils.py (0.8) and compressor.py (0.9), which could lead to inconsistent behavior across code paths.

Low
Fix regex to match newlines

Update the regex to use [\s\S]? instead of .? to match across newlines between
"Avg time:" and "Avg tokens:". This ensures the pattern works even if the two
metrics are on separate lines.

openviking/session/memory_extractor.py [819]

-match = re.search(r"(?im)^-\s*Avg time:.*?Avg tokens:\s*(\d+)", content)
+match = re.search(r"(?im)^-\s*Avg time:[\s\S]*?Avg tokens:\s*(\d+)", content)
Suggestion importance[1-10]: 5

__

Why: The regex uses .*? which does not match newlines by default; using [\s\S]*? ensures the pattern works even if "Avg time:" and "Avg tokens:" are on separate lines, improving parsing robustness.

Low
General
Simplify truncation logic

Remove redundant recomputation of the merged string when truncating. Directly
truncate the already computed merged variable to simplify the code.

openviking/session/memory_extractor.py [962-965]

 merged = "; ".join(parts).strip()
 if len(merged) <= 1000:
     return merged
-limited = "; ".join(parts).strip()[:1000]
-return limited
+return merged[:1000]
Suggestion importance[1-10]: 3

__

Why: The suggestion removes redundant recomputation of the merged string, simplifying the code without changing behavior; this is a minor readability improvement.

Low

@BytedanceFu BytedanceFu requested a review from MaojiaSheng March 10, 2026 09:26
best_skill_name = part_skill
best_status = part.tool_status or "completed"

if best_ratio >= 0.9 and best_skill_name:
Copy link
Collaborator

Choose a reason for hiding this comment

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

[Bug] Skill 校准阈值不一致:这里使用 0.9 作为 skill 模糊匹配阈值,但 tool_skill_utils.calibrate_skill_name 使用的是 0.8

memory_extractor.pyextract() 方法调用 calibrate_skill_name(阈值 0.8),而 compressor.py_get_tool_skill_info 使用 0.9。两条代码路径对同一个 skill name 会产生不同的校准结果——相似度 0.85 的名称在 extract() 能匹配,在这里会失败。

建议统一为相同的阈值,或直接复用 calibrate_skill_name

return (part_tool, "", part.tool_status or "completed")

ratio = SequenceMatcher(None, candidate_norm, part_norm).ratio()
if ratio > best_ratio or (ratio == best_ratio and ratio >= 0):
Copy link
Collaborator

Choose a reason for hiding this comment

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

[Suggestion] 平局处理条件 ratio == best_ratio and ratio >= 0 中,ratio >= 0 对 SequenceMatcher 恒为 true(返回值范围 [0, 1]),实际效果是「同分时后出现的 part 总是覆盖前面的」。

从测试用例 test_best_match_tie_picks_most_recent_tool_part 来看这是有意为之,建议加注释说明这个设计意图(如 # tie-break: prefer the last occurrence),避免后续维护者误解。tool_skill_utils.py:64 存在同样的写法。

candidate_skill = candidate.skill_name
from difflib import SequenceMatcher

def _normalize(name: str) -> str:
Copy link
Collaborator

Choose a reason for hiding this comment

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

[Suggestion] _get_tool_skill_info 重复实现了 tool_skill_utils.py 中的模糊匹配逻辑,包括这个局部 _normalize 函数(与 normalize_name 功能完全相同)以及 SequenceMatcher 匹配流程。

这种重复正是上面 skill 阈值不一致 bug 的根本原因。建议直接调用 calibrate_tool_name / calibrate_skill_name,避免逻辑分叉。

@BytedanceFu BytedanceFu requested a review from qin-ctx March 10, 2026 13:53
@MaojiaSheng MaojiaSheng merged commit 347c289 into main Mar 10, 2026
6 checks passed
@MaojiaSheng MaojiaSheng deleted the fix/skill_tool_memory branch March 10, 2026 15:05
@github-project-automation github-project-automation bot moved this from Backlog to Done in OpenViking project Mar 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants