Skip to content

[code-review] knowledge_graph doAdd unconditionally overwrites Tags with nil on update — silent tag data loss #74

Description

@topcheer

File: internal/tool/knowledge_graph.go
Lines: 186
Severity: Medium

Problem

Line 186 unconditionally assigns ex.Tags = p.Tags when updating an existing node. If the caller didn't provide tags (p.Tags is nil from JSON unmarshal), existing tags are silently erased. In contrast, Status at line 187-189 is conditionally preserved with if p.Status != "". Tags get no such guard — inconsistent and surprising data loss.

Trigger Scenario

  1. Node exists with tags: ["decision", "accepted"] and status: "accepted"
  2. User calls knowledge_graph add with the same ID to update only the title (no tags, no status provided)
  3. After update: tags becomes nil (erased), status remains "accepted" (preserved)
  4. Tags are silently destroyed while status survives

Expected vs Actual

  • Expected: Tags are preserved when not provided, just like Status
  • Actual: Tags are unconditionally overwritten with nil

Fix

Add a nil-guard for Tags, matching the Status pattern:

if p.Tags != nil {
    ex.Tags = p.Tags
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions