-
Notifications
You must be signed in to change notification settings - Fork 46.2k
Feat/webhook session key #57972
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Feat/webhook session key #57972
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -665,7 +665,13 @@ async def _handle_webhook(self, request: "web.Request") -> "web.Response": | |
|
|
||
| # Use delivery_id in session key so concurrent webhooks on the | ||
| # same route get independent agent runs (not queued/interrupted). | ||
| session_chat_id = f"webhook:{route_name}:{delivery_id}" | ||
| session_key = "" | ||
| session_key_tpl = route_config.get("session_key", "") | ||
| if session_key_tpl: | ||
| session_key = self._render_prompt(session_key_tpl, payload, event_type, route_name).strip() | ||
| if "{" in session_key: | ||
| session_key = "" | ||
| session_chat_id = f"webhook:{route_name}:{session_key or delivery_id}" | ||
|
|
||
| # Store delivery info for send(). Read by every send() invocation | ||
| # for this chat_id (interim status messages and the final response), | ||
|
|
@@ -749,6 +755,9 @@ async def on_processing_complete( | |
| ``end_session()`` is first-reason-wins and no-ops on an already-ended | ||
| row, so this never clobbers a ``compression``/``agent_close`` reason. | ||
| """ | ||
| route_name = (event.source.user_id or "").removeprefix("webhook:") | ||
| if self._routes.get(route_name, {}).get("session_key"): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This checks only whether the route declares |
||
| return | ||
| await self._end_webhook_session(event, event.source.chat_id) | ||
|
|
||
| async def _end_webhook_session( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With a stable value this becomes the shared key for
_delivery_infobelow.send()resolvesdeliver_extraonly by chat ID, so a second same-key POST can overwrite the first delivery's response destination while the first run is active/queued. Keep response-routing state per delivery rather than using the conversation key for both roles.