Skip to content

fix(chat): conversation uploads stop reading at the size cap and respect a per-user quota (#20217) - #20668

Merged
mrveiss merged 32 commits into
mainfrom
issue-20233-chat-file-defects
Nov 3, 2026
Merged

mrveiss merged 32 commits into
mainfrom
issue-20233-chat-file-defects

Conversation

@mrveiss

@mrveiss mrveiss commented Nov 2, 2026 •

Copy link
Copy Markdown
Owner

Closes #20217

Lands after #20540. It reads the same file_cleanup_queue predicate: a deleted file counts only while its queue row is unprocessed. Without #20540, nothing processes those rows, so deleted bytes keep counting. Conflicts are expected in conversation_file_manager.py, conversation_file_route_api.py, en.json and the i18n ratchet.

Thinking Path

  • await file.read() buffered the whole body before the size check, so an oversize upload still cost its full size in memory.
  • A check in the route misses /files/create and agent-create. Every way in ends at add_file, so that's where the quota belongs.
  • A read followed by a write lets N uploads each pass and overshoot by up to N x 50 MiB, so the sum and the insert are one statement.
  • Bytes awaiting human-approved removal are still on disk, so they count. The message has to say that, or a user reads "0 bytes left" with nothing stored.

What Changed

  • api/conversation_file_upload.py: _read_within reads 1 MiB chunks and refuses once past the limit.

  • New conversation_file_quota.py: USER_QUOTA_BYTES from AUTOBOT_CONVERSATION_FILE_USER_QUOTA_BYTES (default 1 GiB), insert_within_quota, resize_within_quota, usage and quota_refusal. _insert_file_record in the manager calls it.

  • A 413 carries detail = {code, message, figures}: conversation_file_too_large or conversation_file_quota_exceeded, with live_bytes, pending_removal_bytes, limit_bytes and remaining_bytes.

  • conversationFileUpload.ts maps those codes to i18n keys. When deleted bytes still count, the text says removal is awaiting human review. There is no purge of any kind.

  • idx_conversation_files_uploaded_by on (uploaded_by, is_deleted), through the schema file and migration 001's expected set. These tables live in their own SQLite database, not alembic.

  • Three English-only keys with baselines raised; size ceilings lowered.

  • _validate_file_size raises the same coded refusal, so /files/create and /generate answer 413 with conversation_file_too_large. useConversationFiles.ts maps it through the shared keys, and extractApiErrorMessage returns detail.message for an object.

  • copy_file re-raises a refusal, and a failed deduplicated add no longer removes the existing file's bytes.

Open decision

Agent-created files are charged to the agent's name, so all users share one agent bucket and one user's agent can lock out everyone else's. That is the current behaviour here, and the maintainer decision is #20678. uploaded_by IS NULL is one shared bucket under the same quota.

Behaviour to review

  • In the route, the file manager now resolves before the filename is validated, so a missing manager returns 503 before a bad filename returns 400.
  • copy_file stores no new bytes, so it has no quota.

Verification

  • test_concurrent_writers_cannot_overshoot_the_quota: 8 manager instances on one real database file, a 25-byte quota, 10-byte files. Exactly 2 stored, 6 refused, no refused bytes on disk.
  • Backend, including the new conversation_file_quota_store_20217_test.py, upload limits, owner upload, real manager and review tests, and two ratchets: 114 passed.
  • Env and size guards: 91 passed. check_env_var_registry_test.py: 25 passed.
  • conversationFileUpload.spec.ts: 18 passed, with reka-ui stubbed.
  • After the last review: size cap, quota store and upload limit tests re-run on the final head; frontend specs for the refusal mapping, upload and error extraction, 40 passed.
  • Not run: vue-tsc, ESLint, ChatInput tests, a manual chat UI check, and any full suite.

Model Used

Claude Opus 5.5

Refs #20233

mrveiss and others added 21 commits November 1, 2026 13:07
…nup-proposals

# Conflicts:
#	repo_tests/no_tracked_key_material_test.py
…ls (#20234)

# Conflicts:
#	repo_tests/autobot_has_no_pro_edition_19982_test.py
…ls (#20234)

# Conflicts:
#	repo_tests/credential_field_name_only_17336_test.py
#	repo_tests/enum_hand_copy_guard_test.py
#	repo_tests/slm_node_id_one_home_19322_test.py
@mrveiss mrveiss added this to the M3 - Refined GUI complete milestone Nov 2, 2026
@mrveiss mrveiss added the phase:M3.9 Chat, Agents, Analytics and Settings screens label Nov 2, 2026
@coderabbitai

coderabbitai Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 23 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
Commits

Reviewing files that changed from the base of the PR and between fd4c2df and 4fad5e7.

Files ignored due to path filters: 1
  • scripts/python_file_size_known_large.py is excluded by !scripts/python_file_size_known_large.py
Files selected for processing: 35
  • autobot-backend/api/conversation_file_cleanup_admin.py
  • autobot-backend/api/conversation_file_upload.py
  • autobot-backend/api/conversation_files.py
  • autobot-backend/api/conversation_files_owner_upload_20133_test.py
  • autobot-backend/api/conversation_files_upload_limits_20217_test.py
  • autobot-backend/conversation_file_cleanup.py
  • autobot-backend/conversation_file_cleanup_20234_test.py
  • autobot-backend/conversation_file_cleanup_admin_20234_test.py
  • autobot-backend/conversation_file_cleanup_bounds_20234_test.py
  • autobot-backend/conversation_file_cleanup_reproposal_20234_test.py
  • autobot-backend/conversation_file_manager.py
  • autobot-backend/conversation_file_manager_init_test.py
  • autobot-backend/conversation_file_quota.py
  • autobot-backend/conversation_file_quota_store_20217_test.py
  • autobot-backend/conversation_file_route_api.py
  • autobot-backend/conversation_file_size_cap_20217_test.py
  • autobot-backend/database/migrations/001_create_conversation_files.py
  • autobot-backend/database/schemas/conversation_files_schema.sql
  • autobot-backend/initialization/router_registry/core_routers.py
  • autobot-backend/migrations/versions/20261101_110_approvals_pending_file_cleanup_unique.py
  • autobot-backend/models/approval.py
  • autobot-backend/services/conversation_file_cleanup_action.py
  • autobot-backend/services/conversation_file_cleanup_proposals.py
  • autobot-frontend/src/components/llc/StuckFileCleanupPanel.vue
  • autobot-frontend/src/components/llc/__tests__/StuckFileCleanupPanel.test.ts
  • autobot-frontend/src/composables/__tests__/useConversationFiles.createRefusal.spec.ts
  • autobot-frontend/src/composables/useConversationFiles.ts
  • autobot-frontend/src/i18n/locales/en.json
  • autobot-frontend/src/utils/__tests__/conversationFileUpload.spec.ts
  • autobot-frontend/src/utils/conversationFileUpload.ts
  • autobot-frontend/src/utils/errorExtract.ts
  • autobot-frontend/src/views/llc/ApprovalsInbox.vue
  • autobot_shared/env_registry_knowledge.py
  • docs/developer/ENV_VARS.md
  • repo_tests/i18n_untranslated_ratchet_test.py
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Notice: 29 open PRs — past the runaway threshold (25)

This is not a request to defer this PR. There is no cap on open PRs (#19397) -- nothing blocks opening or pushing a PR.

This notice only means the count is high enough to be worth a glance for a runaway — something opening PRs in a loop, or a merge pipeline that has stalled so nothing is draining.

Currently open:

If the queue is draining normally, ignore this. Otherwise:

  1. Check whether CI is dispatching at all — see the ci-dispatch-watchdog status on these PRs
  2. Approved PRs land through the merge train the coordinator sequences (merge commits, never squash) -- check the open chore(merge-train) PR is moving, not each PR on its own
  3. Look for a loop opening near-identical PRs

Warn-only runaway detector — .github/workflows/pr-queue-gate.yml. It never blocks a merge.

@mrveiss

mrveiss commented Nov 2, 2026

Copy link
Copy Markdown
Owner Author

Code review on PR #20668 (head 99a8d00): changes needed.

Read against the diff and main; nothing was run. The chunked read is sound: _read_within stops at the cap and nothing is written first. Closes #20217 isn't supported yet.

Severity Where Finding Fix
High conversation_files.py, /files/create and the agent-create route The quota is checked only on multipart /upload. These routes call file_manager.create_file without a check, so an owner can write unlimited bytes. Enforce the quota in the manager's store path, so every route is covered.
High conversation_file_upload.py, conversationFileUpload.ts:69 The 413 detail is free English text with no stable code, and the frontend reduces it to a generic {status} message. The user sees "HTTP 413", never "too large" or "quota". So the "clear error" criterion is met only in the API. Return a stable code for each case and map it to an i18n key.
High remaining_upload_quota Point (a) is true, and as shipped it's a defect: the query has no is_deleted filter, nothing purges today, and #20234's consumer #20540 hasn't landed. A user at the cap is locked out for good, and is told "0 bytes left" after deleting everything. Counting soft-deleted bytes is sound. The lockout and the message aren't. Keep counting and don't purge, since no agent deletes data on its own. Report live bytes and bytes pending removal separately, and name the recovery path. Land after #20540.
Medium remaining_upload_quota Point (b) understates it. The check runs before the body is read, so N concurrent uploads can each pass: the overshoot is up to N x 50 MiB, not one file. Use a conditional insert. If it affects no rows, remove the stored bytes and return 413.
Medium conversation_files_schema.sql:98-104 No index on uploaded_by, so each upload scans the whole table, deleted rows included. Add an index with a migration.
Medium conversation_files.py:143 A session with no username becomes uploaded_by IS NULL, which is one shared bucket for all those files. Agent files land in a bucket named after the agent. Decide this explicitly, and test it.
Low _read_within tests They feed BytesIO, not the real multipart path. The framework parses the body into a spool before the handler runs, so the cap bounds the handler's buffering, not what's already received. I found no body limit in front of it. Add one ASGI test and say what bounds the spool.
Low Usage The quota isn't visible to the user anywhere. Add a read-only usage field, which also answers the lockout.

Not checked: the #20195 decision comment for the third criterion (don't tick it without quoting that comment), upstream body-size middleware, whether dedupe by hash skips the check, and how many backend workers run.

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

✅ SSOT Configuration Compliance: Passing

🎉 No new hardcoded values of either class — ssot and other both block.

Known backlog in pipeline-scripts/hardcoded_values_baseline.txt is suppressed and tracked in #14371.

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Auto-sync: merging main into issue-20233-chat-file-defects conflicts

The sync aborted the merge and pushed nothing. Conflicts are information, so it never resolves one itself. Below, for each conflicted file, are the commits that touched it on each side since the merge base 6c34ee1318. Merge main in yourself and push; the label clears on the first run that finds this branch 0 behind.

autobot-backend/api/conversation_files.py

side commit subject issue refs
main 7d9d28808 chore(merge): merge origin/main into issue-20195-attachments-reach-answer (#20195) #20195
main c1c8d1592 fix(chat): attachments need the strict session posture, stay out of checkpoints, and gate every tool call (#20195) #20195
main 19e3294fc fix(chat): an owning writer may delete, and attachments count against the model window (#20195) #20195
main 72f457651 fix(chat): owners list, download, preview and delete their own conversation files (#20195) #20195
this branch 79b2760eb fix(chat): upload quota enforced in the store path with stable error codes and a pending-removal split (#20217) #20217
this branch 99a8d00b5 fix(chat): conversation uploads stop reading at the size cap and respect a per-user quota (#20217) #20217

scripts/python_file_size_known_large.py

side commit subject issue refs
main 4a9cc5958 Merge main into the merge train (#20667) #20667
main a35798d47 Merge #20401 @ 7d9d288 into the merge train #20401
main d9e618ade Merge remote-tracking branch 'origin/main' into issue-20628-slm-admin-only none
main 7d9d28808 chore(merge): merge origin/main into issue-20195-attachments-reach-answer (#20195) #20195
main 0d126afa8 Merge remote-tracking branch 'origin/main' into issue-20195-attachments-reach-answer none
main 67302bbda chore(merge): merge origin/main into issue-20195-attachments-reach-answer (#20195) #20195
main e8ba5cf63 chore(merge): merge origin/main into issue-20195-attachments-reach-answer (#20195) #20195
main 5aa9c9d72 chore(merge): merge origin/main into issue-20195-attachments-reach-answer (#20195) #20195
main 47e8e75e5 fix(chat): attachment approvals reach the graph, the floor sticks to the chat, admin setting can lift it (#20195) #20195
main 2f5cf21c2 chore(merge): merge origin/main into issue-20195-attachments-reach-answer (#20195) #20195
main 2bbd16812 fix(chat): strict attachment check on resume, bounds by content, bounded one-read extraction (#20195) #20195
main 0496e5c48 chore(merge): merge origin/main into issue-20195-attachments-reach-answer (#20195) #20195
main c1c8d1592 fix(chat): attachments need the strict session posture, stay out of checkpoints, and gate every tool call (#20195) #20195
main 8a1cd6074 chore(merge): merge origin/main into issue-20195-attachments-reach-answer (#20195) #20195
main cf26562f0 fix(chat): attached files reach the answer as bounded untrusted data (#20195) #20195
main 1 more commit(s) not listed
this branch 4d26a27ba fix(chat): coded 413 on create/generate size cap, translated create refusal, dedupe keeps bytes (#20217) #20217
this branch 9f6e3f8fa Merge remote-tracking branch 'origin/issue-20233-chat-file-defects' into issue-20233-chat-file-defects none
this branch 79b2760eb fix(chat): upload quota enforced in the store path with stable error codes and a pending-removal split (#20217) #20217
this branch 7cebb14d6 Merge main into issue-20233-chat-file-defects (auto-sync) [skip ci] none
this branch 99a8d00b5 fix(chat): conversation uploads stop reading at the size cap and respect a per-user quota (#20217) #20217

@github-actions github-actions Bot added the sync-conflict Set by the branch sync (#19548) label Nov 2, 2026
@mrveiss

mrveiss commented Nov 2, 2026

Copy link
Copy Markdown
Owner Author

Code review on PR #20668 (head 4fad5e7): approve.

Covers the merge of #20540 only, read at the resolved tree; tests not re-run. The upload path keeps a single read and uses existing_only=True. By the author's account and the _HELD query, an approved removal releases the quota. It boards the train after #20540 lands.

mrveiss added a commit that referenced this pull request Nov 3, 2026
@mrveiss
mrveiss merged commit 0e212c1 into main Nov 3, 2026
4 of 5 checks passed
@mrveiss
mrveiss deleted the issue-20233-chat-file-defects branch November 3, 2026 09:40
timothybrush pushed a commit to timothybrush/AutoBot-AI that referenced this pull request Nov 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

phase:M3.9 Chat, Agents, Analytics and Settings screens sync-conflict Set by the branch sync (#19548)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

hardening(chat): user-reachable conversation uploads have no per-user quota and buffer the body before the size check

1 participant