@@ -25,7 +25,7 @@ def _scheduler_packet(
2525 before : dict [str , Any ],
2626 * ,
2727 surface : str ,
28- state_key : str ,
28+ state_key : str | None ,
2929) -> tuple [dict [str , Any ], dict [str , Any ], dict [str , Any ]]:
3030 scheduler_hint = (
3131 before .get ("scheduler_hint" )
@@ -36,7 +36,10 @@ def _scheduler_packet(
3636 packet_key = "app_automation"
3737 elif (
3838 surface == CODEX_APP_SURFACE
39- and state_key == APP_AUTOMATION_STATEFUL_BACKOFF_STATE_KEY
39+ and (
40+ state_key == APP_AUTOMATION_STATEFUL_BACKOFF_STATE_KEY
41+ or (state_key is None and isinstance (scheduler_hint .get ("app_automation" ), dict ))
42+ )
4043 ):
4144 packet_key = "app_automation"
4245 else :
@@ -54,6 +57,15 @@ def _scheduler_packet(
5457 return scheduler_hint , surface_packet , stateful_backoff
5558
5659
60+ def _followup_state_key (
61+ before : dict [str , Any ], * , surface : str , state_key : str | None ,
62+ ) -> str :
63+ if state_key is not None :
64+ return state_key
65+ _ , _ , backoff = _scheduler_packet (before , surface = surface , state_key = None )
66+ return str (backoff .get ("state_key" ) or CODEX_APP_STATEFUL_BACKOFF_STATE_KEY )
67+
68+
5769def _current_hint_identity (
5870 before : dict [str , Any ],
5971 * ,
@@ -277,7 +289,7 @@ def record_quota_scheduler_ack_for_decision(
277289 agent_id : str | None ,
278290 execute : bool = False ,
279291 surface : str = CODEX_APP_SURFACE ,
280- state_key : str = CODEX_APP_STATEFUL_BACKOFF_STATE_KEY ,
292+ state_key : str | None = None ,
281293 applied_rrule : str | None = None ,
282294 reset_token : str | None = None ,
283295 identity_signature : str | None = None ,
@@ -286,6 +298,7 @@ def record_quota_scheduler_ack_for_decision(
286298 use_current_hint : bool = False ,
287299 host_match_observed : bool = False ,
288300) -> dict [str , Any ]:
301+ state_key = _followup_state_key (before , surface = surface , state_key = state_key )
289302 safe_agent_id = normalize_todo_claimed_by (agent_id )
290303 if host_match_observed and (
291304 not str (applied_rrule or "" ).strip ()
@@ -374,12 +387,13 @@ def record_quota_scheduler_failure_for_decision(
374387 agent_id : str | None ,
375388 execute : bool = False ,
376389 surface : str = CODEX_APP_SURFACE ,
377- state_key : str = CODEX_APP_STATEFUL_BACKOFF_STATE_KEY ,
390+ state_key : str | None = None ,
378391 failed_rrule : str | None = None ,
379392 observed_host_rrule : str | None = None ,
380393 failure_kind : str = "host_tool_failure" ,
381394 generated_at : str | None = None ,
382395) -> dict [str , Any ]:
396+ state_key = _followup_state_key (before , surface = surface , state_key = state_key )
383397 safe_agent_id = normalize_todo_claimed_by (agent_id )
384398 target_rrule = normalize_scheduler_rrule (failed_rrule )
385399 try :
0 commit comments