Handle reused Codex approval request IDs
Treat app-server request IDs as connection-local by reopening reused approval rows when the thread, turn, or item context changes. Keep duplicate resolved approvals in the same context closed, and add focused approval-path diagnostics without changing the Telegram approval UI.
This commit is contained in:
@@ -496,9 +496,41 @@ INSERT INTO pending_approvals (
|
||||
message_chat_id, message_id, status
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, 'pending')
|
||||
ON CONFLICT(telegram_user_id, codex_request_id) DO UPDATE SET
|
||||
codex_thread_id = excluded.codex_thread_id,
|
||||
turn_id = excluded.turn_id,
|
||||
item_id = excluded.item_id,
|
||||
kind = excluded.kind,
|
||||
payload_json = excluded.payload_json,
|
||||
message_chat_id = CASE WHEN pending_approvals.status = 'pending' THEN excluded.message_chat_id ELSE pending_approvals.message_chat_id END,
|
||||
message_id = CASE WHEN pending_approvals.status = 'pending' THEN excluded.message_id ELSE pending_approvals.message_id END`,
|
||||
message_chat_id = CASE
|
||||
WHEN pending_approvals.codex_thread_id = excluded.codex_thread_id
|
||||
AND pending_approvals.turn_id = excluded.turn_id
|
||||
AND pending_approvals.item_id = excluded.item_id
|
||||
THEN pending_approvals.message_chat_id
|
||||
ELSE excluded.message_chat_id
|
||||
END,
|
||||
message_id = CASE
|
||||
WHEN pending_approvals.codex_thread_id = excluded.codex_thread_id
|
||||
AND pending_approvals.turn_id = excluded.turn_id
|
||||
AND pending_approvals.item_id = excluded.item_id
|
||||
THEN pending_approvals.message_id
|
||||
ELSE excluded.message_id
|
||||
END,
|
||||
status = CASE
|
||||
WHEN pending_approvals.status <> 'pending'
|
||||
AND pending_approvals.codex_thread_id = excluded.codex_thread_id
|
||||
AND pending_approvals.turn_id = excluded.turn_id
|
||||
AND pending_approvals.item_id = excluded.item_id
|
||||
THEN pending_approvals.status
|
||||
ELSE 'pending'
|
||||
END,
|
||||
resolved_at = CASE
|
||||
WHEN pending_approvals.status <> 'pending'
|
||||
AND pending_approvals.codex_thread_id = excluded.codex_thread_id
|
||||
AND pending_approvals.turn_id = excluded.turn_id
|
||||
AND pending_approvals.item_id = excluded.item_id
|
||||
THEN pending_approvals.resolved_at
|
||||
ELSE ''
|
||||
END`,
|
||||
approval.TelegramUserID, approval.CodexRequestID, approval.CodexThreadID, approval.TurnID,
|
||||
approval.ItemID, approval.Kind, approval.PayloadJSON, approval.MessageChatID, approval.MessageID)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user