Skip to content

Commit 2a54cd2

Browse files
sicoyleCasperGN
andauthored
fix: backport some fixes + version bump to release (#952)
* fix: ensure response format passed in aio. Ensure reconnecting rather than breaking. Correctly bubble up workflow name if set Signed-off-by: Casper Nielsen <casper@diagrid.io> * chore: fix f-string Signed-off-by: Casper Nielsen <casper@diagrid.io> * chore: add todo string Signed-off-by: Casper Nielsen <casper@diagrid.io> * fix: address conflicts Signed-off-by: Samantha Coyle <sam@diagrid.io> * chore(test): increase coverage Signed-off-by: Casper Nielsen <casper@diagrid.io> * chore(format): ruff Signed-off-by: Casper Nielsen <casper@diagrid.io> * fix: bump versions everywhere for new release Signed-off-by: Samantha Coyle <sam@diagrid.io> --------- Signed-off-by: Casper Nielsen <casper@diagrid.io> Signed-off-by: Samantha Coyle <sam@diagrid.io> Co-authored-by: Casper Nielsen <casper@diagrid.io>
1 parent 7cafe86 commit 2a54cd2

19 files changed

Lines changed: 382 additions & 32 deletions

File tree

dapr/aio/clients/grpc/client.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@
2525

2626
import grpc.aio # type: ignore
2727
from google.protobuf.any_pb2 import Any as GrpcAny
28+
from google.protobuf.duration_pb2 import Duration as GrpcDuration
2829
from google.protobuf.empty_pb2 import Empty as GrpcEmpty
2930
from google.protobuf.message import Message as GrpcMessage
31+
from google.protobuf.struct_pb2 import Struct as GrpcStruct
3032
from grpc import StatusCode # type: ignore
3133
from grpc.aio import ( # type: ignore
3234
AioRpcError,
@@ -1883,6 +1885,8 @@ async def converse_alpha2(
18831885
temperature: Optional[float] = None,
18841886
tools: Optional[List[conversation.ConversationTools]] = None,
18851887
tool_choice: Optional[str] = None,
1888+
response_format: Optional[GrpcStruct] = None,
1889+
prompt_cache_retention: Optional[GrpcDuration] = None,
18861890
) -> conversation.ConversationResponseAlpha2:
18871891
"""Invoke an LLM using the conversation API (Alpha2) with tool calling support.
18881892
@@ -1896,6 +1900,8 @@ async def converse_alpha2(
18961900
temperature: Optional temperature setting for the LLM to optimize for creativity or predictability
18971901
tools: Optional list of tools available for the LLM to call
18981902
tool_choice: Optional control over which tools can be called ('none', 'auto', 'required', or specific tool name)
1903+
response_format: Optional response format (google.protobuf.struct_pb2.Struct, ex: json_schema for structured output)
1904+
prompt_cache_retention: Optional retention for prompt cache (google.protobuf.duration_pb2.Duration)
18991905
19001906
Returns:
19011907
ConversationResponseAlpha2 containing the conversation results with choices and tool calls
@@ -1951,6 +1957,10 @@ async def converse_alpha2(
19511957
request.temperature = temperature
19521958
if tool_choice is not None:
19531959
request.tool_choice = tool_choice
1960+
if response_format is not None and hasattr(request, 'response_format'):
1961+
request.response_format.CopyFrom(response_format)
1962+
if prompt_cache_retention is not None and hasattr(request, 'prompt_cache_retention'):
1963+
request.prompt_cache_retention.CopyFrom(prompt_cache_retention)
19541964

19551965
try:
19561966
response, call = await self.retry_policy.run_rpc_async(

dapr/clients/grpc/client.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,16 @@ def stream_messages(sub):
640640
break
641641
except StreamCancelledError:
642642
break
643+
except Exception:
644+
# Stream died — reconnect via the subscription's own
645+
# reconnect logic (which waits for the sidecar to be healthy).
646+
try:
647+
sub.reconnect_stream()
648+
except Exception:
649+
# Sidecar still unavailable — back off before retrying
650+
# TODO: Make this configurable
651+
time.sleep(5)
652+
continue
643653

644654
def close_subscription():
645655
subscription.close()

dapr/clients/grpc/subscription.py

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import logging
12
import queue
23
import threading
34
from typing import Optional
@@ -13,6 +14,8 @@
1314
)
1415
from dapr.proto import api_v1, appcallback_v1
1516

17+
logger = logging.getLogger(__name__)
18+
1619

1720
class Subscription:
1821
def __init__(self, stub, pubsub_name, topic, metadata=None, dead_letter_topic=None):
@@ -67,7 +70,7 @@ def outgoing_request_iterator():
6770
def reconnect_stream(self):
6871
self.close()
6972
DaprHealth.wait_for_sidecar()
70-
print('Attempting to reconnect...')
73+
logger.info('Subscription stream reconnecting...')
7174
self.start()
7275

7376
def next_message(self):
@@ -84,10 +87,17 @@ def next_message(self):
8487
message = next(self._stream)
8588
return SubscriptionMessage(message.event_message)
8689
except RpcError as e:
87-
# If Dapr can't be reached, wait until it's ready and reconnect the stream
88-
if e.code() == StatusCode.UNAVAILABLE or e.code() == StatusCode.UNKNOWN:
89-
print(
90-
f'gRPC error while reading from stream: {e.details()}, Status Code: {e.code()}'
90+
# If Dapr can't be reached, wait until it's ready and reconnect the stream.
91+
# INTERNAL covers RST_STREAM from cloud proxies (e.g. Diagrid Cloud).
92+
if e.code() in (
93+
StatusCode.UNAVAILABLE,
94+
StatusCode.UNKNOWN,
95+
StatusCode.INTERNAL,
96+
):
97+
logger.warning(
98+
'Subscription stream error (%s): %s — reconnecting',
99+
e.code(),
100+
e.details(),
91101
)
92102
self.reconnect_stream()
93103
elif e.code() == StatusCode.CANCELLED:
@@ -111,7 +121,7 @@ def respond(self, message, status):
111121
raise StreamInactiveError('Stream is not active')
112122
self._send_queue.put(msg)
113123
except Exception as e:
114-
print(f"Can't send message on inactive stream: {e}")
124+
logger.warning(f"Can't send message on inactive stream: {e}")
115125

116126
def respond_success(self, message):
117127
self.respond(message, TopicEventResponse('success').status)
@@ -135,15 +145,12 @@ def _is_stream_active(self):
135145
return self._stream_active
136146

137147
def close(self):
148+
self._set_stream_inactive()
138149
if self._stream:
139150
try:
140151
self._stream.cancel()
141-
self._set_stream_inactive()
142-
except RpcError as e:
143-
if e.code() != StatusCode.CANCELLED:
144-
raise Exception(f'Error while closing stream: {e}')
145-
except Exception as e:
146-
raise Exception(f'Error while closing stream: {e}')
152+
except Exception:
153+
pass # Stream already dead — safe to ignore
147154

148155
def __iter__(self):
149156
return self

dapr/version/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
limitations under the License.
1414
"""
1515

16-
__version__ = '1.17.1'
16+
__version__ = '1.17.2'

dev-requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Flask>=1.1
1414
# needed for auto fix
1515
ruff===0.14.1
1616
# needed for dapr-ext-workflow
17-
durabletask-dapr >= 0.17.1
17+
durabletask-dapr >= 0.17.2
1818
# needed for .env file loading in examples
1919
python-dotenv>=1.0.0
2020
# needed for enhanced schema generation from function features

ext/dapr-ext-fastapi/dapr/ext/fastapi/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
limitations under the License.
1414
"""
1515

16-
__version__ = '1.17.1'
16+
__version__ = '1.17.2'

ext/dapr-ext-fastapi/setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ python_requires = >=3.10
2525
packages = find_namespace:
2626
include_package_data = True
2727
install_requires =
28-
dapr >= 1.17.1
28+
dapr >= 1.17.2
2929
uvicorn >= 0.11.6
3030
fastapi >= 0.60.1
3131

ext/dapr-ext-grpc/dapr/ext/grpc/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
limitations under the License.
1414
"""
1515

16-
__version__ = '1.17.1'
16+
__version__ = '1.17.2'

ext/dapr-ext-grpc/setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ python_requires = >=3.10
2424
packages = find_namespace:
2525
include_package_data = True
2626
install_requires =
27-
dapr >= 1.17.1
27+
dapr >= 1.17.2
2828
cloudevents >= 1.0.0
2929

3030
[options.packages.find]

ext/dapr-ext-langgraph/dapr/ext/langgraph/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
limitations under the License.
1414
"""
1515

16-
__version__ = '1.17.1'
16+
__version__ = '1.17.2'

0 commit comments

Comments
 (0)