Skip to content

FILES-001 follow-ups — needs refinement before pickup (12 items) #490

Open

Description

@pavshulin

Tracker for follow-up work identified during the FILES-001 outbound file sharing production-readiness audit (see docs/drafts/amazing-file-outbound-production-readiness.md).

Each item is small enough to pick up independently but needs scoping/discussion before being split into its own issue — in particular, several interact with each other (e.g. G1 streaming extraction affects G3 quota math) so ordering matters.

Parent feature: FILES-001 outbound file sharing (#295, closed as shipped). Phase 1 (9 critical fixes) landed on branch feature/295-files-outbound-sharing on 2026-04-24. This issue covers the deferred "LATER" work.


G-items — triage + discussion

Performance

  • G1 — Stream tar extraction to cap peak memory at 64 KB per share
    services/agent_shared_files_service.py:extract_from_agent() currently reads the entire tar stream into a bytearray, caps at 50 MB + 4 KB overhead, then extracts the single file fully into memory. Under concurrent shares this is 100 MB+ per in-flight request. Discussion: swap to streaming tarfile read that writes directly to the target /data/agent-files/{id} path without a full in-memory copy. Needs care around MIME detection (still needs first ~4 KB buffered) and the 50 MB cap enforcement during streaming.

  • G2 — Shard /data/agent-files/ by UUID prefix
    Flat directory; ext4 directory lookups degrade past ~10k entries. Propose two-level sharding: /data/agent-files/ab/cdef-… using first 2 hex chars. Discussion: migration for existing files (bulk mv in a maintenance window vs. dual-read), impact on cleanup sweep.

  • G10 — OTel explicit span + metrics for shares/downloads
    SEC-001 Phase 3 already wraps MCP tools (so share_file is audit-wrapped for free), but there's no explicit span around create_share() or metric for per-agent download volume. Discussion: span naming (files.share.create vs trinity.files.share), which labels are high-cardinality, whether to emit counter+histogram or just counter.

Security

  • G3 — Platform-wide storage quota setting (in addition to per-agent 500 MB)
    Current limits are per-file (50 MB) and per-agent (500 MB). 100 agents × 500 MB = 50 GB potential. Discussion: reasonable default (10 GB?), per-install configurable via system_settings, enforcement order vs. per-agent check, error message UX.

  • G6 — Sanitize download URLs from stored chat_messages / schedule_executions
    The ?sig=token value ends up in persisted agent-response transcripts for up to 7 days. DB-read access therefore grants URL reuse until expiration. Discussion: where to strip (pre-write in sanitize_response, or at read-time for admin audit queries?), whether to keep URL + redact only the token, migration of existing rows.

  • G7 — One-time download links with link-previewer UA defense
    Deferred from MVP. Schema columns (one_time, consumed_at) already in place. Discussion: which UAs to allowlist for preview-without-consumption (Slackbot, Twitterbot, Discordbot, facebookexternalhit, LinkedInBot, Telegrambot, WhatsApp, SkypeUriPreview, …), how to prevent UA spoofing abuse (probably acceptable since the spoofer already has the token).

  • G11 — Enable PRAGMA foreign_keys = ON per SQLite connection (platform-wide)
    Trinity's db/connection.py doesn't enable FK enforcement, so every ON DELETE/UPDATE CASCADE declaration across the schema is aspirational. We manually cascade in rename_agent() (17 tables) and the agent delete handler. Flipping the pragma would be a real simplification but risks surfacing latent orphans. Discussion: one-shot audit to count orphans, enable via feature flag first, plan coverage for migrations that previously left orphans.

Quality / coverage

  • G5 — Pytest coverage for share / download / list / revoke endpoints
    Unit coverage today is only schema/migration + DB mixin + mount-match helper (33 tests). Discussion: FastAPI TestClient with in-memory DB + mocked Docker SDK; which adversarial paths to cover (path traversal, MIME blocklist, quota breach, cross-agent defense, HEAD mirror).

  • G12 — Unify ShareFileRequest (internal) + ShareFileMcpRequest (MCP) models
    Near-identical shape; one has agent_name in body, the other takes it from the URL. Could be a single model with an optional field, or keep separate for type safety. Discussion: does the split help readability or hurt it?

UX / observability

  • G4 — Index file_share_download audit events by file_id
    Audit rows currently have target_type='agent', target_id=agent_name + file_id buried in details JSON. Fast per-file lookup would need either a JSON-indexed query or a promoted column. Discussion: extend audit schema with a resource_id column, or just add a GIN-style index on json_extract(details, '\$.file_id').

  • G8 — Remove legacy ?download_token= alias once clients migrate
    The download endpoint accepts both ?sig= (canonical) and ?download_token= (legacy — but the credential sanitizer strips that token from agent transcripts, so any URLs in that format are already broken). Discussion: confirm no long-lived URLs still reference it and remove the alias.

  • G9 — UI polish: pagination, download-trend chart, clipboard fallback
    FileSharingPanel shows an unpaginated table (fine for <50 shares, grows ugly at 500+). No trend chart (just total count). `navigator.clipboard` fails on non-HTTPS contexts. Discussion: pagination threshold, whether per-file sparkline is worth the room, fallback UX for clipboard failures.


Process

  • Suggested cadence: batch discussion of 3–4 items per session; convert to individual issues only when scope is locked. Don't block on the whole list.
  • Ordering hint: G11 first (unlocks cleaner design for G1/G2), then G5 (tests before further refactors), then G1+G2 together, then security (G3/G6/G7), then UX (G4/G8/G9/G10/G12).
  • Owner: @pavshulin to decide which to pick up, split out, or drop.

References

  • Feature flow: docs/memory/feature-flows/file-sharing-outbound.md
  • Design doc: docs/drafts/amazing-file-outbound.md
  • Production-readiness plan: docs/drafts/amazing-file-outbound-production-readiness.md §4
  • Phase 1 execution: docs/drafts/amazing-file-outbound-phase1-execution.md

Activity

  1. added
    priority-p2
    type-refactor
    security
    on Apr 24, 2026
  2. added
    complexity-medium
    theme-infrastructure
    on Jun 3, 2026
  3. added
    status-incubating
    on Jun 14, 2026
  4. removed
    security
    on Aug 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    complexity-mediumpriority-p2status-incubatingtheme-infrastructuretype-refactor

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions