Skip to content

feat(agent): support batch config file uploads (SNP-997) - #44947

Merged
zyssyz123 merged 14 commits into
mainfrom
feat/snp-997-batch-upload
Oct 29, 2026
Merged

zyssyz123 merged 14 commits into
mainfrom
feat/snp-997-batch-upload

Conversation

@zyssyz123

@zyssyz123 zyssyz123 commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Agent configuration accepts one file at a time, and binding files can race with Composer saves that replace the full configuration snapshot. This adds multi-select and multi-file drop, uploads the files in parallel, then binds all successful upload IDs through one atomic batch request.

The new POST config/files/batch endpoints accept upload_file_ids, validate tenant ownership, and merge files while holding Agent and Draft row locks. Asset mutations and Composer saves use the same lock order and refresh cached Draft state after locking. Ordinary Composer saves omit config_files, preserving the latest server-managed files even when another tab submits a stale configuration. Explicit lists still replace the files, and [] clears them for Apply/import flows. Autosave, manual save, publish, and page-close scheduling retain their existing behavior.

Per-file limits, same-name replacement, retry with cached upload IDs, and duplicate-submit/close protection remain in the upload dialog. Batch binding is all-or-nothing; individual upload failures leave other successful uploads eligible for binding. Prompt uploads preserve the original cursor and trailing text while inserting all successful references. All 25 locales and generated API contracts are updated; the existing single-file endpoint remains compatible.

Validation:

  • Focused backend regressions: 273 passed; adjacent Agent services, entities, and controller tests: 848 passed.
  • Affected frontend unit tests: 101 passed; Chromium Prompt caret regression: 1 passed.
  • Workspace type checks, full static checks, API Ruff/Pyrefly/response-contract checks, i18n checks, and production Web build passed.
  • E2E upload helpers now validate the batch endpoint and response. Type/lint checks and the four-scenario Cucumber dry-run passed; real full-stack execution runs in CI.
  • Verified on agent dev, API/Web revision 3846ebf47b: three files uploading concurrently; stale second-tab autosave preserving all files after refresh; atomic batch failure with no partial binding; retry reusing the same uploaded ID (one DB upload record before/after); two Prompt references inserted between existing text; and refresh persistence for all six files.
  • Actual PostgreSQL concurrency checks passed in both bind/save orders and delete/stale-save order. Each check observed a wait on the holding transaction through pg_blocking_pids and preserved the expected configuration. The dedicated test Draft and metadata were restored. Only API and Web images changed; worker, beat, and nginx retained their images and start times.

Issue: https://linear.app/dify/issue/SNP-997/agent支持批量上传文件

@codecov

codecov Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.21813% with 31 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.55%. Comparing base (70975c1) to head (bd7409c).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
api/services/agent/composer_service.py 86.40% 6 Missing and 8 partials ⚠️
api/services/agent_config_service.py 86.11% 6 Missing and 4 partials ⚠️
...ure/components/orchestrate/files/upload-dialog.tsx 96.55% 3 Missing ⚠️
...ure/components/orchestrate/prompt-editor/slash.tsx 78.57% 3 Missing ⚠️
...l/configure/components/orchestrate/tools/index.tsx 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main   #44947       +/-   ##
===========================================
+ Coverage   59.62%   89.55%   +29.93%     
===========================================
  Files        6011     6011               
  Lines      377116   377264      +148     
  Branches    76358    76386       +28     
===========================================
+ Hits       224848   337875   +113027     
+ Misses     146276    33395   -112881     
- Partials     5992     5994        +2     
Flag Coverage Δ
api 89.41% <88.68%> (+<0.01%) ⬆️
cli 94.28% <ø> (ø)
dify-ui 92.65% <ø> (ø)
web 89.52% <94.69%> (+74.20%) ⬆️

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

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions github-actions Bot added the size:XXL This PR changes 1000+ lines, ignoring generated files. label Oct 28, 2026
@github-actions

github-actions Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Pyrefly Type Coverage

Metric Base PR Delta
Type coverage 80.28% 80.30% +0.01%
Strict coverage 79.97% 79.98% +0.01%
Typed symbols 77,275 77,341 +66
Untyped symbols 19,052 19,053 +1
Modules 3988 3989 +1

@github-actions

github-actions Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-10-29 04:36:34.783750916 +0000
+++ /tmp/pyrefly_pr.txt	2026-10-29 04:36:23.727745936 +0000
@@ -5779,53 +5779,53 @@
 ERROR Argument `Literal['emoji']` is not assignable to parameter `icon_type` with type `AgentIconType | SQLCoreOperations[AgentIconType | None] | None` in function `models.agent.Agent.__init__` [bad-argument-type]
     --> tests/unit_tests/services/agent/test_roster_service.py:2497:19
 ERROR Argument `Literal['emoji']` is not assignable to parameter `icon_type` with type `AgentIconType | SQLCoreOperations[AgentIconType | None] | None` in function `models.agent.Agent.__init__` [bad-argument-type]
-    --> tests/unit_tests/services/agent/test_roster_service.py:2652:19
+    --> tests/unit_tests/services/agent/test_roster_service.py:2653:19
 ERROR Object of class `object` has no attribute `prompt` [missing-attribute]
-    --> tests/unit_tests/services/agent/test_roster_service.py:3064:12
+    --> tests/unit_tests/services/agent/test_roster_service.py:3073:12
 ERROR Cannot index into `object` [bad-index]
-    --> tests/unit_tests/services/agent/test_roster_service.py:3255:12
+    --> tests/unit_tests/services/agent/test_roster_service.py:3264:12
 ERROR Cannot index into `object` [bad-index]
-    --> tests/unit_tests/services/agent/test_roster_service.py:3256:12
+    --> tests/unit_tests/services/agent/test_roster_service.py:3265:12
 ERROR Cannot index into `object` [bad-index]
-    --> tests/unit_tests/services/agent/test_roster_service.py:3257:12
+    --> tests/unit_tests/services/agent/test_roster_service.py:3266:12
 ERROR Argument `list[str | None]` is not assignable to parameter `version_ids` with type `list[str]` in function `services.agent.roster_service.AgentRosterService._load_versions_by_id` [bad-argument-type]
-    --> tests/unit_tests/services/agent/test_roster_service.py:4362:52
+    --> tests/unit_tests/services/agent/test_roster_service.py:4371:52
 ERROR Argument `Literal[0]` is not assignable to parameter `message_unit_price` with type `Decimal | SQLCoreOperations[Decimal]` in function `models.model.Message.__init__` [bad-argument-type]
-    --> tests/unit_tests/services/agent/test_roster_service.py:4521:36
+    --> tests/unit_tests/services/agent/test_roster_service.py:4530:36
 ERROR Argument `Literal[0]` is not assignable to parameter `answer_unit_price` with type `Decimal | SQLCoreOperations[Decimal]` in function `models.model.Message.__init__` [bad-argument-type]
-    --> tests/unit_tests/services/agent/test_roster_service.py:4523:35
+    --> tests/unit_tests/services/agent/test_roster_service.py:4532:35
 ERROR Argument `Literal[0]` is not assignable to parameter `total_price` with type `Decimal | SQLCoreOperations[Decimal | None] | None` in function `models.model.Message.__init__` [bad-argument-type]
-    --> tests/unit_tests/services/agent/test_roster_service.py:4524:29
+    --> tests/unit_tests/services/agent/test_roster_service.py:4533:29
 ERROR Object of class `NoneType` has no attribute `conversation_id` [missing-attribute]
-    --> tests/unit_tests/services/agent/test_roster_service.py:5297:16
+    --> tests/unit_tests/services/agent/test_roster_service.py:5306:16
 ERROR Argument `Literal['simple']` is not assignable to parameter `prompt_type` with type `PromptType | SQLCoreOperations[PromptType]` in function `models.model.AppModelConfig.__init__` [bad-argument-type]
-    --> tests/unit_tests/services/agent/test_roster_service.py:5401:25
+    --> tests/unit_tests/services/agent/test_roster_service.py:5410:25
 ERROR Unpacked keyword argument `Any | None` is not assignable to parameter `prompt_type` with type `PromptType | SQLCoreOperations[PromptType]` in function `models.model.AppModelConfig.__init__` [bad-argument-type]
-    --> tests/unit_tests/services/agent/test_roster_service.py:5409:34
+    --> tests/unit_tests/services/agent/test_roster_service.py:5418:34
 ERROR Object of class `object` has no attribute `name` [missing-attribute]
-    --> tests/unit_tests/services/agent/test_roster_service.py:5515:16
+    --> tests/unit_tests/services/agent/test_roster_service.py:5524:16
 ERROR Object of class `object` has no attribute `mode` [missing-attribute]
-    --> tests/unit_tests/services/agent/test_roster_service.py:5516:16
+    --> tests/unit_tests/services/agent/test_roster_service.py:5525:16
 ERROR Object of class `object` has no attribute `agent_role` [missing-attribute]
-    --> tests/unit_tests/services/agent/test_roster_service.py:5517:16
+    --> tests/unit_tests/services/agent/test_roster_service.py:5526:16
 ERROR Object of class `object` has no attribute `config_snapshot` [missing-attribute]
-    --> tests/unit_tests/services/agent/test_roster_service.py:5527:16
+    --> tests/unit_tests/services/agent/test_roster_service.py:5536:16
 ERROR Object of class `object` has no attribute `home_snapshot_id` [missing-attribute]
-    --> tests/unit_tests/services/agent/test_roster_service.py:5529:16
+    --> tests/unit_tests/services/agent/test_roster_service.py:5538:16
 ERROR Object of class `object` has no attribute `summary` [missing-attribute]
-    --> tests/unit_tests/services/agent/test_roster_service.py:5530:16
+    --> tests/unit_tests/services/agent/test_roster_service.py:5539:16
 ERROR Object of class `object` has no attribute `version_note` [missing-attribute]
-    --> tests/unit_tests/services/agent/test_roster_service.py:5531:16
+    --> tests/unit_tests/services/agent/test_roster_service.py:5540:16
 ERROR Object of class `object` has no attribute `active_config_has_model` [missing-attribute]
-    --> tests/unit_tests/services/agent/test_roster_service.py:5532:16
+    --> tests/unit_tests/services/agent/test_roster_service.py:5541:16
 ERROR Object of class `object` has no attribute `active_config_is_published` [missing-attribute]
-    --> tests/unit_tests/services/agent/test_roster_service.py:5533:16
+    --> tests/unit_tests/services/agent/test_roster_service.py:5542:16
 ERROR Object of class `object` has no attribute `updated_by` [missing-attribute]
-    --> tests/unit_tests/services/agent/test_roster_service.py:5534:16
+    --> tests/unit_tests/services/agent/test_roster_service.py:5543:16
 ERROR Object of class `object` has no attribute `id` [missing-attribute]
-    --> tests/unit_tests/services/agent/test_roster_service.py:5535:35
+    --> tests/unit_tests/services/agent/test_roster_service.py:5544:35
 ERROR Object of class `object` has no attribute `agent_role` [missing-attribute]
-    --> tests/unit_tests/services/agent/test_roster_service.py:5605:16
+    --> tests/unit_tests/services/agent/test_roster_service.py:5614:16
 ERROR Argument `object` is not assignable to parameter `pwd` with type `bytes | None` in function `zipfile.ZipFile.read` [bad-argument-type]
    --> tests/unit_tests/services/agent/test_skill_package_service.py:306:44
 ERROR Object of class `NoneType` has no attribute `node_job_config_dict` [missing-attribute]
