Make sleep own durable memory promotion
This commit is contained in:
parent
868e242ce4
commit
5df282e6b4
13 changed files with 130 additions and 44 deletions
|
|
@ -267,12 +267,12 @@ function Assert-AllowedMemoryMaintenanceOperation {
|
|||
|
||||
$operationName = Get-ObjectPropertyString -Value $Operation -Name "operation"
|
||||
$allowed = @(
|
||||
"append_distilled_memory",
|
||||
"merge_incubation_support",
|
||||
"queue_candidate_intervention",
|
||||
"retire_candidate_intervention",
|
||||
"propose_memory_distillation",
|
||||
"apply_memory_distillation"
|
||||
"apply_memory_distillation",
|
||||
"prune_short_term_memories"
|
||||
)
|
||||
|
||||
if ($null -eq $operationName -or -not $allowed.Contains($operationName)) {
|
||||
|
|
@ -349,7 +349,8 @@ $codexExecArgs = if ($envValues.ContainsKey("CODEX_EXEC_ARGS")) { Split-CommandA
|
|||
$typedContext = Get-TypedSelfState
|
||||
$typedState = $typedContext.typedState
|
||||
$isSleepMaintenance = [bool]$typedState.scheduledRuntime.sleepCycle.isNapping
|
||||
$memoryCount = @(Convert-ToValueArray -Value $typedState.thoughtMemory.memories).Count
|
||||
$shortTermMemoryCount = @(Convert-ToValueArray -Value $typedState.thoughtMemory.shortTerm).Count
|
||||
$longTermMemoryCount = @(Convert-ToValueArray -Value $typedState.thoughtMemory.memories).Count
|
||||
$incubationCount = @(Convert-ToValueArray -Value $typedState.thoughtMemory.incubation).Count
|
||||
$activeCandidateCount = @(
|
||||
@(Convert-ToValueArray -Value $typedState.candidateInterventions.interventions) |
|
||||
|
|
@ -358,7 +359,7 @@ $activeCandidateCount = @(
|
|||
$status -eq "queued" -or $status -eq "deferred"
|
||||
}
|
||||
).Count
|
||||
$maintenancePressure = $memoryCount + $incubationCount + $activeCandidateCount
|
||||
$maintenancePressure = $shortTermMemoryCount + $incubationCount + $activeCandidateCount
|
||||
|
||||
Write-JsonFile -Path $contextPath -Data @{
|
||||
generated = "now"
|
||||
|
|
@ -367,13 +368,15 @@ Write-JsonFile -Path $contextPath -Data @{
|
|||
mode = if ($isSleepMaintenance) { "sleep_maintenance" } else { "awake_memory_maintenance" }
|
||||
maintenanceBoundary = "This pass may propose only typed memory/incubation/candidate operations. Exact timestamps stay in typed state; prompt-facing chronology uses relative phrases."
|
||||
sleepDirective = @{
|
||||
forceDistillation = [bool]($isSleepMaintenance -and $maintenancePressure -gt 1)
|
||||
forceDistillation = [bool]($isSleepMaintenance -and $maintenancePressure -gt 0)
|
||||
maintenancePressure = [int]$maintenancePressure
|
||||
memoryCount = [int]$memoryCount
|
||||
shortTermMemoryCount = [int]$shortTermMemoryCount
|
||||
longTermMemoryCount = [int]$longTermMemoryCount
|
||||
incubationCount = [int]$incubationCount
|
||||
activeCandidateCount = [int]$activeCandidateCount
|
||||
rule = "During sleep, yesterday's rumination residue must be pruned or compressed. Return [] only when the typed surfaces are already minimal or no meaning-preserving operation is possible."
|
||||
}
|
||||
shortTermMemories = @(Project-MemoriesForRumination -Memories $typedState.thoughtMemory.shortTerm -Now $startedAtUtc)
|
||||
memories = @(Project-MemoriesForRumination -Memories $typedState.thoughtMemory.memories -Now $startedAtUtc)
|
||||
incubation = @(Project-IncubationForRumination -Threads $typedState.thoughtMemory.incubation -Now $startedAtUtc)
|
||||
candidateInterventions = @(Project-InterventionsForRumination -Interventions $typedState.candidateInterventions.interventions -Now $startedAtUtc)
|
||||
|
|
@ -436,7 +439,7 @@ if (-not (Test-Path $operationOutputPath)) {
|
|||
$proposedOperations = @(Convert-ToOperationArray -Value (Read-JsonFile -Path $operationOutputPath))
|
||||
$appliedOperations = @()
|
||||
|
||||
if ((-not $SkipModel) -and $isSleepMaintenance -and $maintenancePressure -gt 1 -and @($proposedOperations).Count -eq 0) {
|
||||
if ((-not $SkipModel) -and $isSleepMaintenance -and $maintenancePressure -gt 0 -and @($proposedOperations).Count -eq 0) {
|
||||
throw "Sleep memory maintenance returned no operations despite maintenance pressure $maintenancePressure."
|
||||
}
|
||||
|
||||
|
|
@ -445,6 +448,14 @@ foreach ($operation in $proposedOperations) {
|
|||
$appliedOperations += Apply-TypedOperation -Operation $operation
|
||||
}
|
||||
|
||||
if ((-not $SkipModel) -and $isSleepMaintenance) {
|
||||
$refreshedTypedState = Get-TypedSelfState
|
||||
$remainingShortTermCount = @(Convert-ToValueArray -Value $refreshedTypedState.typedState.thoughtMemory.shortTerm).Count
|
||||
if ($remainingShortTermCount -gt 0) {
|
||||
throw "Sleep memory maintenance left $remainingShortTermCount short-term memories unpromoted."
|
||||
}
|
||||
}
|
||||
|
||||
$finishedAtUtc = [DateTime]::UtcNow
|
||||
$lastMessage = if (Test-Path $lastMessagePath) { Get-Content -Path $lastMessagePath -Raw -Encoding UTF8 } else { "" }
|
||||
|
||||
|
|
|
|||
|
|
@ -277,6 +277,24 @@ function Convert-ToOperationArray {
|
|||
return @($Value)
|
||||
}
|
||||
|
||||
function Assert-AllowedRuminationOperation {
|
||||
param($Operation)
|
||||
|
||||
$operationName = Get-ObjectPropertyString -Value $Operation -Name "operation"
|
||||
$allowed = @(
|
||||
"upsert_open_case",
|
||||
"close_open_case",
|
||||
"record_short_term_memory",
|
||||
"merge_incubation_support",
|
||||
"queue_candidate_intervention",
|
||||
"retire_candidate_intervention"
|
||||
)
|
||||
|
||||
if ($null -eq $operationName -or -not $allowed.Contains($operationName)) {
|
||||
throw "Rumination proposed disallowed operation '$operationName'."
|
||||
}
|
||||
}
|
||||
|
||||
function Convert-LastSpeechToReceiptOperation {
|
||||
param($Speech)
|
||||
|
||||
|
|
@ -440,6 +458,7 @@ Write-JsonFile -Path $contextPath -Data @{
|
|||
openCases = @(Project-OpenCasesForRumination -Cases $typedState.moderationCursor.openCases -Now $startedAtUtc)
|
||||
speechReceipts = @(Project-SpeechReceiptsForRumination -Receipts $typedState.speechReceipts.recentReceipts -Now $startedAtUtc)
|
||||
memories = @(Project-MemoriesForRumination -Memories $typedState.thoughtMemory.memories -Now $startedAtUtc)
|
||||
shortTermMemories = @(Project-MemoriesForRumination -Memories $typedState.thoughtMemory.shortTerm -Now $startedAtUtc)
|
||||
incubation = @(Project-IncubationForRumination -Threads $typedState.thoughtMemory.incubation -Now $startedAtUtc)
|
||||
candidateInterventions = @(Project-InterventionsForRumination -Interventions $typedState.candidateInterventions.interventions -Now $startedAtUtc)
|
||||
scheduledRuntime = Project-ScheduledRuntimeForRumination -Runtime $typedState.scheduledRuntime -Now $startedAtUtc
|
||||
|
|
@ -518,6 +537,7 @@ foreach ($operation in $proposedOperations) {
|
|||
if ($null -eq $operation -or $null -eq $operationName) {
|
||||
continue
|
||||
}
|
||||
Assert-AllowedRuminationOperation -Operation $operation
|
||||
$appliedOperations += Apply-TypedOperation -Operation $operation
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue