Skip to content

feat(opentrons-ai-server): backend support for settings page #18837

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 9, 2025

Conversation

Elyorcv
Copy link
Contributor

@Elyorcv Elyorcv commented Jul 4, 2025

Overview

Closes AUTH-2016
PR made changes to the backend with respect to frontend settings page.

Test Plan and Hands on Testing

CI

Review requests

Make sure everything is working as expected

Risk assessment

Low

@Elyorcv Elyorcv changed the title feat(opentrons-ai-client, opentrons-ai-server): backend support feat(opentrons-ai-server): backend support for settings page Jul 4, 2025
@Elyorcv Elyorcv marked this pull request as ready for review July 7, 2025 08:40
@Elyorcv Elyorcv requested review from a team as code owners July 7, 2025 08:40
@Elyorcv Elyorcv requested review from koji, ddcc4 and y3rsh July 7, 2025 08:40
Comment on lines +102 to +106
{location.pathname === '/' && (
<Box marginLeft={SPACING.spacing16}>
<SettingsButton onClick={handleSettingsClick} />
</Box>
)}
Copy link
Contributor

Choose a reason for hiding this comment

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

why this change is neccessary?
it feels quite unusual that app settings can only be changed from the landing page.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good question! This is mainly because of the current implementation of state management. For example, if you go to the chat page, submit a prompt, navigate to settings, and come back, it restarts the generation process. This is not what we want.
The decision to restrict settings access to the landing page was made to:

  1. Prevent state loss: Avoid interrupting ongoing API calls or active chat sessions
  2. Simplify navigation: Users can access settings from a predictable, central location
  3. Avoid complexity: Prevents issues with navigating away during active operations

Fixing this would require refactoring the frontend state management to properly preserve application context when navigating between routes - a more substantial change that was out of scope for this implementation. This is my understanding.

If you think it is easy to implement let me know.

Copy link
Contributor

Choose a reason for hiding this comment

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

@Elyorcv
could you post the screen capture that is what you mentioned to ai-dev cahnnel(For example, if you go to the chat page, submit a prompt, navigate to settings, and come back)?

Comment on lines +35 to +38
headers: {
...config?.headers,
...analyticsHeaders,
},
Copy link
Contributor

@koji koji Jul 7, 2025

Choose a reason for hiding this comment

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

why do you need this?
the data will be sent to Mixpanel from the frontend. what does the backend need to know about that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

While the frontend handles user interaction analytics with Mixpanel, the backend handles chat analytics with Weave which is why we coordinate them with the x-enable-analytics header.

Your question reminds me to implement disabling mixpanel when toggle is off.

At the moment, when toggle is off, backend stops tracking whereas frontend analytics continue.

logger.debug(f"Analytics {'enabled' if enable_analytics else 'disabled'} for this request")

# Initialize Weave on first call (regardless of analytics preference)
if not _weave_initialized:
Copy link
Collaborator

Choose a reason for hiding this comment

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

If weave.init() fails for any reason, this implementation will continue to call it for every request. Is that what you want?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch. Now added a finally block that sets _weave_initialized = True regardless of success or failure. We would want to initialize only once.

global _weave_initialized, _analytics_enabled

# Update analytics preference
_analytics_enabled = enable_analytics
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you explain how these global variables work? Is there only one _analytics_enabled for the whole server, but each request can choose to set it to True or False? What if you get 2 requests at the same time, and they have differing preferences for enable_analytics?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch. Concurrency problem occurs! Completely removed the global _analytics_enabled variable and made analytics preference request-scoped.

Copy link
Collaborator

@ddcc4 ddcc4 left a comment

Choose a reason for hiding this comment

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

Approving for the Python changes. See if Koji has anything else about the frontend stuff.

@Elyorcv Elyorcv force-pushed the AUTH-2016-backend-settings-page branch from 90e50c4 to 909f1f1 Compare July 8, 2025 21:19
Copy link

codecov bot commented Jul 8, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 26.84%. Comparing base (5d6e238) to head (909f1f1).
Report is 5 commits behind head on edge.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             edge   #18837   +/-   ##
=======================================
  Coverage   26.84%   26.84%           
=======================================
  Files        3252     3252           
  Lines      257814   257814           
  Branches    32609    32609           
=======================================
  Hits        69223    69223           
  Misses     188567   188567           
  Partials       24       24           
Flag Coverage Δ
protocol-designer 19.14% <ø> (-0.01%) ⬇️
step-generation 5.34% <ø> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Elyorcv Elyorcv merged commit 5bbd596 into edge Jul 9, 2025
54 of 56 checks passed
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