[BUG] - promptflow executor raises KeyError in _update_operation_context
Describe the bug When running a promptflow which calls a second promptflow as a function, we occassionally (but not always) get the following error message:
`2024-03-05 10:34:51 +0000 18 execution.flow INFO Node service_caller completes. [2024-03-05 10:34:53,913][pfserving-app][ERROR] - Promptflow serving app error: {'message': "'flow_id'", 'messageFormat': '', 'messageParameters': {}, 'code': 'SystemError', 'innerError': {'code': 'KeyError', 'innerError': None}} [2024-03-05 10:34:53,914][pfserving-app][ERROR] - Promptflow serving error traceback: Traceback (most recent call last): File "/azureml-envs/prompt-flow/runtime/lib/python3.9/site-packages/flask/app.py", line 1484, in full_dispatch_request rv = self.dispatch_request() File "/azureml-envs/prompt-flow/runtime/lib/python3.9/site-packages/flask/app.py", line 1469, in dispatch_request return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args) File "/azureml-envs/prompt-flow/runtime/lib/python3.9/site-packages/promptflow/_sdk/_serving/app.py", line 148, in score flow_result = app.flow_invoker.invoke(data, run_id=run_id, disable_input_output_logging=disable_data_logging) File "/azureml-envs/prompt-flow/runtime/lib/python3.9/site-packages/promptflow/_sdk/_serving/flow_invoker.py", line 175, in invoke result = self._invoke(data, run_id=run_id, disable_input_output_logging=disable_input_output_logging) File "/azureml-envs/prompt-flow/runtime/lib/python3.9/site-packages/promptflow/_sdk/_serving/flow_invoker.py", line 160, in _invoke result = self.executor.exec_line(data, index=0, run_id=run_id, allow_generator_output=self.streaming()) File "/azureml-envs/prompt-flow/runtime/lib/python3.9/site-packages/promptflow/executor/flow_executor.py", line 714, in exec_line line_result = self._exec_with_trace( File "/azureml-envs/prompt-flow/runtime/lib/python3.9/contextlib.py", line 126, in exit next(self.gen) File "/azureml-envs/prompt-flow/runtime/lib/python3.9/site-packages/promptflow/executor/flow_executor.py", line 747, in _update_operation_context operation_context.pop(k) KeyError: 'flow_id'
**How To Reproduce the bug**
Steps to reproduce the behavior, how frequent can you experience the bug:
1. Create a promptflow which invokes a second flows like this
second_flow = promptflow.load_flow(flow_path) second_flow()
2. Invoke the (first) promptflow.
**Expected behavior**
The flow should succeed.
**Running Information(please complete the following information):**
- Promptflow Package Version: 16.0
- Operating System: macos
- Python Version using 3.9.18
**Additional context**
The error only occurs intermittently. We suspect that it might be a concurrency issue in `_update_operation_context`.
The error does not occur with promptflow 14.0.6
Thank you for reporting this bug, we will investigate it and fix it asap.
The fix has been merged, will be released in the next version.
Thanks!