Skip to content

fix(agent): preserve upload Markdown provenance - #4691

Open
PeaceMaker-best wants to merge 8 commits into
bytedance:mainfrom
PeaceMaker-best:fix/upload-markdown-provenance
Open

fix(agent): preserve upload Markdown provenance#4691
PeaceMaker-best wants to merge 8 commits into
bytedance:mainfrom
PeaceMaker-best:fix/upload-markdown-provenance

Conversation

@PeaceMaker-best

@PeaceMaker-best PeaceMaker-best commented Aug 5, 2026

Copy link
Copy Markdown

Why

Web upload responses already identify the converted Markdown companion through markdown_file, including collision-renamed files such as a_1.md. That provenance was dropped before Agent execution, so UploadsMiddleware guessed <stem>.md. With same-stem uploads, the Agent could receive another document's outline; an explicit no-conversion result could also accidentally fall back to an unrelated Markdown file.

The explicit companion path was also validated separately from the later read. A writable sandbox process could replace the file between those operations and make unrelated content enter <current_uploads>.

What changed

  • Preserve nullable markdown_file provenance in current-turn web-upload message metadata and use one shared frontend mapper for optimistic and submitted messages.
  • Enforce tri-state Agent semantics: absent key keeps the legacy <stem>.md fallback, explicit null disables fallback, and a valid string selects only the named companion.
  • Validate explicit basenames and fail closed for traversal, staging files, missing files, symlinks/reparse points, hard links, NTFS alternate data streams, and replacement races.
  • Parse outline and preview from the same authoritative handle: directory-relative O_NOFOLLOW on POSIX and pinned, verified native handles on Windows.
  • Keep raw companion metadata out of the model-visible <current_uploads> block and document the compatibility contract.

Surface area

  • Frontend UI - page / component / setting / interaction under frontend/
  • Backend API - endpoint / SSE event / request-response shape under backend/app
  • Agents / LangGraph - Agent upload context and grounding behavior
  • Sandbox - docker/ or sandboxed execution
  • Skills - change under skills/
  • Dependencies - no dependency changes
  • Default behavior change - current-turn uploads now use explicit conversion provenance instead of guessing when the field is present
  • Docs / tests / CI only - runtime behavior changes

Screenshots / Recording

Not applicable; this changes upload metadata propagation and Agent grounding, with no visual UI change.

Bug fix verification

  • Reproduction tests: frontend/tests/unit/core/uploads/message-files.test.ts and backend/tests/test_uploads_middleware_core_logic.py.
  • The provenance/crosstalk regressions went red before implementation (7 new backend failures plus the missing frontend mapper).
  • The replacement-race, single-open preview, Windows directory-swap, and ADS regressions went red against the pre-fix implementation and green after the secure-handle change.

Validation

  • Frontend: 989/989 tests passed across 126 files; ESLint, TypeScript, and Prettier checks passed.
  • Backend changed area: 64 upload-middleware tests, 1 blocking-I/O anchor, and 32 file-outline compatibility tests passed.
  • Ruff check/format, the repository blocking-I/O static detector, and git diff --check passed.
  • Clean Windows full non-live comparison: this branch had 10,901 passed / 111 skipped / 132 failed; fresh origin/main had the exact same 132 failing node IDs (intersection 132, branch-only 0).

AI assistance

Tool(s) used: Codex

How you used it: Codex helped investigate the bug, draft the approved design, implement the change with RED/GREEN tests, run full validation, and perform independent task-level and final security reviews. This Draft PR intentionally leaves the human responsibility confirmation unchecked until the author personally reviews every line.

  • I've read and understand every line of this change and take responsibility for it - it's not unreviewed AI output.

@CLAassistant

CLAassistant commented Aug 5, 2026

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ PeaceMaker-best
❌ Beautyl0ve
You have signed the CLA already but the status is still pending? Let us recheck it.

@PeaceMaker-best
PeaceMaker-best marked this pull request as ready for review August 5, 2026 05:28
@github-actions github-actions Bot added area:agents Agents, subagents, graph wiring, prompts, langgraph.json area:backend Gateway / runtime / core backend under backend/ area:docs Documentation and Markdown only area:frontend Next.js frontend under frontend/ needs-validation Touches front/back contract surface; needs real-path validation risk:high High risk: backend API, agents, sandbox, auth, deps, CI size/XL PR changes 700+ lines labels Aug 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:agents Agents, subagents, graph wiring, prompts, langgraph.json area:backend Gateway / runtime / core backend under backend/ area:docs Documentation and Markdown only area:frontend Next.js frontend under frontend/ needs-validation Touches front/back contract surface; needs real-path validation risk:high High risk: backend API, agents, sandbox, auth, deps, CI size/XL PR changes 700+ lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants