fix(entities): count actual inserted rows in recordEntities on conflict (#27) - #28
Merged
7vignesh merged 1 commit intoSep 21, 2026
Conversation
…ct (7vignesh#27) In recordEntities, the loop previously incremented recorded += 1 unconditionally for every entity in the loop, even when the insert statement executed ON CONFLICT DO NOTHING. For multi-kind matches (such as entities recognized as both a package and a service like redis, docker, or kubernetes) which share the same (memory_rowid, entity) PRIMARY KEY, conflict no-ops caused the returned count to overstate the rows actually written. Use the statement result changes property (recorded += result.changes) to track actual inserts and add a regression test. Fixes 7vignesh#27
|
@DYNOSuprovo is attempting to deploy a commit to the vignesh's projects Team on Vercel. A member of the Team first needs to authorize it. |
7vignesh
approved these changes
Sep 21, 2026
7vignesh
left a comment
Owner
There was a problem hiding this comment.
Clean one-line fix, and the test surfaced something I underestimated when filing #27 - redis/docker/kubernetes live in both KNOWN_PACKAGES and KNOWN_SERVICES, and the table PK is (memory_rowid, entity) without kind, so the conflict is actually reachable, not just theoretical. Verified locally: typecheck clean, all entity tests pass, green on Node 20/22. Thanks @DYNOSuprovo!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #27
Summary of Changes
src/lib/entities.ts, updatedrecordEntitiesto count actual rows written usingresult.changesfrominsert.run(memoryRowId, entity, kind)instead of unconditionally incrementingrecorded += 1.redis,docker,kubernetes, which exist in bothKNOWN_PACKAGESandKNOWN_SERVICES),extractEntitiesemits multiple entries with the sameentityname. Becausememory_entitieshasPRIMARY KEY (memory_rowid, entity), subsequent inserts hitON CONFLICT DO NOTHINGand returnchanges: 0. Trackingresult.changesensures the returned count accurately reflects rows written into SQLite.tests/entities.test.ts, added a regression testrecordEntities counts actual inserted rows, not no-op conflictsverifying that multi-kind entities withON CONFLICT DO NOTHINGreturn the exact count matching rows stored in the database.Verification
npm run typecheck: Passed with 0 errors.tsx --test tests/*.test.ts: All 232 tests passed (including the new regression test).npm run build: Successful build (dist/index.js,dist/cli.js).npm run smoke: Smoke test passed cleanly.