feat(kernel,server): rehydrate() + POST /sessions/{id}/resume

This commit is contained in:
2026-06-08 10:13:33 +04:00
parent 5ad945ccb4
commit b830528d31
5 changed files with 192 additions and 1 deletions
@@ -162,6 +162,22 @@ class DefaultSessionOrchestrator(
fun validatedArtifactContent(sessionId: SessionId, artifactId: ArtifactId): String? =
artifactContentCache["${sessionId.value}:${artifactId.value}"]
/**
* Rebuilds [artifactContentCache] from durable events after a server restart.
* Scans all events for [ArtifactValidatedEvent] and re-fetches the stored bytes
* from [artifactStore] for each one. Must be called before [resume] to ensure
* transition conditions that read artifact content work correctly.
*/
suspend fun rehydrate(sessionId: SessionId) {
repositories.eventStore.readFrom(sessionId, fromSequence = 0L).forEach { event ->
val p = event.payload as? ArtifactValidatedEvent ?: return@forEach
val key = "${sessionId.value}:${p.artifactId.value}"
artifactStore.get(p.artifactId)
?.toString(Charsets.UTF_8)
?.let { artifactContentCache[key] = it }
}
}
suspend fun resume(
sessionId: SessionId,
graph: WorkflowGraph,
@@ -134,7 +134,7 @@ private const val REPO_MAP_INJECT_TOP_K = 30
abstract class SessionOrchestrator(
repositories: OrchestratorRepositories,
engines: OrchestratorEngines,
private val artifactStore: ArtifactStore,
protected val artifactStore: ArtifactStore,
private val decisionJournalRepository: DefaultDecisionJournalRepository,
private val decisionJournalRenderer: DecisionJournalRenderer = DecisionJournalRenderer(),
) {