Skip to content

feat(upload): require explicit session_kind and remove legacy chunk a…#430

Merged
AptS-1547 merged 2 commits into
masterfrom
feat/issue-407-remove-legancy-upload-strategy
Jul 23, 2026
Merged

feat(upload): require explicit session_kind and remove legacy chunk a…#430
AptS-1547 merged 2 commits into
masterfrom
feat/issue-407-remove-legancy-upload-strategy

Conversation

@AptS-1547

@AptS-1547 AptS-1547 commented Jul 23, 2026

Copy link
Copy Markdown
Member

…ssembly

Breaking Changes:

  • upload_sessions.session_kind is now NOT NULL
  • Removed 0.4.x payload-per-chunk chunk_N, assembled assembly/relay, kind inference, and assembly limiter
  • Migration will fail if null or invalid session_kind values exist; deployments must clean up expired sessions before upgrading to 0.5.0

Changes:

  • Chunk PUT, Progress, Complete, Cancel/Cleanup now only accept persisted explicit UploadSessionKind
  • Still validate multipart, temp key, and provider session metadata invariants
  • OffsetStaging, StreamStaging, provider/remote relay multipart, presigned, and provider resumable paths remain unchanged
  • Upload service continues generating Init plan from connector-owned transport without introducing DriverType routing matrix
  • Removed LegacyChunkFiles kind, assemble_legacy_local_chunks_to_temp_file, stream_legacy_local_chunks_into_writer, compatibility classifier for null rows, and chunk assembly limiter
  • Removed UploadRuntime from PrimaryAppState (no longer needed without assembly serialization)
  • Simplified resolve_upload_session_kind to direct field read without fallback inference
  • Added migration m20260723_000001_require_upload_session_kind with pre-flight validation that rejects upgrades containing legacy rows
  • Updated tests to create sessions with explicit kinds and verify migration rollback/reapply behavior
    hanges:
  • Deployment or upgrade notes:

Summary by CodeRabbit

  • 重大变更
    • 上传会话的上传类型(session_kind)现为必填且数据库侧不再允许为 NULL;升级时若发现空值或非法类型,将中止升级并保留原数据。
    • 会话类型与分片/临时对象信息不一致将返回明确的“会话损坏”错误,不再静默降级兼容旧路径。
  • 改进
    • 分片上传/进度/完成/取消/清理流程改为仅基于持久化的显式会话类型执行,完成合约收口到 offset/stream staging。
  • 文档
    • 更新“断点续传/分片上传”的会话语义与完成契约说明,移除旧版兼容说明。

…ssembly

**Breaking Changes:**
- `upload_sessions.session_kind` is now `NOT NULL`
- Removed 0.4.x payload-per-chunk `chunk_N`, `assembled` assembly/relay, kind inference, and assembly limiter
- Migration will fail if null or invalid `session_kind` values exist; deployments must clean up expired sessions before upgrading to 0.5.0

**Changes:**
- Chunk PUT, Progress, Complete, Cancel/Cleanup now only accept persisted explicit `UploadSessionKind`
- Still validate multipart, temp key, and provider session metadata invariants
- OffsetStaging, StreamStaging, provider/remote relay multipart, presigned, and provider resumable paths remain unchanged
- Upload service continues generating Init plan from connector-owned transport without introducing `DriverType` routing matrix
- Removed `LegacyChunkFiles` kind, `assemble_legacy_local_chunks_to_temp_file`, `stream_legacy_local_chunks_into_writer`, compatibility classifier for null rows, and chunk assembly limiter
- Removed `UploadRuntime` from `PrimaryAppState` (no longer needed without assembly serialization)
- Simplified `resolve_upload_session_kind` to direct field read without fallback inference
- Added migration `m20260723_000001_require_upload_session_kind` with pre-flight validation that rejects upgrades containing legacy rows
- Updated tests to create sessions with explicit kinds and verify migration rollback/reapply behavior
@AptS-1547 AptS-1547 self-assigned this Jul 23, 2026
@AptS-1547 AptS-1547 added Enhancement New feature or request Priority: Medium Medium priority issue Rust Pull requests that update Rust code labels Jul 23, 2026
@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 812ab8d7-b6ee-4460-8c44-0c5494756255

📥 Commits

Reviewing files that changed from the base of the PR and between 1a205b2 and e5bef1b.

📒 Files selected for processing (5)
  • migration/src/m20260723_000001_require_upload_session_kind.rs
  • src/services/files/upload/chunk.rs
  • src/services/files/upload/kind.rs
  • tests/test_remote_storage.rs
  • tests/test_upload.rs
🚧 Files skipped from review as they are similar to previous changes (4)
  • tests/test_remote_storage.rs
  • migration/src/m20260723_000001_require_upload_session_kind.rs
  • src/services/files/upload/kind.rs
  • src/services/files/upload/chunk.rs

📝 Walkthrough

Walkthrough

上传会话改为持久化合法且非空的 UploadSessionKind。迁移会拒绝遗留数据,上传流程移除旧 chunk assembly、assembled 兼容路径和 UploadRuntime,相关测试与文档同步更新。

Changes

上传会话契约与迁移

Layer / File(s) Summary
session_kind 非空迁移
migration/src/..., src/entities/upload_session.rs, src/types/upload_session.rs
新增跨数据库迁移,拒绝 null/非法 kind,并将模型字段与枚举收窄为显式合法值。
迁移与会话夹具验证
tests/test_migrations.rs, tests/test_database_backends.rs, tests/test_maintenance.rs, tests/test_policies.rs, tests/test_services.rs, CHANGELOG.md
测试覆盖迁移回滚、重放、失败保留原行及显式 session_kind 创建。

上传路径与运行时收窄

Layer / File(s) Summary
持久化 kind 校验与生命周期路由
src/services/files/upload/kind.rs, chunk.rs, progress.rs, lifecycle.rs
Chunk、Progress、Complete 和生命周期流程直接校验持久化 kind 及相关字段组合。
Chunk 完成路径收窄
src/services/files/upload/chunk.rs, complete/*, staging.rs
移除 legacy chunk 文件、assembled 拼装和兼容完成路径,保留 staging 与 relay multipart 流程。
上传运行时与 connector 接口清理
src/runtime/*, src/storage/connectors/*, src/services/files/upload/runtime.rs
删除 UploadRuntime、assembly limiter 及 connector 的 chunked completion 决策接口。

上传测试与契约同步

Layer / File(s) Summary
上传行为回归测试
tests/test_upload.rs, src/services/files/upload/*
测试改用显式 kind、staging 文件和数据库 receipts,覆盖完成、进度、relay 校验与并发幂等。
运行时测试状态更新
src/api/routes/*, src/services/**/tests.rs, src/webdav/*, tests/common/*, tests/test_auth.rs
测试状态构造移除 upload_runtime 并保留其他运行时字段。
上传契约与变更说明
developer-docs/zh-CN/..., CHANGELOG.md
文档说明 NOT NULL、显式 kind、receipt 进度和 legacy 路径移除。

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related issues

Possibly related PRs

Suggested labels: Documentation

Suggested reviewers: apts-1738

Poem

kind 已落库,旧路归尘,
staging 持 receipt,稳稳守门。
assembled 退场,limiter 无声,
迁移若遇旧影——原行留存。

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning 描述包含核心变更,但未按模板提供 Summary、完整 Test plan 和 Notes for reviewers 等必填部分。 按模板补齐 Summary、Test plan 和 Notes for reviewers,并明确迁移、升级说明与验证项。
Docstring Coverage ⚠️ Warning Docstring coverage is 44.55% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed 标题与变更主体一致,准确概括了强制显式 session_kind 并移除旧 chunk 兼容路径。
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/issue-407-remove-legancy-upload-strategy

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

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (2)
src/services/files/upload/kind.rs (1)

8-17: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

validate_persisted_kindkind 参数是多余的,留着迟早坑人。

resolve_upload_session_kind 永远传 session.session_kind,可 validate_persisted_kind 又单独收一个 kind 去跟 session 的字段比对。现在没事,但哪天有人手滑传进来一个跟持久化字段不一致的 kind,它会安安静静按错的类型放行——而这个 kind 后面是要决定上传路由的。既然只有这么一个真实用法,就别留这个洞。

♻️ 直接读持久化字段
 pub(crate) fn resolve_upload_session_kind(
     session: &upload_session::Model,
 ) -> Result<UploadSessionKind> {
-    validate_persisted_kind(session, session.session_kind)
+    validate_persisted_kind(session)
 }

-pub(crate) fn validate_persisted_kind(
-    session: &upload_session::Model,
-    kind: UploadSessionKind,
-) -> Result<UploadSessionKind> {
+pub(crate) fn validate_persisted_kind(
+    session: &upload_session::Model,
+) -> Result<UploadSessionKind> {
+    let kind = session.session_kind;
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/services/files/upload/kind.rs` around lines 8 - 17, 移除
validate_persisted_kind 的 kind 参数,改为在函数内部直接读取并校验 session.session_kind;同时更新
resolve_upload_session_kind 仅传入 session,确保上传类型始终来源于持久化字段。
migration/src/m20260723_000001_require_upload_session_kind.rs (1)

164-260: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

泛型参数名不副实:外键始终硬编码 SQLITE_REBUILT_TABLE

upload_sessions_table<T: IntoIden> 接受任意 table,但 foreign_key().from() 里写死了 Alias::new(SQLITE_REBUILT_TABLE) 而不是复用传入的 table。目前唯一调用点恰好两者一致,凑巧没炸,但函数签名承诺的通用性和实现是脱节的,之后谁复用这个函数换个表名就会悄悄拿到错的外键定义。既然只有一处调用,不如把泛型去掉,直接接受具体表名或者复用 table 变量。

♻️ 建议修复
-fn upload_sessions_table<T>(table: T, nullable: bool) -> TableCreateStatement
-where
-    T: IntoIden,
-{
+fn upload_sessions_table(table: impl IntoIden + Clone, nullable: bool) -> TableCreateStatement {
     let mut session_kind = ColumnDef::new(UploadSessions::SessionKind);
     session_kind.string_len(32);
     ...
         .foreign_key(
             ForeignKey::create()
-                .from(Alias::new(SQLITE_REBUILT_TABLE), UploadSessions::UserId)
+                .from(table.clone(), UploadSessions::UserId)
                 .to(Users::Table, Users::Id)
                 .on_delete(ForeignKeyAction::Cascade),
         )
         .to_owned()
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@migration/src/m20260723_000001_require_upload_session_kind.rs` around lines
164 - 260, Update upload_sessions_table so the foreign key’s from-table uses the
function’s table parameter instead of the hardcoded SQLITE_REBUILT_TABLE alias;
preserve the existing table creation behavior and generic table support.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/test_upload.rs`:
- Around line 3326-3331: 增强该并发测试:不要仅依赖 tokio::join!,应在 part claim 或 staging
写入临界区注入可控的 barrier/failpoint,确保两个请求都进入关键区后再继续;随后断言并发进入确实发生,并验证最终 staging/part
仅登记一次。
- Line 177: 将 UploadSessionSpec::new 修改为强制接收 UploadSessionKind 参数,移除其中自动填充
OffsetStaging 的隐式默认值;同步更新所有调用方(包括仅调用 object_upload 的 fixture),显式传入正确的
session_kind,避免遗漏配置时生成错误组合。

---

Nitpick comments:
In `@migration/src/m20260723_000001_require_upload_session_kind.rs`:
- Around line 164-260: Update upload_sessions_table so the foreign key’s
from-table uses the function’s table parameter instead of the hardcoded
SQLITE_REBUILT_TABLE alias; preserve the existing table creation behavior and
generic table support.

In `@src/services/files/upload/kind.rs`:
- Around line 8-17: 移除 validate_persisted_kind 的 kind 参数,改为在函数内部直接读取并校验
session.session_kind;同时更新 resolve_upload_session_kind 仅传入
session,确保上传类型始终来源于持久化字段。
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 24a48998-8ef1-4967-a580-36411dcaa503

📥 Commits

Reviewing files that changed from the base of the PR and between c07cd2e and 1a205b2.

⛔ Files ignored due to path filters (1)
  • frontend-panel/src/services/api.generated.ts is excluded by !**/*.generated.*
📒 Files selected for processing (56)
  • CHANGELOG.md
  • developer-docs/zh-CN/api/files.md
  • developer-docs/zh-CN/design/upload-finalization-contracts.md
  • migration/src/lib.rs
  • migration/src/m20260723_000001_require_upload_session_kind.rs
  • src/api/routes/files/access.rs
  • src/api/routes/frontend.rs
  • src/api/routes/health.rs
  • src/api/routes/share_public.rs
  • src/entities/upload_session.rs
  • src/runtime/mod.rs
  • src/runtime/startup/primary.rs
  • src/runtime/tasks.rs
  • src/services/files/file/deletion/tests.rs
  • src/services/files/file/download/tests.rs
  • src/services/files/file/resource_handle.rs
  • src/services/files/lock/tests.rs
  • src/services/files/upload/chunk.rs
  • src/services/files/upload/complete/chunked.rs
  • src/services/files/upload/complete/mod.rs
  • src/services/files/upload/complete/object_multipart.rs
  • src/services/files/upload/complete/plan.rs
  • src/services/files/upload/complete/tests.rs
  • src/services/files/upload/init/context.rs
  • src/services/files/upload/init/mod.rs
  • src/services/files/upload/kind.rs
  • src/services/files/upload/lifecycle.rs
  • src/services/files/upload/mod.rs
  • src/services/files/upload/progress.rs
  • src/services/files/upload/runtime.rs
  • src/services/files/upload/shared.rs
  • src/services/files/upload/staging.rs
  • src/services/media/metadata/tests.rs
  • src/services/ops/audit/tests.rs
  • src/services/ops/config/system.rs
  • src/services/storage_policy/credential/oauth/tests.rs
  • src/services/storage_policy/policy/policies.rs
  • src/services/task/dispatch/tests.rs
  • src/services/workspace/scope/mod.rs
  • src/services/workspace/storage/tests.rs
  • src/storage/connectors/mod.rs
  • src/storage/connectors/tests.rs
  • src/storage/connectors/upload.rs
  • src/types/upload_session.rs
  • src/webdav/auth.rs
  • src/webdav/file/tests.rs
  • src/webdav/handler_tests/mod.rs
  • tests/common/mod.rs
  • tests/test_auth.rs
  • tests/test_database_backends.rs
  • tests/test_maintenance.rs
  • tests/test_migrations.rs
  • tests/test_policies.rs
  • tests/test_remote_storage.rs
  • tests/test_services.rs
  • tests/test_upload.rs
💤 Files with no reviewable changes (28)
  • src/services/storage_policy/credential/oauth/tests.rs
  • src/services/task/dispatch/tests.rs
  • src/webdav/handler_tests/mod.rs
  • src/services/ops/audit/tests.rs
  • src/services/files/upload/runtime.rs
  • src/api/routes/health.rs
  • src/services/files/upload/mod.rs
  • src/services/files/file/download/tests.rs
  • src/runtime/tasks.rs
  • src/services/storage_policy/policy/policies.rs
  • src/api/routes/frontend.rs
  • src/api/routes/files/access.rs
  • src/services/workspace/storage/tests.rs
  • src/api/routes/share_public.rs
  • src/services/files/lock/tests.rs
  • src/types/upload_session.rs
  • src/services/ops/config/system.rs
  • src/webdav/auth.rs
  • src/services/workspace/scope/mod.rs
  • src/services/files/file/deletion/tests.rs
  • src/runtime/startup/primary.rs
  • tests/test_auth.rs
  • src/storage/connectors/upload.rs
  • src/services/media/metadata/tests.rs
  • src/services/files/file/resource_handle.rs
  • tests/common/mod.rs
  • src/storage/connectors/tests.rs
  • src/webdav/file/tests.rs

Comment thread tests/test_upload.rs
Comment thread tests/test_upload.rs
…arameters

- Add rendezvous barrier before staging write lock acquisition for more reliable concurrency testing
- Replace timeout-based overlap detection with entry barrier and counter
- Remove redundant `kind` parameter from `validate_persisted_kind` function
- Fix foreign key reference in migration to use correct table identifier
- Update test helper to require explicit `session_kind` in constructor
- Improve concurrent chunk upload test with proper synchronization verification
- Add entry count assertion to duplicate chunk test
- Update remote storage test assertion to check for transient error kind
@AptS-1547
AptS-1547 merged commit 891b233 into master Jul 23, 2026
14 checks passed
@AptS-1547
AptS-1547 deleted the feat/issue-407-remove-legancy-upload-strategy branch July 23, 2026 07:13
@AptS-1547 AptS-1547 linked an issue Jul 23, 2026 that may be closed by this pull request
41 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Enhancement New feature or request Priority: Medium Medium priority issue Rust Pull requests that update Rust code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Refactor]: 0.5.0 移除 legacy chunk upload compatibility 并收紧 session kind

1 participant