Skip to content

fix: append observations for duplicate entities in AddObservations - #6

Merged
okooo5km merged 2 commits into
okooo5km:mainfrom
tekicode:fix/3-add-observations-dedup
Mar 18, 2026
Merged

okooo5km merged 2 commits into
okooo5km:mainfrom
tekicode:fix/3-add-observations-dedup

Conversation

@tekicode

@tekicode tekicode commented Mar 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • AddObservations silently lost data when the same entity appeared twice in the input array — the map assignment (=) overwrote the first entry's observations
  • Changed to append() so all observations accumulate per entity
  • Added TestAddObservationsDuplicateEntity regression test in main_test.go

Test plan

  • New test sends two ObservationAddition entries for same entity with [obs-a, obs-b] and [obs-c, obs-d], asserts all 4 preserved
  • make check && go test ./... && make build passes clean

Fixes tekicode#3

🤖 Generated with Claude Code

AddObservations silently lost data when the same entity appeared twice
in the input array — the map assignment overwrote the first entry's
observations. Use append to accumulate all observations per entity.

Fixes #3

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings March 18, 2026 04:20

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Fixes a data-loss bug in KnowledgeGraphManager.AddObservations where multiple ObservationAddition entries for the same entity would overwrite earlier observations instead of accumulating them.

Changes:

  • Update AddObservations to append observations per entity rather than overwrite the per-entity map entry.
  • Add a regression test to ensure duplicate-entity additions preserve all observations.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
main.go Accumulates observations for duplicate entities using append() when building the per-entity observation map.
main_test.go Adds TestAddObservationsDuplicateEntity to verify observations from duplicate-entity additions are all retained.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread main.go Resolved
Comment thread main_test.go Resolved
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@okooo5km
okooo5km merged commit b2dc2cd into okooo5km:main Mar 18, 2026
1 check passed
@okooo5km

Copy link
Copy Markdown
Owner

Thanks for this fix, @tekicode! 🎉

Great catch on the obsMap overwrite bug — the append fix is clean and minimal, and the test covers the regression scenario well. Merged!

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.

AddObservations drops data when same entity appears twice in input

3 participants