Skip to content

SW-06 接线休眠模块:assembler P2-P4 进 p3/p5、compress_history 进 p3 远端历史(ADR-0018) - #14

Merged
randypanding merged 1 commit into
mainfrom
sw/sw-06-context-wiring
Aug 22, 2026
Merged

SW-06 接线休眠模块:assembler P2-P4 进 p3/p5、compress_history 进 p3 远端历史(ADR-0018)#14
randypanding merged 1 commit into
mainfrom
sw/sw-06-context-wiring

Conversation

@randypanding

Copy link
Copy Markdown
Owner

这个 PR 改的是哪一层?(必选其一)

  • A 资产层spec/ profiles/ brands/ cases/export/)→ 必须打标签 asset-change 并附 ADR
  • B 生成物层src/ tests/)→ 无需 ADR
  • 文档 / CI

ADR: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 远端历史永远原文透传。

改动

  1. P2-P4 接入 p3/p5nsc.passes.assemble_context 统一入口):
    • p3:P1=episode_json 锚;P2=前情窗口文本;P3=known_facts;P4=retrieved;P5=bible/profile(低保)
    • p5:P1=scene+beats 锚;P4=retrieved;P5=characters/profile
    • 降级序 = assembler 既定语义(P4 整层丢 → P2 截尾 → P3 前缀截断 → P5 低保 400)
  2. compress_history 接入pipeline._history_text):context.history_compress: true 且窗口 > keep_recent 时,远端集经 make_llm_summarizer(LLM 走 models 路由)压成【前情】,近端保原文【上一集】;run_pipeline 与 recompile 两路同享
  3. ContextSettingsbudget/core_guarantee/history_compress/history_keep_recent/history_compress_ratio(缺省 32768/400/false/1/0.1)

缺省零变化(设计约束)

  • budget=32768 → 全存活,p3/p5 输入逐字节同接线前(golden 快照测试守护)
  • history_compress=false → 零压缩 LLM 调用;不开开关时输出带【前情】标记会改变缺省 prompt 字节(缓存键漂移),故压缩必须显式开

偏差记录

卡面称"profile 的 context.* 配置段已存在"——该段在 origin/main 不存在(只在 delivery/30ep-song-hotel 分支);本卡在 SW-05 新建的 context 段上扩容,字段名对齐 delivery 分支 T-33 设计。

验收命令(贴出你本地跑通的输出)

uv run pytest tests/test_context_wiring.py -q    # 5 passed
uv run ruff format --check . && uv run ruff check .   # All checks passed
uv run pyright    # 0 errors
两个 profile 过 _schema 验证 / make spec-guard 六项   # 全 OK
uv run pytest -m "not llm" -n auto   # 531 passed, 1 failed(test_db_export_fresh,本机未提交 cases.db 现场所致,干净 worktree 通过)

检查表

  • 测试先红后绿(4 例先红:assemble_context 缺失 / _budgeted_inputs 缺失 / 压缩未接线;1 例缺省零压缩是守护用例)
  • 没有在 Python 里写业务规则(预算/低保额/压缩比全在 profile;降级序是 assembler 既定机制)
  • 未新增 check 规则(不适用)
  • 没有手改 prompts/
  • 手写行数仍在预算内(src 净增 ~95 行;context 模块未动)
  • 未改 IR
  • 未改 rubric

影响生成结果吗?

  • 否(缺省零变化;profile 显式调低 budget 或开 history_compress 才影响,届时 profile 版本进缓存键)

Copilot AI lite review requested due to automatic review settings August 21, 2026 21:33
@randypanding randypanding added the asset-change 改动 spec/profiles/brands,需 ADR + 人工 approve label Aug 21, 2026

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.

🟡 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_context and use it to budget/degrade p3 (P2–P5) and p5 (P4–P5) inputs.
  • Route p3 “far history” through compress_history when context.history_compress is enabled and the window exceeds history_keep_recent.
  • Introduce/extend ContextSettings in profiles/_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.

Comment thread src/nsc/passes/p3_beatsheet.py Outdated
Comment on lines +116 to +118
for _k in ("bible_json", "profile_json"):
if _k not in ref_keys:
inputs.pop(_k)

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

已修正(932a2a0):采纳保留键、置空值方案——_budgeted_inputs 对 bible_json/profile_json 超配额时不再 pop,改置空串;并把 p3 的装配块抽成与 p5 同形的 _budgeted_inputs(可单测)。回归 test_p3_degradation_keeps_keys

Comment on lines +85 to +89
out = {**inputs, "retrieved_cases": rag}
for _k in ("characters_json", "profile_json"):
if _k not in ref_keys:
out.pop(_k)
return out

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

已修正(932a2a0):同上——characters_json/profile_json 降级置空串、键保留;test_p5_budgeted_inputs 增加了"预算降级不得删除必填键"断言。

Comment thread src/nsc/passes/pipeline.py Outdated
Comment on lines +654 to +655
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)

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

该问题成立且已修复:本分支已 rebase 到 PR #13 的修正提交 10227b0_known_fact_fields_ofis None 判定,显式 known_fact_fields: [] 现在是合法空投影),review 看到的是 rebase 前的旧 commit。PR #13 内有对应回归断言。

@randypanding
randypanding force-pushed the sw/sw-06-context-wiring branch from a4b63c7 to 10227b0 Compare August 21, 2026 21:49
randypanding added a commit that referenced this pull request Aug 21, 2026
Copilot review(PR #14):
- p3/p5 参考层(bible/profile/characters_json)超配额时原实现 pop 掉键,
  而 signature 把它们声明为必填 InputField → 改为保留键、置空值
- p3 装配抽成 _budgeted_inputs(与 p5 同形,可单测)
- 回归:test_p3_degradation_keeps_keys + test_p5_budgeted_inputs 增键存在断言
- 第 3 条意见(known_fact_fields 空列表)已在 rebase 自 PR #1310227b0 修复
@randypanding

Copy link
Copy Markdown
Owner Author

关于 review 总结里"ADRs contain future dates":ADR-0017/0018 的日期 2026-08-22 即今日(本仓库时区),非未来日期,无需修正。其余三条意见已在 932a2a0 / rebase 10227b0 处理并逐条回复。

@randypanding
randypanding force-pushed the sw/sw-06-context-wiring branch from 932a2a0 to cfd3c4a Compare August 22, 2026 05:05
@randypanding
randypanding enabled auto-merge (squash) August 22, 2026 05:05
@randypanding
randypanding merged commit 330a700 into main Aug 22, 2026
10 checks passed
@randypanding
randypanding deleted the sw/sw-06-context-wiring branch August 22, 2026 05:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

asset-change 改动 spec/profiles/brands,需 ADR + 人工 approve

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants