Skip to content

fix(agent): use atomic_json_write for request debug dumps instead of bare write_text#30602

Closed
sprmn24 wants to merge 1 commit into
NousResearch:mainfrom
sprmn24:fix/agent-runtime-atomic-debug-dump
Closed

fix(agent): use atomic_json_write for request debug dumps instead of bare write_text#30602
sprmn24 wants to merge 1 commit into
NousResearch:mainfrom
sprmn24:fix/agent-runtime-atomic-debug-dump

Conversation

@sprmn24

@sprmn24 sprmn24 commented May 22, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

dump_api_request_debug() in agent/agent_runtime_helpers.py writes the request debug dump with bare write_text(). If the process is killed mid-write (OOM, SIGKILL during a bad API call storm), the dump file is left partially written — this is the file most likely to be examined post-mortem, so corruption here hurts diagnosis of the very failures it was meant to capture.

atomic_json_write is already imported from utils at the top of the file but unused here.

Type of Change

  • Bug fix

Changes Made

  • Replaced 4-line write_text(json.dumps(...)) block with a single atomic_json_write(dump_file, dump_payload) call
  • No behavioral change — same output, same file path, now crash-safe

How to Test

  1. Review agent/agent_runtime_helpers.py around line 1065
  2. Verify atomic_json_write is now used instead of write_text
  3. Run python -m pytest tests/ -q — no regressions expected

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix
  • I've tested on my platform: Ubuntu 24.04 (WSL2)

Documentation & Housekeeping

  • No documentation changes needed
  • Cross-platform considered — no platform-specific impact

@alt-glitch alt-glitch added type/bug Something isn't working P3 Low — cosmetic, nice to have comp/agent Core agent loop, run_agent.py, prompt builder labels May 22, 2026
@teknium1

Copy link
Copy Markdown
Contributor

Merged via PR #30857 — your commit was cherry-picked onto current main with your authorship preserved (commit 53cb6d3). Added default=str on top so dump payloads containing datetime / httpx Response / other non-JSON-native objects still serialize cleanly (without it, the whole dump silently TypeErrors and gets lost in the except block). Thanks for the fix!

@teknium1 teknium1 closed this May 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent loop, run_agent.py, prompt builder P3 Low — cosmetic, nice to have type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants