The previous state.toml marked status = 'completed' despite the
track FAILING 4 of 10 acceptance criteria:
- VC1: .get() sites 26 (target < 15)
- VC2: subscript sites 79 (target < 20)
- VC4: effective codepaths not measured
- VC6: 7/11 batched tiers pass (target 10/11)
This commit:
1. Sets state.toml status to 'active' (track is NOT complete)
2. Marks Phase 11 as 'failed' (verification did not pass)
3. Rewrites the completion report to lead with the FAILED status
The 50% reduction in .get() sites (52 -> 26) is meaningful progress
but the spec's quantitative gates were not met. Do not merge this
branch as complete.
In Phase 2 (commit 96f0aa54), I migrated the half-measure pattern
to use 'models.FileItem.from_dict(fi)'. This worked in some scopes
but failed in _send_qwen/_send_grok/_send_llama because ai_client.py
imports 'FileItem' from src.type_aliases (which is a TypeAlias string
forward reference 'models.FileItem', NOT the class). The earlier
import from src.models was shadowed by the type_aliases import
at line 71. Hence 'isinstance(fi, FileItem)' failed with
'isinstance() arg 2 must be a type'.
Fix: add local 'from src.models import FileItem as _FIC' inside
the if-block and use _FIC for isinstance + from_dict.
Discovered by test_qwen_provider.py::test_qwen_vision_vl_model_accepts_image.
Tests: 11/11 pass (test_qwen_provider, test_ai_client_result,
test_ai_client_tool_loop).
In Phase 10 batch 1 (commit 28799766), I migrated the total_cost
sum in render_mma_track_summary using 'MMAUsageStats.from_dict()'
directly instead of the local '_MMA' alias used elsewhere in the
same function. This caused NameError at runtime when the code path
was exercised.
Fix: add 'from src.type_aliases import MMAUsageStats as _MMA'
and use '_MMA.from_dict()' consistently.
Discovered by test_mma_approval_indicators.py::test_no_approval_badge_when_idle
which exercises render_mma_dashboard -> render_mma_track_summary.
Tests: 4/4 pass in test_mma_approval_indicators.py.
Required by Phase 10 migrations which call these from_dict methods.
Without these, CustomSlice.from_dict() and MMAUsageStats.from_dict()
used in gui_2.py would raise AttributeError at runtime.
Adds the from_dict pattern consistent with the existing
CommsLogEntry/HistoryMessage/ToolDefinition from_dict:
- Filter dict keys to only the dataclass fields (ignore extras)
- Pass filtered dict to cls(**filtered)
Field definitions unchanged. No-op behavior for callers that
already have a dataclass instance (they pass through isinstance check).
Tests: 51/51 pass across all related test files.
Phase 10 (batch 2): DiscussionSettings
Before: 1 .get('temperature'/...) site in src/gui_2.py
After: 0
Delta: -1 (plan expected 3 sites; 2 were already migrated by Tier 2)
Migrates the summary line in persona preferred model rendering:
entry.get('temperature', 0.7)
entry.get('top_p', 1.0)
entry.get('max_output_tokens', 0)
to:
ds = DiscussionSettings.from_dict(entry) if isinstance(entry, dict) else ds
ds.temperature, ds.top_p, ds.max_output_tokens
The dataclass defaults match the original .get() defaults exactly
(temperature=0.7, top_p=1.0, max_output_tokens=0), so behavior is preserved.
Phase 9: RAGChunk
Before: 0 .get('document',...) sites
After: 0
Delta: -0 (expected: -3; Tier 2 had already migrated these sites
before this track started; the lines at aggregate.py:3259,
app_controller.py:251,4162 referenced in the plan no longer
exist in the current code)
Verification:
- aggregate.py: no remaining .get('document',...) sites
- app_controller.py: no remaining chunk.get(...) sites
- rag_engine.RAGChunk dataclass + from_dict() method available
- _rag_search_result returns Result[list[Metadata]] (chunks are dicts)
No code changes; the phase is verified complete by Tier 2's earlier
migration. Phase 9 has no remaining .get() sites on the RAGChunk
aggregate, satisfying the per-phase hard guard (delta = 0 because
baseline is already 0).
Phase 8: ToolDefinition
Before: 2 .get('description',...) sites
After: 0
Delta: -2 (expected: -2 or -3 per plan; the 3rd site gui_2.py:5875
is 'server' field which is NOT on ToolDefinition)
Migrates:
1. src/mcp_client.py:1968 (was 1970) - list_tools in _get_tool_definitions:
tinfo.get('description', '') -> ToolDefinition.from_dict(tinfo).description
(tinfo.get('inputSchema', ...) stays because 'inputSchema' key
does not match ToolDefinition's 'parameters' field name)
2. src/gui_2.py:5878 - render_external_tools_panel:
tinfo.get('description', '') -> ToolDefinition.from_dict(tinfo).description
Notes:
- gui_2.py:5875 (tinfo.get('server', 'unknown')) is NOT migrated;
'server' is not a ToolDefinition field. The tinfo here may be a
ToolInfo or server-info dict, not ToolDefinition. Classified as
collapsed-codepath per FR2.
Tests: 10/10 pass (test_tool_definition, test_external_mcp,
test_external_mcp_e2e). 2 test_type_aliases failures are pre-existing
(forward references in TypeAlias declarations; not caused by these
changes).
Phase 6: UsageStats
Before: 4 .get('input_tokens'/...) sites in src/app_controller.py
After: 0
Delta: -4 (expected: -4)
Migrates the explicit UsageStats constructor:
u_stats = models.UsageStats(
input_tokens=u.get('input_tokens', 0) or 0,
output_tokens=u.get('output_tokens', 0) or 0,
cache_read_tokens=u.get('cache_read_input_tokens', 0) or 0,
cache_creation_tokens=u.get('cache_creation_input_tokens', 0) or 0,
)
to:
u_stats = UsageStats.from_dict(u)
Behavior notes:
- UsageStats.from_dict() filters dict keys to dataclass fields.
The dict has 'cache_read_input_tokens' but the dataclass field is
'cache_read_tokens' (different name). from_dict() will not populate
cache_read_tokens from cache_read_input_tokens; it stays at the
default 0.
- Only input_tokens and output_tokens are used downstream
(new_mma_usage[tier]['input'/'output'], new_token_history entry).
cache_read_tokens and cache_creation_tokens are never read in this
scope, so the behavior change is invisible.
- Local import 'from src.openai_schemas import UsageStats as _US'
follows the existing pattern in src/ai_client.py.
Tests: 16/16 pass (test_session_logger_optimization,
test_session_logger_reset, test_session_logging, test_logging_e2e,
test_comms_log_entry, test_token_usage, test_usage_analytics_popout_sim).
Phase 5: ChatMessage (part 2)
Before: 6 .get('content'/'role'/'tool_calls'/'tool_call_id') sites
After: 0
Delta: -6
Migrates:
1. _send_deepseek API response parsing (lines 2321-2324):
- message.get('content', '') -> message.content or ''
- message.get('tool_calls', []) -> [tc.to_dict() for tc in message.tool_calls]
- message.get('reasoning_content') -> kept as choice.get('message', {}).get('reasoning_content', '')
(reasoning_content is NOT a ChatMessage field)
2. _repair_minimax_history generator (line 2454):
- m.get('role') == 'tool' -> _CM.from_dict(m).role == 'tool'
- m.get('tool_call_id') -> _CM.from_dict(m).tool_call_id
Used inline conversion because the generator iterates over a
dict list and reads 2 fields. Inline conversion avoids an
intermediate list comprehension.
openai_schemas.py:
- ChatMessage.from_dict() now provides defaults for required fields
('role' -> 'assistant', 'content' -> '') when the input dict is
missing them. This handles the case where DeepSeek's API returns
an empty {} for 'message' (e.g., finish_reason='length' with no
content). Without this default, ChatMessage.__init__() raises
TypeError.
Tests: 46/46 pass (test_ai_client_result, test_ai_client_tool_loop,
test_deepseek_provider, test_openai_schemas, test_minimax_provider).
Phase 5: ChatMessage (part 1)
Before: 6 .get('role'/'content'/'tool_calls'/'tool_call_id') sites in _send_deepseek
After: 0
Delta: -6
Migrates _send_deepseek's history transformation loop from
dict-style access to ChatMessage direct field access:
msg = _ChatMessage.from_dict(msg_raw)
msg.role (was msg.get('role'))
msg.content (was msg.get('content'))
msg.tool_calls (was msg.get('tool_calls') / msg['tool_calls'])
msg.tool_call_id (was msg.get('tool_call_id'))
The api_msg dict (output for the DeepSeek API) is constructed via
direct field access. The tool_calls list is converted to dicts via
tc.to_dict() (preserves the existing API payload format).
Notes:
- msg_raw.get('reasoning_content') is preserved as-is because
reasoning_content is NOT a ChatMessage field.
- Local import 'from src.openai_schemas import ChatMessage as _ChatMessage'
follows the existing pattern in this file (lazy imports inside functions).
Tests: 36/36 pass (test_ai_client_result, test_ai_client_tool_loop,
test_deepseek_provider, test_openai_schemas).
Infrastructure change required by Phase 5/6/7 of the
type_alias_unfuck_20260626 track. The plan's migration pattern
(var = Aggregate.from_dict(var)) requires from_dict on the
target dataclasses. None existed for the openai_schemas
classes, so this commit adds them.
from_dict semantics:
- Filter dict keys to only the dataclass fields (ignore extra keys
like _est_tokens)
- For ChatMessage: convert nested tool_calls list to tuple of ToolCall
- For ToolCall: convert nested function dict to ToolCallFunction
- For UsageStats: direct field mapping
Field definitions unchanged. Behavior: zero impact on existing tests
(no callers exist yet for from_dict on these classes).
Tests: syntax check OK; manual instantiation confirms from_dict works.
Phase 3: CommsLogEntry
Before: 3 .get('source_tier',...) sites + 1 half-measure in src/gui_2.py
After: 0
Delta: -4 (expected: -5 per plan; the 5th site was app_controller.py:1930
which returns None for missing source_tier and cannot be migrated
without breaking test_append_tool_log_dict_keys)
Migrates the following CommsLogEntry-related sites in src/gui_2.py:
1. gui_2.py:1810 - cache filter source_tier (.get('source_tier', ''))
2. gui_2.py:1818 - cache filter source_tier (.get('source_tier', ''))
3. gui_2.py:5104 - render_comms_log_panel source_tier (.get('source_tier', 'main'))
4. gui_2.py:5106 - render_comms_log_panel ts (.get('ts', '00:00:00'))
5. gui_2.py:5107 - render_comms_log_panel direction (.get('direction', '??'))
6. gui_2.py:5110 - render_comms_log_panel model (.get('model', '?'))
7. gui_2.py:5802 - render_tool_calls_panel half-measure
(subscript + 'in' check; entry['source_tier'] if 'source_tier' in entry else 'main')
All migrated via:
ce = CommsLogEntry.from_dict(entry)
ce.<field> # direct attribute access
The dataclass default for source_tier is 'main', which preserves the
fallback behavior for sites that had 'main' as the default. For sites
with '' as the default (cache filters), the behavior change is benign
because both '' and 'main' fail to match any non-trivial agent prefix.
Notes:
- The 'kind' field is NOT migrated because it has a legacy 'type'
fallback ('kind' OR 'type') that the dataclass default doesn't
preserve.
- 'provider' and 'payload' are NOT on CommsLogEntry; they remain
as entry.get(...) calls.
- src/app_controller.py:1930 is NOT migrated because its
no-default behavior (returns None) is asserted by
test_append_tool_log_dict_keys.
Tests: 16/16 pass (test_mma_agent_focus_phase1, test_comms_log_entry,
test_gui2_events).
TIER-2 READ AGENTS.md conductor/workflow.md conductor/edit_workflow.md conductor/tier2/githooks/forbidden-files.txt conductor/tracks/tier2_leak_prevention_20260620/spec.md conductor/code_styleguides/data_oriented_design.md conductor/code_styleguides/error_handling.md conductor/code_styleguides/type_aliases.md before pre-flight
Regenerate the type registry to bring docs into sync with the
current src/type_aliases.py and src/models.py state. Pre-flight
required by Phase 0: 'uv run python scripts/generate_type_registry.py --check'
must exit 0 before per-phase work begins.
Diff: index.md + src_type_aliases.md + type_aliases.md (3 files).
FileItem moved from 'dataclass in src/type_aliases.py' to 'TypeAlias
in src/type_aliases.py' because the canonical FileItem is now
src.models.FileItem (per the previous track's commit b4bd772d which
pointed the alias and removed the duplicate).