iomgaa
ae0a718f67
feat: thread and persist sub_pattern into accepted questions
2026-07-14 13:45:31 -04:00
iomgaa
25f2a845ff
fix: run_gates must use current_tree after video resample
2026-07-14 13:40:46 -04:00
iomgaa
d7d7ce5bdc
feat(question_gen): register ActionRecognitionStrategy, replace temp VISUAL binding
...
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com >
2026-07-14 06:51:50 -04:00
iomgaa
d0a8019fe1
feat(question_gen): add ActionRecognitionStrategy with 6 SubPatterns
...
Self-contained strategy targeting 6 Agent failure modes in Action
Recognition: premature_evidence_anchoring, temporal_reasoning_failure,
semantic_rigidity, fine_grained_visual_action,
cross_segment_entity_tracking, evidence_gap_confabulation.
- L2 default sampling (upgrade from L3) with 3 patterns overriding to L1
- Weighted random SubPattern selection (0.20/0.20/0.15/0.15/0.15/0.15)
- Each SubPattern includes instruction, examples, distractor rules
- Satisfies TaskTypeStrategy Protocol without extending BaseTaskTypeStrategy
- 32 unit tests covering all properties, definitions, and selection behavior
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com >
2026-07-14 06:49:03 -04:00
iomgaa
b9616de21e
fix(tests): update test_generator_v2 to use new generator signatures
...
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com >
2026-07-14 05:55:08 -04:00
iomgaa
afa77173e3
refactor(question_gen): adapt generator/gates/store signatures for strategy
...
- generator_v2: _load_prompt_template takes template_name str instead of
QuestionFamilySpec; _build_v2_prompt takes prompt_template + strategy_name
+ sub_pattern_instruction; generate_one_v2 takes discrete params
(prompt_template, strategy_name, skill_target, sub_pattern_instruction)
- gates: _gate_leak_test and run_gates take leak_probe_template str
instead of QuestionFamilySpec
- run_store: add sub_pattern column to DDL + idempotent migration;
record_item accepts optional sub_pattern param
- Remove QuestionFamilySpec imports from generator_v2 and gates modules
- Update test call sites accordingly
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com >
2026-07-14 05:50:47 -04:00
iomgaa
c49d0ff12f
fix(sampler): validate level param rejects invalid values
...
Add ValueError guard at the top of sample_material_v2 for level not in
{1, 2, 3}, preventing silent fallthrough to L1 sampling. Add unit test
for the new validation.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com >
2026-07-14 05:43:28 -04:00
iomgaa
e2325b6535
refactor(sampler): replace family_spec param with level+constraint
...
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com >
2026-07-14 05:38:14 -04:00
iomgaa
b6b6a48503
feat(question_gen): add TaskTypeStrategy Protocol and BaseTaskTypeStrategy
...
- TaskTypeStrategy Protocol: pipeline 的唯一接口,定义 task_type、
sampling_level、sampling_constraint、prompt_template 等属性
- SubPattern frozen dataclass: 出题子模式,靶向特定失败机制
- BaseTaskTypeStrategy: 封装现有 QuestionFamilySpec 行为的默认策略,
所有属性委托给绑定的 family
- _TASK_TYPE_TO_FAMILY: 消歧绑定表,12 个题型确定性绑定到 1 个 family
- register_strategy/get_strategy: 注册表 API,未注册题型自动创建
BaseTaskTypeStrategy
- 13 个单元测试全部通过
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com >
2026-07-14 05:24:29 -04:00
iomgaa
dec7346da3
feat(harness): add Action Recognition training experiment
...
- PerCategoryPoolStrategy: filter test pool by task_types
- RunConfig: add run_holdout_eval toggle (default true)
- load_config: fix YAML task_types list-to-tuple conversion
- Runner: conditionally skip _holdout_four_way when disabled
- CLI: add --no-run-holdout-eval flag
- New config/train_action_recognition.yaml (3 epochs, per_category)
- New scripts/train_action_recognition.sh (baseline + seed + train)
2026-07-14 00:58:54 -04:00
iomgaa
c66a00c924
feat(harness): refactor build_or_load_pools to accept PoolStrategy + per_category freeze format
...
- save_pools: extended with split_mode and config params; per_category
mode writes categories metadata (seed, train_ratio, test_source) for
incremental append and consistency validation
- load_pools: compatible with both old format (no split_mode) and new
format; extra metadata fields ignored during load
- build_or_load_pools: signature changed to (config, strategy, db_path);
baseline_run_id read from seed.json (not config.run_id); per_category
mode does consistency check on reload and supports incremental category
append via strategy.build_incremental
- Added _to_pool_config, _read_baseline_run_id,
_validate_per_category_consistency helpers
- Tests: TestPerCategorySaveLoad with 5 test cases covering roundtrip,
missing config error, global split_mode field, legacy format compat,
multi-type categories
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com >
2026-07-12 22:53:19 -04:00
iomgaa
e5b07ac974
feat(harness): add task_types, pool_split_mode, train_ratio, test_questions to RunConfig
...
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com >
2026-07-12 22:46:28 -04:00
iomgaa
73ae1f7143
fix(harness): change _runs INSERT OR IGNORE to ON CONFLICT DO UPDATE for incremental infer
...
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com >
2026-07-12 22:45:18 -04:00
iomgaa
21c6a53aed
feat(harness): add PerCategoryPoolStrategy with correctness-stratified 2:1 split
...
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com >
2026-07-12 22:41:48 -04:00
iomgaa
cd5c9c01fb
feat(app): add PoolStrategy Protocol to application ports
2026-07-12 22:34:47 -04:00
iomgaa
0d0f275134
feat(core): add PoolConfig dataclass for pool strategy configuration
2026-07-12 22:33:49 -04:00
iomgaa
4fb7a61f8b
fix(question_gen): resolve pipeline integration issues from final review
...
1. Apply postprocess shuffle result (pp.options, pp.answer) to final
GeneratedQuestion output instead of using original candidate values.
2. Record dedup rejection in store via new mark_item_rejected() method,
preventing items from staying as 'accepted' after dedup rejects them.
3. Add .flatten() to embed_fn outputs in _is_duplicate and embed_pool
append to handle 2D (1,D) arrays from embedding implementations.
4. Validate exactly 4 options in _validate_parsed_fields (was >= 2),
matching the A-D answer constraint.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com >
2026-07-12 00:14:12 -04:00
iomgaa
eecb86e27a
feat(question_gen): add generate-v2 CLI subcommand and experiment script
...
- Add generate-v2 subparser with --config, --store-dir, --db-path,
--seed, and --dry-run arguments to tools/generate_questions.py
- Implement _run_generate_v2 async handler: config loading, video
discovery, DI client construction, TreeIndex loading, pipeline
invocation, and result persistence
- Add scripts/generate_questions_v2.sh following build_trees.sh
conventions (source .env, conda run python path, MODE=mock support)
- Update app/question_gen/__init__.py to export full v2 public API:
run_pipeline_v2, PipelineConfig, PipelineResult, QuestionFamilySpec,
ALL_FAMILIES, CandidateQuestion, generate_one_v2, GateReport, run_gates
- Add QuestionGenStore.load_progress() for pipeline resumption
- Add integration tests for CLI help and dry-run behavior
- Update test_question_gen_api to match expanded __all__
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com >
2026-07-12 00:04:42 -04:00
iomgaa
cf51d2de9d
feat(question_gen): add v2 generator with per-family prompt templates
...
Implement generator_v2.py with:
- CandidateQuestion dataclass (canonical location)
- _load_prompt_template: loads per-family .md from store/prompts/
- _build_v2_prompt: constructs system+user messages with material context
- _parse_v2_response: JSON extraction, json_repair, field validation
- generate_one_v2: async VLM call orchestration with reject_reason support
Add 5 family-specific prompt templates:
- retrieval.md: factual recall from visible content
- reasoning.md: multi-hop inference across segments
- enumeration.md: counting/listing entities and actions
- visual.md: visual details requiring frame observation
- spatial.md: spatial relationships between objects/people
Tests: 11 unit tests covering prompt build, parse, and e2e generation.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com >
2026-07-11 23:41:36 -04:00
iomgaa
9053233f99
fix(question_gen): gates reject_reason returns raw reason; short-circuit skips LLM
...
- GateReport.reject_reason now returns gate.reason directly (no [name] prefix)
- verbatim short-circuit sets other 3 gates to SKIP without calling LLM
- test_high_verbatim_shortcircuits asserts zero LLM calls and SKIP verdicts
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com >
2026-07-11 23:33:57 -04:00
iomgaa
f74711cd11
feat(question_gen): add v2 material sampler with family constraints
...
Implement sample_material_v2 module that samples tree nodes with
QuestionFamilySpec-aware constraint validation, providing richer
MaterialContext output (subtitles, cross-L2 context, frame paths).
Key components:
- AnchorContext/MaterialContext frozen dataclasses
- _validate_sampling_constraints: multi-level constraint checking
- _collect_subtitle_sentences: subtree subtitle extraction
- _collect_cross_l2_context: peer L2 event descriptions
- sample_material_v2: main entry with retry-on-constraint-violation
Tests: 11 unit tests covering normal sampling, used-node exclusion,
constraint violation retries, cross-L2 population, and subtitle
collection.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com >
2026-07-11 23:30:56 -04:00
iomgaa
271d1682c9
feat(question_gen): add lightweight 4-gate quality check
...
Implement 4 concurrent LLM-based quality gates for generated questions:
- key_verify: validates answer evidence in source material
- blind_answer: rejects questions answerable without video context
- multi_true: detects ambiguous multi-correct options
- leak_test: per-family shortcut detection (5 probe templates)
Includes run_gates orchestrator with verbatim_ratio short-circuit,
JSON response parsing with fallback, and 9 unit tests (all passing).
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com >
2026-07-11 23:30:13 -04:00
iomgaa
9627ac9cf9
fix(question_gen): raise ValueError on UPDATE of missing rows
...
record_run_end, update_gates, and update_difficulty now check
cursor.rowcount after UPDATE+commit and raise ValueError if 0 rows
were affected. Prevents silent telemetry loss.
Adds three negative-path tests:
- test_record_run_end_missing_run_raises
- test_update_gates_missing_item_raises
- test_update_difficulty_missing_item_raises
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com >
2026-07-11 23:23:48 -04:00
iomgaa
7abe92eb1c
fix(question_gen): check_verbatim covers question_text + add missing blacklist patterns
...
- check_verbatim now computes n-gram overlap for BOTH question_text and
correct_option vs source texts, returning max(question_ratio, option_ratio).
Extracted _ngram_overlap_ratio helper for reuse.
- Added 4 missing blacklist patterns: 'this segment', 'this frame',
'the current frame', 'frame summary'.
- Added 5 new test cases covering the above changes.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com >
2026-07-11 23:23:37 -04:00
iomgaa
6a5424a618
feat(question_gen): add SQLite run store for generation telemetry
...
Implements QuestionGenStore with:
- Idempotent schema initialization (question_gen_runs + question_gen_items)
- Run lifecycle: record_run_start / record_run_end / get_run_stats
- Per-item recording: record_item / update_gates / update_difficulty
- GateReportLike Protocol for duck-type gate report compatibility
- WAL mode + foreign keys + check_same_thread=False
DDL aligns with research-wiki/schemas/question-gen-{runs,items}.md.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com >
2026-07-11 23:15:53 -04:00
iomgaa
c83d771923
feat(question_gen): add deterministic postprocess layer
...
Add app/question_gen/postprocess.py with zero-LLM deterministic
post-processing for generated questions:
- shuffle_options: deterministic option permutation with answer remapping
- check_referent_blacklist: detect self-referential language (this clip, etc.)
- check_verbatim: word-level n-gram overlap ratio measurement
- has_time_anchor: timestamp and temporal phrase detection
- check_forbidden_material: T1/T7 source material validation
- run_postprocess: orchestration returning PostprocessResult
Tests: 31 unit tests covering all functions.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com >
2026-07-11 23:14:43 -04:00
iomgaa
75e6d8c550
feat(question_gen): add 5 question family specs with sampling constraints
...
Define QuestionFamilySpec, LeakTestProfile, SamplingConstraint dataclasses
and instantiate 5 families (RETRIEVAL/REASONING/ENUMERATION/VISUAL/SPATIAL)
targeting failure mechanisms M1-M5. Implement get_family_for_slot with
legal-type filtering + weighted random selection.
13 unit tests cover: full task-type coverage, skill_target uniqueness,
deterministic seeding, invalid input errors, and chi-square distribution.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com >
2026-07-11 23:14:22 -04:00
iomgaa
811ffa648b
feat(types): extend GeneratedQuestion with skill_target & difficulty_steps
...
- Add skill_target (str | None) and difficulty_steps (int | None) fields
to GeneratedQuestion dataclass with field(default=None)
- Update loader.py to pass new fields from JSON (backward-compatible)
- Update pools.py _q_to_dict/_dict_to_q for serialization compat
- Add question_gen_v2 config section to default.yaml
- Add comprehensive test coverage (7 tests)
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com >
2026-07-11 23:05:38 -04:00
iomgaa
56fe138a46
feat(tools): batch tree build orchestration with shared API semaphore
2026-07-11 11:56:36 -04:00
iomgaa
978ddef91b
feat(tools): add build_trees skeleton with discovery helpers
2026-07-11 11:41:22 -04:00
iomgaa
e9073bfdc2
feat(tree): expose build_async and accept injected API semaphore
...
Core algorithms #1/#2/#3 unchanged: only entry wrapping and semaphore
source switch (injected vs self-built); build logic untouched.
- rename _build_async to public build_async (body unchanged)
- __init__ accepts keyword-only api_semaphore for cross-video sharing
- default path (no injection) is verbatim-equivalent to previous code
2026-07-11 11:14:45 -04:00
iomgaa
1c21e215e2
test(tree): cover L1 entity fields and block ordering in view_node
2026-07-11 09:02:03 -04:00
iomgaa
4e0e05210d
feat(search): append raw entity fields after view_node summary
...
view_node 按题两轮摘要(summarize_node)会吞掉 entities/visible_text
字段信号,Agent 站在证据节点上仍漏读实体(benchmark 错题 M1,案例
786-2、872-3、750-1)。dispatcher 侧在摘要后确定性追加 [实体]/[画面
文字] 原文区块,LLM 无法吞掉。
- TreeEnvironment.node_entity_fields:按层级取 card 实体字段原文,
去空白、去重、分号拼接;空字段省键;未知节点抛 KeyError
- _handle_view_node Phase 2.5:摘要后、子节点概览前追加实体区块
- 附带 ruff format 修正 test_tree_environment.py 两处既有格式
算法 #11(树环境语义搜索)数据访问层扩展,不改搜索算法本身。
2026-07-11 08:53:56 -04:00
iomgaa
291a8108e1
test(agent): tighten type annotations in step-retry tests
2026-07-11 08:48:04 -04:00
iomgaa
badfcce4cb
fix(agent): validate non-empty retry delays; pin exhaustion semantics
...
核心算法 #10(Agent Loop):Codex 质量审查跟进,仅加固防御与
可观测,不改变循环语义。
- __init__ 校验 step_retry_delays 非空,空序列直接抛 ValueError
(P5 fail-fast,避免首次可重试异常时 IndexError 掩盖原始 LLM
异常、违背方法契约)
- 补耗尽语义窄测试(耗尽后原样抛出最后一次原始异常)与空序列
构造校验测试
- run() 最终失败日志补异常类型名,便于回溯归因
2026-07-11 08:44:47 -04:00
iomgaa
e3184c11f9
feat(agent): step-level retry for transient LLM errors (20s/40s backoff)
...
核心算法 #10(Agent Loop):仅加固异常路径的韧性兜底,不改变
解析协议、hook 时序与步数语义。benchmark 错题 796-3 显示一次
SSL BAD_RECORD_MAC 穿透 GovernedLLMClient 重试栈后废掉 13 步
已积累上下文;本次在 run() Phase 1 增加步级重试(默认 2 次,
20s/40s 退避),可重试异常限定 (TimeoutError, OSError),非可
重试异常照旧 fail-fast 整题终止,行为与现状一致(P5 显式异常)。
为满足 radon C 级复杂度约束,重试循环抽取为私有方法
_call_llm_with_step_retry,行为不变。
2026-07-11 08:37:35 -04:00
iomgaa
cf529f2c8f
test(agent): add docstring to empty-content boundary test
2026-07-11 08:33:36 -04:00
iomgaa
439dc29b3b
fix(agent): reject argless action in normalization; add boundary test
...
核心算法 #10(Agent Loop):修复 Codex 质量审查 Critical——
_normalize_action 仅在除 tool 外至少存在一个平铺参数键时才收拢,
{"tool": "x"} 无参结构不再被静默升级为空 args 合法结构,照旧
返回 None 走 retry 追问路径。补边界测试 + 测试辅助方法类型注解
与中文 docstring。
2026-07-11 08:28:59 -04:00
iomgaa
6034d4172d
test(question_gen): update __all__ assertion to include synthesizer exports
2026-07-11 08:21:06 -04:00
iomgaa
a31b1fbf37
test(question_gen): drop tests for removed calibrate pairing validator
2026-07-11 08:19:45 -04:00
iomgaa
8d84d5e236
fix(agent): normalize fenced and flat-args LLM outputs in parser
...
核心算法 #10(Agent Loop):仅加固 _parse_response 解析路径——
剥除 ```json 围栏 + 收拢 action 平铺参数(deepseek 稳定输出变体,
案例 637-3/615-3 三连拒 0 步阵亡)。Thinking+JSON 协议、json_repair
兜底链、hook 时序与步数语义均未改动。
2026-07-11 08:16:28 -04:00
iomgaa
ba400417e2
config: concurrency=24, max_steps=40, breaker_threshold=48
...
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com >
2026-07-09 12:27:05 -04:00
iomgaa
a7ca6d15ed
feat(harness): InferenceDepsRouter per-video 路由器
...
按 video_id 懒加载 InferenceDeps 并缓存,路由 dispatch/prompt_builder:
- create_dispatch: 按 session_id 路由到对应视频的工具调度
- create_prompt_builder: 自动注册 qid→vid 映射并路由 prompt 构建
- 三元组 (video_id, skills_dir, prompts_dir) 缓存键
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com >
2026-07-09 12:20:32 -04:00
iomgaa
f21bf345a6
feat(runner): 注入 tool_dispatch_factory/prompt_builder_factory + fail-fast
...
Runner.__init__ 新增 2 个可选参数:
- tool_dispatch_factory: 工具调度工厂
- prompt_builder_factory: prompt 构建工厂
infer/eval/train 模式缺少工厂时 fail-fast 抛 ValueError。
_make_tool_dispatch_fn/_make_prompt_builder 优先使用注入工厂。
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com >
2026-07-09 12:20:25 -04:00
iomgaa
924160c779
feat(ports): 新增 ToolDispatchFactory/PromptBuilderFactory Protocol
...
4 个新 Protocol 类型:
- ToolDispatchFn: 工具调度函数签名
- ToolDispatchFactory: per-version 工具调度工厂
- PromptBuilderFn: Prompt 构建函数签名
- PromptBuilderFactory: per-version prompt 构建工厂
含 runtime_checkable isinstance 测试。
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com >
2026-07-09 12:20:16 -04:00
iomgaa
d3be9b1322
refactor(tree): subtitle 迁入 L3Card/L2Card + 建树管线修正
...
- L3Card/L2Card 新增 subtitle: str 字段(L1Card 不加)
- L3Node 移除 subtitle 字段(数据迁入 Card)
- assign_subtitles_voronoi 改写 Card.subtitle + L2 聚合
- _collect_card_strings 增加 skip_fields 排除 subtitle
- _node_full_text/_node_anchored_text 保持 字幕:/[sN] 语义
- get_subtitle 读 Card.subtitle(L2/L3)
- verify.py/synthesizer.py: l3.subtitle → l3.card.subtitle
- 迁移脚本 tools/migrate_subtitle_to_card.py(幂等,300 棵树已迁移)
- 9→6 个测试文件适配(3 个无需改动)
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com >
2026-07-09 11:57:41 -04:00
iomgaa
45403b23b4
feat(repair): regenerator + supplement 防御修复 + 迁移脚本
...
- 新增 app/tree/repair/regenerator.py(VLM 重生成 + 级联修复)
- supplement.py: deduplicate_field str() 防御 + inject_value strip
- patch.py: ruff format 格式化
- repair_trees.sh: conda source 激活修复
- 新增 migrate_from_trm4.sh 迁移工具
- enhance/__init__.py → repair/__init__.py 重命名
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com >
2026-07-09 07:53:59 -04:00
iomgaa
f57ee45dc0
fix: Codex 全量审查修正
...
Critical:
- C1: assemble_mode 'plain' → 'ids'(合法枚举值)
- C2: question_id 加入 task_type slug 避免跨题型冲突
Important/Minor:
- generate_one 移除未用的 embed_fn/similarity_threshold 参数
- config.py 注释 11→12 同步
- 测试 question_id 断言更新
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com >
2026-07-09 07:40:27 -04:00
iomgaa
93c9be8bfa
feat(tools): generate_questions.py calibrate 子命令
...
- Fisher exact test + effect size 组合判定(PASS/WARN/FAIL)
- 按 video_id 分组推理,避免跨视频树错用
- baseline 支持从 DB 读取或自动跑推理
- 对比表输出 + 退出码控制
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com >
2026-07-09 05:47:52 -04:00
iomgaa
11f3c90200
feat(tools): generate_questions.py generate 子命令
...
- VLM 出题 + embedding 去重 + 断点续跑 + 并发控制
- 单线程汇总点保证去重原子性
- 18 个单元测试覆盖 progress/exemplar/pool rebuild/JSON append
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com >
2026-07-09 05:42:50 -04:00