-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Persona simplification r2 #5031
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
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Greptile Summary
This PR implements a significant architectural change to simplify the persona system across the application. The key changes include:
- Introduction of a
MinimalPersonaSnapshottype that contains only essential fields needed for basic persona functionality - Widespread replacement of full
Personatype withMinimalPersonaSnapshotacross frontend components - Refactoring of database queries and API endpoints to support efficient loading of minimal persona data
- Removal of unnecessary complexity around file/folder ID checks for retrieval capabilities
- Improved type safety and code organization through better interface segregation
The changes aim to optimize data transfer between frontend and backend by ensuring components only receive the data they actually need, potentially improving performance and reducing unnecessary prop drilling.
Confidence score: 4 /5
- This PR is safe to merge with proper testing as it's primarily a type-level change with careful interface design
- High score due to consistent implementation across many files and clear architectural benefits, slightly reduced due to lack of testing details in PR description
- Key files needing attention:
- backend/onyx/server/features/persona/models.py - New MinimalPersonaSnapshot implementation
- web/src/app/admin/assistants/interfaces.ts - Core type definitions
- web/src/app/chat/ChatPage.tsx - Critical component using new types
50 files reviewed, 6 comments
Edit PR Review Bot Settings | Greptile
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cubic found 26 issues across 50 files. Review them in cubic.dev
React with 👍 or 👎 to teach cubic. Tag @cubic-dev-ai to give specific feedback.
| db_session=db_session, user=user, get_editable=get_editable | ||
| ) | ||
| return [DocumentSetSummary.from_document_set(ds) for ds in document_sets] | ||
| return [DocumentSetSummary.from_model(ds) for ds in document_sets] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rule violated: Prefer long, explicit variable names
Variable name "ds" is an overly abbreviated identifier and violates the explicit naming rule; use a descriptive name with at least 3 words and 12 characters.
| return [DocumentSetSummary.from_model(ds) for ds in document_sets] | |
| return [DocumentSetSummary.from_model(document_set) for document_set in document_sets] |
| </button> | ||
| ))} | ||
| {syncEnabledAssistants.map( | ||
| (persona: MinimalPersonaSnapshot) => ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rule violated: Prefer long, explicit variable names
Function parameter name "persona" does not meet the minimum 3-word, 12-character requirement specified by the naming rule.
| const sync: Persona[] = []; | ||
| const available: Persona[] = []; | ||
| const sync: MinimalPersonaSnapshot[] = []; | ||
| const available: MinimalPersonaSnapshot[] = []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rule violated: Prefer long, explicit variable names
Variable name "available" is not descriptive enough; it must have at least 3 words and 12 characters according to the naming rule.
| const [syncEnabledAssistants, availableAssistants] = useMemo(() => { | ||
| const sync: Persona[] = []; | ||
| const available: Persona[] = []; | ||
| const sync: MinimalPersonaSnapshot[] = []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rule violated: Prefer long, explicit variable names
Variable name "sync" is overly abbreviated and violates the naming rule requiring at least 3 words and 12 characters for clarity.
| export const useAdminPersonas = (options?: UseAdminPersonasOptions) => { | ||
| const { includeDeleted = false, getEditable = false } = options || {}; | ||
|
|
||
| const url = buildApiPath("/api/admin/persona", { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rule violated: Prefer long, explicit variable names
Multiple newly introduced variable names (options, includeDeleted, getEditable, url, data, error, isLoading, mutate) are shorter than 3 words and/or fewer than 12 characters, violating the "Prefer long, explicit variable names" guideline.
| ) -> ListAssistantsResponse: | ||
| personas = list( | ||
| get_personas_for_user( | ||
| persona_snapshots = list( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rule violated: Everything Python should be as strictly typed as possible
Variable 'persona_snapshots' is assigned a non-literal value without an explicit type annotation, violating the strict typing rule.
| persona_snapshots = list( | |
| persona_snapshots: list[Persona] = list( |
| first_id=assistants[0].id if assistants else None, | ||
| last_id=assistants[-1].id if assistants else None, | ||
| has_more=len(personas) == limit, | ||
| has_more=len(persona_snapshots) == limit, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
has_more is calculated after the list was sliced to limit, so it returns true whenever exactly limit items are returned, even when no additional records exist, providing inaccurate pagination information.
| personas = list( | ||
| get_personas_for_user( | ||
| persona_snapshots = list( | ||
| get_raw_personas_for_user( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
get_raw_personas_for_user does not eager-load related tables; persona_to_assistant later accesses persona.tools and persona.prompts, so each access triggers separate queries, causing an N+1 performance issue.
| get_editable: getEditable.toString(), | ||
| }); | ||
|
|
||
| const { data, error, isLoading, mutate } = useSWR<Persona[]>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rule violated: Prefer pure stateless functions
Calling useSWR here triggers an HTTP request (via errorHandlingFetcher), making useAdminPersonas an impure function in direct conflict with the "Prefer pure stateless functions" rule which prohibits I/O operations inside function bodies.
| selectinload(Persona.document_sets), | ||
| selectinload(Persona.user), | ||
| ) | ||
| results = db_session.scalars(stmt).all() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rule violated: Prefer pure stateless functions
Performs a database query inside the function, introducing I/O and external state dependency, in direct violation of the "Prefer pure stateless functions" rule.
* Revert "Revert "Reduce amount of stuff we fetch on `/persona` (onyx-dot-app#4988)" (onyx-dot-app#5024)" This reverts commit 457e43d. * Enhancements / fix re-render * re-arrange * greptile
Description
^
How Has This Been Tested?
Tested locally
Backporting (check the box to trigger backport action)
Note: You have to check that the action passes, otherwise resolve the conflicts manually and tag the patches.
Summary by cubic
Simplified the persona API and frontend data model to only fetch and use minimal persona data on
/persona, reducing payload size and improving performance.MinimalPersonaSnapshotfor lightweight persona data.