Skip to content

fix(cron): read jobs.json with utf-8-sig to tolerate BOM (#66607) - #66623

Closed
AlexFucuson9 wants to merge 1 commit into
NousResearch:mainfrom
AlexFucuson9:fix/cron-jobs-json-bom-utf8-sig
Closed

fix(cron): read jobs.json with utf-8-sig to tolerate BOM (#66607)#66623
AlexFucuson9 wants to merge 1 commit into
NousResearch:mainfrom
AlexFucuson9:fix/cron-jobs-json-bom-utf8-sig

Conversation

@AlexFucuson9

Copy link
Copy Markdown
Contributor

Summary

Fixes #66607load_jobs() crashes with RuntimeError when jobs.json has a UTF-8 BOM.

Root cause

Four readers of ~/.hermes/cron/jobs.json open with plain encoding='utf-8'. Python's json.load rejects a leading BOM (EF BB BF) under plain UTF-8.

Fix

Switch all four readers to encoding='utf-8-sig':

  • cron/jobs.py:838load_jobs primary open
  • cron/jobs.py:844load_jobs strict=False retry
  • hermes_cli/dump.py:170_cron_summary
  • hermes_cli/status.py:532show_status

Writers remain on plain utf-8 so saves stay BOM-free.

Testing

TMP=$(mktemp -d)
mkdir -p "$TMP/cron"
printf '{"jobs": []}
' > "$TMP/cron/jobs.json"
HERMES_HOME="$TMP" python -c 'from cron.jobs import load_jobs; print(load_jobs())'
rm -rf "$TMP"
  • py_compile passes on all 3 modified files
  • No behavioral change for non-BOM files

Four independent readers of ~/.hermes/cron/jobs.json used plain
encoding='utf-8'. A leading UTF-8 BOM (EF BB BF), commonly added
by Windows Notepad or PowerShell Set-Content -Encoding UTF8, causes
json.load to raise JSONDecodeError which escalates to RuntimeError:
'Cron database corrupted and unrepairable'.

Switch all four readers to encoding='utf-8-sig' which transparently
strips the BOM if present and behaves identically to utf-8 otherwise.
Writers remain on plain utf-8 so saves stay BOM-free.

Fixes NousResearch#66607

Refs:
- cron/jobs.py:838 load_jobs primary open
- cron/jobs.py:844 load_jobs strict=False retry
- hermes_cli/dump.py:170 _cron_summary
- hermes_cli/status.py:532 show_status

@tonydwb tonydwb left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review Summary

Verdict: Approved with Comment

PR #66623fix(cron): read jobs.json with utf-8-sig to tolerate BOM

  • Adds encoding='utf-8-sig' to Path.read_text() call in cron jobs loading.
  • Fixes BOM handling for Windows-generated JSON files.
  • 4-line change, well-scoped fix with clear rationale.
  • No security implications; file reading only.

Suggestions

  • Consider whether other Path.read_text() calls in the same file need the same treatment.

Reviewed by Hermes Agent

@alt-glitch alt-glitch added type/bug Something isn't working comp/cli CLI entry point, hermes_cli/, setup wizard comp/cron Cron scheduler and job management P1 High — major feature broken, no workaround sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades duplicate This issue or pull request already exists labels Jul 18, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

Duplicate of #66609, which is open and implements the same utf-8-sig changes for all four jobs.json readers with broader regression coverage.

@tonydwb tonydwb left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{
"event": "COMMENT",

Code Review Summary

Verdict: Comment (prior COMMENT activity noted)

Fixes jobs.json and _cron_summary reading to use utf-8-sig encoding instead of plain utf-8, tolerating BOM at the start of the file. Two read sites in cron/jobs.py and one in hermes_cli/dump.py updated.


Reviewed by Hermes Agent",
"comments": []
}

@teknium1

Copy link
Copy Markdown
Contributor

Closing as a duplicate of #66609, which was submitted 31 minutes earlier with the identical 4-site utf-8-sig fix (cron/jobs.py ×2, hermes_cli/dump.py, hermes_cli/status.py) plus regression tests covering the crash repro, BOM-less regression, bare-list auto-repair, and the strict=False arm.

Credit to you for independently identifying all four readers — including the dump.py/status.py sites that the earlier #41604 missed. The fix will land via #66609. Thanks for the contribution!

@teknium1

Copy link
Copy Markdown
Contributor

Merged via PR #66825, which salvaged #66609 (submitted ~30 minutes earlier with the same four utf-8-sig reader changes plus regression tests) as the base. Your PR independently identified the same fix including the dump.py/status.py sites — credited in the salvage PR body. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/cli CLI entry point, hermes_cli/, setup wizard comp/cron Cron scheduler and job management duplicate This issue or pull request already exists P1 High — major feature broken, no workaround sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cron: UTF-8 BOM in jobs.json crashes load_jobs (RuntimeError)

4 participants