Skip to content

Fix llm logs --data-ids using response id for conversation id#1464

Open
alvinttang wants to merge 1 commit into
simonw:mainfrom
alvinttang:fix/data-ids-uses-response-id-for-conversation-key
Open

Fix llm logs --data-ids using response id for conversation id#1464
alvinttang wants to merge 1 commit into
simonw:mainfrom
alvinttang:fix/data-ids-uses-response-id-for-conversation-key

Conversation

@alvinttang
Copy link
Copy Markdown

Summary

llm logs --data-ids populates both response_id and conversation_id in the emitted JSON items with the response ULID. The conversation reference the flag exists to provide — and that #800 explicitly documented as the use case ("a --data-ids option which includes the response and conversation IDs") — is silently lost, so the join back to the responses table doesn't work.

Root cause

llm/cli.py around line 1916 (block introduced by commit eafe141):

item[find_unused_key(item, "response_id")] = row["id"]
item[find_unused_key(item, "conversation_id")] = row["id"]   # should be row["conversation_id"]

The selecting SQL (responses.conversation_id, around line 1509) already exposes the right column on row. The second assignment just reads the wrong field. The existing test_logs_schema_data_ids only checked key presence (not values), so this was invisible to CI.

Fix

3-LOC change in llm/cli.py: row["id"]row["conversation_id"] in the conversation key assignment. No schema or query change needed.

Tests

New test_logs_schema_data_ids_values in tests/test_llm_logs.py (29 LOC). Asserts:

  • response_id != conversation_id
  • conversation_id == "abc123" (the fixture value)

RED proof on main:

AssertionError: assert '01ksyc5rw9q269e07pqk8synfg' != '01ksyc5rw9q269e07pqk8synfg'

GREEN after patch: 755 passed in tests/ (network-required tests skipped). ruff check + black --check clean.

Risk notes

  • row["conversation_id"] can be NULL if a response was logged without a conversation. JSON will then emit null — same behaviour as any other null cell in logs output; not a new regression.
  • 3-LOC merge surface, no schema change.

Refs #800

`llm logs --data-ids` was added in simonw#800 so callers could join the
JSON output back against the responses table. It populates a
`response_id` key with `row["id"]` and a `conversation_id` key, but
both assignments read `row["id"]`, so every emitted item carries the
response ULID under both keys and the conversation reference is lost.

The existing regression test (`test_logs_schema_data_ids`) only
asserted that the keys exist, not their values, which is why this
slipped in.

Patch reads `row["conversation_id"]` for the conversation key. The
SQL in `logs_list` already selects `responses.conversation_id`, so no
schema or query change is needed.

Added `test_logs_schema_data_ids_values` that asserts the two ids
differ and that the conversation id matches the fixture value
("abc123"). It fails on main and passes with the fix.

Refs simonw#800
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant