Skip to content

Improve user id handling#644

Merged
guarin merged 6 commits intomainfrom
trn-1839-improve-posthog-userid
Mar 19, 2026
Merged

Improve user id handling#644
guarin merged 6 commits intomainfrom
trn-1839-improve-posthog-userid

Conversation

@guarin
Copy link
Copy Markdown
Contributor

@guarin guarin commented Mar 17, 2026

What has changed and why?

How has it been tested?

  • Unit tests

Did you update CHANGELOG.md?

  • Yes
  • Not needed (internal change)

Did you update the documentation?

  • Yes
  • Not needed (internal change without effects for user)

Copilot AI review requested due to automatic review settings March 17, 2026 11:38
@guarin
Copy link
Copy Markdown
Contributor Author

guarin commented Mar 17, 2026

/review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 23a8f36718

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/lightly_train/_events/tracker.py Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR replaces the ephemeral per-process analytics identifier with a persistent user ID stored under the Lightly Train cache directory, and updates/extends unit tests to validate the new behavior.

Changes:

  • Introduce _user_id and _load_user_id() to persist a UUID in userid.txt under Env.LIGHTLY_TRAIN_CACHE_DIR.
  • Update event payload distinct_id to use the persisted _user_id rather than a session UUID.
  • Expand tracker unit tests to cover file creation, reading an existing ID, and read/write error fallbacks.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/lightly_train/_events/tracker.py Implements persistent user ID loading/creation and uses it as distinct_id for event tracking.
tests/_events/test_tracker.py Updates existing assertions and adds tests for _load_user_id() file-based persistence and error fallbacks.
Comments suppressed due to low confidence (1)

src/lightly_train/_events/tracker.py:154

  • track_event initializes _user_id (and may read/write userid.txt) before checking LIGHTLY_TRAIN_EVENTS_DISABLED / rate-limiting / queue-size early returns. This introduces a side effect (creating a persistent identifier file) even when analytics are disabled or the event is dropped. Consider moving the _user_id lazy-load to just before building event_data, after all early-return checks (at least after the events-disabled guard).
    global _last_flush, _user_id
    if _user_id is None:
        _user_id = _load_user_id()

    current_time = time.time()
    if Env.LIGHTLY_TRAIN_EVENTS_DISABLED.value or (
        current_time - _last_event_time.get(event_name, -100.0) < _RATE_LIMIT_SECONDS
    ):
        return

You can also share your feedback on Copilot code review. Take the survey.

Comment thread tests/_events/test_tracker.py
Comment thread src/lightly_train/_events/tracker.py Outdated
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b527e02a18

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/lightly_train/_events/tracker.py Outdated
@guarin
Copy link
Copy Markdown
Contributor Author

guarin commented Mar 17, 2026

/review

Comment thread src/lightly_train/_events/tracker.py Outdated
Comment thread src/lightly_train/_events/tracker.py
Copy link
Copy Markdown
Contributor

@yutong-xiang-97 yutong-xiang-97 left a comment

Choose a reason for hiding this comment

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

Approved

@guarin guarin enabled auto-merge (squash) March 19, 2026 13:44
@guarin guarin merged commit 90d602f into main Mar 19, 2026
19 of 22 checks passed
@guarin guarin deleted the trn-1839-improve-posthog-userid branch March 19, 2026 14:58
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.

3 participants