diff --git a/simulation/ai-polygon/nav2/check_http_integration.py b/simulation/ai-polygon/nav2/check_http_integration.py index a7d25046..9bc59d78 100644 --- a/simulation/ai-polygon/nav2/check_http_integration.py +++ b/simulation/ai-polygon/nav2/check_http_integration.py @@ -245,6 +245,24 @@ def main(): changed=request('/plan',retreat) assert changed['status']=='path' and 'action_result' not in changed,changed report['new_goal_after_completion']=changed + # An unobserved destination is rejected by the native planner with + # allow_unknown=False. Report that exact action result to selection; + # do not mislabel it as a measured obstacle or retain the old command. + retreat.update(goal=[6.,0.,0.],observation_id='unobserved-local-goal') + rejected=request('/plan',retreat) + assert rejected['status']=='blocked' and rejected['diagnostic']['failure']=='no-path',rejected + assert rejected['planning_result']==dict(status='aborted',goal_xy=[6.,0.]),rejected + assert rejected['route_observation']['observation']==dict(pose=reached, + simulation_time_seconds=retreat['simulation_time_seconds'], + execution_inputs_sha256=inputs['sha256']),rejected + with condition:state.update(enabled=True,observation_id=retreat['observation_id']) + time.sleep(.1) + assert responses[-1]['speed_mps']==responses[-1]['yaw_rate_rps']==0.,responses[-1] + report['aborted_local_plan']=dict(plan=rejected,command=responses[-1]) + retreat.update(goal=[1.8,.2,0.],observation_id='replacement-observed-goal') + replacement=request('/plan',retreat) + assert replacement['status']=='path' and 'planning_result' not in replacement,replacement + report['replacement_local_plan']=replacement with condition: state.update(pose=[0.,0.,.37,0.,0.,0.,1.],enabled=False) retreat['pose']=[0.,0.,.37,0.,0.,0.,1.] diff --git a/simulation/ai-polygon/nav2/check_native_adapter.py b/simulation/ai-polygon/nav2/check_native_adapter.py index 30f1fdcb..28ac1608 100644 --- a/simulation/ai-polygon/nav2/check_native_adapter.py +++ b/simulation/ai-polygon/nav2/check_native_adapter.py @@ -72,7 +72,7 @@ def main(): bridge.activate() history=[] for goal in ([5.,0.], [3.,1.]): - planned=bridge.plan(pose,goal,math.atan2(goal[1],goal[0])) + planned,status=bridge.plan(pose,goal,math.atan2(goal[1],goal[0])) assert planned is not None and len(planned.poses)>1 proposed=bridge.follow(planned) assert proposed is not None diff --git a/simulation/ai-polygon/nav2/ros_navigation.py b/simulation/ai-polygon/nav2/ros_navigation.py index 14a663f3..15ebb125 100644 --- a/simulation/ai-polygon/nav2/ros_navigation.py +++ b/simulation/ai-polygon/nav2/ros_navigation.py @@ -144,7 +144,8 @@ class RosNavigation(Node): # Do not leave work from a timed-out HTTP transaction as authority. self.await_result(handle.cancel_goal_async(), .2) raise - return result.result.path if result.status == GoalStatus.STATUS_SUCCEEDED else None + return (result.result.path if result.status == GoalStatus.STATUS_SUCCEEDED else None, + result.status) def accept(self, client, request, timeout, feedback_callback=None): if self.failed: diff --git a/simulation/ai-polygon/nav2/server.py b/simulation/ai-polygon/nav2/server.py index 3302f525..124ed030 100644 --- a/simulation/ai-polygon/nav2/server.py +++ b/simulation/ai-polygon/nav2/server.py @@ -204,10 +204,14 @@ class Navigation: # capture leases and command gates still refresh above/every tick. if (not continuing or self.path is None or self.node.native_command() is None or entered-self.path_planned_at >= 1.0): - path = self.node.plan(pose, goal, math.atan2(goal[1]-pose[1],goal[0]-pose[0])) + path, status = self.node.plan(pose, goal, math.atan2(goal[1]-pose[1],goal[0]-pose[0])) if path is None or len(path.poses) < 2: self.node.stop() - return self.reply('no-path', status='blocked', route_observation=route) + # Humble has no typed planner error code. Preserve its + # terminal abort without inventing an obstacle diagnosis. + feedback = (dict(planning_result=dict(status='aborted', goal_xy=goal[:2].tolist())) + if status == GoalStatus.STATUS_ABORTED else {}) + return self.reply('no-path', status='blocked', route_observation=route, **feedback) if not continuing: with self.owner_lock: self.action_key = None diff --git a/simulation/ai-polygon/navigation_client.py b/simulation/ai-polygon/navigation_client.py index dad32641..147bc0fa 100644 --- a/simulation/ai-polygon/navigation_client.py +++ b/simulation/ai-polygon/navigation_client.py @@ -837,6 +837,8 @@ class ComposedInference: "allow_reverse": intent["state"] == "reversing", }, ) + self.mission.reject_local_plan( + result, pose, inputs["source.simulation-time"], self.inputs["sha256"]) self.mission.recovery.observe_navigation( result, pose, inputs["source.simulation-time"], recovery_option, self.inputs["sha256"], diff --git a/src/k1link/simulation/ai_polygon/mission_policy.py b/src/k1link/simulation/ai_polygon/mission_policy.py index 8cccfa4e..d66b9fb7 100644 --- a/src/k1link/simulation/ai_polygon/mission_policy.py +++ b/src/k1link/simulation/ai_polygon/mission_policy.py @@ -114,6 +114,25 @@ class WaypointMission: self.failed_goals.append(self.goal) self.goal = None + def reject_local_plan(self, result, pose, seconds, execution_inputs_sha256): + """Retire an intermediate intent after its bound native planner abort. + + This is not an obstacle label or motion permission. The next observed + candidate must obtain its own native path and current command admission. + Preserve task arrival evidence and the existing progress/retry budget. + """ + if (self.fault or self.recovery.active or self.goal is None + or self.last_time != seconds or self.last_pose != tuple(pose)): + return + expected = dict(pose=list(pose), simulation_time_seconds=seconds, + execution_inputs_sha256=execution_inputs_sha256) + if (result.get("route_observation", {}).get("observation") == expected + and result.get("status") == "blocked" + and result.get("speed_mps") == result.get("yaw_rate_rps") == 0. + and result.get("planning_result") == dict( + status="aborted", goal_xy=list(self.goal[:2]))): + self.retire_local_goal(self.arrival_target(), failed=True) + def arrival_candidate(self, pose): return bool( self.route diff --git a/tests/test_ai_polygon_mission.py b/tests/test_ai_polygon_mission.py index b4326163..ebd7b481 100644 --- a/tests/test_ai_polygon_mission.py +++ b/tests/test_ai_polygon_mission.py @@ -101,7 +101,7 @@ def test_wrong_direction_never_replenishes_route_attempts(): assert intent["state"] == "stuck" -def test_signed_motion_contract_accepts_reverse_but_stays_bounded(): +def test_signed_motion_contract_accepts_reverse_but_requires_finite_speed(): from pydantic import ValidationError from k1link.simulation.ai_polygon.contracts import Decision @@ -112,8 +112,11 @@ def test_signed_motion_contract_accepts_reverse_but_stays_bounded(): ).speed_mps < 0 ) - with pytest.raises(ValidationError): - Decision(speed_mps=-1.1, yaw_rate_rps=0, reason="road", road_fraction=1, obstacle_count=0) + # The configured robot/run owns the speed ceiling; this transport contract + # has no fixed one-metre-per-second limit. Non-finite commands remain invalid. + for speed in (float("inf"), float("-inf"), float("nan")): + with pytest.raises(ValidationError): + Decision(speed_mps=speed, yaw_rate_rps=0, reason="road", road_fraction=1, obstacle_count=0) def test_slow_regulated_progress_is_not_mistaken_for_stall(): @@ -242,3 +245,55 @@ def test_heading_credit_keeps_existing_retry_count_and_expires(): for seconds in range(9, 80): mission.update(yaw_pose(min((seconds - 8) * 0.08, 3.14)), seconds, choose) assert mission.fault == "stuck" and mission.attempts == 4 + + +def aborted_plan(goal, p, seconds): + return dict(status="blocked", speed_mps=0., yaw_rate_rps=0., + planning_result=dict(status="aborted", goal_xy=list(goal[:2])), + route_observation=dict(observation=dict(pose=p, simulation_time_seconds=seconds, + execution_inputs_sha256="run"))) + + +def test_native_abort_selects_another_observed_intent_without_resetting_progress(): + mission = WaypointMission([[8, 0]]) + first, _ = mission.update(pose(), 0, goal) + mission.reject_local_plan(aborted_plan(first, pose(), 0), pose(), 0, "run") + assert mission.goal is None and mission.failed_goals == [first] + assert mission.anchor_time == 0 and mission.attempts == 0 + second, _ = mission.update(pose(), .1, goal) + assert second != first and mission.route == [[8, 0]] + # Repeated planner rejection and goal changes cannot create progress. + for t in range(1, 34): + current, _ = mission.update(pose(), t, goal) + if current is not None: + mission.reject_local_plan(aborted_plan(current, pose(), t), pose(), t, "run") + assert mission.fault == "stuck" + + +@pytest.mark.parametrize("invalid", ["old-goal", "old-pose", "old-time", "old-run", + "missing-result", "canceled", "moving", "waiting", "old-caller", "recovery"]) +def test_only_current_native_abort_can_retire_local_intent(invalid): + mission = WaypointMission([[8, 0]]) + first, _ = mission.update(pose(), 1, goal) + result = aborted_plan(first, pose(), 1) + observation = result["route_observation"]["observation"] + if invalid == "old-goal": result["planning_result"]["goal_xy"] = [3, 0] + elif invalid == "old-pose": observation["pose"] = pose(.1) + elif invalid == "old-time": observation["simulation_time_seconds"] = 0 + elif invalid == "old-run": observation["execution_inputs_sha256"] = "other" + elif invalid == "missing-result": result.pop("planning_result") + elif invalid == "canceled": result["planning_result"]["status"] = "canceled" + elif invalid == "moving": result["speed_mps"] = .1 + elif invalid == "waiting": result["status"] = "waiting-for-plan" + elif invalid == "recovery": mission.recovery.begin(pose(), 1, []) + mission.reject_local_plan(result, pose(), 0 if invalid == "old-caller" else 1, "run") + assert mission.goal == first and mission.failed_goals == [] + + +def test_native_abort_keeps_task_arrival_evidence_and_requires_new_observation(): + mission = WaypointMission([[2, 0]]) + first, _ = mission.update(pose(), 0, goal) + mission.reject_local_plan(aborted_plan(first, pose(), 0), pose(), 0, "run") + assert mission.goal == first and mission.failed_goals == [] + assert mission.update(pose(), .1, lambda *_: None)[0] is None + assert mission.index == 0 and mission.fault is None diff --git a/tests/test_recovery_navigation_integration.py b/tests/test_recovery_navigation_integration.py index 13c87e18..c08560fc 100644 --- a/tests/test_recovery_navigation_integration.py +++ b/tests/test_recovery_navigation_integration.py @@ -30,11 +30,11 @@ def test_navigation_delivers_current_option_veto_and_stale_data_does_not_retire_ semantic_visible=lambda points,calibration:np.ones(len(points),bool)) monkeypatch.setattr(module,'project',lambda points,*args:(points,np.zeros(len(points)), np.zeros(len(points)),np.ones(len(points),bool))) - failure=['no-path'] + failure=['no-path']; planning=[None] def response(path,request): assert path=='/plan' return dict(status='blocked',path=[],speed_mps=0.,yaw_rate_rps=0., - diagnostic=dict(failure=failure[0]),route_observation=dict(observation=dict( + planning_result=planning[0],diagnostic=dict(failure=failure[0]),route_observation=dict(observation=dict( pose=list(request['pose']),simulation_time_seconds=request['simulation_time_seconds'], execution_inputs_sha256=request['execution_inputs_sha256']))) model.navigation=SimpleNamespace(request=response) @@ -63,3 +63,15 @@ def test_navigation_delivers_current_option_veto_and_stale_data_does_not_retire_ assert model.navigate(inputs)['motion.command']['speed_mps']==0 assert not model.mission.recovery.active assert model.mission.recovery.sequence==model.mission.recovery.option==0 + + # Normal mission selection also receives a bound planner abort immediately, + # without entering the recovery state or changing the task destination. + selected, _ = model.mission.update(p, 1., lambda *_: [2.,0.,0.]) + model.goal=selected + planning[0]=dict(status='aborted',goal_xy=selected[:2]) + inputs['source.simulation-time']=1. + model.navigate(inputs) + assert model.mission.goal is None + assert model.mission.failed_goals == [selected] + assert model.mission.anchor_time == 1. and model.mission.attempts == 0 + assert model.mission.route == [[10,0]] and not model.mission.recovery.active