Skip to content

fix(cli): keep diagnostics working when config TOML is malformed - #13167

Merged
kodjima33 merged 3 commits into
BasedHardware:mainfrom
Nofates:fix/cli-toml-malformed-config
Sep 9, 2026
Merged

kodjima33 merged 3 commits into
BasedHardware:mainfrom
Nofates:fix/cli-toml-malformed-config

Conversation

@Nofates

@Nofates Nofates commented Sep 8, 2026 •

Copy link
Copy Markdown

Summary

Fixes #13161 — with an isolated OMI_CONFIG containing invalid TOML (e.g. active_profile = [), omi version, omi config path, and omi --json config path all failed with TOMLDecodeError. These diagnostics are most useful precisely when the config needs repair and don't require its contents.

Change

cfg.load() now treats malformed TOML and invalid UTF-8 as a recoverable load error for read-only diagnostics, while retaining that state on Config.load_error. save() refuses to overwrite a config that failed to parse, so write commands cannot silently destroy profiles or credentials that may still be repaired manually.

Verification

  • Regression tests cover malformed TOML, invalid UTF-8, save refusal, omi version, human-readable omi config path, and parsed JSON omi --json config path output
  • All new regression tests fail without the fix and pass with it
  • python -m pytest -q sdks/python-cli/tests/test_config.py — 23 passed, 1 skipped
    Failure-Class: none

Review in cubic

@cubic-dev-ai cubic-dev-ai Bot 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.

1 issue found across 5 files

Confidence score: 4/5

  • backend/utils/task_integrations_ops.py changes the endpoint while the Todoist E2E regression test still expects /rest/v2/tasks, so the suite will fail until the migration is reflected in the test; update the expectation to verify the intended endpoint.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="backend/utils/task_integrations_ops.py">

<violation number="1" location="backend/utils/task_integrations_ops.py:256">
P2: This endpoint change breaks the existing Todoist E2E regression test because it still expects `/rest/v2/tasks`. Update the test expectation alongside this migration so the suite passes and verifies the intended endpoint.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread sdks/python-cli/omi_cli/config.py Resolved
Comment thread backend/utils/task_integrations_ops.py Outdated

response = await client.post(
'https://api.todoist.com/rest/v2/tasks',
'https://api.todoist.com/api/v1/tasks',

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2: This endpoint change breaks the existing Todoist E2E regression test because it still expects /rest/v2/tasks. Update the test expectation alongside this migration so the suite passes and verifies the intended endpoint.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At backend/utils/task_integrations_ops.py, line 256:

<comment>This endpoint change breaks the existing Todoist E2E regression test because it still expects `/rest/v2/tasks`. Update the test expectation alongside this migration so the suite passes and verifies the intended endpoint.</comment>

<file context>
@@ -253,7 +253,7 @@ async def create_task_internal(
 
             response = await client.post(
-                'https://api.todoist.com/rest/v2/tasks',
+                'https://api.todoist.com/api/v1/tasks',
                 headers={'Authorization': f'Bearer {access_token}', 'Content-Type': 'application/json'},
                 json=body,
</file context>

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

This file is no longer part of this PR — the branch was cleaned to contain only the config-TOML fix (sdks/python-cli/omi_cli/config.py + tests/test_config.py). The Todoist endpoint migration lives in its own PR (#13166), where the e2e test assertion was updated in the same change.

Comment thread sdks/python-cli/omi_cli/config.py Resolved
Comment thread sdks/python-cli/tests/test_config.py Resolved
omi version, omi config path, and omi --json config path crashed with
TOMLDecodeError when the config file was malformed — exactly when those
diagnostics are most needed. cfg.load() now returns an empty Config on
TOMLDecodeError (same as a missing file), so read-only commands work and
config-writing commands can rebuild a healthy default.

Failure-Class: none

Verification:
- 3 new regression tests (load + version + config path with malformed
  TOML) pass with the fix, fail without it (confirmed via stash)
- full config test suite passes
@Nofates
Nofates force-pushed the fix/cli-toml-malformed-config branch from e1e3541 to 5249ead Compare September 8, 2026 17:49
load() now records the parse failure (invalid TOML or invalid UTF-8) on
Config.load_error instead of silently returning a pristine Config, and
save() refuses to overwrite such a file. A write command (config set,
config profile use/delete, auth login/logout) can no longer destroy a
malformed config the user could still repair by hand; read-only
diagnostics (version, config path, --json config path) still work on a
corrupt file.

Regression tests: malformed TOML, invalid UTF-8, save refusal, and the
--json config path branch.

Failure-Class: none

Verification:
- 6 new/updated regression tests fail without the fix (stash proof),
  pass with it
- full tests/test_config.py suite passes (30 tests)
@Git-on-my-level

Copy link
Copy Markdown
Member

Verified independently — nice fix, and good response to the earlier review feedback: all four findings from the previous head are addressed on 16c3dce (load_error recording, UTF-8 handling, save() refusal, --json path test), and the Todoist endpoint change correctly moved out to #13166.

What I checked:

sdks/python-cli/omi_cli/config.py

  • load() now returns an empty Config with load_error set for both tomllib.TOMLDecodeError and UnicodeDecodeError, so the root callback in main.py (which calls cfg.load() on every invocation) no longer crashes read-only diagnostics. Confirmed with a real CLI run: omi version, omi config path, and omi --json config path all exit 0 with active_profile = [ on disk.
  • The save() guard is the right call: every write surface (config set / config profile use|delete in commands/config.py, and all four cfg.save() call sites in auth/store.py) funnels through it, so a malformed file can no longer be silently clobbered. Verified: omi config set api_base ... refuses with a clear message, exit 1, file byte-identical afterward.
  • New tests fail on main's config.py (red proof via file swap) and pass on this head: tests/test_config.py + test_main.py + test_config_literal_status.py = 34 passed, 1 skipped in a clean Python 3.12 container.

sdks/python-cli/tests/test_config.py

  • Six focused regression tests covering the malformed-TOML load, invalid UTF-8, the save refusal (including byte-for-byte file preservation), and all three diagnostic commands. Behavioral and tight — matches the repo's regression-test-per-fix bar.

Two optional polish ideas for a follow-up (not blocking):

  • omi config show prints an empty profile list when the config is corrupt; surfacing config.load_error there (or a stderr warning) would make the repair path more discoverable.
  • save() raises a bare PermissionError, which main.py's last-chance handler prints as "omi: unexpected error: ...". A typed CliError would get the standard rendering and a stable exit code. The message text itself is clear either way.

Thanks @anakinsuper — clean, well-scoped robustness fix with the failure modes thought through. Leaving the merge call to the maintainers; nothing here needs product judgment.

Automated maintainer-review feedback on behalf of the Omi maintainers.


by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.

@Git-on-my-level Git-on-my-level added positive-signal Automation verified a genuine fix/quality contribution python labels Sep 8, 2026
Failure-Class: none

Verification:
- python -m pytest -q sdks/python-cli/tests/test_config.py (23 passed, 1 skipped)

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Scoped bug fix, confirmed not yet fixed on main, tests added/updated, CI has no red required checks (pending).

@kodjima33
kodjima33 merged commit 2187c42 into BasedHardware:main Sep 9, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

positive-signal Automation verified a genuine fix/quality contribution python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CLI version and config path fail when config TOML is malformed

3 participants