|
| 1 | +# CAVE Integration Spike (Non-invasive) |
| 2 | + |
| 3 | +## Objective |
| 4 | +Define a **CAVE-compatible data flow** for PyTC Client that can be implemented incrementally without changing current runtime behavior. |
| 5 | + |
| 6 | +This spike is documentation-first and establishes a contract for future work. |
| 7 | + |
| 8 | +--- |
| 9 | + |
| 10 | +## Target use case in this app |
| 11 | +Primary use case: allow a user to run existing PyTC workflows (training, inference, proofreading, and visualization handoff) while optionally publishing workflow artifacts to a CAVE-aligned backend for downstream analysis. |
| 12 | + |
| 13 | +In practical terms: |
| 14 | +- Users continue using current PyTC routes and UI exactly as they do today. |
| 15 | +- A future, explicit integration path can transform local workflow outputs (predictions, masks, metadata, provenance) into CAVE-style entities. |
| 16 | +- Teams that rely on CAVE tooling can consume PyTC results without changing PyTC core execution paths. |
| 17 | + |
| 18 | +Non-goal for this spike: |
| 19 | +- No live auth, network calls, or deployment wiring. |
| 20 | +- No routing changes in existing server endpoints. |
| 21 | + |
| 22 | +--- |
| 23 | + |
| 24 | +## Expected inputs and outputs |
| 25 | + |
| 26 | +### Inputs (from current PyTC workflow artifacts) |
| 27 | +1. **Run context** |
| 28 | + - run ID / job ID |
| 29 | + - timestamp |
| 30 | + - model/config reference |
| 31 | +2. **Dataset references** |
| 32 | + - source image path(s) |
| 33 | + - optional chunk/volume coordinates |
| 34 | + - resolution metadata |
| 35 | +3. **Inference / proofreading outputs** |
| 36 | + - segmentation or mask outputs |
| 37 | + - object-level summaries/statistics where available |
| 38 | +4. **Provenance and annotations** |
| 39 | + - operator/user reference (if available) |
| 40 | + - comments or QC notes (if available) |
| 41 | + |
| 42 | +### Outputs (CAVE-aligned payload expectations) |
| 43 | +1. **Dataset/collection descriptor** |
| 44 | + - canonical dataset key |
| 45 | + - spatial metadata |
| 46 | +2. **Versioned result artifact record** |
| 47 | + - result identifier tied to run context |
| 48 | + - linkage to upstream input dataset references |
| 49 | +3. **Optional annotation payload(s)** |
| 50 | + - typed annotation entries linked to coordinates/objects |
| 51 | +4. **Status envelope** |
| 52 | + - accepted/rejected/queued semantics (for future async transport) |
| 53 | + |
| 54 | +--- |
| 55 | + |
| 56 | +## Mapping: PyTC workflow artifacts → CAVE concepts |
| 57 | + |
| 58 | +| PyTC artifact / concept | CAVE-aligned concept | Mapping notes | |
| 59 | +|---|---|---| |
| 60 | +| Training/inference run ID | Version / operation reference | Preserve immutable run identifier for lineage. | |
| 61 | +| Input image volume path + scale | Dataset / image source descriptor | Include voxel resolution and bounds when available. | |
| 62 | +| Output mask / segmentation file | Segmentation payload reference | Publish as versioned result; avoid overwriting by default. | |
| 63 | +| Detected objects / stats | Table/annotation-like records | Map each object to stable ID and geometric summary. | |
| 64 | +| Proofreading edits | Annotation update set | Track editor and timestamp in provenance fields. | |
| 65 | +| Config YAML path + hash | Metadata / provenance attachment | Enables reproducibility checks in CAVE consumers. | |
| 66 | +| Runtime status/result message | Ingest status envelope | Normalize to queued/succeeded/failed taxonomy. | |
| 67 | + |
| 68 | +--- |
| 69 | + |
| 70 | +## Suggested integration contract (future) |
| 71 | +Introduce an **explicit opt-in adapter path** that is only invoked by future routes or background jobs, for example: |
| 72 | +- `prepare_cave_payload(run_artifacts) -> CavePayload` |
| 73 | +- `validate_cave_payload(payload) -> ValidationResult` |
| 74 | +- `publish_to_cave(payload, transport) -> PublishResult` |
| 75 | + |
| 76 | +Design constraints: |
| 77 | +- Adapter must be import-safe and side-effect free. |
| 78 | +- No network or auth dependency at import time. |
| 79 | +- Existing endpoints continue untouched unless a new flag/route explicitly calls the adapter. |
| 80 | + |
| 81 | +--- |
| 82 | + |
| 83 | +## Non-invasive rollout plan |
| 84 | +1. **Phase 0 (this spike):** document contract and mappings (this file). |
| 85 | +2. **Phase 1:** add inert adapter scaffolding with interface stubs only. |
| 86 | +3. **Phase 2:** add offline payload generation and validation tests. |
| 87 | +4. **Phase 3:** add optional transport implementation behind explicit feature flag. |
| 88 | +5. **Phase 4:** wire opt-in route or async task that calls adapter. |
| 89 | + |
| 90 | +--- |
| 91 | + |
| 92 | +## TODOs (auth/network/deployment assumptions) |
| 93 | + |
| 94 | +### Auth TODOs |
| 95 | +- Define service-to-service auth model (token issuer, rotation policy, scopes). |
| 96 | +- Decide whether end-user identity is propagated or service account is used. |
| 97 | +- Specify failure behavior for auth expiration (retry vs fail-fast). |
| 98 | + |
| 99 | +### Network TODOs |
| 100 | +- Define allowed egress targets and timeout/retry policy. |
| 101 | +- Decide sync vs async delivery semantics for large artifacts. |
| 102 | +- Define payload size limits and chunking/compression behavior. |
| 103 | + |
| 104 | +### Deployment TODOs |
| 105 | +- Define environment variables/secrets required for CAVE endpoints. |
| 106 | +- Choose deployment topology (in-process transport vs worker queue). |
| 107 | +- Add observability requirements (structured logs, metrics, tracing IDs). |
| 108 | + |
| 109 | +--- |
| 110 | + |
| 111 | +## Actionable next steps |
| 112 | +1. Create `server_api/workflow/cave_adapter.py` with pure interface stubs and typed payload models. |
| 113 | +2. Add `tests/test_cave_adapter_contract.py` to lock down: |
| 114 | + - no side effects on import, |
| 115 | + - deterministic payload mapping from fixture artifacts, |
| 116 | + - explicit invocation requirement (not called in default app path). |
| 117 | +3. Add a feature flag proposal (`PYTC_ENABLE_CAVE_ADAPTER=false` default) for a future opt-in route. |
| 118 | +4. Review mapping table with CAVE stakeholders and finalize required fields. |
| 119 | + |
| 120 | +This keeps current behavior unchanged while preparing a low-risk implementation path. |
0 commit comments