|
| 1 | +# Akoflow Runtime Execution Flow for AI |
| 2 | + |
| 3 | +Purpose: compact reference for how each runtime works and how the classes relate. |
| 4 | + |
| 5 | +Akoflow is the workflow engine core of the project. It takes workflow definitions and turns them into executions on supported backends. |
| 6 | + |
| 7 | +Supported backends: |
| 8 | + |
| 9 | +- Kubernetes clusters |
| 10 | +- HPC environments orchestrated with Slurm |
| 11 | + |
| 12 | +## Shared Dispatch Path |
| 13 | + |
| 14 | +`RunActivityInClusterService` is the common entrypoint for activity execution. |
| 15 | + |
| 16 | +This service is part of the execution core: it decides where the activity runs and forwards control to the correct runtime implementation. |
| 17 | + |
| 18 | +1. Load `WorkflowActivities` and `Workflow` from repositories. |
| 19 | +2. Read `runtimeId` from the activity. |
| 20 | +3. Call `runtimes.GetRuntimeInstance(runtimeId)`. |
| 21 | +4. Execute `ApplyJob(workflowID, activityID)` on the selected runtime wrapper. |
| 22 | + |
| 23 | +## Runtime Pattern |
| 24 | + |
| 25 | +- Wrapper package: `pkg/server/runtimes/<runtime>`. |
| 26 | +- Service package: `pkg/server/runtimes/<runtime>/<runtime>_service`. |
| 27 | +- Wrapper: implements the common interface and delegates. |
| 28 | +- Service: builds commands, calls connectors, updates repositories, collects logs and metrics. |
| 29 | + |
| 30 | +## Local Runtime |
| 31 | + |
| 32 | +### Main classes |
| 33 | + |
| 34 | +- `LocalRuntime` |
| 35 | +- `LocalRuntimeService` |
| 36 | +- `connector_local` |
| 37 | + |
| 38 | +### Execution |
| 39 | + |
| 40 | +1. `LocalRuntime.ApplyJob` delegates to `LocalRuntimeService.ApplyJob`. |
| 41 | +2. The service loads activity and workflow records. |
| 42 | +3. It builds a local shell command from `wfa.Run`. |
| 43 | +4. It appends a completion marker file and redirects stdout/stderr to the mount path. |
| 44 | +5. `connector_local.RunCommand` executes the command. |
| 45 | +6. Workflow and activity status are set to running. |
| 46 | +7. The process ID is saved in the activity record. |
| 47 | + |
| 48 | +### Verification |
| 49 | + |
| 50 | +- `VerifyActivitiesWasFinished` checks for the completion marker file. |
| 51 | +- If the job is still running, it extracts metrics and logs from the command output. |
| 52 | +- Metrics go to `metrics_repository` and logs go to `logs_repository`. |
| 53 | + |
| 54 | +## Singularity Runtime |
| 55 | + |
| 56 | +### Main classes |
| 57 | + |
| 58 | +- `SingularityRuntime` |
| 59 | +- `SingularityRuntimeService` |
| 60 | +- `MakeSingularityActivityService` |
| 61 | +- `connector_singularity` |
| 62 | + |
| 63 | +### Execution |
| 64 | + |
| 65 | +1. `SingularityRuntime.ApplyJob` delegates to `SingularityRuntimeService.ApplyJob`. |
| 66 | +2. The service loads activity and workflow records. |
| 67 | +3. `MakeSingularityActivityService` creates the `singularity exec` command. |
| 68 | +4. The command binds the workflow mount path and sets the container working directory. |
| 69 | +5. `connector_singularity.RunCommand` submits the command. |
| 70 | +6. Workflow and activity status are updated. |
| 71 | +7. The process ID is saved. |
| 72 | + |
| 73 | +### Verification |
| 74 | + |
| 75 | +- `VerifyActivitiesWasFinished` runs the Singularity monitor script. |
| 76 | +- The output is parsed to detect completion. |
| 77 | +- Metrics and logs are extracted and persisted when the job is still active. |
| 78 | + |
| 79 | +## HPC Runtime |
| 80 | + |
| 81 | +### Main classes |
| 82 | + |
| 83 | +- `HpcRuntime` |
| 84 | +- `HPCRuntimeService` |
| 85 | +- `MakeSingularityActivityService` |
| 86 | +- `MakeSBatchHPCRuntimeActivityService` |
| 87 | +- `connector_hpc` |
| 88 | +- `runtime_repository` |
| 89 | + |
| 90 | +### See Also |
| 91 | + |
| 92 | +- [`HPC_EXECUTION.md`](HPC_EXECUTION.md) contains the full AI-focused HPC execution map. |
| 93 | + |
| 94 | +### Execution |
| 95 | + |
| 96 | +1. `HpcRuntime.ApplyJob` delegates to `HPCRuntimeService.ApplyJob`. |
| 97 | +2. The service loads activity and workflow records. |
| 98 | +3. It may prepare workflow data and environment for the first activity. |
| 99 | +4. Runtime metadata is loaded from `runtime_repository`. |
| 100 | +5. `MakeSingularityActivityService` builds the Singularity command used on the cluster. |
| 101 | +6. `MakeSBatchHPCRuntimeActivityService` wraps that command in an sbatch submission. |
| 102 | +7. `connector_hpc` checks VPN connectivity. |
| 103 | +8. `connector_hpc` submits the remote command. |
| 104 | +9. The returned job ID is stored as the process ID. |
| 105 | +10. Workflow and activity status are updated to running. |
| 106 | + |
| 107 | +### Volume Sync |
| 108 | + |
| 109 | +- `syncWorkflowVolumes` prepares remote directories. |
| 110 | +- It copies workflow data to the cluster and later pulls results back. |
| 111 | +- This is the critical relation between workflow volumes and remote execution. |
| 112 | + |
| 113 | +### Verification |
| 114 | + |
| 115 | +- `VerifyActivitiesWasFinished` checks each running activity. |
| 116 | +- It reads remote completion state and job status. |
| 117 | +- If the job is complete or failed, it syncs volumes back and closes the activity. |
| 118 | + |
| 119 | +## Kubernetes Runtime |
| 120 | + |
| 121 | +### Main classes |
| 122 | + |
| 123 | +- `KubernetesRuntime` |
| 124 | +- `KubernetesRuntimeService` |
| 125 | +- `ModeRunActivityService` |
| 126 | +- `MonitorVerifyActivityWasFinishedService` |
| 127 | +- `MonitorGetLogsActivityService` |
| 128 | +- `MonitorGetMetricsActivityService` |
| 129 | + |
| 130 | +### Execution |
| 131 | + |
| 132 | +1. `KubernetesRuntime.ApplyJob` delegates to `KubernetesRuntimeService.ApplyJob`. |
| 133 | +2. The service loads activity and workflow records. |
| 134 | +3. It resolves the workflow mode. |
| 135 | +4. The mode-specific service prepares Kubernetes resources. |
| 136 | +5. The job is applied in the cluster. |
| 137 | + |
| 138 | +### Monitoring |
| 139 | + |
| 140 | +- `VerifyActivitiesWasFinished` delegates to a monitor service. |
| 141 | +- `GetLogs` and `GetMetrics` delegate to dedicated monitor services. |
| 142 | +- `HealthCheck` validates the runtime and discovers nodes. |
| 143 | + |
| 144 | +## Docker Runtime |
| 145 | + |
| 146 | +- Docker exists in the runtime factory. |
| 147 | +- It behaves like a placeholder compared to the other runtimes. |
| 148 | + |
| 149 | +## Relationship Summary |
| 150 | + |
| 151 | +- Entities define workflow state. |
| 152 | +- Repositories store workflow state. |
| 153 | +- Connectors perform external I/O. |
| 154 | +- Runtime services coordinate everything. |
| 155 | +- Runtime wrappers only adapt to the common interface. |
| 156 | + |
| 157 | +## AI Guidance |
| 158 | + |
| 159 | +- When tracing a bug, start with the runtime wrapper, then the runtime service, then the connector and repositories. |
| 160 | +- For persistence bugs, inspect mount path handling first. |
| 161 | +- For execution bugs, inspect runtime selection and activity state transitions first. |
0 commit comments