Skip to content

Harden error handling + code-review quick wins (A+B)#142

Merged
devdanzin merged 1 commit into
mainfrom
harden-error-handling
Jun 29, 2026
Merged

Harden error handling + code-review quick wins (A+B)#142
devdanzin merged 1 commit into
mainfrom
harden-error-handling

Conversation

@devdanzin

Copy link
Copy Markdown
Owner

Summary

Works through the still-live items from doc/code-review-findings.md (several originally-listed items were already fixed).

(A) Error-handling hardening

  • C2Agent.__del__ no longer calls the raising send() on Ctrl-C (the agent is already inactive there, so send() raised AgentError and masked the interrupt); now best-effort and never escapes __del__.
  • H1python_source.on_session_start catches Exception (not BaseException) around loadModule, so a slow/wedged import stays interruptible.
  • H2list_all_modules._process_package drops the redundant except (ImportError, Exception); catches Exception and skips the package instead of aborting discovery.
  • H3utils.remove_logging_pycache is best-effort: guards a missing __pycache__ (was an uncaught startup crash) and wraps the reload.
  • H4 + MApplication.exit() runs deinitX11()/config=None in finally; runProject()'s teardown destroy() is guarded so it can't leak X11 access or mask an in-flight exception.
  • Policy — exception chaining (raise X from e) at the re-raise sites in config.py, process/create.py, session_directory.py.

(B) Quick wins

  • Removed the fragile runtime import cycle: argument_generator imports fusil.python.tricky_weird directly instead of the fusil.python package hub.
  • oom_dedup._BT_SKIP now skips the eval-loop teardown / generic-dealloc detector frames, in lockstep with the catalog's gen_known_sites.GENERIC_DETECTOR_FUNCS.
  • Retired the broken standalone test_doc.py (stale Py2-era doc/*.rst doctests); the surviving green module doctests (fusil.tools, fusil.process.tools) now run under unittest via tests/python/test_doctests.py.

Test plan

  • Full suite: 320 tests OK (+6: 5 doctests wired into unittest, 1 new oom_dedup detector-skip test).
  • ruff check + ruff format --check clean over fusil/ tests/ fuzzers/fusil-python-threaded.
  • --help smoke confirms the import-cycle change keeps the package init + option parser building cleanly.

Remaining backlog (complexity refactors, softer M-series sentinel warnings, legacy-coupled dead code) stays documented in doc/code-review-findings.md.

Closes #141

(A) Error-handling hardening:
- Agent.__del__ no longer calls the raising send() on KeyboardInterrupt (the agent is
  already inactive there, so send() raised AgentError and masked the interrupt) -- now
  best-effort, never escapes __del__ (C2).
- python_source.on_session_start catches Exception, not BaseException, around loadModule,
  so a slow/wedged import stays interruptible (H1).
- list_all_modules._process_package: drop the redundant `except (ImportError, Exception)`;
  catch Exception and skip the package instead of aborting discovery (H2).
- utils.remove_logging_pycache is now best-effort: guards a missing __pycache__ (was an
  uncaught crash at startup) and wraps the reload (H3).
- Application.exit() runs deinitX11()+config=None in `finally`, and runProject()'s teardown
  destroy() is guarded, so cleanup can't leak X11 access or mask an in-flight exception (H4 + M).
- Exception chaining (`raise X from e`) at the re-raise sites in config.py, process/create.py,
  session_directory.py.

(B) Quick wins:
- argument_generator imports fusil.python.tricky_weird directly instead of the package hub,
  removing the fragile runtime import cycle.
- oom_dedup._BT_SKIP now skips the eval-loop teardown / generic-dealloc detector frames
  (_Py_Dealloc, PyStackRef_XCLOSE, _PyFrame_ClearLocals, _PyFrame_ClearExceptCode,
  clear_thread_frame), in lockstep with the catalog's gen_known_sites.GENERIC_DETECTOR_FUNCS.
- Retired the broken standalone test_doc.py (it ran stale Py2-era doc/*.rst doctests);
  the surviving green module doctests (fusil.tools, fusil.process.tools) now run under
  unittest via tests/python/test_doctests.py.

Suite 320 OK; ruff check + format clean. Remaining backlog (complexity refactors, the
softer M-series sentinel warnings, legacy-coupled dead code) stays in doc/code-review-findings.md.

Closes #141

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@devdanzin devdanzin merged commit dd4d575 into main Jun 29, 2026
2 checks passed
@devdanzin devdanzin deleted the harden-error-handling branch June 29, 2026 20:45
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.

Error-handling hardening + quick wins (code-review backlog A+B)

1 participant