Skip to content

fix report and library#225

Merged
spashii merged 3 commits intomainfrom
fix/report-and-lib-0
Jul 17, 2025
Merged

fix report and library#225
spashii merged 3 commits intomainfrom
fix/report-and-lib-0

Conversation

@spashii
Copy link
Copy Markdown
Member

@spashii spashii commented Jul 17, 2025

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling of report creation errors, providing clearer feedback when context limits are exceeded.
    • Enhanced token budget management for project reports, ensuring summaries and transcripts fit within allowed limits.
    • Updated logic for determining empty conversations to consider conversation completion status.
  • Refactor

    • Shifted data retrieval from direct database queries to an external API client for greater consistency and reliability.
    • Updated internal logic for fetching and organizing project conversations, prioritizing recent activity and optimizing context usage.
    • Modified project views data fetching to adjust aspects-related fields and remove nested sorting.
  • Chores

    • Removed deprecated and commented-out code for cleaner and more maintainable endpoints.

@spashii spashii requested a review from ArindamRoy23 July 17, 2025 15:47
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Jul 17, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

This PR refactors project-related API endpoints to use Directus client calls instead of direct database queries, updates error handling, and removes deprecated or commented-out code. It also improves report content assembly by enforcing token limits more precisely and prioritizing recent conversations, with enhanced logging and metadata.

Changes

File(s) Change Summary
echo/server/dembrane/api/project.py Refactored API endpoints to use Directus client, updated error handling, removed deprecated code, and changed function signatures to drop DB session parameters.
echo/server/dembrane/report_utils.py Enhanced conversation fetching and token counting for reports, added metadata, improved logging, and enforced token limits more strictly.
echo/frontend/src/lib/api.ts Modified getProjectViews to fetch different aspects fields and removed nested sorting on aspects.
echo/frontend/src/routes/project/conversation/ProjectConversationTranscript.tsx Updated isEmptyConversation logic to require conversation to be finished in addition to having no valid transcripts.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant API
    participant Directus
    participant ProjectService

    Client->>API: POST /projects/{id}/library or /view
    API->>ProjectService: Fetch project by ID via Directus client
    ProjectService-->>API: Project data or 404
    API->>Directus: Create or update project library/view/report
    Directus-->>API: Success/Error
    API-->>Client: Response
Loading
sequenceDiagram
    participant API
    participant ReportUtils
    participant Directus

    API->>ReportUtils: get_report_content_for_project(project_id, language)
    ReportUtils->>Directus: Fetch conversations (sorted by updated_at desc)
    Directus-->>ReportUtils: Conversations data
    loop Until token limit reached
        ReportUtils->>ReportUtils: Add summary, check token count
    end
    loop Until token limit reached
        ReportUtils->>ReportUtils: Add transcript, check token count
    end
    ReportUtils-->>API: Final report content
Loading

Possibly related PRs

Suggested reviewers

  • ussaama

📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c65b54e and 31761f6.

📒 Files selected for processing (4)
  • echo/frontend/src/lib/api.ts (1 hunks)
  • echo/frontend/src/routes/project/conversation/ProjectConversationTranscript.tsx (1 hunks)
  • echo/server/dembrane/api/project.py (5 hunks)
  • echo/server/dembrane/report_utils.py (5 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @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.

ArindamRoy23
ArindamRoy23 previously approved these changes Jul 17, 2025
@coderabbitai coderabbitai bot added the Feature label Jul 17, 2025
@spashii spashii added this pull request to the merge queue Jul 17, 2025
cursor[bot]

This comment was marked as outdated.

@spashii spashii removed this pull request from the merge queue due to a manual request Jul 17, 2025
Copy link
Copy Markdown
Contributor

@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: 1

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6870f46 and c65b54e.

📒 Files selected for processing (2)
  • echo/server/dembrane/api/project.py (5 hunks)
  • echo/server/dembrane/report_utils.py (5 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: spashii
PR: Dembrane/echo#142
File: echo/frontend/src/lib/query.ts:730-740
Timestamp: 2025-05-13T15:18:29.107Z
Learning: When working with Directus API in this codebase, foreign key relationships must be specified using nested objects with `id` properties (e.g., `conversation_id: { id: conversationId } as Conversation`) rather than direct ID values, even though this appears redundant.
echo/server/dembrane/report_utils.py (1)
Learnt from: spashii
PR: Dembrane/echo#142
File: echo/frontend/src/lib/query.ts:680-696
Timestamp: 2025-05-13T15:20:25.165Z
Learning: In the Echo project, the conversation tags feature is designed with an implicit limit of 100 tags per conversation. Having more than 100 tags indicates a misuse of the feature rather than a limitation that needs to be addressed in the code. Errors for exceeding this limit should be handled at a logical level above the implementation.
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Cursor BugBot
  • GitHub Check: ci-check-server
🔇 Additional comments (7)
echo/server/dembrane/report_utils.py (4)

42-52: LGTM! Smart move prioritizing recent convos.

Sorting by updated_at descending ensures we get the freshest data when hitting token limits. Ship it.


60-105: Solid token management. This is the way.

Pre-checking tokens before adding prevents overruns. Dict structure makes the second pass O(1) lookups. Clean.


106-142: Two-pass approach FTW. Efficient AF.

Get summaries first, then pack in transcripts. Early break when sorted by recency = optimal. This is how you handle token budgets.


146-149: Logging game on point.

Clear visibility into token usage. Essential for debugging and capacity planning.

echo/server/dembrane/api/project.py (3)

200-213: Clean Directus migration. Error handling ✓

Proper context manager usage and exception handling. This is how you migrate from ORM to API calls.


266-296: Consistent refactoring pattern. Ship it.

Same clean migration pattern as other endpoints. Dict access for Directus responses is the way.


304-335: Exception handling done right. 🚀

Specific error codes for specific exceptions. Early returns. Proper context manager usage throughout. This is production-grade error handling.

Comment on lines +239 to 249
# analysis_run = get_latest_project_analysis_run(project.id)

if analysis_run and analysis_run.processing_status in [
ProcessingStatusEnum.PENDING,
ProcessingStatusEnum.PROCESSING,
]:
raise HTTPException(
status_code=409,
detail="Analysis is already in progress",
)
# if analysis_run and analysis_run["processing_status"] in [
# ProcessingStatusEnum.PENDING,
# ProcessingStatusEnum.PROCESSING,
# ]:
# raise HTTPException(
# status_code=409,
# detail="Analysis is already in progress",
# )

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Dead code alert. Either use it or lose it.

Commented-out analysis run check should be removed if no longer needed, or add a TODO explaining why it's disabled.

-    # analysis_run = get_latest_project_analysis_run(project.id)
-
-    # if analysis_run and analysis_run["processing_status"] in [
-    #     ProcessingStatusEnum.PENDING,
-    #     ProcessingStatusEnum.PROCESSING,
-    # ]:
-    #     raise HTTPException(
-    #         status_code=409,
-    #         detail="Analysis is already in progress",
-    #     )
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# analysis_run = get_latest_project_analysis_run(project.id)
if analysis_run and analysis_run.processing_status in [
ProcessingStatusEnum.PENDING,
ProcessingStatusEnum.PROCESSING,
]:
raise HTTPException(
status_code=409,
detail="Analysis is already in progress",
)
# if analysis_run and analysis_run["processing_status"] in [
# ProcessingStatusEnum.PENDING,
# ProcessingStatusEnum.PROCESSING,
# ]:
# raise HTTPException(
# status_code=409,
# detail="Analysis is already in progress",
# )
🤖 Prompt for AI Agents
In echo/server/dembrane/api/project.py around lines 239 to 249, there is
commented-out code checking the latest project analysis run status that is
currently unused. Either remove this dead code entirely if it is no longer
needed, or if it is temporarily disabled for a reason, add a clear TODO comment
explaining why it is commented out and when it should be revisited.

@spashii spashii added this pull request to the merge queue Jul 17, 2025
Merged via the queue into main with commit 1898afe Jul 17, 2025
9 of 10 checks passed
Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Bug: Security and Task Management Vulnerabilities

This commit introduces two bugs:

  1. Authorization Bypass: In post_create_project_library and post_create_view, changing the project access from project.directus_user_id to project.get("directus_user_id", "") creates a potential authorization bypass. If the directus_user_id key is missing from the project data and the authenticated user's ID is an empty string, the comparison "" != "" incorrectly grants access. The original logic would correctly deny access by comparing None != "".
  2. Concurrent Task Execution: In post_create_project_library, the logic that checked for an in-progress analysis run (preventing new tasks if one was PENDING or PROCESSING) was commented out. This removes the protection against starting multiple concurrent library generation tasks, which can lead to resource conflicts or duplicate processing.

echo/server/dembrane/api/project.py#L248-L261

if not auth.is_admin and project.get("directus_user_id", "") != auth.user_id:
raise HTTPException(status_code=403, detail="User does not have access to this project")
# analysis_run = get_latest_project_analysis_run(project.id)
# if analysis_run and analysis_run["processing_status"] in [
# ProcessingStatusEnum.PENDING,
# ProcessingStatusEnum.PROCESSING,
# ]:
# raise HTTPException(
# status_code=409,
# detail="Analysis is already in progress",
# )

echo/server/dembrane/api/project.py#L296-L298

if not auth.is_admin and project.get("directus_user_id", "") != auth.user_id:
raise HTTPException(status_code=403, detail="User does not have access to this project")

Fix in CursorFix in Web


Was this report helpful? Give feedback by reacting with 👍 or 👎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants