-
Notifications
You must be signed in to change notification settings - Fork 162
fix(email): make --trace write a real trace on the daemon-relay path - #3346
Draft
github-actions[bot] wants to merge 1 commit into
Draft
fix(email): make --trace write a real trace on the daemon-relay path #3346github-actions[bot] wants to merge 1 commit into
github-actions[bot] wants to merge 1 commit into
Conversation
gaia email --trace was parsed and dropped: the query path relays through the daemon, and run_query() had no trace parameter, so the flag silently behaved like omitting it. The relay path has no in-process agent to introspect, so the canonical SSE stream is the trace — run_query now records the request plus every status/token/tool_call/tool_result/final event to ./<agent>_trace_<timestamp>_<run_id>.json, echoes the path on stderr, and returns it as QueryOutcome.trace_path. Interrupted runs and streams that die without a terminal event still write what they saw, which is when a trace is worth most. Closes #3345
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
gaia email --tracewas advertised in--helpbut did nothing — the flag was parsed and then dropped, so you got no trace file, no warning, and no way to capture what the email agent actually did during a run. It now writes a JSON trace of the run into the current directory (email_trace_<timestamp>_<run-id>.json) and prints the path, so anyone benchmarking or debugging the email agent can see the full request, every tool call and result, and the final answer.Closes #3345
Test plan
python -m pytest tests/unit/test_agent_query.py tests/unit/test_email_cli.py -qpassespython util/lint.py --allpassesgaia email --trace -q 'summarize my unread emails'prints📝 trace written to ...and the named file contains the tool calls the run madegaia email -q 'summarize my unread emails'(no--trace) leaves no JSON file behindgaia email --trace -iwrites one trace file per turn🔍 Technical details
Root cause:
gaia email -qrelays through the daemon viagaia.daemon.agent_query.run_query()(src/gaia/cli.py:4633), whose signature had notraceparameter.args.tracecame from the sharedparent_parser, was never read onthis path, and never reached the request.
What changed:
src/gaia/daemon/agent_query.py—run_query(..., trace=False). There is noin-process agent to introspect on the relay path, so the canonical SSE stream is the
trace:
_consume()takes an optional sink and_write_trace()dumps{agent_id, run_id, recorded_at, request, terminal_type, final_answer, error_detail, events}to
./<agent>_trace_<timestamp>_<run_id>.json.run_idis in the filename so two REPLturns in the same second can't collide. The path is echoed on stderr
(
ConsoleRenderer.on_trace_written) and returned asQueryOutcome.trace_path.terminal event (the CLI-synthesized
errorframe is recorded alongside the realevents). A trace is most useful exactly when the run broke.
DaemonErrornaming the path andthe fix rather than skipping the file.
src/gaia/cli.py—handle_email_commandreadsargs.traceand passes it torun_query;_email_interactivetakestraceand writes one file per turn.--tracerow added to the email options tables indocs/reference/cli.mdxanddocs/guides/email.mdx, with a note that a trace contains real email content.Verified: 4 new tests in
tests/unit/test_agent_query.py(file written with the fullevent stream, nothing written without the flag, partial capture when the stream has no
terminal event) and 1 in
tests/unit/test_email_cli.py(the flag reachesrun_query);37 tests across the email/agent-query suites pass. Also exercised
run_query(trace=True)against a stubbed relay to confirm the file contents. Black + isort clean; pylint's 2
remaining errors are pre-existing and unrelated (
PIL.Image.LANCZOS, atry-except-raisein the UI router).
Only
gaia emailusesrun_querytoday, so no other CLI surface changes behavior.