Skip to content

Added debug-mode through query params #380

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 13 commits into from
Apr 11, 2025
Merged

Added debug-mode through query params #380

merged 13 commits into from
Apr 11, 2025

Conversation

SahilKumar000
Copy link
Contributor

@SahilKumar000 SahilKumar000 commented Apr 10, 2025

Description

Added debug-mode through query params Now if Global debug_mode is false then we can explicitly add a query param as &debug=true to enable debug mode

Testing

Additional Notes

Summary by CodeRabbit

  • New Features

    • Introduced enhanced controls for debug information during search operations, enabling dynamic logging based on environmental and operational factors.
  • Refactor

    • Standardized search and time-filter parameters by consolidating them into a unified configuration, streamlining both search and related chat functionality.
  • Tests

    • Updated test cases to align with the new parameter structure and debug flag integration, ensuring consistent performance and reliability.

Copy link

coderabbitai bot commented Apr 10, 2025

Walkthrough

This update enhances search functionality and debug management across both frontend and backend modules. In the Search component, the state tracking for debug information is refined to use an environment variable combined with a runtime property. The search parameter schema is updated to always include a debug flag. On the server side, API endpoints and the search function now accept a debug parameter via a configuration object, enabling enhanced logging and refined query payloads. Additional changes include using a timestamp range for chat searches, minor formatting improvements, and updated test invocations.

Changes

File(s) Change Summary
frontend/src/routes/_authenticated/search.tsx Enhanced debug handling in the Search component: introduced a showDebugInfo state with an updater, initialized via VITE_SHOW_DEBUG_INFO and search.debug; added a debug property to the searchParams schema with a transformation ensuring a default value of false; updated debug propagation in navigation.
frontend/src/routes/_authenticated/index.tsx Added a debug property (set to false) to the search object in the navigation call within the handleSearch function.
server/api/search.ts Added a debug parameter to the SearchApi and AnswerApi functions, passing it as requestDebug to the searchVespa function for enhanced logging and troubleshooting.
server/search/vespa.ts Refactored the searchVespa function: introduced a new type VespaQueryConfig and updated the function signature to accept a configuration object with parameters including an optional requestDebug. Updated payload construction based on an isDebugMode flag.
server/api/chat.ts Updated calls to searchVespa to use a timestampRange object instead of separate timestamp parameters. Reformatted multiline object declarations for readability in classification setup.
server/ai/eval.ts Made formatting adjustments (removal/addition of blank lines) within the endToEndFlow function; no impact on functionality.
server/tests/search.test.ts Updated test cases to call searchVespa with an object parameter (e.g., { limit: 10 }) instead of fixed positional arguments.
server/eval/evaluate.ts Modified the processQuery function to pass parameters to searchVespa as an object with a limit property, replacing the previous positional parameters approach.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant SearchComponent
    participant useEffect
    participant Navigation

    User->>SearchComponent: Initiate search action
    SearchComponent->>useEffect: Evaluate debug info (env var & search.debug)
    useEffect-->>SearchComponent: Update showDebugInfo state
    SearchComponent->>Navigation: Navigate with query & debug flag
Loading
sequenceDiagram
    participant Client
    participant API
    participant searchVespa

    Client->>API: Send search request with debug flag
    API->>searchVespa: Forward query config including `requestDebug`
    searchVespa->>searchVespa: Determine `isDebugMode` (using config.isDebugMode || requestDebug)
    searchVespa-->>API: Return search results with debug details (if enabled)
Loading

Poem

I'm a little rabbit on a coding spree,
Hopping through debug trails as clear as can be.
From frontend paths to server dens,
Each line refined with clever pens.
Cheers to cleaner code—let’s hop on with glee! 🐇✨

Tip

⚡💬 Agentic Chat (Pro Plan, General Availability)
  • We're introducing multi-step agentic chat in review comments and issue comments, within and outside of PR's. This feature enhances review and issue discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments and add commits to existing pull requests.

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e450790 and 7fac040.

