Rifqi Hafizuddin Claude Fable 5 commited on
Commit
4253733
·
1 Parent(s): 4ceb058

[NOTICKET] refactor: mint message_id as UUID to mirror analyses_messages id shape

Browse files

Change the Python-minted assistant turn id from msg_<12hex> to a canonical
UUID string (str(uuid.uuid4())) in both mint sites (v2 chat + help), so the
value is format-compatible with Go's analyses_messages.id (UUID). Still
Python-minted and independent; only the shape now matches. No schema change
(message_traceability.message_id stays String). Stale msg_<12hex> comments
in models.py updated.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

src/api/v1/help.py CHANGED
@@ -51,8 +51,9 @@ async def help_stream(request: HelpRequest, db: AsyncSession = Depends(get_db)):
51
  2. chunk — text fragments of the guidance
52
  3. done — `{"message_id": "..."}` for the observability lookup
53
  """
54
- # Server-authoritative turn id — never accepted from the caller (keys /observability).
55
- message_id = f"msg_{uuid.uuid4().hex[:12]}"
 
56
  try:
57
  history = await load_history(db, request.analysis_id, limit=10)
58
 
 
51
  2. chunk — text fragments of the guidance
52
  3. done — `{"message_id": "..."}` for the observability lookup
53
  """
54
+ # Server-authoritative turn id — never accepted from the caller (keys traceability).
55
+ # Canonical UUID string, matching Go's `analyses_messages.id` shape (mirrors v2 chat).
56
+ message_id = str(uuid.uuid4())
57
  try:
58
  history = await load_history(db, request.analysis_id, limit=10)
59
 
src/api/v2/chat.py CHANGED
@@ -70,8 +70,11 @@ async def _save_empty_chat_trace(analysis_id: str, user_id: str, message_id: str
70
 
71
  def _mint_message_id() -> str:
72
  """Mint the assistant turn id. Server-authoritative — never accepted from the caller
73
- (it keys the future /observability lookup). Returned on `done`; open-Q #1 resolved."""
74
- return f"msg_{uuid.uuid4().hex[:12]}"
 
 
 
75
 
76
 
77
  class ChatRequest(BaseModel):
 
70
 
71
  def _mint_message_id() -> str:
72
  """Mint the assistant turn id. Server-authoritative — never accepted from the caller
73
+ (it keys the GET /api/v1/traceability lookup). Returned on `done`; open-Q #1 resolved.
74
+
75
+ A canonical UUID string, matching Go's `analyses_messages.id` shape, so the value stays
76
+ format-compatible if we later swap to the real message-row id (still Python-minted now)."""
77
+ return str(uuid.uuid4())
78
 
79
 
80
  class ChatRequest(BaseModel):
src/db/postgres/models.py CHANGED
@@ -265,7 +265,7 @@ class MessageTraceabilityRow(Base):
265
  (src\\traceability\\schemas.py:TraceabilityPayload) serialized via
266
  `model_dump(mode="json", by_alias=True)`; the read path rehydrates with
267
  `TraceabilityPayload.model_validate(...)`. One row per assistant `message_id`
268
- (the Python-minted turn id "msg_<12hex>"), written before the `done` SSE event
269
  and served by `GET /api/v1/traceability`.
270
 
271
  OWNERSHIP / HANDOFF (KM-691): **Python-owned for now**, the same pattern as
@@ -278,7 +278,7 @@ class MessageTraceabilityRow(Base):
278
  """
279
  __tablename__ = "message_traceability"
280
 
281
- message_id = Column(String, primary_key=True) # Python-minted turn id ("msg_<12hex>")
282
  analysis_id = Column(UUID(as_uuid=False), nullable=False, index=True) # analysis session id
283
  user_id = Column(String, nullable=False)
284
  intent = Column(String, nullable=False)
 
265
  (src\\traceability\\schemas.py:TraceabilityPayload) serialized via
266
  `model_dump(mode="json", by_alias=True)`; the read path rehydrates with
267
  `TraceabilityPayload.model_validate(...)`. One row per assistant `message_id`
268
+ (the Python-minted turn id, a UUID string), written before the `done` SSE event
269
  and served by `GET /api/v1/traceability`.
270
 
271
  OWNERSHIP / HANDOFF (KM-691): **Python-owned for now**, the same pattern as
 
278
  """
279
  __tablename__ = "message_traceability"
280
 
281
+ message_id = Column(String, primary_key=True) # Python-minted turn id (UUID string)
282
  analysis_id = Column(UUID(as_uuid=False), nullable=False, index=True) # analysis session id
283
  user_id = Column(String, nullable=False)
284
  intent = Column(String, nullable=False)