Repository navigation
refactor(quota): share context references across existing quota and Turn readers - #7457
loopx-agent wants to merge 3 commits into
Conversation
Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>
Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>
Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>
loopx-agent
left a comment
There was a problem hiding this comment.
Reviewer: model_agent; runtime_reported; gpt-6.1-sol; OpenAI; reasoning_effort=max
Approval conclusion (author-owned PR; GitHub blocks formal self-approval)
动机 / Motivation
使用普通 quota CLI、捕获后的重规划入口及 TurnEnvelope 的 Agent,会反复读取同一任务正文和 Explore 结果指导。同一份完整说明在任务源、操作摘要和结算附件中重复出现时,原 Python 入口自行选择可引用的副本,TypeScript 读者另行搬运上下文;以后修改同一规则需要同时核对两处。本版让普通入口实际调用同一个 typed owner,并在读者搬运上下文前恢复完整指导。普通 CLI 已实际采用共享实现;同一冻结输入的十八份投影或公开 reader 输出与旧版完全相等,原任务正文、负证据和结算身份均保留。这是已被调用的内部前置切片;不宣称完成 C1 的统一 producer/consumer 切换,也不宣称减少模型 token、入口延迟或长期费用。C1 的完整 schema、各最终 Host 输入、writer 切换和旧 reader 退出仍由原 C1 工作承接;本 PR 不将这些未验项目标为完成。
这里的 owner 指负责解释规则的唯一实现,引用只是同一捕获内对原文的定位。实用增量在于以后修改同一引用规则时只维护一处,同时已有普通入口立即采用;完整源和原结算继续由既有 owner 负责。未发现 blocking finding,下面的批准只针对这个已采用切片。
改动思路 / Approach
同一引用规则归现有 TypeScript owner,Python 仅保留显示整理和一次传输;没有新增 authority、配置或持久状态。当前交付是普通 quota CLI 已采用的引用 owner 与完整读者恢复,C1 切换及实际模型收益保持在原后续验收。
普通 CLI 完成原决策后,compact_quota_should_run_cli_payload 调用一次既有 TypeScript 事务通道;Task 详情与 vision 详情分别控制两种引用,两者都显式展开或没有 source carrier 时跳过。原来只省略重复显示标签的 Python 逻辑仍留在显示层,不参与权威源匹配。
| 规则 | 旧路径 | 当前 head |
|---|---|---|
| Task 标题引用 | Python 选择完整当前 Task 的相同正文 | TS currentTaskTitleOwner/referenceCurrentTaskTitle;要求完整、唯一、已匹配且非 done/archive,按 Unicode code point 保持原阈值。 |
| Explore 指导引用 | Python 查找相同结算附件文本 | TS referenceExploreGuidance;仅 exact-text 同 packet 的 inline durable-writeback Explore owner,短文或不同文不引用。 |
| 完整读者 | TS 各自搬运上下文 | resolveExploreGuidance 先恢复原文,再交原 replanWorkContext;坏引用明确拒绝。 |
这是源码导出的归属表,不当作执行证据。真实执行证据见后文。通用完整性约束归原 typed owner,Python 保留 IO;Explore optional attachment 仍是可选能力,既有结算和 required validation 不变。仓库 #5944 经验适用于核对“是否有实际调用者和有用结果”,不要求这个内部前置 PR 交付整个父路线图或凭回执宣称模型收益。
具体改动 / Changes
审查完整 head 56559929aad42dc86df8b0035092595a48ba0ac8,不可变 base 71057d44f0d50a3636fcd8796f7c98717ce41742,共七条路径、+339/-87:生产 +113/-83、测试 +182/-1、文档 +44/-3,无生成文件或新模块。删除 Python 两段匹配算法,在原 TS 文件加入共享匹配/恢复,并改接实际 caller;新增181行用例覆盖同源/不同源、短文、Unicode、多 owner、坏引用和详情分支。另一测试只补齐原有 status=tentative 必填夹具,使它真正到达原本要验证的缺 Todo 身份拒绝,未放松产品要求。
规范依据:完整阅读 不可变 controller/executor RFC、同版本 compaction 协议,并核对现有整体路线图 S2/S6/S7 的完整来源、单 owner 和成本边界。spec_revision=71057d44f0d50a3636fcd8796f7c98717ce41742。各 criterion_id 的本 head 处置:
| criterion_id | 处置 |
|---|---|
| §5 one complete work contract | deferred:完整 producer/final Host/cutover 不在本 PR,由原 C1 承接,未宣称完成。 |
| §5 typed owner and full requirements | implemented:现有 TS owner,普通 CLI 实际采用,完整 Task/证据保留。 |
| §7 recovery and authority | implemented(本切片):原 source、Task/Turn、可执行结算与 once-only 读回保持;无新执行权。 |
| §8 full-first and differential context | implemented(引用边界):精确同 capture、恢复前校验、源不变及负例成立;不代表整个差分系统新资格。 |
| §9 matched outcomes and full cost | deferred:实际 Host/模型/完整费用和受控延迟未验,不把字节或测试数算收益。 |
| §11 implementation and first cutover | implemented(阶段说明):双语把可用前置与 first cutover 区分,首次切换仍需 producer+consumer 资格,不将 serializer/存活状态算完成。 |
关键代码讲解
cli_projection.py:770::_reference_context只做 carrier/详情选择并调用原 transport,不复制“哪个 source 合法”的业务判断。适用普通投影新增一次粗粒度 bridge 调用,这有序列化成本,不能宣称提速。turn_envelope.ts:275::currentTaskTitleOwner/referenceCurrentTaskTitle绑定 selected Todo 与唯一完整 source;只给相同 text/title 建别名,保留历史 caller-owned reference。Array.from(JSON.stringify(title)).length避免 emoji 被 UTF-16 双计,匹配旧 Python 字符阈值。turn_envelope.ts:244::referenceExploreGuidance比较的是完整相同字符串;不同 owner 文本、短指导、缺附件和非 Explore source 保留 inline。它不把“可发现”当启用、不推导用户意图,也不新建 state。turn_envelope.ts:222::resolveExploreGuidance检查结构化路径必须指向 inline durable-writeback Explore 附件,拒绝悬空/错 step/错 capability/chain/inline+ref。对象经过复制,删除 alias 不修改原输入;完整 reader 在搬运 source 前恢复原文,保持测量反馈、负证据和原结算。
对主干的风险 / Risks
没有当前 blocking finding。 最强风险是引用搬运后丢掉执行前义务,或为了减少重复文字而扩大权限/删除未知。本次逐条核对了原 Task 完整正文、先读 measurement_feedback、保持原 task lease 到 refresh、raw logs 留本地、capture optional、实际被评价 candidate/版本范围、负证据/unknown、原 validation→writeback→spend 顺序和原 Task/Turn 绑定;不是只比 reason、schema 或大小。它们在同源别名与恢复后保持原文。六种显式非法引用拒绝,短文/不同文/无 owner 保留 inline;done/archive/不完整/歧义 Task 不借摘要伪造完整源。
PASS:独立运行145项相关 Python、73项 TypeScript、control-plane typecheck、改动 Python Ruff;标准 premerge 6 direct + 17 selected 全过、零 manual hold,包含双语 RFC、semantic/maintainability/public-boundary。最终七路径 CQR cqr_a1f680f99f458f97b12c 为 PASS,物理规范回执在首次公开结论前完整读取。
真实路径比较:同一私有合成 harness 在固定旧 base 和当前 head 各运行10个 File/SQLite CLI 场景,覆盖 Explore off/on、显式 detail、捕获 replan 与 envelope,原 Task/claim/status、full source 和 settlement identity 保留,未新增 Spend。另把同十份冻结完整 capture 交给两版实际 CLI projection dispatcher 和每版8次公开 quota replan-view:共18份可比完整输出逐字段/字节相等,没有任何规范化。独立 native fixture 路径和时钟不同,完整 fingerprint 分别保留,不把它们冒作逐字相同。
回归敏感性:在真实 CLI projection seam 刻意删掉完整 Explore guidance/ref,两种真实后端均被原 full-graph oracle 抓住;正常 head 十例通过。另8个真实 CLI 反事实只改投影输入、保持 authority 决策不变:去重复 inline 副本而保留合法同源引用、加入80条无关 source、倒转其显示顺序、标明 carrier 不完整,均保留完整 Task/图中义务、负证据、原身份和零额外扣额。这些 seam 变异不冒充 storage 故障或真实模型执行。done/archive title 属显示资格,未改生命周期或授权 gate,已有相关测试保持 inline。
补充探针的早期失败已保留并归因:多行文本被既有 CLI 空白规范化、未先进入原重规划准入、误以为 replan packet 必有 selected-Todo source,以及把文件字节 SHA 当 typed canonical JSON hash;还有一次把只返回 review/writeback 数据的公开 reader 当作 work_context reader。更正夹具/读取方式后使用当前完整对照,未删除产品断言或把这些探针错误归为 PR 缺陷。没有查询或等待 GitHub CI。原 PG authority/schema/writer 未改,此处不新宣称 PG qualification;完整仓库、最大 packet/持续负载、正式安装 Host 与模型行为未新验。
语义与 CI 对齐
复用现有 *_ref 词汇与 TypeScript transaction owner;reference_context 是现有通道的本地 operation,不是新 actor/权限协议。regex 只校验结构化 JSON 路径,不按自然语言 substring 决定业务状态。Explore 关闭的两份完整冻结输出与旧版完全相等,整个 shared builder 的 schema/指导/原决策/身份都核对过,不能仅靠“没有 feature object”推断隔离。没有默认开启新能力或新增机器义务;optional 指导与 enforced bad-reference refusal 分开。RFC 阶段文字是明确提案修订,父级 C1 与 matched-cost 资格仍保留。
我的整体评价 / Verdict
这是 justified_increment,完整源及可恢复引用在现有入口实际采用,long_horizon 与 user_experience 均为 preserved;局部维护收益来自删除重复决策,不从测试数、字节、单次耗时推长期效果。同一引用规则归现有 TypeScript owner,Python 仅保留显示整理和一次传输;没有新增 authority、配置或持久状态。当前交付是普通 quota CLI 已采用的引用 owner 与完整读者恢复,C1 切换及实际模型收益保持在原后续验收。
代码量为 bounded 的原 owner 扩展,没有新模块、设置或用户操作轮次;保留真实 full capture/原 reader 的兼容义务,未来 producer cutover 继续由原 C1 验收。额外 bridge 序列化、最大输入和完整性能/费用是明确未验边界;PR 也未作提速或 token 节省承诺。visual_review=not_applicable:七路径没有 rendered UI,相关视觉未验范围为 none;安装和实际模型采用仍未资格。
English verdict: APPROVE at 5655992: the ordinary CLI adopts the existing typed reference owner, full instruction/identity semantics survive native and identical-input comparisons, and required local checks pass. This qualifies the bounded prerequisite only; full C1 cutover, installed Host/model adoption and performance/cost benefit remain unverified.
Quota context sharing currently owns exact Task-title and Explore-guidance rules in Python while Turn/replan readers relocate the same context in TypeScript. A same-response Explore reference can therefore outlive the path it points to when a reader moves the context.
This PR routes the existing quota callers through one coarse call to the existing TypeScript owner and restores referenced guidance before Turn/replan relocation. It removes the duplicate Python algorithms while retaining current quota/Turn schemas and entrypoints. It is an independently usable prerequisite for #7430; the complete-contract producer/consumer cutover remains there. The paired controller RFC now distinguishes an acceptance target from a mandatory single PR.
Behavior and boundaries
Validation
loopx checkpassed; public-boundary scan clean for all seven changed files. Diff-scoped semantic advisory found no supported new closed-vocabulary carriers; this is not proof of semantic parity.tentative, allowing its intended missing-settlement-identity refusal to be tested; product validation was not weakened. An initial global-registry check reported an unrelated unmigrated Goal; the explicit project-scoped check passed.Cost evidence and limits
A controlled warm projection experiment rotates three arms over the same synthetic 26.9/32.7/86.7 KB inputs (60 samples each): original base Python, the prior two-call shape, and the new one-call shape. The two-call arm uses the prior Python caller with its internal operation names mapped to the same current TypeScript owner; this isolates call count and is not a full-revision comparison. All outputs are exactly equal and inputs remain unchanged.
With the existing CLI request scope already resolved, median projection times are:
The intervention reduces this added projection cost by about 46–47%, but remains slower than the original Python projection. Direct calls outside a request scope also repeat runtime source fingerprinting and have materially higher, variable costs. An earlier post-change run overlapped tests and is excluded from the controlled comparison; profiler sampling cannot attribute child-process CPU. These are synthetic component timings, not default-provider CLI latency, model token/quality results, or complete-cost qualification. Raw packets/profiles stay private. No performance budget or acceptance criterion is relaxed.
No packaged/installed adoption, model-effectiveness comparison or complete-cost measurement is claimed. This changes existing internal composition and recovery, not a new frontend journey. CI and independent review remain pending.