diff --git a/core/kernel/src/main/kotlin/com/correx/core/kernel/orchestration/DefaultSessionOrchestrator.kt b/core/kernel/src/main/kotlin/com/correx/core/kernel/orchestration/DefaultSessionOrchestrator.kt index ab6ee780..997600a7 100644 --- a/core/kernel/src/main/kotlin/com/correx/core/kernel/orchestration/DefaultSessionOrchestrator.kt +++ b/core/kernel/src/main/kotlin/com/correx/core/kernel/orchestration/DefaultSessionOrchestrator.kt @@ -699,7 +699,7 @@ class DefaultSessionOrchestrator( compactionService?.let { svc -> val journalState = decisionJournalRepository.getJournal(ctx.sessionId) val journalText = DecisionJournalRenderer().render(journalState) - val tokenEstimate = journalText.length / 4 + val tokenEstimate = estimateTokens(journalText) svc.compactIfNeeded( sessionId = ctx.sessionId, state = journalState, diff --git a/core/kernel/src/main/kotlin/com/correx/core/kernel/orchestration/SessionOrchestrator.kt b/core/kernel/src/main/kotlin/com/correx/core/kernel/orchestration/SessionOrchestrator.kt index 7553c93b..e87ef556 100644 --- a/core/kernel/src/main/kotlin/com/correx/core/kernel/orchestration/SessionOrchestrator.kt +++ b/core/kernel/src/main/kotlin/com/correx/core/kernel/orchestration/SessionOrchestrator.kt @@ -511,7 +511,7 @@ abstract class SessionOrchestrator( content = journalText, sourceType = "decisionJournal", sourceId = "decision-journal", - tokenEstimate = journalText.length / 4, + tokenEstimate = estimateTokens(journalText), role = EntryRole.SYSTEM, ), )