Skip to content

Conversation

@jaskfla
Copy link
Contributor

@jaskfla jaskfla commented Dec 9, 2025

No description provided.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @jaskfla, 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 significantly refactors the ClientSyncManager to enhance its internal state management and external observability. It transitions key internal properties to private class fields and introduces a more granular, strongly-typed event system. This allows for more precise communication of sync status, progress, and stage changes to other parts of the application, ultimately leading to a more robust, maintainable, and predictable synchronization experience.

Highlights

  • Encapsulation of Sync State: The ClientSyncManager now uses private class fields (prefixed with #) for its internal state, such as database, models, syncInterval, and status. This improves encapsulation and prevents direct external modification of critical internal properties.
  • Granular Sync Events: The generic SYNC_STATE_CHANGED event has been replaced with more specific, strongly-typed events: SYNC_PROGRESS_CHANGED, SYNC_STAGE_CHANGED, and SYNC_STATUS_CHANGED. This allows external components to react with greater precision to different aspects of the sync process.
  • Explicit Sync Status Management: A new SYNC_STATUS enum and a private setter for the status property have been introduced. This centralizes state transitions and ensures that an appropriate event is emitted whenever the sync status changes (e.g., to REQUESTING, QUEUING, SYNCING, IDLE, INACTIVE).
  • Improved Readability and Maintainability: By centralizing state updates and event emissions within private setters and dedicated methods, the sync logic becomes easier to understand, debug, and maintain. The SyncPage view has been updated to consume these new events, reflecting the sync state more accurately.
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.

Comment on lines 69 to 92
static #instance: ClientSyncManager | null = null;

static async getInstance(models: DatatrakWebModelRegistry): Promise<ClientSyncManager> {
if (!ClientSyncManager.#instance) {
const deviceId = await getDeviceId(models);
ClientSyncManager.#instance = new ClientSyncManager(models, deviceId);
}
return ClientSyncManager.#instance;
}

private database: DatatrakDatabase;
#database: DatatrakDatabase;

private models: DatatrakWebModelRegistry;
#models: DatatrakWebModelRegistry;

private deviceId: string;
#deviceId: string;

private urgentSyncInterval: NodeJS.Timeout | null = null;
#urgentSyncInterval: ReturnType<typeof setInterval> | null = null;

private isInitialSync: boolean = false;
#isInitialSync: boolean = false;

private syncInterval: NodeJS.Timeout | null = null;
#syncInterval: ReturnType<typeof setInterval> | null = null;

progressMaxByStage = STAGE_MAX_PROGRESS_INCREMENTAL;
#progressMaxByStage: typeof STAGE_MAX_PROGRESS_INCREMENTAL | typeof STAGE_MAX_PROGRESS_INITIAL =
STAGE_MAX_PROGRESS_INCREMENTAL;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

No logical changes

#progress: number | null = null;

progress: number | null = null;
#statusMessage: string | null = null;
Copy link
Contributor Author

@jaskfla jaskfla Dec 9, 2025

Choose a reason for hiding this comment

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

Renamed “progress message” to “status message”. Honestly could just be “message”, but that might be conflated with the message from stream()

Even though all progress updates come with a message update, not all message updates are tied to sync progressing

e.g. “Requesting sync…” is unrelated to the progress of a sync session

Copy link
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 refactors the ClientSyncManager class to enhance encapsulation and type safety by migrating internal state properties to TypeScript private class fields (#private). It replaces multiple boolean flags (e.g., isSyncing, isRequestingSync) with a single status property, managed by private setters that emit specific, strongly-typed events (SYNC_STATUS_CHANGED, SYNC_STAGE_CHANGED, SYNC_PROGRESS_CHANGED). The event system itself is updated with new event types and a SyncEvents type for improved clarity and type checking. The SyncPage component is also updated to consume these new ClientSyncManager APIs. A review comment highlighted a redundant this.status = SYNC_STATUS.SYNCING; assignment, suggesting its removal for better code clarity as the status is already correctly set earlier or changed to QUEUING based on session ID validity.

Comment on lines 124 to 146
private set status(status: SyncStatus) {
this.#status = status;
this.emitter.emit(SYNC_EVENT_ACTIONS.SYNC_STATUS_CHANGED, { status });
}
Copy link
Contributor Author

@jaskfla jaskfla Dec 9, 2025

Choose a reason for hiding this comment

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

Emit event when we do syncManager.status = 'newStatus'

Ditto syncStage setter

Comment on lines 129 to 158
get isRequestingSync() {
return this.#status === 'requesting';
}

get isSyncing() {
return this.#status === 'syncing';
}

get isQueuing() {
return this.#status === 'queuing';
}
Copy link
Contributor Author

@jaskfla jaskfla Dec 9, 2025

Choose a reason for hiding this comment

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

This lets us:

- this.isQueuing = false
- this.isSyncing = true
+ this.status = 'syncing'

@jaskfla jaskfla force-pushed the finer-events branch 2 times, most recently from 46a3e45 to c7475b2 Compare December 9, 2025 04:16
Comment on lines +179 to +182
get emitter() {
return this.#emitter;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Felt strange that we could, in React-land, just overwrite the emitter. Not sure it was a “real” problem, but this was so trivial to tighten up

this.emitter.emit(SYNC_EVENT_ACTIONS.SYNC_ERROR, { error: error.message });
this.errorMessage = error.message;
} finally {
// Reset all the values to default only if sync actually started, otherwise they should still be default values
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Idempotent anyway, so took out the if

Hard to keep the if guard because the try and catch blocks update the status to IDLE | ERROR, so isSyncing will always be false in the finally block

@jaskfla jaskfla force-pushed the finer-events branch 2 times, most recently from 3ae6bbd to faabf50 Compare December 9, 2025 04:36

if (this.#urgentSyncInterval) {
clearInterval(this.#urgentSyncInterval);
this.#urgentSyncInterval = null;
Copy link

Choose a reason for hiding this comment

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

Bug: Urgent sync retry interval cleared prematurely when queued

The finally block unconditionally clears #urgentSyncInterval, but this breaks the urgent sync retry mechanism. Previously, the if (this.isSyncing) guard in the finally block prevented the interval from being cleared when sync was merely queued (returned early without actually syncing). Now when an urgent sync is queued by the server, the interval is immediately cleared after the first attempt, preventing the scheduled retries that are supposed to poll for queue status changes every 10 seconds.

Fix in Cursor Fix in Web

@jaskfla jaskfla marked this pull request as draft December 9, 2025 04:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant