Skip to content

fix #29: Add config validation on restart to prevent data corruption; fix config example typo; change 'tuft' to 'tuft launch'#69

Merged
xuanrui-L merged 5 commits intomainfrom
fix/persistence
Feb 2, 2026
Merged

fix #29: Add config validation on restart to prevent data corruption; fix config example typo; change 'tuft' to 'tuft launch'#69
xuanrui-L merged 5 commits intomainfrom
fix/persistence

Conversation

@xuanrui-L
Copy link
Copy Markdown
Collaborator

@xuanrui-L xuanrui-L commented Jan 30, 2026

  • Convert AppConfig, ModelConfig, TelemetryConfig from dataclass to Pydantic
    models for native JSON serialization support
  • Add ConfigSignature to store complete AppConfig snapshot in Redis
  • Validate config on startup (read-only), save signature after successful init
  • Add check_fields option in PersistenceConfig to configure which fields
    to validate (default: ["supported_models"])
  • Add --refresh-persistence CLI flag to clear existing data and start fresh
  • Add --force-refresh-persistence to skip confirmation prompt

If config mismatch is detected, server exits with clear error message
suggesting to either restore original config or use --refresh-persistence.

fix config example typos

- Convert AppConfig, ModelConfig, TelemetryConfig from dataclass to Pydantic
  models for native JSON serialization support
- Add ConfigSignature to store complete AppConfig snapshot in Redis
- Validate config on startup (read-only), save signature after successful init
- Add `check_fields` option in PersistenceConfig to configure which fields
  to validate (default: ["supported_models"])
- Add --refresh-persistence CLI flag to clear existing data and start fresh
- Add --force-refresh-persistence to skip confirmation prompt

If config mismatch is detected, server exits with clear error message
suggesting to either restore original config or use --refresh-persistence.
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @xuanrui-L, 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 introduces a critical safety feature to prevent data corruption in the TuFT server when using persistence. It implements a robust configuration validation system that checks for consistency between the running server's configuration and the previously persisted state. This ensures that incompatible configuration changes do not lead to silent data loss or unexpected behavior upon restart. The changes also include a migration of core configuration models to Pydantic for enhanced data validation and a clearer mechanism for users to manage persistence data when configuration changes are necessary.

Highlights

  • Configuration Validation on Restart: Implemented a critical mechanism to validate the current server configuration against a stored signature in the persistence layer (Redis) upon startup. This prevents data corruption that could occur if the server restarts with an incompatible configuration.
  • ConfigMismatchError: Introduced a new exception, ConfigMismatchError, which is raised if a configuration mismatch is detected. This error provides detailed information about the differences and offers clear options for resolution, such as using a different Redis database or refreshing persistence data.
  • Persistence Data Refresh Options: Added new CLI options, --refresh-persistence and --force-refresh-persistence, allowing users to explicitly clear all persisted data in the current namespace. This is crucial when intentionally changing configurations that would otherwise cause a mismatch, ensuring a clean slate.
  • Pydantic Migration for Config Models: Refactored core configuration models (AppConfig and ModelConfig) from dataclass to pydantic.BaseModel. This migration enhances configuration handling, validation, and serialization capabilities, making the configuration more robust and easier to manage.
  • Persistence Mode Renaming and Documentation: Standardized persistence mode names to uppercase (e.g., 'disabled' to 'DISABLE', 'redis_url' to 'REDIS_URL') across documentation and code for improved consistency and clarity. The README and example configurations have been updated accordingly.
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.

@xuanrui-L xuanrui-L changed the title fix #29: Add config validation on restart to prevent data corruption fix #29: Add config validation on restart to prevent data corruption; fix config example typo; change 'tuft' to 'tuft launch' Jan 30, 2026
Copy link
Copy Markdown
Contributor

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

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 introduces a critical feature to prevent data corruption by validating the application configuration against a stored signature upon restart, especially when persistence is enabled. The implementation is robust, featuring a migration of configuration classes from dataclasses to pydantic for better validation, a user-friendly CLI for handling configuration mismatches, and comprehensive tests. My review focuses on improving consistency in the CLI's exit behavior, simplifying some redundant code, and fixing a small bug in the error message generation. Overall, this is an excellent contribution that significantly improves the reliability of the application.

Comment thread src/tuft/exceptions.py Outdated
Comment thread src/tuft/cli.py Outdated
Comment thread src/tuft/config.py Outdated
@pan-x-c
Copy link
Copy Markdown
Collaborator

pan-x-c commented Jan 30, 2026

/unittest

@xuanrui-L
Copy link
Copy Markdown
Collaborator Author

/unittest

Comment thread README.md Outdated
Comment thread README.md Outdated
Comment thread config/tuft_config.example.yaml Outdated
Comment thread config/tuft_config.example.yaml
Comment thread src/tuft/cli.py Outdated
Comment thread tests/test_persistence.py
with pytest.raises(ConfigMismatchError):
validate_config_signature(config2)

def test_refresh_persistence_allows_restart_with_new_config(self, setup):
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The test cases mentioned here should be modified/added to the integration test suite. Scenarios involving restarts and data cleanup are particularly important—both successful and failed restart cases need to be covered to ensure system reliability.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This test currently aligns with the persistence unit test requirements. We can also add the corresponding config test coverage in the integration tests later—pls create an issue so we can track and address it.

- Changed persistence mode names in README and configuration files from `REDIS_URL` to `REDIS` and `FILE_REDIS` to `FILE` for consistency.
- Updated CLI commands to replace `--refresh-persistence` with `tuft clear persistence` for clearing existing data.
- Adjusted default namespace in persistence configuration to `persistence-tuft-server`.
- Enhanced documentation to reflect these changes and improve clarity on usage.
@xuanrui-L xuanrui-L merged commit 7402b52 into main Feb 2, 2026
9 checks passed
@xuanrui-L xuanrui-L deleted the fix/persistence branch February 2, 2026 04:43
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.

After changing the configuration and restarting, the server fails to start up.

3 participants