-
Notifications
You must be signed in to change notification settings - Fork 1
fix: roll back unauthorized Global Ask turns (v2.20.3) #374
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
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 |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| ### Fixed | ||
|
|
||
| - Roll back a Global Ask turn and its citations when final authorization fails, | ||
| so a rejected answer cannot poison the existing session. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -179,6 +179,7 @@ | |
| load_global_ask_context, | ||
| persist_global_ask_summary, | ||
| persist_global_ask_turn, | ||
| persist_global_ask_turn_in_transaction, | ||
| persist_post_chat, | ||
| ) | ||
| from backend.app.post_summary_ingestion import ( | ||
|
|
@@ -2787,25 +2788,26 @@ async def chat_about_post( | |
| ) from exc | ||
| cited_ids = list(answer.cited_post_ids) | ||
| async with pool.acquire() as conn: | ||
| await persist_post_chat( | ||
| conn, | ||
| post_id, | ||
| question, | ||
| answer.answer_text, | ||
| cited_ids, | ||
| knowledge_cutoff=knowledge_cutoff, | ||
| ) | ||
| answer_evidence = await read_authorized_ask_evidence( | ||
| conn, | ||
| cited_post_ids=cited_ids, | ||
| corporate_entity_ids=account.corporate_entity_ids, | ||
| knowledge_cutoff=knowledge_cutoff, | ||
| ) | ||
| if not answer_evidence.all_citations_visible: | ||
| raise HTTPException( | ||
| status.HTTP_503_SERVICE_UNAVAILABLE, | ||
| "Post chat evidence changed before the answer could be returned", | ||
| ) | ||
| async with conn.transaction(): | ||
| await persist_post_chat( | ||
| conn, | ||
| post_id, | ||
| question, | ||
| answer.answer_text, | ||
| cited_ids, | ||
| knowledge_cutoff=knowledge_cutoff, | ||
| ) | ||
| answer_evidence = await read_authorized_ask_evidence( | ||
| conn, | ||
| cited_post_ids=cited_ids, | ||
| corporate_entity_ids=account.corporate_entity_ids, | ||
| knowledge_cutoff=knowledge_cutoff, | ||
| ) | ||
| if not answer_evidence.all_citations_visible: | ||
| raise HTTPException( | ||
| status.HTTP_503_SERVICE_UNAVAILABLE, | ||
| "Post chat evidence changed before the answer could be returned", | ||
| ) | ||
| await publish_activity_event( | ||
| valkey, | ||
| post_id, | ||
|
|
@@ -2946,24 +2948,25 @@ async def ask_agent( | |
| ) from exc | ||
| cited_ids = list(answer.cited_post_ids) | ||
| async with pool.acquire() as conn: | ||
| await persist_global_ask_turn( | ||
| conn, | ||
| conversation.session_id, | ||
| question, | ||
| answer.answer_text, | ||
| cited_ids, | ||
| ) | ||
| answer_evidence = await read_authorized_ask_evidence( | ||
| conn, | ||
| cited_post_ids=cited_ids, | ||
| corporate_entity_ids=account.corporate_entity_ids, | ||
| knowledge_cutoff=knowledge_cutoff, | ||
| ) | ||
| if not answer_evidence.all_citations_visible: | ||
| raise HTTPException( | ||
| status.HTTP_503_SERVICE_UNAVAILABLE, | ||
| "Global Ask evidence changed before the answer could be returned", | ||
| ) | ||
| async with conn.transaction(): | ||
| await persist_global_ask_turn_in_transaction( | ||
| conn, | ||
| conversation.session_id, | ||
| question, | ||
| answer.answer_text, | ||
| cited_ids, | ||
| ) | ||
| answer_evidence = await read_authorized_ask_evidence( | ||
| conn, | ||
| cited_post_ids=cited_ids, | ||
| corporate_entity_ids=account.corporate_entity_ids, | ||
| knowledge_cutoff=knowledge_cutoff, | ||
| ) | ||
|
Comment on lines
+2959
to
+2964
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. 📝 Info: Reauthorization read now runs inside the write transaction The final Was this helpful? React with 👍 or 👎 to provide feedback. |
||
| if not answer_evidence.all_citations_visible: | ||
| raise HTTPException( | ||
| status.HTTP_503_SERVICE_UNAVAILABLE, | ||
| "Global Ask evidence changed before the answer could be returned", | ||
| ) | ||
| await publish_operation_event( | ||
| valkey, | ||
| account.user_account_id, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.