Make ToC channel lazy to avoid file creation at log_level 0 - #105
Conversation
When with_table_of_contents=true and log_level=0, the ToC file was created eagerly even though no entries would be written. Fix by: - Gate ToC creation on log_level > 0 in shared_config (covers Flushing) - Add lazy get_toc_ch() in PrintBox functor that creates the ToC file on first access using config.with_toc_listing/toc_flame_graph and debug_ch_name(), supporting runtime log_level changes - Add for_append field to printbox_config so the lazy path respects the caller's open mode (truncate vs append) - Add test verifying no files created at log_level 0 Fixes #60 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
064e202 to
81682f2
Compare
|
@codex review Focus on bugs, correctness issues, and edge cases. Do not check adherence to a spec or plan. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 81682f2f19
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
|
||
| let table_of_contents_ch = | ||
| if with_table_of_contents then ( | ||
| if with_table_of_contents && log_level > 0 then ( |
There was a problem hiding this comment.
Keep ToC available after log level starts at 0
The new && log_level > 0 guard makes shared_config.table_of_contents_ch permanently None for file-backed debug_flushing runtimes created with ~log_level:0 ~with_table_of_contents:true. That runtime still allows logging later via Debug_runtime.log_level := ... (and can log level-0 entries immediately), but Flushing.close_log only emits ToC rows when table_of_contents_ch is Some, so ToC output is silently lost for the whole run in these cases.
Useful? React with 👍 / 👎.
| (match get_toc_ch () with | ||
| | None -> () |
There was a problem hiding this comment.
Rewind lazy ToC channel during snapshots
Switching ToC writes to get_toc_ch () means snapshot code can now write to a lazily-created ToC file, but snapshot rewind still operates on Log_to.table_of_contents_ch from shared_config. When that field is None (e.g. runtime initialized with log_level=0), snapshot_ch/reset_to_snapshot never track the new channel, so periodic snapshots (snapshot_every_sec) can leave duplicate/stale ToC entries instead of rolling them back.
Useful? React with 👍 / 👎.
Shadow snapshot_ch/reset_to_snapshot in PrintBox functor to track the lazily-created ToC channel. When table_of_contents_ch is None (lazy case), the wrapper flushes/rewinds the lazy channel directly. When table_of_contents_ch is already Some, defers to Log_to's implementations which already handle it. Fixes Codex review: snapshot_every_sec could leave stale ToC entries when the ToC channel was created lazily. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Retrospective: What I'd do differently1. Clarify API-stability constraints upfrontThis PR took 5 review rounds largely because I didn't ask early whether changing 2. Consider the functor-internal lazy pattern firstThe final approach — keeping 3. Don't forget snapshot interactionsThe Codex review caught that 4. Squash iterative commits before reviewThe 5-commit chain of back-and-forth changes made rebasing painful and the review history hard to follow. Next time: squash into a clean commit before requesting review, or at least before rebasing onto upstream. 5. Potential future cleanup
|
Summary
log_level > 0inshared_config(covers Flushing backend)get_toc_ch()inPrintBoxfunctor that creates the ToC file on first access usingconfig.with_toc_listing/toc_flame_graphanddebug_ch_name(), supporting runtimelog_levelchangesfor_appendfield toprintbox_configso the lazy path respects the caller's open modelog_level 0withwith_toc_listing=trueShared_configpublic API unchanged (table_of_contents_ch : out_channel option)Fixes #60
Test plan
dune build @runtest-toc-no-file-at-level0passesdune runtestpasses (all existing tests, no regressions)🤖 Generated with Claude Code