@@ -5989,17 +5989,17 @@
 ERROR `in` is not supported between `Literal['not found']` and `None` [not-iterable]
    --> tests/unit_tests/services/retention/workflow_run/test_restore_archived_workflow_run.py:894:16
 ERROR Argument `SimpleNamespace` is not assignable to parameter `version` with type `AgentConfigDraft | AgentConfigSnapshot` in function `services.agent_config_service.AgentConfigTarget.__init__` [bad-argument-type]
-   --> tests/unit_tests/services/test_agent_config_service.py:159:17
+   --> tests/unit_tests/services/test_agent_config_service.py:161:17
 ERROR Cannot index into `object` [bad-index]
-    --> tests/unit_tests/services/test_agent_config_service.py:1023:12
+    --> tests/unit_tests/services/test_agent_config_service.py:1021:12
 ERROR Type `object` is not iterable [not-iterable]
-    --> tests/unit_tests/services/test_agent_config_service.py:1024:38
+    --> tests/unit_tests/services/test_agent_config_service.py:1022:38
 ERROR Cannot index into `object` [bad-index]
-    --> tests/unit_tests/services/test_agent_config_service.py:1181:38
+    --> tests/unit_tests/services/test_agent_config_service.py:1179:38
 ERROR Cannot index into `object` [bad-index]
-    --> tests/unit_tests/services/test_agent_config_service.py:1182:12
+    --> tests/unit_tests/services/test_agent_config_service.py:1180:12
 ERROR Type `object` is not iterable [not-iterable]
-    --> tests/unit_tests/services/test_agent_config_service.py:1218:38
+    --> tests/unit_tests/services/test_agent_config_service.py:1216:38
 ERROR Object of class `FromClause` has no attribute `create` [missing-attribute]
    --> tests/unit_tests/services/test_api_token_service.py:309:13
 ERROR Argument `Literal['app']` is not assignable to parameter `value` with type `ApiTokenType | SQLCoreOperations[ApiTokenType]` in function `sqlalchemy.orm.base.Mapped.__set__` [bad-argument-type]

autofix-ci Bot and others added 6 commits October 28, 2026 14:49
- Compose parallel uploads and the batch bind in one dialog-root mutation; keep the pending list inside the dialog popup and show each failed file's server message.
- Pass a list through `onAdded`; the Files panel inserts prompt references for every bound file when the upload dialog closes, so the prompt editor change is reverted.
- Use the strict `es-toolkit` `omit` for composer saves that leave `config_files` to the server.
- Return the normal Draft's files for inline workflow nodes while it is based on the bound snapshot, so loads match what the next node save persists.
- Refetch the build draft before applying it in workflow nodes so a newer file list is not replaced by a cached one.
- Drop the per-file status keys and restore the file type label in every locale.
- Read the current prompt when inserting slash-menu references, since file references now arrive when the upload dialog closes.
- Stop applying a workflow build draft when refreshing it fails instead of saving the cached copy.
- Keep an explicitly requested workflow snapshot's own files; only the bound node state shows the normal Draft's files.
lyzno1
lyzno1 previously approved these changes Oct 29, 2026
@zyssyz123
zyssyz123 added this pull request to the merge queue Oct 29, 2026
Merged via the queue into main with commit 9e978de Oct 29, 2026
62 checks passed
@zyssyz123
zyssyz123 deleted the feat/snp-997-batch-upload branch October 29, 2026 04:49
@laipz8200 laipz8200 mentioned this pull request Nov 3, 2026
1 task done
41tair added a commit that referenced this pull request Nov 6, 2026
Restore the lock-and-refresh behavior from #44947 in the extracted Agent config repository. Flush caller-owned Agent edits before refreshing the locked Agent and Draft without autoflushing stale Draft changes.

The caller owns the session and transaction; successful reads retain row locks until commit or rollback. Cover stale identity-map state, pending Agent creation, owner scoping, and lock clauses with real-session regression tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

e2e End-to-end tests and E2E test infrastructure. size:XXL This PR changes 1000+ lines, ignoring generated files. web This relates to changes on the web.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants