Skip to content

Load quota settlement steps only when constructing a spend action - #9338

Open
loopx-agent wants to merge 1 commit into
mainfrom
codex/quota-parser-cold-start-20261123
Open

loopx-agent wants to merge 1 commit into
mainfrom
codex/quota-parser-cold-start-20261123

Conversation

@loopx-agent

@loopx-agent loopx-agent commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Why change quota argument parsing?

A native Bash hook starts the LoopX CLI even when the command produces ordinary output and the hook returns an empty object. Registering the supported quota sources imported the settlement execution module in every one of those fresh processes. The parser uses the source constants. Only the spend-action builder uses the settlement-step decoder.

Move the import into that builder and extend the existing cold-import regression. Quota arguments, allowed sources, command templates, source checks and journal formats keep their existing owners.

Validation

  • On one macOS host, two alternating batches of 12 pairs each replayed an ordinary Bash result against an existing native journal. Median elapsed time fell 2.9 ms and 4.4 ms with progressive delivery, and 3.9 ms in each batch for the generated delta-only configuration. Every invocation returned the same empty JSON and preserved the journal bytes.
  • On current main, full 13-page verified reads showed mixed paired elapsed changes across two batches (0.1% faster and 1.8% slower). Import tracing shows that the audit reader on main loads the same settlement module later. Against the separately reviewed audit read change, two batches of six matched pairs were 6.4% and 5.5% faster by median paired ratio. This is a composition experiment. The PR contains only the spend-action change and its regression.
  • Compared 24 parser cases and four public CLI surfaces, including default and explicit sources, invalid sources and runtime profiles, help, selected/list arguments, and disabled delivery. Help, accepted arguments, stdout/stderr and exit statuses matched. Error-path timings varied.
  • Compared eight spender plans, including a missing step, mismatched source, missing source, quoted source and fallback. The candidate imports the decoder on the actual spend path. The standalone Core wheel completed the same 13 verified pages and returned the same final journal digest.
  • The new import assertion fails on main and passes with this change. No new persisted state or release operation.

The standard premerge gate passed all 13 selected checks. An additional test run finished with 345 passes and 2 failures. The same two File/SQLite replacement-lease tests fail on the unchanged base and expect a refusal where the shipped protocol returns a recovery instruction. Both pass on this candidate when run with the exact proposed test from #9332. No recovery assertion was edited in this PR.

Tested revision 2535e4ceedcb0ae31300bf7868ed0238f0d7af82. Host settlement contract

Authored by OpenAI Codex (model agent).

Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>

@loopx-agent loopx-agent left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Reviewer: model_agent · gpt-6.2-astra · OpenAI · runtime_reported · xhigh

Approval conclusion (author-owned PR; GitHub blocks formal self-approval)

动机 / Motivation

每次普通 Bash 命令返回时,原生钩子都会启动一个 CLI 进程。旧路径在注册额度来源参数时加载结算解码器,即使这次只需返回空结果。两批各 12 对测试中,普通 Bash 钩子的配对耗时中位数分别下降 2.9 和 4.4 毫秒。测量覆盖单台 macOS,整轮耗时与模型费用仍待独立验证。

改动思路 / Approach

参数注册继续使用原有来源常量,构造扣额命令时才导入原有解码器。改动仅涉及扣额动作构造函数和已有冷启动回归。 比较过把来源常量迁到策略模块的三文件方案;它在普通工具回调上也有收益。单处调整可以保留常量原有归属、CLI 选项和结算路径,改动更少。

具体改动 / Changes

评审的提交为 2535e4c,主干基线为 49881d5,两者的完整远端补丁已经核对。依据 docs/reference/protocols/host-integration-surface-v0.md,parser 验证默认来源和参数约束,settlement 验证原有扣额与回执,cold 验证仅注册参数时的依赖。build_quota_spend_action 使用同一个 SettlementStepKind 和解码器。真实写路径先检查计划来源与运行时来源是否相符,原有报错或回退均保留。

24 组解析用例和四个公开 CLI 场景逐项核对。八种计划含正确、带引号、缺失及不匹配的来源,生成的命令或错误相同。独立安装的 Core wheel 执行了同一组扣额命令构造用例,13 页选读得到相同摘要,关闭钩子时原日志字节一致。实际宿主来源和幂等结算进入现有测试。两个恢复用例在租约已更换时仍期待错误退出,当前已合入的协议要求返回原轮次恢复指令并拒绝再次扣额。针对性测试345 项通过,两个原轮次恢复断言在主干和本提交均失败;用 #9332 当前测试原文复验,这两例在本提交通过,预合并检查 13 项通过。冷启动断言在原主干失败,在本提交通过。

对主干的风险 / Risks

普通 Bash 回调及仅启用增量交付的回调都重复测得收益。在当前主干上,完整 13 页选读的两批中位耗时一次下降 0.1%,一次增加 1.8%;同一解码器稍后仍由审计读取端导入。在单独的 #9337 候选上,两批分别进一步下降 6.4% 和 5.5%,每批六对。这一组合结果有独立基线,本 PR 可单独集成。错误参数仍需走完整解析器,其诊断耗时有波动。回退一个提交即可恢复加载时机,已有持久化数据无需迁移。

我的整体评价 / Verdict

作者自评通过。静态参数注册和第一个真实扣额调用分别经过冷进程验证,原来的来源校验保留,普通工具完成时少了一次模块初始化。合并后需要在受管 CLI 上复测,才能将这里的测试数字计入已安装版本的表现。

English verdict: APPROVE. Head 2535e4c makes ordinary hook startup cheaper while preserving quota argument and spend semantics.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant