[codex] Add structured MCP run logging - #90
Conversation
|
Live validation against the local game install passed after closing and relaunching Slay the Spire 2. Checked:
No follow-up code changes were needed from this test pass. |
|
Token accounting implementation and validation added in Validated locally:
The fixture summary verified total-token consistency, external usage rollups, hidden polling cost, repeated-state cost, replay artifact token metadata, and redaction of sensitive |
|
Prompt/turn accounting implementation and validation added in Validated locally:
The fixture verified total prompts, total turns, model/tool message counts, agent decision message count, by-turn message linkage, external usage reconciliation by message id, exact-vs-estimated token source rollups, hidden polling cost, repeated-state cost, and prompt privacy behavior ( |
Summary
tool_call_idlog_agent_decision(...)for explicit agent decision annotations before important choicesget_game_stateandmp_get_game_statesmart-poll by default through enemy turns and other transient non-actionable states, with opt-out and timeout controlsResearch-grade detail in this slice
Each JSONL row includes
schema_version,run_id,sequence, UTCtimestamp,monotonic_ms,event_type, and relevant tool identifiers. Tool and HTTP result payloads include character length, byte length, SHA-256 hash, bounded preview text, and truncation status. This gives downstream analysis a stable ordering key, wall-clock time, relative timing, integrity checks, and enough payload detail for lightweight review without requiring full response retention by default.The logger records
session_start,tool_call_start,tool_call_result,tool_call_error,http_request,http_response,http_error,state_poll,state_poll_final_format, andagent_decision. Sensitive keys containingauthorization,cookie,password,secret,token,api_key, orapikeyare redacted recursively before writes.Validation
python3 -m py_compile mcp/server.py mcp/run_logger.pyuv run --directory mcp python server.py --helplog_agent_decision, and combat actionability predicatesgit diff --checkFixes #10
Token accounting update
input_tokens,output_tokens,tool_response_tokens,hidden_poll_tokens,total_tokens,token_source,tokenizer_name,tokenizer_version,model_family, andestimation_methodrun_<id>.summary.jsonwith rollups by tool, event type, state type, game mode, action category, run phase, and floor where availablelog_external_token_usage(usage_json)so clients can attach exact provider/model token usage byrelated_tool_call_id,related_event_id, or another stable idmcp/validate_run_log.pyfor JSONL, monotonic sequence, token rollup, summary consistency, and deterministic fixture validationPrompt and turn accounting update
model_messagerecords throughlog_model_message(...)with stablemessage_id,turn_id,turn_index, role/source, content hash/preview metadata, privacy flags, state hash links, related tool/event links, and optional exact token usagerelated_message_idas well as existing tool/event ids