-
Notifications
You must be signed in to change notification settings - Fork 6.6k
feat: Support for logging session request-response pairs as OpenAI messages #7538
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
titu1994
wants to merge
12
commits into
anomalyco:dev
Choose a base branch
from
titu1994:log_messages
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+739
−15
Conversation
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
…rray Updated the TraceLogger to combine system prompts into the messages array with the role "system". Adjusted related tests to verify the new structure and ensure proper functionality.
…onse structure Introduced a new CLI option `--trace-dir` to specify the directory for saving request-response trace logs. Updated the TraceLogger to initialize from this option or the corresponding environment variable. Enhanced the response structure to include additional fields and improved error handling, ensuring comprehensive logging of requests and responses.
…on fields Added modelID and duration fields to the TraceLogger for improved request tracking. Updated tools handling to support both array and object formats. Adjusted tests to reflect changes in response structure and ensure accurate logging of errors and tool calls.
Introduced a new CLI option `--project-dir` to allow users to define the project directory for running commands. Updated the command handler to use the specified directory or default to the current working directory. Adjusted file resolution and SDK initialization to reflect the new directory option.
Implemented a new function to fetch models data at runtime, replacing the previous macro import due to compatibility issues with `bun run --conditions=browser`. The function checks for a local environment variable and falls back to fetching from a remote API if not found.
- Resolved conflicts in run.ts: kept both project-dir and variant options - Resolved conflicts in llm.ts: kept both TraceLogger and PermissionNext imports
Contributor
|
Hey! Your PR title Please update it to start with one of:
Where See CONTRIBUTING.md for details. |
Contributor
|
The following comment was made by an LLM, it may be inaccurate: No duplicate PRs found |
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.
What does this PR do?
Fixes #7535
This pull request introduces a new trace logging feature for LLM request-response pairs, allowing users to save detailed traces of model interactions for debugging or auditing purposes. It adds a
--trace-dirCLI option (also configurable via theOPENCODE_TRACE_DIRenvironment variable), implements aTraceLoggerutility, and integrates trace logging into the LLM streaming pipeline.Additionally, it has some workarounds for project directory handling for the run command due to bun dev issues. I can revert those.
The most important changes are:
Trace Logging Infrastructure:
TraceLoggerutility (trace-logger.ts) to create, update, and persist detailed trace logs of LLM requests and responses, including errors and system info. Traces are saved as JSON files in a configurable directory.--trace-dirCLI option andOPENCODE_TRACE_DIRenv variable to enable trace logging, and initialized the logger during CLI startup.opencode runis done on a separate directory with specific .opencode configuration of different permissions. This causes repeated network IO to download and install 6.4MB of opencode package in node modules and blows up disk space as well as network bandwidth.CLI and Project Directory Handling:
--project-diroption to theruncommand, allowing users to specify the working directory for project execution. All relevant paths and server initialization now respect this directory.opencode runfrom the directory I wanted to wasnt working. Maybe this isnt strictly necessary and i just didnt use it properly with the bun dev setup.Model Data Loading Fix:
bun run.How did you verify your code works?
I ran the following command
opencode run {problem_text} --project-dir {task_dir} --trace-dir {trace_dir}And here are some traces -
2026-01-09T22-43-08-873Z_ses_45b128da9ffevGAq3ugKoAeozK_trace_mk7gphvn_1smwbk5h.json
2026-01-09T22-43-40-672Z_ses_45b128da9ffevGAq3ugKoAeozK_trace_mk7gpm2h_8cwrj23j.json
2026-01-09T22-43-45-843Z_ses_45b128da9ffevGAq3ugKoAeozK_trace_mk7gqam5_fubms5zt.json