Skip to content

Conversation

@Weves
Copy link
Contributor

@Weves Weves commented Jul 15, 2025

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.

  • This PR should be backported (make sure to check that the backport attempt succeeds)
  • [Optional] Override Linear Check

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.

  • Refactors
    • Added MinimalPersonaSnapshot for lightweight persona data.
    • Updated backend endpoints and frontend components to use minimal persona data where possible.
    • Removed unused fields from persona fetches and refactored related hooks, context, and utilities.

@Weves Weves requested a review from a team as a code owner July 15, 2025 21:03
@vercel
Copy link

vercel bot commented Jul 15, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
internal-search ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 15, 2025 9:42pm

Copy link
Contributor

@greptile-apps greptile-apps bot left a 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:

  1. Introduction of a MinimalPersonaSnapshot type that contains only essential fields needed for basic persona functionality
  2. Widespread replacement of full Persona type with MinimalPersonaSnapshot across frontend components
  3. Refactoring of database queries and API endpoints to support efficient loading of minimal persona data
  4. Removal of unnecessary complexity around file/folder ID checks for retrieval capabilities
  5. 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

  1. This PR is safe to merge with proper testing as it's primarily a type-level change with careful interface design
  2. High score due to consistent implementation across many files and clear architectural benefits, slightly reduced due to lack of testing details in PR description
  3. 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

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a 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]
Copy link
Contributor

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.
Suggested change
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) => (
Copy link
Contributor

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[] = [];
Copy link
Contributor

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[] = [];
Copy link
Contributor

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", {
Copy link
Contributor

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(
Copy link
Contributor

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.
Suggested change
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,
Copy link
Contributor

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(
Copy link
Contributor

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[]>(
Copy link
Contributor

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()
Copy link
Contributor

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.

@Weves Weves merged commit 3bb58a3 into main Jul 15, 2025
13 of 14 checks passed
@Weves Weves deleted the persona-simplification-r2 branch July 15, 2025 21:51
Weves added a commit that referenced this pull request Jul 15, 2025
* Revert "Revert "Reduce amount of stuff we fetch on `/persona` (#4988)" (#5024)"

This reverts commit f7ed7cd.

* Enhancements / fix re-render

* re-arrange

* greptile
Weves added a commit that referenced this pull request Aug 20, 2025
* Revert "Revert "Reduce amount of stuff we fetch on `/persona` (#4988)" (#5024)"

This reverts commit f7ed7cd.

* Enhancements / fix re-render

* re-arrange

* greptile
AnkitTukatek pushed a commit to TukaTek/onyx that referenced this pull request Sep 23, 2025
* 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
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.

2 participants