📒 Files selected for processing (1)
  • server/ai/eval.ts (7 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • server/ai/eval.ts

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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.

Hello @SahilKumar000, 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!

Summary of Changes

This pull request introduces a debug mode that can be activated via a query parameter. This allows enabling debug information even when the global debug_mode is set to false. The changes involve modifying the search.tsx file in the frontend and search.ts and vespa.ts in the server to handle the new debug query parameter.

Highlights

  • Debug Mode via Query Parameter: The primary change is the addition of a debug query parameter that, when set to true, enables debug mode, overriding the global VITE_SHOW_DEBUG_INFO environment variable.
  • Frontend Changes: The frontend code in search.tsx is modified to read the debug query parameter and update the showDebugInfo state accordingly. The debug flag is also passed to the backend.
  • Backend Changes: The backend API in search.ts is updated to extract the debug query parameter and pass it to the searchVespa function. The searchVespa function in vespa.ts is modified to accept the debug parameter and enable trace-level logging if it's set to true.
  • Schema Validation: The searchParams schema in search.tsx is updated to include a debug boolean parameter with a default value of false.

Changelog

Click here to see the changelog
  • frontend/src/routes/_authenticated/search.tsx
    • Modified the showDebugInfo state initialization to consider the debug query parameter.
    • Added setDebugInfo to update debug info based on query params
    • Added search as a dependency to the useEffect hook to update the query.
    • Passed the showDebugInfo flag to the backend.
    • Updated the searchParams schema to include a debug boolean parameter.
  • server/api/search.ts
    • Extracted the debug query parameter from the request.
    • Passed the debug parameter to the searchVespa function in both SearchApi and AnswerApi.
  • server/search/vespa.ts
    • Modified the searchVespa function to accept a requestDebug boolean parameter.
    • Enabled trace-level logging in Vespa if either the global config.isDebugMode or the requestDebug parameter is true.
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

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 issue 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 is currently in preview and 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 to provide feedback.

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.


A query's tale,
Debug's flag, now set to sail,
Tracing through the night.

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.

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 introduces a debug mode that can be enabled via a query parameter, which is a useful feature for debugging purposes. The changes look good overall, but there are a few areas that could be improved for clarity and maintainability.

Summary of Findings

  • Inconsistent debug flag usage: The debug flag is being checked in multiple places, which could lead to inconsistencies if not managed carefully. Consider centralizing the debug flag check to ensure consistent behavior throughout the application.
  • Potential security risk: Enabling debug mode via a query parameter could expose sensitive information if not properly secured. Ensure that debug mode is only enabled for authorized users or environments.

Merge Readiness

The pull request is almost ready for merging, but there are a few issues that need to be addressed before merging. I would recommend addressing the potential security risk and centralizing the debug flag check to ensure consistent behavior throughout the application. I am unable to approve this pull request, and recommend that others review and approve this code before merging.

Comment on lines 106 to 107
const [showDebugInfo, setDebugInfo] = useState(
import.meta.env.VITE_SHOW_DEBUG_INFO === "true" || search.debug || false,
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Consider using a more descriptive name for the state variable. setDebugInfo is good, but isDebugMode would be more explicit about what the variable represents. Also, it might be beneficial to initialize this state using a function to avoid re-renders when the component mounts, especially if search.debug is expensive to compute.

  const [isDebugMode, setIsDebugMode] = useState(
    () => import.meta.env.VITE_SHOW_DEBUG_INFO === "true" || search.debug || false,
  )

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (6)
frontend/src/routes/_authenticated/search.tsx (1)

106-108: Good addition, but consider extracting the debug logic into a helper function.

The initialization of showDebugInfo now correctly includes the search.debug value from URL parameters, which enables debug mode via query params.

Consider extracting this debug logic into a helper function since it's duplicated at line 180:

+const getDebugModeEnabled = (search: any) => 
+  import.meta.env.VITE_SHOW_DEBUG_INFO === "true" || search?.debug || false;

 const [showDebugInfo, setDebugInfo] = useState(
-  import.meta.env.VITE_SHOW_DEBUG_INFO === "true" || search.debug || false,
+  getDebugModeEnabled(search)
 )
server/api/search.ts (3)

143-146: Properly extract the debug flag from query parameters.

The extraction of the debug parameter from the request is implemented correctly.

Consider removing the @ts-ignore comment by properly typing the request parameters:

let {
  query,
  groupCount: gc,
  offset,
  page,
  app,
  entity,
  lastUpdated,
  isQueryTyped,
  debug,
  // Extract debug query param
- // @ts-ignore
} = c.req.valid("query")

165-169: Debug parameter correctly passed to searchVespa.

The debug flag is now properly passed to the searchVespa function.

Consider using named parameters to improve code readability, especially when there are many undefined parameters:

searchVespa(
  decodedQuery,
  email,
  app,
  entity,
  page,
  offset,
  0.5,
  timestampRange,
  undefined,
  undefined,
  undefined,
  debug,
)

// Could be refactored to use an options object pattern in future improvements

211-213: Debug mode passed to searchVespa in AnswerApi.

The AnswerApi is correctly passing the global debug setting from config.

For consistency with SearchApi, consider extracting the debug parameter from the request query parameters:

- searchVespa(decodedQuery, email, app, entity, config.answerPage, 0, 0.5, undefined, undefined, undefined, undefined, config.isDebugMode)
+ // @ts-ignore 
+ const { debug } = c.req.valid("query")
+ searchVespa(decodedQuery, email, app, entity, config.answerPage, 0, 0.5, undefined, undefined, undefined, undefined, debug || config.isDebugMode)
server/search/vespa.ts (2)

446-447: Good addition of the requestDebug parameter.

The new optional parameter correctly enables client-side control of debug mode.

Remove the unnecessary parentheses around the default value:

- requestDebug: boolean = (false),
+ requestDebug: boolean = false,

450-451: Properly combines global and request debug flags.

The new isDebugMode variable correctly combines both the global configuration and the request-specific debug flag.

The || false at the end is redundant since the expression will already return a boolean:

- const isDebugMode = config.isDebugMode || requestDebug || false; 
+ const isDebugMode = config.isDebugMode || requestDebug;
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 087cdd4 and 4c4a946.

📒 Files selected for processing (3)
  • frontend/src/routes/_authenticated/search.tsx (4 hunks)
  • server/api/search.ts (4 hunks)
  • server/search/vespa.ts (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
server/api/search.ts (1)
server/search/vespa.ts (1)
  • searchVespa (434-490)
server/search/vespa.ts (1)
server/search/types.ts (1)
  • VespaSearchResponse (670-670)
🔇 Additional comments (5)
frontend/src/routes/_authenticated/search.tsx (3)

180-182: useEffect dependency handling looks good.

The effect correctly updates the debug state when the search parameters change, enabling dynamic toggling of debug mode.


248-249: Good implementation passing debug state to the search params.

Passing showDebugInfo to the API call ensures the debug mode setting is properly communicated to the backend.


535-536: Good schema update for the new debug parameter.

The addition of the debug property to the schema with appropriate defaults ensures type safety and validation for the new feature.

server/api/search.ts (1)

187-191: Debug parameter correctly passed in the else block.

The debug flag is consistently passed to searchVespa in the else block.

server/search/vespa.ts (1)

477-480: Correctly uses isDebugMode for conditional debugging properties.

The payload now properly includes debug properties based on the combined debug mode state.

@zereraz zereraz requested a review from junaid-shirur April 10, 2025 08:26
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
server/tests/search.test.ts (1)

10-236: Consider adding tests for the new debug functionality.

While the test updates correctly reflect the changed searchVespa signature, none of the tests validate the new requestDebug functionality that was added to the API. Consider adding a test case that verifies the behavior when requestDebug is set to true.

// Add a new test case to test debug mode functionality
+ test("search with debug mode enabled", async () => {
+   const query = "test query with debug";
+   // Use type assertion to access the debug-specific fields
+   const searchResults = await searchVespa(query, user, null, null, { 
+     limit: 10, 
+     requestDebug: true 
+   });
+   
+   // Verify that debug information is included in the response
+   // For example, check for the presence of ranking features or trace information
+   expect(searchResults.root.hasOwnProperty('featureNames')).toBeTrue();
+   // or other assertions specific to what debug mode should return
+ });
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 221777f and 0384797.

📒 Files selected for processing (5)
  • frontend/src/routes/_authenticated/search.tsx (5 hunks)
  • server/api/chat.ts (7 hunks)
  • server/api/search.ts (4 hunks)
  • server/search/vespa.ts (2 hunks)
  • server/tests/search.test.ts (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
  • server/api/chat.ts
  • server/api/search.ts
  • frontend/src/routes/_authenticated/search.tsx
  • server/search/vespa.ts
🧰 Additional context used
🧬 Code Graph Analysis (1)
server/tests/search.test.ts (1)
server/search/vespa.ts (1)
  • searchVespa (445-501)
🔇 Additional comments (3)
server/tests/search.test.ts (3)

26-26: Good update to the searchVespa function call.

The function call has been correctly updated to use the new object-based parameter structure with the limit property. This aligns with the recent changes to the searchVespa function signature in server/search/vespa.ts where a single object parameter is now accepted instead of multiple positional parameters.


196-197: Function call correctly updated to use object parameter.

The call to searchVespa has been properly updated to use the new parameter structure. This is consistent with the function's updated signature in server/search/vespa.ts.


214-215: Function call correctly updated to use object parameter.

The searchVespa function call has been properly updated to use the new object parameter with the limit property, consistent with other changes in this file.

@zereraz zereraz merged commit 9ca5109 into main Apr 11, 2025
4 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