Skip to content

perf(files): batch session attachment validation YEF-1058 - #562

Merged
Yevanchen merged 2 commits into
mainfrom
perf/files-batch-attachment-validation
Aug 21, 2026
Merged

perf(files): batch session attachment validation YEF-1058#562
Yevanchen merged 2 commits into
mainfrom
perf/files-batch-attachment-validation

Conversation

@Yevanchen

Copy link
Copy Markdown
Collaborator

Summary

  • Replace per-attachment file and session reads with one target-session authorization check and one bulk file lookup.
  • Preserve requested attachment order and duplicates, with a regression test that pins the D1 statement count.

Why

  • Attachment admission previously prepared two D1 statements per attachment, up to 200 statements at the 100-file session limit. The new path prepares two statements for any batch size while retaining O(n) in-memory validation.
  • Closes YEF-1058

Verification

  • Commands:
    • just test-file apps/api/tests/file-session-attachment-validation.test.ts (1 passed; baseline measured 6 statements for three inputs, optimized path measures 2)
    • just test-file apps/api/tests/send-agent-session-events.test.ts (8 passed)
    • just tc-package @mosoo/api
    • just test-package @mosoo/api (1,227 passed)
    • just commit-check
    • just check (format, docs, lint, and typecheck passed; the repository test phase stopped on 11 process-watchdog failures in the untouched apps/driver submodule after 1,220 passes)
  • Manual steps: N/A
  • Not run: Browser/E2E flows and the final Public API contract step skipped by the failed full gate; this change does not alter UI or Public API contracts.

Impact

  • User/API/contract changes: None; internal session attachment admission keeps the same return order and validation rules.
  • Generated files / GraphQL / DB / lockfile: None.
  • Env or config changes: None.
  • Risk and rollback: Low; authorization remains explicit before the bulk read, and reverting 0deec857 restores the prior lookup path.

Review

  • Closest review areas: Session file authorization, invalid attachment handling, duplicate/order preservation, and the D1 statement-count assertion.
  • Known trade-offs: The two D1 reads remain sequential so target-session authorization completes before file records are loaded; the bulk result is indexed in memory in O(n).

@Yevanchen Yevanchen changed the title perf(files): batch session attachment validation perf(files): batch session attachment validation YEF-1058 Aug 20, 2026
@Yevanchen
Yevanchen force-pushed the perf/files-batch-attachment-validation branch from 0deec85 to 478fadf Compare August 20, 2026 16:36
@Yevanchen
Yevanchen merged commit c921ad9 into main Aug 21, 2026
9 checks passed
@Yevanchen
Yevanchen deleted the perf/files-batch-attachment-validation branch August 21, 2026 10:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant