Repository navigation
Description
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-sharingon 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 abytearray, 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 streamingtarfileread 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 (soshare_fileis audit-wrapped for free), but there's no explicit span aroundcreate_share()or metric for per-agent download volume. Discussion: span naming (files.share.createvstrinity.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 viasystem_settings, enforcement order vs. per-agent check, error message UX. -
G6 — Sanitize download URLs from stored
chat_messages/schedule_executions
The?sig=tokenvalue 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 insanitize_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 = ONper SQLite connection (platform-wide)
Trinity'sdb/connection.pydoesn't enable FK enforcement, so everyON DELETE/UPDATE CASCADEdeclaration across the schema is aspirational. We manually cascade inrename_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: FastAPITestClientwith 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 hasagent_namein 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_downloadaudit events byfile_id
Audit rows currently havetarget_type='agent', target_id=agent_name+file_idburied indetailsJSON. Fast per-file lookup would need either a JSON-indexed query or a promoted column. Discussion: extend audit schema with aresource_idcolumn, or just add a GIN-style index onjson_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