From 622a62cc26febe60056002b1d5e3717aa419445d Mon Sep 17 00:00:00 2001 From: axiomlogicnexus Date: Tue, 28 Apr 2026 03:02:16 +0200 Subject: [PATCH] Bias queue competition by deferred-first history --- .../HyperTwistTrainingCoachLibrary.cpp | 96 +++++++++++++++++-- 1 file changed, 89 insertions(+), 7 deletions(-) diff --git a/UnrealHyperTwist/Source/UnrealHyperTwist/Private/HyperTwistTraining/HyperTwistTrainingCoachLibrary.cpp b/UnrealHyperTwist/Source/UnrealHyperTwist/Private/HyperTwistTraining/HyperTwistTrainingCoachLibrary.cpp index 98086e8..a69ed46 100644 --- a/UnrealHyperTwist/Source/UnrealHyperTwist/Private/HyperTwistTraining/HyperTwistTrainingCoachLibrary.cpp +++ b/UnrealHyperTwist/Source/UnrealHyperTwist/Private/HyperTwistTraining/HyperTwistTrainingCoachLibrary.cpp @@ -235,6 +235,31 @@ namespace HyperTwistTrainingCoachLibraryInternal ); } + float ResolveDeferredFirstFollowUpPacketPressure( + const FHyperTwistTrainingCoachMemorySnapshot& CoachMemorySnapshot) + { + const bool bPreferredGuidanceSource = + CoachMemorySnapshot.PreferredGuidanceSourceLabel + == TEXT("recommendation-history-deferred-first-follow-up"); + const bool bPreferredHandoffSource = + CoachMemorySnapshot.PreferredCoachHandoffSourceLabel + == TEXT("recommendation-history-deferred-first-follow-up"); + if (CoachMemorySnapshot.DeferredFirstFollowUpPacketHistoryCount <= 0 + && !bPreferredGuidanceSource + && !bPreferredHandoffSource) + { + return 0.0f; + } + + return FMath::Clamp( + (static_cast(CoachMemorySnapshot.DeferredFirstFollowUpPacketHistoryCount) * 1.5f) + + (bPreferredGuidanceSource ? 2.0f : 0.0f) + + (bPreferredHandoffSource ? 2.0f : 0.0f), + 0.0f, + 8.0f + ); + } + float ResolvePreferredGuidanceQueueBias( const FString& SourceLabel, const FHyperTwistTrainingCoachMemorySnapshot& CoachMemorySnapshot, @@ -377,6 +402,7 @@ namespace HyperTwistTrainingCoachLibraryInternal float ResolveDeferredLaunchCompetitionQueueBias( const FString& SourceLabel, const FHyperTwistCoachBrief& FollowUpBrief, + const FHyperTwistTrainingCoachMemorySnapshot& CoachMemorySnapshot, const bool bHasCompetingGuidanceEntry, const bool bHasArchiveEntry) { @@ -386,25 +412,51 @@ namespace HyperTwistTrainingCoachLibraryInternal return 0.0f; } - const float FollowUpBoost = FMath::Clamp( + float FollowUpBoost = FMath::Clamp( (DeferredLaunchPressure * 0.6f) + (bHasCompetingGuidanceEntry ? 1.5f : 0.0f) + (FollowUpBrief.bHasTightenedLaunchOverflow ? 1.5f : 0.0f), 0.0f, 9.0f ); - const float PrimaryPenalty = FMath::Clamp( + float PrimaryPenalty = FMath::Clamp( (DeferredLaunchPressure * 0.4f) + (bHasCompetingGuidanceEntry ? 1.0f : 0.0f), 0.0f, 6.0f ); - const float ArchivePenalty = FMath::Clamp( + float ArchivePenalty = FMath::Clamp( (DeferredLaunchPressure * 0.22f) + (FollowUpBrief.bHasTightenedLaunchOverflow ? 0.5f : 0.0f), 0.0f, 3.0f ); + const float DeferredFirstPacketPressure = ResolveDeferredFirstFollowUpPacketPressure( + CoachMemorySnapshot + ); + if (DeferredFirstPacketPressure > 0.0f) + { + const bool bFollowUpPreferredLane = + CoachMemorySnapshot.PreferredGuidanceLane + == EHyperTwistTrainingCoachGuidanceLane::FollowUp; + FollowUpBoost = FMath::Clamp( + FollowUpBoost + + (DeferredFirstPacketPressure * 0.7f) + + (bFollowUpPreferredLane ? 1.0f : 0.0f), + 0.0f, + 12.0f + ); + PrimaryPenalty = FMath::Clamp( + PrimaryPenalty + (DeferredFirstPacketPressure * 0.55f), + 0.0f, + 8.0f + ); + ArchivePenalty = FMath::Clamp( + ArchivePenalty + (DeferredFirstPacketPressure * 0.2f), + 0.0f, + 4.0f + ); + } if (SourceLabel == TEXT("follow-up-brief")) { @@ -445,12 +497,18 @@ namespace HyperTwistTrainingCoachLibraryInternal } const bool bNeedsDeferredLaunchCompetition = FollowUpBrief.bNeedsDeferredLaunchRecovery && FollowUpBrief.DeferredLaunchCaseCount > 0; + const float DeferredFirstPacketPressure = ResolveDeferredFirstFollowUpPacketPressure( + CoachMemorySnapshot + ); + const bool bDeferredFirstFollowUpHistoryPreferred = DeferredFirstPacketPressure > 0.0f; const bool bScheduleRecoveryPrefersFollowUp = CoachMemorySnapshot.bNeedsScheduleFrictionRecovery && CoachMemorySnapshot.PreferredQueueRecoveryAction == EHyperTwistTrainingQueueRecoveryAction::PromoteDeferred && CoachMemorySnapshot.PreferredGuidanceLane == EHyperTwistTrainingCoachGuidanceLane::FollowUp; - if (!bScheduleRecoveryPrefersFollowUp && !bNeedsDeferredLaunchCompetition) + if (!bScheduleRecoveryPrefersFollowUp + && !bNeedsDeferredLaunchCompetition + && !bDeferredFirstFollowUpHistoryPreferred) { return true; } @@ -464,11 +522,25 @@ namespace HyperTwistTrainingCoachLibraryInternal + static_cast(CoachMemorySnapshot.FollowUpGuidanceContinueBias) + (static_cast(CoachMemorySnapshot.SuppressedPrimaryQueuePressureCount) * 2.0f) + (FollowUpBrief.bNeedsCoachReview ? 8.0f : 0.0f) - + DeferredLaunchPressure; - const bool bShouldCreate = RecommendedRetentionScore >= FollowUpPressureScore + 8.0f; + + DeferredLaunchPressure + + DeferredFirstPacketPressure; + const float RecommendedRetentionThreshold = + bDeferredFirstFollowUpHistoryPreferred ? 10.0f : 8.0f; + const bool bShouldCreate = + RecommendedRetentionScore >= FollowUpPressureScore + RecommendedRetentionThreshold; if (!bShouldCreate && OutSuppressionReason != nullptr) { - if (bNeedsDeferredLaunchCompetition) + if (bNeedsDeferredLaunchCompetition && bDeferredFirstFollowUpHistoryPreferred) + { + *OutSuppressionReason = FString::Printf( + TEXT("Recommended queue creation was suppressed because successful deferred-first follow-up history is reinforcing narrowed continuation while tightened-budget deferred coach work remains unresolved (recommended %.1f vs follow-up %.1f, deferredLaunchCases=%d, deferredFirstHistory=%d)."), + RecommendedRetentionScore, + FollowUpPressureScore, + FollowUpBrief.DeferredLaunchCaseCount, + CoachMemorySnapshot.DeferredFirstFollowUpPacketHistoryCount + ); + } + else if (bNeedsDeferredLaunchCompetition) { *OutSuppressionReason = FString::Printf( TEXT("Recommended queue creation was suppressed because tightened-budget deferred coach work is still unresolved (recommended %.1f vs follow-up %.1f, deferredLaunchCases=%d)."), @@ -477,6 +549,15 @@ namespace HyperTwistTrainingCoachLibraryInternal FollowUpBrief.DeferredLaunchCaseCount ); } + else if (bDeferredFirstFollowUpHistoryPreferred) + { + *OutSuppressionReason = FString::Printf( + TEXT("Recommended queue creation was suppressed because successful deferred-first follow-up history is reinforcing narrowed continuation before broader recommendation work resumes (recommended %.1f vs follow-up %.1f, deferredFirstHistory=%d)."), + RecommendedRetentionScore, + FollowUpPressureScore, + CoachMemorySnapshot.DeferredFirstFollowUpPacketHistoryCount + ); + } else { *OutSuppressionReason = FString::Printf( @@ -1727,6 +1808,7 @@ FHyperTwistCoachSessionQueueSummary UHyperTwistTrainingCoachLibrary::DeriveCoach HyperTwistTrainingCoachLibraryInternal::ResolveDeferredLaunchCompetitionQueueBias( SourceLabel, FollowUpBrief, + CoachMemorySnapshot, bHasCompetingGuidanceEntry, bHasArchiveEntry );