Skip to content

Conversation

@arvinxx
Copy link
Member

@arvinxx arvinxx commented Jan 3, 2026

πŸ’» Change Type

  • ✨ feat
  • πŸ› fix
  • ♻️ refactor
  • πŸ’„ style
  • πŸ‘· build
  • ⚑️ perf
  • βœ… test
  • πŸ“ docs
  • πŸ”¨ chore

πŸ”— Related Issue

πŸ”€ Description of Change

πŸ§ͺ How to Test

  • Tested locally
  • Added/updated tests
  • No tests needed

πŸ“Έ Screenshots / Videos

Before After
... ...

πŸ“ Additional Information

Summary by Sourcery

Bug Fixes:

  • Fallback to the client-provided file size when remote metadata cannot be fetched and reject uploads smaller than one byte.

@vercel
Copy link

vercel bot commented Jan 3, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
lobehub Ready Ready Preview, Comment Jan 3, 2026 5:08am

@chatgpt-codex-connector
Copy link

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@dosubot dosubot bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Jan 3, 2026
@gru-agent
Copy link
Contributor

gru-agent bot commented Jan 3, 2026

TestGru Assignment

Summary

Link CommitId Status Reason
Detail b7acb1c βœ… Finished

History Assignment

Files

File Pull Request
src/server/routers/lambda/file.ts ❌ Failed (I failed to setup the environment.)

Tip

You can @gru-agent and leave your feedback. TestGru will make adjustments based on your input

@arvinxx arvinxx changed the title πŸ› fix: fix upload πŸ› fix: fix file upload issue Jan 3, 2026
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Jan 3, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adjusts file upload size determination to fall back gracefully when metadata lookup fails and enforces a minimum file size of 1 byte before creating the file record.

Sequence diagram for updated file upload size determination

sequenceDiagram
  participant Client
  participant FileRouter
  participant FileService
  participant FileModel

  Client->>FileRouter: uploadFile(url, size)
  FileRouter->>FileService: getFileMetadata(url)
  alt metadata lookup succeeds
    FileService-->>FileRouter: contentLength
    alt contentLength >= 1
      FileRouter->>FileRouter: actualSize = contentLength
    else contentLength < 1
      FileRouter->>FileRouter: actualSize = input size
    end
  else metadata lookup fails
    FileService-->>FileRouter: error
    FileRouter->>FileRouter: actualSize = input size
  end

  alt actualSize < 1
    FileRouter-->>Client: TRPCError BAD_REQUEST
  else actualSize >= 1
    FileRouter->>FileModel: create(fileRecord with actualSize)
    FileModel-->>FileRouter: created file id
    FileRouter-->>Client: success with file id
  end
Loading

Class diagram for file upload router and services

classDiagram
  class FileRouter {
    +uploadFile(url, size)
  }

  class FileService {
    +getFileMetadata(url) contentLength
  }

  class FileModel {
    +create(fileRecord) id
  }

  FileRouter --> FileService : uses
  FileRouter --> FileModel : creates fileRecord
Loading

File-Level Changes

Change Details Files
Make file size determination more robust and enforce a minimum file size when handling uploads.
  • Initialize actual file size from the client-provided input size before attempting metadata lookup.
  • Wrap file metadata retrieval in a try/catch block so failures fall back to the provided size instead of breaking the upload flow.
  • Only override the initial size when the fetched content length is at least 1 byte.
  • Validate the final resolved size and reject uploads with a size less than 1 byte using a BAD_REQUEST TRPC error.
src/server/routers/lambda/file.ts

Possibly linked issues

  • #(not provided): PR changes file size detection and validation, preventing legitimate uploads from being treated as empty, matching the reported error
  • #N/A: PR adjusts file size detection and validation in upload flow, likely fixing uploads that hang indefinitely as in issue.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-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.

Hey - I've found 1 issue, and left some high level feedback:

  • The silent catch around getFileMetadata makes it hard to debug metadata failures; consider at least logging or tagging the error path so operators can distinguish genuine tiny files from metadata lookup issues.
  • The fallback to input.size assumes it is always defined and trustworthy; if this comes from the client, consider validating it (e.g., non-negative, reasonable upper bound) or making the type/constraints explicit to avoid abuse.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The silent catch around `getFileMetadata` makes it hard to debug metadata failures; consider at least logging or tagging the error path so operators can distinguish genuine tiny files from metadata lookup issues.
- The fallback to `input.size` assumes it is always defined and trustworthy; if this comes from the client, consider validating it (e.g., non-negative, reasonable upper bound) or making the type/constraints explicit to avoid abuse.

## Individual Comments

### Comment 1
<location> `src/server/routers/lambda/file.ts:73-74` </location>
<code_context>
+        if (contentLength >= 1) {
+          actualSize = contentLength;
+        }
+      } catch {
+        // If metadata fetch fails, use original size from input
+      }
+
</code_context>

<issue_to_address>
**suggestion (bug_risk):** Empty catch may hide unexpected failures in metadata lookup

Swallowing all exceptions here means configuration, permission, or `fileService` outages will be silently masked by falling back to `input.size`, which may be wrong and hard to diagnose. Please either log failures (e.g., debug/warn) or restrict the catch to the specific, expected error types so operational issues remain visible without changing user-facing behavior.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click πŸ‘ or πŸ‘Ž on each comment and I'll use the feedback to improve your reviews.

Comment on lines +73 to +74
} catch {
// If metadata fetch fails, use original size from input
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (bug_risk): Empty catch may hide unexpected failures in metadata lookup

Swallowing all exceptions here means configuration, permission, or fileService outages will be silently masked by falling back to input.size, which may be wrong and hard to diagnose. Please either log failures (e.g., debug/warn) or restrict the catch to the specific, expected error types so operational issues remain visible without changing user-facing behavior.

@codecov
Copy link

codecov bot commented Jan 3, 2026

Codecov Report

βœ… All modified and coverable lines are covered by tests.
βœ… Project coverage is 77.60%. Comparing base (885964e) to head (e045f37).
⚠️ Report is 10 commits behind head on next.

Additional details and impacted files
@@           Coverage Diff            @@
##             next   #11122    +/-   ##
========================================
  Coverage   77.59%   77.60%            
========================================
  Files        1120     1120            
  Lines       84379    84404    +25     
  Branches    11191    10781   -410     
========================================
+ Hits        65476    65503    +27     
+ Misses      18903    18901     -2     
Flag Coverage Ξ”
app 70.37% <100.00%> (+0.01%) ⬆️
database 94.35% <ΓΈ> (ΓΈ)
packages/agent-runtime 90.26% <ΓΈ> (ΓΈ)
packages/context-engine 86.44% <ΓΈ> (ΓΈ)
packages/conversation-flow 95.79% <ΓΈ> (ΓΈ)
packages/electron-server-ipc 93.76% <ΓΈ> (ΓΈ)
packages/file-loaders 92.20% <ΓΈ> (ΓΈ)
packages/model-bank 100.00% <ΓΈ> (ΓΈ)
packages/model-runtime 89.75% <ΓΈ> (ΓΈ)
packages/prompts 77.55% <ΓΈ> (ΓΈ)
packages/python-interpreter 96.50% <ΓΈ> (ΓΈ)
packages/utils 89.43% <ΓΈ> (ΓΈ)
packages/web-crawler 96.81% <ΓΈ> (ΓΈ)

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Ξ”
Store 69.72% <ΓΈ> (ΓΈ)
Services 52.54% <ΓΈ> (ΓΈ)
Server 73.28% <100.00%> (+0.01%) ⬆️
Libs 41.77% <ΓΈ> (ΓΈ)
Utils 93.03% <ΓΈ> (ΓΈ)
πŸš€ New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • πŸ“¦ JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels Jan 3, 2026
@arvinxx arvinxx merged commit 1ae327a into next Jan 3, 2026
62 checks passed
@arvinxx arvinxx deleted the fix/fix-upload branch January 3, 2026 05:55
@lobehubbot
Copy link
Member

❀️ Great PR @arvinxx ❀️

The growth of project is inseparable from user feedback and contribution, thanks for your contribution! If you are interesting with the lobehub developer community, please join our discord and then dm @arvinxx or @canisminor1990. They will invite you to our private developer channel. We are talking about the lobe-chat development or sharing ai newsletter around the world.

lobehubbot pushed a commit that referenced this pull request Jan 3, 2026
## [Version&nbsp;2.0.0-next.197](v2.0.0-next.196...v2.0.0-next.197)
<sup>Released on **2026-01-03**</sup>

#### β™» Code Refactoring

- **misc**: Remove client db and refactor test.

#### πŸ› Bug Fixes

- **misc**: Fix file upload issue.

<br/>

<details>
<summary><kbd>Improvements and Fixes</kbd></summary>

#### Code refactoring

* **misc**: Remove client db and refactor test, closes [#11123](#11123) ([bb2799d](bb2799d))

#### What's fixed

* **misc**: Fix file upload issue, closes [#11122](#11122) ([1ae327a](1ae327a))

</details>

<div align="right">

[![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)

</div>
@lobehubbot
Copy link
Member

πŸŽ‰ This PR is included in version 2.0.0-next.197 πŸŽ‰

The release is available on:

Your semantic-release bot πŸ“¦πŸš€

JamieStivala pushed a commit to jaworldwideorg/OneJA-Bot that referenced this pull request Jan 5, 2026
## [Version&nbsp;1.148.0](v1.147.0...v1.148.0)
<sup>Released on **2026-01-05**</sup>

#### β™» Code Refactoring

- **redis**: Disable automatic deserialization in upstash provider.
- **utils**: Remove unused geo server utilities.
- **misc**: Refactor and fix model runtime initialize, refactor to remove access code, remove client db and refactor test.

#### ✨ Features

- **misc**: Add new provider Xiaomi MiMo, add work path for local system, update the sandbox export files & save files way.

#### πŸ› Bug Fixes

- **electron**: Correct next config codemod pattern matching.
- **gtd**: Fix frozen object mutation in updateTodos.
- **model-runtime**: Handle array content in anthropic assistant messages, handle incremental tool call chunks in Qwen stream, handle Qwen tool_calls without initial arguments.
- **misc**: Add lost like button in discover detail page, Auto jump to group, filter empty assistant messages for Anthropic API, fix data inconsistency in ai provider config, fix editor modal when Markdown rendering off, fix file upload issue, fix tool call message content missing, restore window position safely, restore window resizable before hard reload in desktop onboarding, slove the old agents open profiles error problem, support thoughtSignature for openrouter, update CI bun version to v1.2.4, use configured embedding provider instead of hardcoded OpenAI, when the document filetype is agent/plan, not show the saveinto docs button.

#### πŸ’„ Styles

- **misc**: Update i18n, update i18n, update i18n.

<br/>

<details>
<summary><kbd>Improvements and Fixes</kbd></summary>

#### Code refactoring

* **redis**: Disable automatic deserialization in upstash provider, closes [lobehub#11210](https://github.com/jaworldwideorg/OneJA-Bot/issues/11210) ([eb5c76c](eb5c76c))
* **utils**: Remove unused geo server utilities, closes [lobehub#11243](https://github.com/jaworldwideorg/OneJA-Bot/issues/11243) ([ee474cc](ee474cc))
* **misc**: Refactor and fix model runtime initialize, closes [lobehub#11134](https://github.com/jaworldwideorg/OneJA-Bot/issues/11134) ([8078cb9](8078cb9))
* **misc**: Refactor to remove access code, closes [lobehub#11120](https://github.com/jaworldwideorg/OneJA-Bot/issues/11120) ([0e9f98c](0e9f98c))
* **misc**: Remove client db and refactor test, closes [lobehub#11123](https://github.com/jaworldwideorg/OneJA-Bot/issues/11123) ([bb2799d](bb2799d))

#### What's improved

* **misc**: Add new provider Xiaomi MiMo, closes [lobehub#10834](https://github.com/jaworldwideorg/OneJA-Bot/issues/10834) ([62f7858](62f7858))
* **misc**: Add work path for local system, closes [lobehub#11128](https://github.com/jaworldwideorg/OneJA-Bot/issues/11128) ([d8deadd](d8deadd))
* **misc**: Update the sandbox export files & save files way, closes [lobehub#11249](https://github.com/jaworldwideorg/OneJA-Bot/issues/11249) ([039b0a1](039b0a1))

#### What's fixed

* **electron**: Correct next config codemod pattern matching, closes [lobehub#11228](https://github.com/jaworldwideorg/OneJA-Bot/issues/11228) ([06cb019](06cb019))
* **gtd**: Fix frozen object mutation in updateTodos, closes [lobehub#11184](https://github.com/jaworldwideorg/OneJA-Bot/issues/11184) ([4970794](4970794))
* **model-runtime**: Handle array content in anthropic assistant messages, closes [lobehub#11206](https://github.com/jaworldwideorg/OneJA-Bot/issues/11206) ([b03845d](b03845d))
* **model-runtime**: Handle incremental tool call chunks in Qwen stream, closes [lobehub#11219](https://github.com/jaworldwideorg/OneJA-Bot/issues/11219) ([03b9407](03b9407))
* **model-runtime**: Handle Qwen tool_calls without initial arguments, closes [lobehub#11211](https://github.com/jaworldwideorg/OneJA-Bot/issues/11211) ([5321d91](5321d91))
* **misc**: Add lost like button in discover detail page, closes [lobehub#11182](https://github.com/jaworldwideorg/OneJA-Bot/issues/11182) ([41215d4](41215d4))
* **misc**: Auto jump to group, closes [lobehub#11187](https://github.com/jaworldwideorg/OneJA-Bot/issues/11187) ([e43578a](e43578a))
* **misc**: Filter empty assistant messages for Anthropic API, closes [lobehub#11129](https://github.com/jaworldwideorg/OneJA-Bot/issues/11129) ([7af750b](7af750b))
* **misc**: Fix data inconsistency in ai provider config, closes [lobehub#11198](https://github.com/jaworldwideorg/OneJA-Bot/issues/11198) ([f8346f2](f8346f2))
* **misc**: Fix editor modal when Markdown rendering off, closes [lobehub#11251](https://github.com/jaworldwideorg/OneJA-Bot/issues/11251) ([eb86d3b](eb86d3b))
* **misc**: Fix file upload issue, closes [lobehub#11122](https://github.com/jaworldwideorg/OneJA-Bot/issues/11122) ([1ae327a](1ae327a))
* **misc**: Fix tool call message content missing, closes [lobehub#11116](https://github.com/jaworldwideorg/OneJA-Bot/issues/11116) ([885964e](885964e))
* **misc**: Restore window position safely ([e0b555e](e0b555e))
* **misc**: Restore window resizable before hard reload in desktop onboarding, closes [lobehub#11144](https://github.com/jaworldwideorg/OneJA-Bot/issues/11144) ([2516874](2516874))
* **misc**: Slove the old agents open profiles error problem, closes [lobehub#11204](https://github.com/jaworldwideorg/OneJA-Bot/issues/11204) ([7d650b6](7d650b6))
* **misc**: Support thoughtSignature for openrouter, closes [lobehub#11117](https://github.com/jaworldwideorg/OneJA-Bot/issues/11117) ([bf5d41e](bf5d41e))
* **misc**: Update CI bun version to v1.2.4, closes [lobehub#11232](https://github.com/jaworldwideorg/OneJA-Bot/issues/11232) ([dd022d5](dd022d5))
* **misc**: Use configured embedding provider instead of hardcoded OpenAI, closes [lobehub#11133](https://github.com/jaworldwideorg/OneJA-Bot/issues/11133) ([503c3eb](503c3eb))
* **misc**: When the document filetype is agent/plan, not show the saveinto docs button, closes [lobehub#11227](https://github.com/jaworldwideorg/OneJA-Bot/issues/11227) ([3a22f32](3a22f32))

#### Styles

* **misc**: Update i18n, closes [lobehub#11213](https://github.com/jaworldwideorg/OneJA-Bot/issues/11213) ([00e0980](00e0980))
* **misc**: Update i18n, closes [lobehub#11145](https://github.com/jaworldwideorg/OneJA-Bot/issues/11145) ([fdadef2](fdadef2))
* **misc**: Update i18n, closes [lobehub#11115](https://github.com/jaworldwideorg/OneJA-Bot/issues/11115) ([072e0dd](072e0dd))

</details>

<div align="right">

[![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)

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

Labels

released on @next size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants