Skip to content

fix(core): encode paths and other non-JSON values in lifecycle.jsonl - #546

Open
ChrisW09 wants to merge 1 commit into
mainfrom
fix/jsonl-encoder
Open

ChrisW09 wants to merge 1 commit into
mainfrom
fix/jsonl-encoder

Conversation

@ChrisW09

@ChrisW09 ChrisW09 commented Oct 21, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #545

Problem

The lifecycle.jsonl writer serializes events with _JsonEncoder, which handled only NumPy integers and floats and otherwise called json.JSONEncoder.default, which raises. The exception propagated out of the event logger into the operation that emitted the event. With structured_logging=True, log_to_file=True and verbosity=3, model.save(pathlib.Path(...)) failed on its save_started event, before torch.save ran, so no artifact was written.

Fix

_JsonEncoder.default in deeptab/core/observability.py now also encodes:

  • NumPy booleans as bool and arrays as lists;
  • path-like objects with os.fspath;
  • anything else by str(o), the same fallback that write_run_config() and write_run_summary() use (default=str).

A value the JSON encoder could not serialize (paths, NumPy booleans and arrays, other objects) no longer makes the logged operation fail.

Tests

In tests/core/test_observability.py:

  • test_lifecycle_jsonl_records_values_json_cannot_encode: a Path, a NumPy integer, boolean and array, and an arbitrary object are written to lifecycle.jsonl with the expected JSON values.
  • test_save_to_a_path_object_with_file_logging: needs structlog. A fitted MLPRegressor with file logging at verbosity 3 saves to a pathlib.Path, and save_completed is logged.

Both fail on main and pass with this change.

Docs

No change needed.

Checks

  • just test: 3238 passed, 46 skipped, 28 xfailed; coverage 91.49%
  • just docs: build succeeded (warnings treated as errors)
  • just check: all hooks passed (ruff, prettier, pyright)

The JSONL event encoder handled only NumPy integers and floats and then
raised for any other value. With log_to_file=True and verbosity=3,
save(pathlib.Path(...)) therefore failed on its save_started event before
writing the artifact. Encode paths with os.fspath, NumPy booleans and
arrays as JSON values, and anything else by its string form, as
write_run_config() and write_run_summary() already do.

Fixes #545
@ChrisW09 ChrisW09 changed the title fix(core): never let lifecycle.jsonl encoding fail the logged operation fix(core): encode paths and other non-JSON values in lifecycle.jsonl Oct 21, 2026

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] save(pathlib.Path) fails and writes no artifact with log_to_file=True and verbosity=3

1 participant