@@ -408,6 +408,8 @@ def __init__(self):
408408 self .tokens = {} # token -> org_id
409409 self .jobs = [] # queued jobs (each {id, org_id, payload, status, leased_by})
410410 self .callbacks = []
411+ self .callback_attempts = 0
412+ self .callback_status = 200
411413 self .acks = []
412414 self ._n = 0
413415
@@ -458,6 +460,9 @@ def handler(self, request: httpx.Request) -> httpx.Response:
458460 return httpx .Response (200 , json = {"ok" : True })
459461
460462 if path == "/api/internal/run-callback" :
463+ self .callback_attempts += 1
464+ if self .callback_status != 200 :
465+ return httpx .Response (self .callback_status , json = {"ok" : False })
461466 self .callbacks .append ({"headers" : dict (request .headers ), "body" : body })
462467 return httpx .Response (200 , json = {"ok" : True })
463468
@@ -520,6 +525,41 @@ def test_full_loop_dispatch_execute_callback_ack():
520525 assert cp .acks [0 ]["status" ] == "done"
521526
522527
528+ @pytest .mark .parametrize ("callback_status" , [400 , 503 ])
529+ def test_callback_rejection_is_retried_but_never_acked (callback_status , monkeypatch ):
530+ monkeypatch .setattr ("openadapt_flow.connector.daemon.time.sleep" , lambda _ : None )
531+ cp = StubControlPlane ()
532+ cp .callback_status = callback_status
533+ cp .enqueue ("org_demo" , _payload ())
534+ transport = httpx .MockTransport (cp .handler )
535+ client = ConnectorClient ("https://app.test" , transport = transport )
536+ client .enroll (enrollment_secret = "s" , org_id = "org_demo" , name = "n" )
537+ settings = ConnectorSettings (
538+ control_plane_url = "https://app.test" ,
539+ org_id = "org_demo" ,
540+ token = client .token ,
541+ poll_wait_s = 0 ,
542+ )
543+
544+ result = run_once (
545+ client ,
546+ settings ,
547+ runner = _fake_success_runner (SUCCESS_REPORT ),
548+ storage_factory = lambda job : InMemoryCustomerStorage (bundle_bytes = _BUNDLE_BYTES ),
549+ )
550+
551+ assert result == {
552+ "job_id" : "bjob_1" ,
553+ "run_id" : _payload ()["run_id" ],
554+ "status" : "success" ,
555+ "callback_accepted" : False ,
556+ }
557+ assert cp .callback_attempts == 3
558+ assert cp .callbacks == []
559+ assert cp .acks == []
560+ assert cp .jobs [0 ]["status" ] == "leased"
561+
562+
523563def test_cross_org_isolation_connector_never_sees_another_orgs_job ():
524564 cp = StubControlPlane ()
525565 cp .enqueue ("org_B" , _payload (org_id = "org_B" )) # a DIFFERENT org's job
0 commit comments