Skip to content

fix: file handle leak, viewBox null check, and stale op_id bug#81

Merged
deacon-mp merged 1 commit intomitre:masterfrom
deacon-mp:fix/codebase-bugs
Mar 16, 2026
Merged

fix: file handle leak, viewBox null check, and stale op_id bug#81
deacon-mp merged 1 commit intomitre:masterfrom
deacon-mp:fix/codebase-bugs

Conversation

@deacon-mp
Copy link
Copy Markdown
Contributor

Summary

  • File handle leak in c_story.py:adjust_icon_svgs()svg.write(open(path, 'wb')) never closes the file handle. Fixed with context manager.
  • Null viewBox crash in c_story.py:adjust_icon_svgs() — crashes if an SVG element lacks a viewBox attribute. Added null check with continue.
  • Stale op_id variable in debrief_svc.py:build_steps_d3() — the second for operation in operations loop referenced op_id from the first loop, causing all operation nodes/links to use the last op_id value when multiple operations are debriefed. Fixed to use operation.id.

Test plan

  • Run existing tests to verify no regressions
  • Debrief multiple operations simultaneously and verify the steps graph correctly attributes nodes to each operation
  • Generate a PDF report and verify SVGs render correctly

🤖 Generated with Claude Code

…eps_d3

- c_story.py: use context manager for svg.write() to prevent file handle leak
- c_story.py: add null check for missing viewBox attribute in adjust_icon_svgs
- debrief_svc.py: use operation.id instead of stale op_id loop variable in
  build_steps_d3 second loop (was referencing last value from first loop)
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes three bugs: a file handle leak when writing SVGs, a null-pointer crash when SVG elements lack a viewBox attribute, and a stale loop variable (op_id) causing incorrect graph data when debriefing multiple operations.

Changes:

  • Added a null check for the viewBox attribute and replaced the leaking open() call with a context manager in adjust_icon_svgs().
  • Replaced stale op_id references with operation.id in the second loop of build_steps_d3(), ensuring each operation's nodes and links use the correct operation identifier.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
app/objects/c_story.py Fixes file handle leak via context manager and adds null check for missing viewBox attribute
app/debrief_svc.py Replaces stale op_id variable with operation.id in the graph-building loop

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@deacon-mp deacon-mp merged commit 722b496 into mitre:master Mar 16, 2026
5 checks passed
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.

2 participants