SW-06 接线休眠模块:assembler P2-P4 进 p3/p5、compress_history 进 p3 远端历史(ADR-0018) - #14
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Budget-degradation currently removes required DSPy signature inputs (risking runtime failures) and ADRs contain future dates that should be corrected for traceability.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR wires the previously-implemented context budget assembler (nsc.context.assemble) and history compression (compress_history) into the p3/p5 pipeline inputs, controlled via new profile.context.* settings (documented in ADR-0017/0018) and guarded by targeted tests.
Changes:
- Add
nsc.passes.assemble_contextand use it to budget/degrade p3 (P2–P5) and p5 (P4–P5) inputs. - Route p3 “far history” through
compress_historywhencontext.history_compressis enabled and the window exceedshistory_keep_recent. - Introduce/extend
ContextSettingsinprofiles/_schema.py, update in-repo profiles with explicit defaults, and add tests for the new wiring/knobs.
File summaries
| File | Description |
|---|---|
| tests/test_p3_context_config.py | Tests SW-05 context knobs (known_facts projection, prev-summary window, threads injection). |
| tests/test_context_wiring.py | Tests SW-06 wiring: assembler budget behavior for p3/p5 and history compression routing. |
| src/nsc/passes/pipeline.py | Adds profile-driven context behavior: history windowing/compression, known_facts projection, threads injection. |
| src/nsc/passes/p5_dialogue.py | Applies budgeted input assembly to p5 dialogue inputs (retrieved + reference layers). |
| src/nsc/passes/p3_beatsheet.py | Applies budgeted input assembly to p3 inputs (prev summary, facts, retrieved, refs). |
| src/nsc/passes/init.py | Exposes assemble_context helper that bridges passes to nsc.context.assemble. |
| profiles/short_video_v1.yaml | Adds context defaults (SW-05/SW-06 knobs) for short_video profile. |
| profiles/short_drama_v1.yaml | Adds context defaults (SW-05/SW-06 knobs) for short_drama profile. |
| profiles/_schema.py | Adds ContextSettings (extra=forbid) and validates known_fact_fields whitelist; includes SW-06 budget/compress knobs. |
| adr/0018-context-wiring.md | Documents SW-06 wiring decisions and constraints for assembler + history compression. |
| adr/0017-p3-context-profile-section.md | Documents SW-05 profile.context knobs and their consumers. |
Review details
- Files reviewed: 11/11 changed files
- Comments generated: 3
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| for _k in ("bible_json", "profile_json"): | ||
| if _k not in ref_keys: | ||
| inputs.pop(_k) |
There was a problem hiding this comment.
已修正(932a2a0):采纳保留键、置空值方案——_budgeted_inputs 对 bible_json/profile_json 超配额时不再 pop,改置空串;并把 p3 的装配块抽成与 p5 同形的 _budgeted_inputs(可单测)。回归 test_p3_degradation_keeps_keys。
| out = {**inputs, "retrieved_cases": rag} | ||
| for _k in ("characters_json", "profile_json"): | ||
| if _k not in ref_keys: | ||
| out.pop(_k) | ||
| return out |
There was a problem hiding this comment.
已修正(932a2a0):同上——characters_json/profile_json 降级置空串、键保留;test_p5_budgeted_inputs 增加了"预算降级不得删除必填键"断言。
| wanted = profile.get("context", {}).get("known_fact_fields") or list(_KNOWN_FACT_FIELDS) | ||
| return tuple(k for k in _KNOWN_FACT_FIELDS if k in wanted) |
a4b63c7 to
10227b0
Compare
932a2a0 to
cfd3c4a
Compare
这个 PR 改的是哪一层?(必选其一)
spec/profiles/brands/cases/export/)→ 必须打标签asset-change并附 ADRsrc/tests/)→ 无需 ADRADR:adr/0018-context-wiring.md(status: proposed,含 profiles/_schema.py 变更,等确认)
⚠️ 分支说明:本卡基于 sw/sw-05-p3-context-config(PR #13)叠加——SW-06 复用 SW-05 的 context 段与窗口机制;请先合 #13,本 PR 的净增量是第二个提交(a4b63c7)。
工单
Closes # · 工单号:SW-06(上游依赖卡,Lab 仓 docs/WORK_ORDERS.md §上游依赖卡)
问题
nsc.context.assemble(T-33 预算装配)与compress_history(LLM 历史压缩)在 main 已实现未接线:没有任何 Pass 输入过预算装配,p3 远端历史永远原文透传。改动
nsc.passes.assemble_context统一入口):pipeline._history_text):context.history_compress: true且窗口 > keep_recent 时,远端集经make_llm_summarizer(LLM 走 models 路由)压成【前情】,近端保原文【上一集】;run_pipeline 与 recompile 两路同享ContextSettings增budget/core_guarantee/history_compress/history_keep_recent/history_compress_ratio(缺省 32768/400/false/1/0.1)缺省零变化(设计约束)
偏差记录
卡面称"profile 的 context.* 配置段已存在"——该段在 origin/main 不存在(只在 delivery/30ep-song-hotel 分支);本卡在 SW-05 新建的 context 段上扩容,字段名对齐 delivery 分支 T-33 设计。
验收命令(贴出你本地跑通的输出)
检查表
prompts/影响生成结果吗?