发布

  • fix(skills): record SkillRuns only for skills opened via load_skill (#2725)

    frostbyte_neo 发布于 2026-04-25 16:26:37 +00:00

    Description

    AgenticRetriever._record_skill_runs writes one SkillRun per skill in
    the
    prefilter catalog, regardless of whether the agent actually opened that
    skill
    via load_skill. So if resolve_skills returns top-3 skills and the
    agent
    only opens one, the graph still gets three SkillRuns — two of which
    blame
    skills the agent never consulted.
    improve_failing_skills reads those rows. With misattributed runs, the
    critic in inspect_skill ends up reasoning about skills that had
    nothing to
    do with the call, and proposed amendments target the wrong skills.
    Fix: track the names of opened skills in a new opened_skills_var
    ContextVar declared next to the existing active_skills_var.
    load_skill
    adds to it on a successful open. The retriever filters the catalog by it
    before persisting on both the success and error paths. If the loop
    opened
    zero skills, zero runs are recorded — no skill is responsible for an
    unconsulted call.

    Acceptance Criteria

    • _record_skill_runs is called only with skills that were opened
      via load_skill
      • When the agent opens zero skills, zero SkillRuns are written
    • _record_skill_runs's signature is unchanged — filtering happens
      in the caller
    • The existing test_agentic_skill_runs_use_neutral_success_score
      continues to pass byte-for-byte
    • load_skill stays safe if invoked outside the agentic loop (the
      new ContextVar defaults to None; the handler is guarded)

    Type of Change

    • Bug fix (non-breaking change that fixes an issue)
      • New feature (non-breaking change that adds functionality)
      • Code refactoring
    • Other (please specify):

    Screenshots

    19/19 tests in cognee/tests/unit/modules/tools/test_skill_ingest.py
    pass.

    Pre-submission Checklist

    • I have tested my changes thoroughly before submitting this PR
      (See CONTRIBUTING.md)
    • This PR contains minimal changes necessary to address the
      issue/feature
    • My code follows the project's coding standards and style
      guidelines
    • I have added tests that prove my fix is effective or that my
      feature works
      • I have added necessary documentation (if applicable)
    • All new and existing tests pass
    • I have searched existing PRs to ensure this change hasn't been
      submitted already
    • I have linked any relevant issues in the description
    • My commits have clear and descriptive messages

    DCO Affirmation

    I affirm that all code in every commit of this pull request conforms to
    the terms of the Topoteretes Developer Certificate of Origin.

    下载附件