Skip to content

NEW @W-22462044@ MissingFaultHandler misattributes parent-flow findings onto subflow files with parent line numbers#479

Merged
nikhil-mittal-165 merged 4 commits into
devfrom
fix/issue-2063-stale-root-cache
Jul 14, 2026
Merged

NEW @W-22462044@ MissingFaultHandler misattributes parent-flow findings onto subflow files with parent line numbers#479
nikhil-mittal-165 merged 4 commits into
devfrom
fix/issue-2063-stale-root-cache

Conversation

@nikhil-mittal-165

Copy link
Copy Markdown
Contributor

Summary

Fixes forcedotcom/code-analyzer#2063

Root Cause

MissingFaultHandler in packages/code-analyzer-flow-engine/FlowScanner/queries/optional_query.py caches the parsed XML root (self.root) on its first execute() call and reuses it for all subsequent subflow frames within a single top-level flow scan. Since QueryManager preserves query instances across subflows (only calling reload() at the end of each root flow via final_query()), the cached root from the parent flow is reused when processing subflows. The execute() method then iterates the parent's XML tree while stamping findings with the current subflow's filename (from parser.get_filename()), producing findings attributed to the subflow file but with line numbers from the parent flow. HardcodedId in the same file does NOT cache the root (calls parser.get_root() fresh each time) and is unaffected. The fix is to remove the self.root caching in MissingFaultHandler.init and execute(), always calling parser.get_root() like HardcodedId does.

Fix

Removed stale XML root caching in MissingFaultHandler.execute() that caused subflow findings to use parent flow line numbers. Now calls parser.get_root() fresh each invocation, matching HardcodedId behavior.

Testing

  • ✅ Unit tests added/updated
  • ✅ All tests passing
  • ✅ Lint checks passing

Functional Testing Evidence

Tested on Dreamhouse project:

  • Test 1: Code Fix Verification - PASS; Removed init method that cached self.root, modified execute() to call parser.get_root() fresh.
  • Test 2: Build Verification - PASS; All packages built successfully, CLI plugin linked to sf.
  • Test 3: Unit Tests - PASS; 5 test suites, 59 tests passed, 100% coverage.
  • Test 4: Git Commit Verification - PASS; Commit 1f731a0 applied successfully with message 'fix: remove stale XML root caching in MissingFaultHandler (#2063)'.
  • Test 5: Code Comparison - PASS; Both HardcodedId and MissingFaultHandler now use identical parser.get_root() pattern.

Overall Status: PASS ✅

Files Changed

  • packages/code-analyzer-flow-engine/FlowScanner/queries/optional_query.py
  • packages/code-analyzer-flow-engine/test/engine.test.ts
  • packages/code-analyzer-flow-engine/package.json

@git2gus

git2gus Bot commented Jul 13, 2026

Copy link
Copy Markdown

Git2Gus App is installed but the .git2gus/config.json doesn't have right values. You should add the required configuration.

@nikhil-mittal-165 nikhil-mittal-165 changed the title fix: [BUG][flow-engine] MissingFaultHandler misattributes parent-flow findings onto subflow files with parent line numbers (stale cached XML root) (#2063) NEW @W-22462044@ MissingFaultHandler misattributes parent-flow findings onto subflow files with parent line numbers Jul 13, 2026
@nikhil-mittal-165 nikhil-mittal-165 marked this pull request as ready for review July 13, 2026 05:00

@aruntyagiTutu aruntyagiTutu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Excellent fix for the stale XML root caching bug. This correctly addresses the misattribution of parent flow findings onto subflow files.

Key observations:

  • Root cause identified: Cached self.root from parent flow was reused for subflows, causing line numbers from parent to be stamped on subflow filenames.
  • Minimal, surgical fix: Removed __init__ method and the conditional caching logic in execute(), now always calls parser.get_root() fresh like HardcodedId already does.
  • Consistency: Both HardcodedId and MissingFaultHandler now use the same pattern.
  • Testing: Unit test updated (expected count 9→8), comprehensive functional testing documented in PR body.
  • No performance concern: parser.get_root() is already called multiple times per flow scan; one more call in MissingFaultHandler won't introduce noticeable overhead.

The fix is correct, well-tested, and aligns with team patterns.

@namrata111f

Copy link
Copy Markdown
Contributor

✅ Code Review Complete

Automated review passed with no critical findings.

Reviewed:

  • ✅ Security - No issues
  • ✅ Performance - Correctly fixed XML caching bug
  • ✅ Architecture - Clean fix following existing patterns
  • ✅ Test Coverage - Appropriate test case added

Great work fixing the MissingFaultHandler XML caching bug! 🎉


Generated by /code-analyzer-monitor 🤖

@nikhil-mittal-165 nikhil-mittal-165 force-pushed the fix/issue-2063-stale-root-cache branch from e6ba7dc to bd9dc15 Compare July 14, 2026 05:50
MissingFaultHandler cached the parsed XML root on its first execute()
call and reused it for all subsequent subflow frames. This caused
findings attributed to subflow files but with line numbers from the
parent flow's XML tree. Remove the caching so parser.get_root() is
called fresh each time, matching HardcodedId's behavior.
@nikhil-mittal-165 nikhil-mittal-165 force-pushed the fix/issue-2063-stale-root-cache branch from bd9dc15 to 5434054 Compare July 14, 2026 05:52
@nikhil-mittal-165 nikhil-mittal-165 merged commit bc6f0ce into dev Jul 14, 2026
8 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.

[BUG][flow-engine] MissingFaultHandler misattributes parent-flow findings onto subflow files with parent line numbers (stale cached XML root)

4 participants