fix(tracking): restore trace persistence after merge - #524
Merged
Nicola Franco (franconicola) merged 1 commit intoJul 26, 2026
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Nicola Franco (franconicola)
marked this pull request as ready for review
July 26, 2026 15:21
Nicola Franco (franconicola)
merged commit Jul 26, 2026
9a49ed5
into
AISecurityLab:main
21 of 22 checks passed
Copilot started reviewing on behalf of
Nicola Franco (franconicola)
July 26, 2026 15:22
View session
There was a problem hiding this comment.
Pull request overview
Restores correct tracking trace persistence behavior by moving _record_failure(...) back into the backend persistence except block in the tracker, preventing UnboundLocalError on successful trace paths and preserving failure auditing when persistence actually fails.
Changes:
- Remove erroneous
_record_failure(..., e)call from the non-exception (success) path in_add_trace(). - Record persistence failures only within the
except Exception as e:block whenbackend.create_trace(...)raises.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
maincurrently raisesUnboundLocalErrorfor every tracking trace because_add_trace()references the exception variableeon the successful path.This breaks normal trace recording before the backend-enabled check and causes five existing unit tests to fail.
Root cause
PR #518 correctly added
_record_failure(...)to theexceptblock around backend trace persistence. When #518 was merged alongside #519's trace-lock changes, the call was misplaced immediately after_emit(...), outside the exception handler.Implementation
Move
_record_failure(...)back into the backend persistenceexceptblock. Successful local and persisted traces no longer reference an undefined exception, while real persistence failures continue to be recorded on the parent run.Testing
uv run ruff check .uv run ruff format --check hackagent/router/tracking/tracker.pyuv run pytest -q tests/unit/attacks/test_error_propagation.py tests/unit/attacks/test_evaluation_updates.py tests/unit/router/tracking/test_goal_tracker_concurrency.py— 28 passeduv run pytest tests/ -q— 2,733 passed, 135 skipped, 177 subtests passedRisk
Low. This is a one-line relocation that restores the behavior already reviewed and tested in #518. It does not change public APIs, schemas, or successful trace ordering.
Backward compatibility
Fully backward compatible.
Future improvements
Because the regression was introduced while merging two independently green PRs, running the unit-test gate against the final merge result would catch this class of conflict-resolution error before
mainadvances.