Skip to content

fix: repair narinfo migration logic for invalid URLs - #642

Merged
kalbasit merged 1 commit into
mainfrom
01-23-fix_repair_narinfo_migration_logic_for_invalid_urls
Jan 24, 2026
Merged

kalbasit merged 1 commit into
mainfrom
01-23-fix_repair_narinfo_migration_logic_for_invalid_urls

Conversation

@kalbasit

Copy link
Copy Markdown
Owner

This commit restores and fixes the logic where a NarInfo with an invalid (NULL) URL in the database is treated as a signal that the record has not yet been fully migrated from storage. The migrate-narinfo command and other parts of the system rely on this url IS NULL condition to identify pending migrations.

Specifically, this change:

  1. Re-enables the background migration trigger in GetNarInfo when it encounters a database record with an invalid URL.
  2. Updates storeInDatabase to properly handle upserts when such a placeholder record exists. Instead of failing with a duplicate key error, it deletes the existing partial record and recreates it with the full details, ensuring the migration can complete successfully.
  3. Adds a regression test TestGetNarInfo_MigratesInvalidURL to verify this behavior.

@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. bug Something isn't working go Pull requests that update go code labels Jan 24, 2026

kalbasit commented Jan 24, 2026 •

Copy link
Copy Markdown
Owner Author

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @kalbasit, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves a critical issue where narinfo records with invalid or null URLs in the database were not being fully migrated from storage. The changes ensure that such partial records correctly trigger a background migration process, and the database storage mechanism can now properly upsert these records by deleting and re-creating them, thereby completing the migration and maintaining data consistency.

Highlights

  • NarInfo Migration Trigger: Re-enabled the background migration trigger in GetNarInfo for narinfo records that have an invalid (NULL) URL in the database, ensuring pending migrations are processed.
  • Database Upsert Logic: Updated the storeInDatabase function to gracefully handle duplicate key errors for narinfo records. Instead of failing, it now deletes the existing partial record and re-inserts the complete narinfo data, facilitating proper upsert behavior during migration.
  • Regression Test: Introduced a new regression test, TestGetNarInfo_MigratesInvalidURL, to specifically verify that narinfo records with invalid URLs are correctly migrated and updated in the database.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request correctly identifies and fixes a bug in the narinfo migration logic where placeholder records with NULL URLs were not being processed. The changes to re-enable the background migration trigger and handle upserts by replacing existing records are well-implemented. The addition of the regression test TestGetNarInfo_MigratesInvalidURL is excellent and ensures this behavior is covered going forward. However, I found a critical syntax error in the new error handling logic that will prevent the code from compiling, which needs to be addressed.

Comment thread pkg/cache/cache.go Resolved
Base automatically changed from 01-23-fix_run.py_did_not_correctly_handle_db_url_or_ha_over_sqlite to main January 24, 2026 06:53
@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Jan 24, 2026
@kalbasit
kalbasit force-pushed the 01-23-fix_repair_narinfo_migration_logic_for_invalid_urls branch from 7152eff to eb9361d Compare January 24, 2026 06:53
@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Jan 24, 2026
@kalbasit
kalbasit enabled auto-merge (squash) January 24, 2026 06:57
This commit addresses an issue where NarInfo records with missing URLs (indicating incomplete migration) were not being correctly identified and migrated to the database.

Changes implemented:

1. **Migration Trigger**: Restored the check for '!nir.URL.Valid' in 'getNarInfoFromStore' (pkg/cache/cache.go). When a NarInfo is found with a NULL URL, the system now correctly triggers 'backgroundMigrateNarInfo' to fetch and update the record.

2. **Idempotent Inserts**: Updated 'CreateNarInfo' SQL queries to use 'ON CONFLICT DO UPDATE' (Upsert). This ensures that the migration process can update existing incomplete records in the database with data fetched from storage, instead of failing with duplicate key errors.

3. **Tests**: Added a regression test 'TestGetNarInfo_MigratesInvalidURL' in 'pkg/cache/cache_test.go' and updated 'TestStoreInDatabaseDuplicateDetection' in 'pkg/cache/cache_internal_test.go' to verify the new upsert behavior.
@kalbasit
kalbasit force-pushed the 01-23-fix_repair_narinfo_migration_logic_for_invalid_urls branch from eb9361d to c9df0ed Compare January 24, 2026 08:57
@dosubot dosubot Bot added size:XL This PR changes 500-999 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Jan 24, 2026
@kalbasit

Copy link
Copy Markdown
Owner Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request provides a robust fix for the narinfo migration logic. The use of conditional UPSERTs across all supported database backends is a solid approach to handle the migration of placeholder records idempotently. The Go code changes are well-integrated with the new SQL logic, and the error handling for different database behaviors is thoughtful. The accompanying tests are comprehensive, covering data integrity, concurrency, and behavior consistency across databases, which significantly increases confidence in the fix. The suggestion to improve the robustness of the error handling in the delete logic has been retained as it aligns with general best practices and is not covered by existing rules.

Comment thread pkg/cache/cache.go Resolved
@kalbasit
kalbasit merged commit c75a8ed into main Jan 24, 2026
@kalbasit
kalbasit deleted the 01-23-fix_repair_narinfo_migration_logic_for_invalid_urls branch January 24, 2026 09:08
kalbasit added a commit that referenced this pull request Jan 24, 2026
#645)

This commit improves the robustness and consistency of database lookups
in the cache layer by correctly utilizing the `database.IsNotFoundError`
helper.
    
Specifically:
- In `deleteNarInfoFromStore`, the logic to check if a NarInfo exists in
the database has been refactored to be more concise and explicit about
error handling.
- In `setupSecretKey`, the error check when fetching the secret key from
the database now correctly ignores "not found" errors, ensuring that the
fallback logic (to the config store or key generation) is correctly
triggered.

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

Labels

bug Something isn't working go Pull requests that update go code size:XL This PR changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant