[OMEGA-310] feat: per-turn reasoning trace (trace_id JSONL) + omegaclaw-trace-summary - #270
[OMEGA-310] feat: per-turn reasoning trace (trace_id JSONL) + omegaclaw-trace-summary#270amiroussama wants to merge 2 commits into
Conversation
c628aa5 to
eae15e7
Compare
…mary Adds an opt-out structured reasoning trace: one JSONL record per loop event, linked by a per-iteration trace_id, so an iteration's LLM call, action parse, policy decision, error, and result are reconstructable end-to-end. Backs the README's "auditable proof trails" claim. - src/tracing.py: contextvars-based current-trace context + typed emitters (begin_session/begin_iteration/trace_llm/.../end_iteration). Best-effort — a trace failure never breaks the loop. Metadata-only by default; full bodies only under OMEGACLAW_TRACE_BODIES. Disable with OMEGACLAW_TRACE_DISABLE; path via OMEGACLAW_TRACE_PATH (default memory/traces/YYYYMMDD.jsonl). - scripts/omegaclaw-trace-summary: aggregates a trace file (per-iteration LLM latency, parse ok/err, policy denials). - Wiring: lib_omegaclaw.metta import; src/loop.metta begin_session/ begin_iteration/end_iteration; src/plugin.py::llmProviderChat emits trace_llm. - Autotests/test_tracing.py (no Docker/LLM/MeTTa) + run_mandatory. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
eae15e7 to
4659544
Compare
timur-ashkenov
left a comment
There was a problem hiding this comment.
@amiroussama
There are several critical issues that need to be fixed, i mentioned below. After that, please rebase on actual main and implement your changes, because there are some conflicts there, especially in loop.metta.
| (RESULTS: $mcerr))) | ||
| ($_ (log INFO "loop" (RESPONSE: $results)))) | ||
| ($_ (log INFO "loop" (RESPONSE: $results))) | ||
| ($_ (py-call (tracing.end_iteration (repr $results))))) |
There was a problem hiding this comment.
Currently, the runtime wiring only calls begin_session, begin_iteration, trace_llm, and end_iteration. The trace_parse, trace_policy, and trace_error functions are defined but never invoked from the actual parsing, policy, or error-handling pipeline. As a result, the produced JSONL cannot reconstruct the advertised LLM -> parse -> policy -> result flow, and omegaclaw-trace-summary will not report zero parse errors and policy denials.
| return c | ||
|
|
||
|
|
||
| def _body(text): |
There was a problem hiding this comment.
When OMEGACLAW_TRACE_BODIES=1 or OMEGACLAW_DEBUG_LLM_RAW=1 is enabled, this function returns the original prompt/response in full. Tokens, API keys, and user data can therefore end up in the trace. This contradicts the PR description’s claim that trace bodies are redacted.
The branch references src/redaction.py from #266, but #266 was closed without being merged, and this file is not included in the current PR. Please either include src/redaction.py in this PR and apply redact_secrets(text) here, or avoid writing bodies to the trace entirely.
| mock/test_transition_metta_to_remember_mock.py | ||
| mock/test_transition_pin_to_remember_mock.py | ||
| mock_websocket/test_wschat_unit.py | ||
| test_tracing.py |
There was a problem hiding this comment.
Unit test location: Autotests/unit/.
Move it there please.
…unit test Addresses PR singnet#270 review (timur-ashkenov): - Secrets no longer leak into trace bodies. Add self-contained src/redaction.py and scrub every body through redact_secrets() in tracing._body(), so enabling OMEGACLAW_TRACE_BODIES / OMEGACLAW_DEBUG_LLM_RAW cannot write tokens/API keys/ Authorization headers to the JSONL. (singnet#266's redaction.py was closed unmerged, so it is included here.) - The advertised LLM -> parse -> policy -> result flow is now actually emitted: * trace_parse — wired in helper.balance_parentheses (the loop's Python parse step); emits tools + unknown-command error_codes, enabling full linkage. * trace_policy — wired in profile/policy.py (apply_security_policy startup and the per-iteration get-io-policy query). * trace_error — wired in src/loop.metta HandleError (the sole error site). emit() is now fully defensive so a trace call can never break the MeTTa loop. - Move Autotests/test_tracing.py -> Autotests/unit/ (per project convention) and update Autotests/run_mandatory. Body test now asserts redaction; add parse-wiring coverage. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Thanks @timur-ashkenov, all three addressed in fc4553b:
On the rebase: heads-up that it's more than a conflict fix — main has since reimplemented this area (parse now goes through |
- Move test to Autotests/unit/ and fix run_mandatory path (matches repo convention); adjust _REPO_ROOT depth for the new location. - Make the src.tracing dependency explicit in docstrings: ingest_trace reads the JSONL emitted by src.tracing (PR singnet#270); this PR is stacked on it. - Clarify the recording API is the loop's integration surface (live wiring is a follow-up). - Add docs/reference-session-store.md and link it from docs/README.md. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Description
Fixes #269. Adds an opt-out structured reasoning trace: one JSONL record per loop event, linked by a per-iteration
trace_id, so an iteration's LLM call, action parse, policy decision, error, and result are reconstructable end-to-end — backing the README's "auditable proof trails" claim.src/tracing.py—contextvars-based current-trace context + typed emitters (begin_session/begin_iteration/trace_llm/trace_parse/trace_policy/trace_error/end_iteration). Best-effort: a trace failure never breaks the loop. Metadata-only by default; redacted bodies only underOMEGACLAW_TRACE_BODIES; disable viaOMEGACLAW_TRACE_DISABLE; output path viaOMEGACLAW_TRACE_PATH(defaultmemory/traces/YYYYMMDD.jsonl).scripts/omegaclaw-trace-summary— aggregates a trace file (per-iteration LLM latency, parse ok/err, policy denials).lib_omegaclaw.mettaimport;src/loop.mettabegin_session/begin_iteration/end_iteration;src/plugin.py::llmProviderChatemitstrace_llm.Depends on #266 — shares
src/redaction.py(used to redact trace bodies). It is included in this branch; if #266 merges first the file is identical and drops out on rebase, if this merges first #266 rebases onto it.How Has This Been Tested?
Autotests/test_tracing.py(pure-Python, no Docker/LLM/MeTTa; registered inrun_mandatory) — trace schema +trace_idlinkage across an iteration's events, metadata-only default vs redacted-bodies mode, the disable gate, and the trace-summary aggregator. 6/6 pass:cd Autotests && python3 test_tracing.py.Note: the additive
src/loop.mettaandsrc/plugin.pywiring executes only inside the MeTTa/Docker runtime, so it is exercised by thebuild / commonCI job on this PR rather than on the host.Checklist