fix(backend/copilot): address PR review - downgrade PII logging and add upload timeout

1. Downgrade content preview logging from WARNING to DEBUG (transcript.py:325-326)
   - Prevents logging up to 500 chars of user conversation content (PII risk)
   - Keep validation failure at WARNING, only preview at DEBUG

2. Add 30s timeout to upload_transcript in finally block (service.py:1557)
   - Prevents session lock from hanging indefinitely if upload stalls
   - Uses asyncio.timeout wrapper around asyncio.shield

Addresses PR review #3903048969 item #2 and discussion r2895449830
This commit is contained in:
Zamil Majdy
2026-03-06 19:16:23 +07:00
parent 042ed42c0b
commit 0eddb6f1bb
2 changed files with 11 additions and 10 deletions

View File

@@ -1554,15 +1554,16 @@ async def stream_chat_completion_sdk(
transcript_builder.entry_count,
len(transcript_content),
)
await asyncio.shield(
upload_transcript(
user_id=user_id,
session_id=session_id,
content=transcript_content,
message_count=len(session.messages),
log_prefix=log_prefix,
async with asyncio.timeout(30):
await asyncio.shield(
upload_transcript(
user_id=user_id,
session_id=session_id,
content=transcript_content,
message_count=len(session.messages),
log_prefix=log_prefix,
)
)
)
except Exception as upload_err:
logger.error(
"%s Transcript upload failed in finally: %s",

View File

@@ -322,8 +322,8 @@ async def upload_transcript(
len(stripped),
len(content),
)
logger.warning("%s Raw content preview: %s", log_prefix, content[:500])
logger.warning("%s Stripped content: %s", log_prefix, stripped[:500])
logger.debug("%s Raw content preview: %s", log_prefix, content[:500])
logger.debug("%s Stripped content: %s", log_prefix, stripped[:500])
return
storage = await get_workspace_storage()