Skip to content

Conversation

jrobertboos
Copy link
Contributor

Description

This PR is one of 2 that is being proposed to close LCORE-383.

Basically what is happening is that attachment content is being appended to messages when accessing them through the /conversations endpoint.

This error can be seen below along with what it looks like after the fix.

Before Fix

This is when the attachment is sent before using the /conversations endpoint to reload the saved conversation.
original_before
This is after the /conversations endpoint is used to reload the conversation.
original_after

After Fix

This is when the attachment is sent before using the /conversations endpoint to reload the saved conversation.
new_before
This is after the /conversations endpoint is used to reload the conversation.
new_after

This is what the response of the /conversations endpoint looks like:

{
  "conversation_id": "94ad27d1-674b-48e5-a2cb-b126370fab3e",
  "chat_history": [
    {
      "messages": [
        {
          "content": "What does this file say?",
          "type": "user",
          "attachments": [
            {
              "attachment_type": "log",
              "content_type": "text/plain",
              "content": "data:text/plain;base64,SW5ncmVkaWVudHM6Ci0gNiBjdXBzIHRoaW5seSBzbGljZWQgYXBwbGVzCi0gMy80IGN1cCBzdWdhcgotIDIgdGFibGVzcG9vbnMgYWxsLXB1cnBvc2UgZmxvdXIKLSAxLzIgdGVhc3Bvb24gZ3JvdW5kIGNpbm5hbW9uCi0gMS80IHRlYXNwb29uIHNhbHQKLSAxLzggdGVhc3Bvb24gZ3JvdW5kIG51dG1lZwotIDEgdGFibGVzcG9vbiBsZW1vbiBqdWljZQotIDEgcGFja2FnZSAoMiBjcnVzdHMpIHJlZnJpZ2VyYXRlZCBwaWUgY3J1c3RzCgpJbnN0cnVjdGlvbnM6CjEuIFByZWhlYXQgb3ZlbiB0byA0MjUgZGVncmVlcyBGICgyMjAgZGVncmVlcyBDKS4KMi4gSW4gYSBsYXJnZSBib3dsLCBtaXggc2xpY2VkIGFwcGxlcywgc3VnYXIsIGZsb3VyLCBjaW5uYW1vbiwgc2FsdCwgbnV0bWVnLCBhbmQgbGVtb24ganVpY2UuCjMuIFBsYWNlIG9uZSBwaWUgY3J1c3QgaW4gYSBwaWUgZGlzaC4gRmlsbCB3aXRoIGFwcGxlIG1peHR1cmUuIENvdmVyIHdpdGggdGhlIHNlY29uZCBjcnVzdC4KNC4gU2VhbCBhbmQgZmx1dGUgZWRnZXMuIEN1dCBzbGl0cyBpbiB0aGUgdG9wIGNydXN0Lgo1LiBCYWtlIGluIHRoZSBwcmVoZWF0ZWQgb3ZlbiBmb3IgNDUgbWludXRlcyBvciB1bnRpbCBjcnVzdCBpcyBnb2xkZW4gYnJvd24uIEFsbG93IHRvIGNvb2wgYmVmb3JlIHNlcnZpbmcu"
            }
          ]
        },
        {
          "content": "The file contains a recipe for an apple pie. Here are the ingredients and instructions:\n\n**Ingredients:**\n- 6 cups thinly sliced apples\n- 3/4 cup sugar\n- 2 tablespoons all-purpose flour\n- 1/2 teaspoon ground cinnamon\n- 1/4 teaspoon salt\n- 1/8 teaspoon ground nutmeg\n- 1 tablespoon lemon juice\n- 1 package (2 crusts) refrigerated pie crusts\n\n**Instructions:**\n1. Preheat oven to 425 degrees F (220 degrees C).\n2. In a large bowl, mix sliced apples, sugar, flour, cinnamon, salt, nutmeg, and lemon juice.\n3. Place one pie crust in a pie dish. Fill with apple mixture. Cover with the second crust.\n4. Seal and flute edges. Cut slits in the top crust.\n5. Bake in the preheated oven for 45 minutes or until crust is golden brown. Allow to cool before serving.",
          "type": "assistant"
        }
      ],
      "started_at": "2025-07-24T17:52:44.361756Z",
      "completed_at": "2025-07-24T17:52:49.855988Z"
    }
  ]
}

I originally wanted to solve this by leveraging the session data in llama-stack to extract the attachment content, however because we pass the message as a string and not a list of InterleavedContentItem's it directly appends the content to the message content string making it difficult to remove.

This PR represents solving the issue in a hacky way that does fully meet the acceptance criteria of LCORE-383. What it does is adds another TextContentItem after the original user message (but before the TextContentItems that contain the attachment content) that contains the attachment meta data. This item is denoted by having <attachment_info> tags.

The attachment metadata is combined with the attachment content to enhance the conversation endpoint response as shown in the jira ticket.

The issue with this however is that we are introducing more context into the query.

Type of change

  • Refactor
  • New feature
  • Bug fix
  • CVE fix
  • Optimization
  • Documentation Update
  • Configuration Update
  • Bump-up service version
  • Bump-up dependent library
  • Bump-up library or tool used for development (does not change the final image)
  • CI configuration change
  • Konflux configuration change
  • Unit tests improvement
  • Integration tests improvement
  • End to end tests improvement

Related Tickets & Documents

Checklist before requesting a review

  • I have performed a self-review of my code.
  • PR has passed all pre-merge test jobs.
  • If it is a core feature, I have added thorough tests.

Testing

  • Please provide detailed steps to perform tests related to this code change.
  • How were the fix/results from this change verified? Please provide relevant screenshots or results.

- Added a new function `parse_attachments_from_content` to extract attachment information from the content structure.
- Updated the `simplify_session_data` function to include parsed attachments in the cleaned messages.
- Modified the `retrieve_response` methods in `query.py` and `streaming_query.py` to format and include attachment information in the messages sent to the agent.
Copy link
Contributor

coderabbitai bot commented Jul 24, 2025

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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 generate unit tests to generate unit tests for 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.

@jrobertboos
Copy link
Contributor Author

This is the other NON-HACKY PR #285

@jrobertboos
Copy link
Contributor Author

I would love feedback from anyone about which direction should be pursued. Thanks!

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.

1 participant