Skip to content

fix: persist deviceId on first call when no config exists#454

Open
HiddenPuppy wants to merge 1 commit intomainfrom
fix/ensureDeviceId-persist-on-first-call
Open

fix: persist deviceId on first call when no config exists#454
HiddenPuppy wants to merge 1 commit intomainfrom
fix/ensureDeviceId-persist-on-first-call

Conversation

@HiddenPuppy
Copy link
Copy Markdown
Collaborator

Problem

On first launch, before a config file exists, ensureDeviceId() generates a random UUID but only persists it when config is non-null. When readConfig() returns null (no config file yet), the function returns a fresh UUID without writing it, so every subsequent call produces a different device ID until something else writes the config.

Fix

When config is null, construct a minimal AppConfig with workspacePath: getDefaultWorkspacePath(), gateways: [], and the new deviceId, then always call writeConfig(...) before returning.

Verification

  • pnpm check passes (40 test files, 243 tests)
  • Manual: delete config file, trigger ensureDeviceId() twice → same UUID both times

Fixes #383

ensureDeviceId() previously generated a random UUID but only wrote it
when a config file already existed. On fresh installs (readConfig()
returns null), every call returned a new UUID until something else
wrote the config.

Now we construct a minimal AppConfig with the required fields
(workspacePath, gateways) and always call writeConfig() so the
deviceId is stable from the very first invocation.

Fixes #383
@HiddenPuppy HiddenPuppy requested a review from samzong as a code owner April 23, 2026 06:44
@github-actions
Copy link
Copy Markdown
Contributor

Hi @HiddenPuppy,
Thanks for your pull request!
If the PR is ready, use the /auto-cc command to assign Reviewer to Review.
We will review it shortly.

Details

Instructions for interacting with me using comments are available here.
If you have questions or suggestions related to my behavior, please file an issue against the gh-ci-bot repository.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 addresses an issue where the device ID was not being correctly persisted during the initial application launch. By ensuring that a default configuration is created and written to disk immediately upon generating a new device ID, the application now maintains a consistent identity across subsequent calls.

Highlights

  • Device ID Persistence: Updated ensureDeviceId to ensure that a generated device ID is persisted even when no configuration file exists yet.
  • Configuration Initialization: Modified the logic to create a default AppConfig object when the initial read returns null, ensuring consistent state management.
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.

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.

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 modifies the ensureDeviceId function to ensure that a deviceId is persisted even if the configuration file is missing, by initializing it with default values. A review comment suggests refactoring this implementation to use the existing updateConfig helper, which would avoid duplicating default configuration logic and keep persistence centralized.

Comment on lines +207 to +212
const updated = config ?? {
workspacePath: getDefaultWorkspacePath(),
gateways: [],
};
updated.deviceId = deviceId;
writeConfig(updated);
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.

medium

Instead of manually re-implementing the logic to handle a missing configuration, you can use the existing updateConfig helper. This avoids duplicating the default configuration object (workspacePath and gateways) and keeps the persistence logic centralized. Note that using this helper will make the config variable on line 204 unused, so you may want to refactor the initial check to readConfig()?.deviceId.

  updateConfig({ deviceId });

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.

[Bug] ensureDeviceId returns a new UUID every call when no config file exists

1 participant