feat(kernel,server): rehydrate() + POST /sessions/{id}/resume
This commit is contained in:
+16
@@ -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,
|
||||
|
||||
+1
-1
@@ -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(),
|
||||
) {
|
||||
|
||||
Reference in New Issue
Block a user