Skip to content

fix(tracking): restore trace persistence after merge - #524

Merged
Nicola Franco (franconicola) merged 1 commit into
AISecurityLab:mainfrom
rksharma-owg:codex/fix-tracker-merge-regression
Jul 26, 2026
Merged

fix(tracking): restore trace persistence after merge#524
Nicola Franco (franconicola) merged 1 commit into
AISecurityLab:mainfrom
rksharma-owg:codex/fix-tracker-merge-regression

Conversation

@rksharma-owg

Copy link
Copy Markdown

Problem

main currently raises UnboundLocalError for every tracking trace because _add_trace() references the exception variable e on 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 the except block 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 persistence except block. 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.py
  • uv 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 passed
  • uv run pytest tests/ -q — 2,733 passed, 135 skipped, 177 subtests passed

Risk

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 main advances.

@codecov

codecov Bot commented Jul 26, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
hackagent/router/tracking/tracker.py 0.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@franconicola
Nicola Franco (franconicola) marked this pull request as ready for review July 26, 2026 15:21
Copilot AI review requested due to automatic review settings July 26, 2026 15:21
@franconicola
Nicola Franco (franconicola) merged commit 9a49ed5 into AISecurityLab:main Jul 26, 2026
21 of 22 checks passed

Copilot AI 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.

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 when backend.create_trace(...) raises.

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

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.

3 participants