From 0133a199a457c0f73186dab80dc289ab40d3836a Mon Sep 17 00:00:00 2001 From: tfarcraw <123211521@163.com> Date: Thu, 19 Nov 2026 02:09:28 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=B9=E6=9C=AA=E8=BE=BE=E9=98=88=E5=80=BC?= =?UTF-8?q?=E7=9A=84=E6=AD=A3=E5=90=91=E7=BA=BF=E7=B4=A2=E7=BB=A7=E7=BB=AD?= =?UTF-8?q?=E8=B7=9F=E8=BF=9B=E6=96=B0=E7=BB=93=E6=9E=9C=E8=80=8C=E4=B8=8D?= =?UTF-8?q?=E6=8F=90=E5=89=8D=E6=94=BE=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Sop/SopEngine.ContinuousChecks.cs | 9 +++++++-- .../VisionDecision.Smoke/ContinuousCheckTests.cs | 15 +++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/SopHelper.CrossPlatform.Engine/Sop/SopEngine.ContinuousChecks.cs b/src/SopHelper.CrossPlatform.Engine/Sop/SopEngine.ContinuousChecks.cs index 0bea0ac..62aea5f 100644 --- a/src/SopHelper.CrossPlatform.Engine/Sop/SopEngine.ContinuousChecks.cs +++ b/src/SopHelper.CrossPlatform.Engine/Sop/SopEngine.ContinuousChecks.cs @@ -21,7 +21,7 @@ public partial class SopEngine ObservationMaxMs = 60000, ObservationMaxFrames = step.AiConfirmation.ObservationMaxFrames, }); - public bool Triggered, SawQuiet, BudgetStarted, StoredBoundary, StoredOutside; + public bool Triggered, SawQuiet, BudgetStarted, StoredBoundary, StoredOutside, FollowCurrentResult; public double? OutsideSince; public List Boundaries = []; public Dictionary Inspected = []; @@ -146,6 +146,9 @@ public partial class SopEngine _acceptedEvidenceTimes[_index] = evaluated.SourceSeconds ?? (evaluated.CapturedAt - DateTime.UnixEpoch).TotalSeconds; return new() { IsMet = true, Message = $"窗口内第 {state.Attempts} 次检查通过:{result.Reason}" }; } + // 已识别到结果但未达放行门槛时,继续观察新结果,不把下一次机会用于无关旧图。 + state.FollowCurrentResult = options.EvidenceMode == VisionEvidenceMode.SingleFrame + && result.Completed && result.EffectiveStatus == VisionDecisionStatus.Completed; } if (expired) { @@ -182,7 +185,9 @@ public partial class SopEngine DecisionCandidatesObserved?.Invoke(step.Id, valid); // 硬截止前的最后检查机会优先看正在形成的新结果,不再全部用于补查历史。 var finalChance = options.CheckWindowMs - state.ElapsedMs <= firstWait; - var selected = InspectionFrameSelector.Select(valid, state.Inspected, state.Boundaries, options.ObservationMinMs / 1000d, finalChance); + var followNewResult = state.FollowCurrentResult && valid.Any(f => ObservationEvidenceWindow.Time(f) + > state.Inspected.Values.DefaultIfEmpty(double.NegativeInfinity).Max()); + var selected = InspectionFrameSelector.Select(valid, state.Inspected, state.Boundaries, options.ObservationMinMs / 1000d, finalChance || followNewResult); frames = selected is null ? [] : [selected]; } if (frames.Length == 0 || state.Inspected.ContainsKey(frames[^1].FrameId) diff --git a/tests/VisionDecision.Smoke/ContinuousCheckTests.cs b/tests/VisionDecision.Smoke/ContinuousCheckTests.cs index 1e0ba12..4db108d 100644 --- a/tests/VisionDecision.Smoke/ContinuousCheckTests.cs +++ b/tests/VisionDecision.Smoke/ContinuousCheckTests.cs @@ -100,6 +100,21 @@ internal static class ContinuousCheckTests SameFeed(4, .5, 35); Check(secondTriggered, "同区域停稳后开始新运动,应能触发下一步,不能强求手离开操作区"); same.Stop(); + var hintConfig = Config(1); hintConfig.Sop.Steps[0].AiConfirmation!.MaxChecks = 3; + var hinted = new Client(); var following = new SopEngine { VisionDecisionClient = hinted }; + following.Load(hintConfig); following.Start(); var hintResults = 0; + following.DecisionEvaluated += (_, _, _) => hintResults++; + void HintFeed(int id, double seconds) => following.ProcessFrame(Frame(id, seconds, 10), () => [(byte)id]); + HintFeed(0, 0); HintFeed(1, .2); await Until(() => hinted.Calls.Count == 1); + HintFeed(2, .4); hinted.Calls.ElementAt(0).Result.SetResult(new(true, .7, "结果尚不够清晰")); + await Until(() => { following.ProcessFrame(Frame(2, .4, 10)); return hintResults == 1; }); + await Until(() => { following.ProcessFrame(Frame(2, .4, 10)); return hinted.Calls.Count == 2; }); + HintFeed(3, .6); HintFeed(4, .8); hinted.Calls.ElementAt(1).Result.SetResult(new(true, .7, "仍未达到完成门槛")); + await Until(() => { following.ProcessFrame(Frame(4, .8, 10)); return hintResults == 2; }); + await Until(() => { following.ProcessFrame(Frame(4, .8, 10)); return hinted.Calls.Count == 3; }); + Check(following.State == EngineState.Running && hinted.Calls.ElementAt(2).Request.FrameId == 4, + "低于阈值的正向线索不能放行,但下一次检查应跟进新结果,不能回退到较早历史帧"); + following.Stop(); Console.WriteLine("PASS: 停稳触发、新帧重试、限时跳过、后续动作持续取证、挂起硬截止、迟到结果隔离和非合格整轮统计"); } }