Rectify: Anomaly Detection Observed-Model Self-Comparison & Scanner Budget Exhaustion — PART A ONLY#3365
Merged
Trecek merged 4 commits intoMay 31, 2026
Conversation
Adds two tests that expose the a5a68f4 regression in flush_session_log where _observed = model_identifier causes detect_model_drift(X, X): - test_flush_session_log_genuine_drift_with_configured_model: positive integration test through flush_session_log; asserts MODEL_DRIFT fires when configured=opus but API-observed dominant model=sonnet. - test_drift_call_site_uses_independent_observed_source: AST guard that walks flush_session_log, finds the detect_model_drift call site, and asserts _observed is assigned from _primary_model_identifier() with no ternary branch that collapses it back to model_identifier. Both tests fail against the current code and will pass after the fix. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ifier Regression introduced in a5a68f4: when model_identifier was set, _observed was assigned model_identifier, causing detect_model_drift(X, X) — comparing the configured model against itself, which permanently disables MODEL_DRIFT detection for any session with a configured model. Fix: _observed is now always derived from _primary_model_identifier(token_usage) (the API-observed dominant model). When model_identifier and the argmax model genuinely agree, detect_model_drift correctly returns no anomaly via _models_match alias handling. When they differ, drift is correctly emitted. effective_model_id is unchanged — it retains model_identifier-or-argmax fallback semantics for session metadata, which is a distinct use case from drift detection. Also updates: - test_flush_session_log_no_false_drift_with_configured_model: corrects the test scenario (opus configured, opus dominates breakdown) and docstring (previously encoded the broken behavior as expected). - test_primary_model_identifier_argmax_returns_subagent_when_dominant: docstring now accurately describes flush_session_log's actual behavior after the fix. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The AST loop checking _observed assignment only matched ast.Assign. If production code refactored to an annotated assignment (_observed: str = ...), the guard would silently fall through to pytest.fail with a misleading message. Now also matches ast.AnnAssign for structural robustness. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
… message Parse JSONL lines once then filter, instead of calling json.loads twice per line. Also adds a descriptive failure message to the drift_entries length assertion for easier diagnosis. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
c63c7a0 to
a8993a1
Compare
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.
Summary
Commit
a5a68f49introduced a regression insession_log.pywhere the_observedmodel variable is set tomodel_identifier(the configured model) whenmodel_identifieris non-empty. This causesdetect_model_drift(model_identifier, model_identifier)— comparing the configured model against itself — which permanently disables MODEL_DRIFT detection for all sessions with a configured model. The existing testtest_flush_session_log_no_false_drift_with_configured_modelvalidates this broken behavior as correct, and the AST guard intest_model_identity_contract.pyonly coversdetect_model_driftinternals, not the call site insession_log.py.The architectural weakness is that
_observedis computed at the call site with no structural enforcement that it must come from a different data source thanconfigured_model. The detection functiondetect_model_drift(configured, observed)has a two-value comparison contract, but the call site collapsed both values to the same source. No test asserts the positive case (real drift fires throughflush_session_log), and no AST guard prevents future regressions at the call site.Part A fixes the
_observedcomputation bug plus adds the tests and AST guard that make this class of regression structurally impossible. Part B will cover scanner-level improvements.Requirements
Conflict Resolution Decisions
The following files had merge conflicts that were automatically resolved.
Implementation Plan
Plan file:
/home/talon/projects/autoskillit-runs/remediation-20260530-171650-060527/.autoskillit/temp/rectify/rectify_anomaly_detection_observed_model_self_comparison_2026-05-30_172500.md🤖 Generated with Claude Code via AutoSkillit
Token Usage Summary
* Step used a non-Anthropic provider; caching behavior may differ.
Token Efficiency
Model Usage Breakdown