Repository navigation
fix(agent): 离线 demo K 线序列从当前价向历史回推,最新收盘价与报价对齐 - #196
Merged
Merged
Conversation
helsome
approved these changes
Sep 24, 2026
helsome
left a comment
Owner
There was a problem hiding this comment.
当前 head 的数值语义修复与验证通过:demo K 线按 oldest→newest 输出时,index=0 才是今天,因此用 step=index 才能让最新 bar 精确落在同一 demo quote 的 lastPrice;新增测试同时锁定多标的/多窗口、时间顺序、OHLC 一致性和 limit 夹取。Issue #195 由作者实际 /claim,Closes #195 与范围一致;作者报告 Windows 11 / Bun 1.4.2,当前 head 的 GitHub PR checks 也已 success。
#186 刚进入 main 后 GitHub 当前将本 PR 计算为 mergeable=false,所以本次只批准代码。请仅解决与最新 main 的实际不可合并状态并重跑 agent focused + basic CI;无需额外 E2E。
demoKlinesFor 的 step 取的是「距最老一根的天数」(count - 1 - index),而 timestamp 决定 index = 0 是今天、index = count - 1 是最老一根。于是 step = 0 (close === quote.lastPrice)落在了最老那根上,最新一根反而拿到 step = count - 1, 把每根的漂移放大了 n-1 次。 后果:离线 demo 模式下最新 K 线收盘价与同一份 demo 报价脱钩,根数越多偏离越大 (AAPL.US limit=120 → 455.18 vs 189.43,偏离 +140%;TSLA.US limit=120 → 572.50 vs 175.22,偏离 +227%),与文件自述契约「ending at the demo quote's last price」及真实 provider 的升序 + 最新在末不一致。 修复:step 直接取 index,使 index = 0(今天)对应 step = 0 → close 精确等于 quote.lastPrice,越老的 bar 漂移越多。 回归用例 demo-market-data.test.ts:main 原始字节上 3 pass / 2 fail (Expected: 189.43 / Received: 190.83;最老一根 close 恰为当前价),修复后 5 pass / 0 fail。另 3 条锁定用例(升序一天网格、high/low 包夹、limit 夹取) 修复前后均通过,证明未连带改动既有行为。typecheck 五工作区 exit 0。
wxrbyte
force-pushed
the
codex/fix-demo-kline-direction
branch
from
September 25, 2026 04:28
8819e0c to
0bc3927
Compare
Contributor
Author
|
已按评审意见处理:只把分支基线同步到最新 main,并重跑 agent focused + 基础 CI,未做额外 E2E。 变更
本地验证(最新 main + 本 PR 改动)
CI(新 head
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题与修复
demoKlinesFor的文档注释声明「Deterministic daily close series ending at the demo quote's last price」,其替代的真实 provider 路径(@finagent/longbridge-tools的getKline)也返回「老 → 新」升序并以slice(-limit)取最新若干根。但生成循环的指数取错了维度:timestamp表明index就是「距今天的天数」,因此step应取index。当前写法让step = 0(close === quote.lastPrice)落在最老一根,最新一根反而取到step = count - 1,把漂移放大约 n-1 次。结果:离线 demo 模式(
FINAGENT_DEMO_DATA=1,kernelHost.ts:356)下,最新一根 K 线收盘价与同一份 demo 报价脱钩,根数越多偏离越大 —— 实测AAPL.US limit=120→ 最新 455.18 vs 报价 189.43(+140%)、TSLA.US limit=120→ 572.50 vs 175.22(+227%)、NVDA.US limit=120→ 1784.03 vs 880.12(+103%)。同时「当前价」这一端恒定落在最老一根上。修复:
step直接取index。index = 0(今天)→step = 0→close精确等于quote.lastPrice,越老的 bar 漂移越多,序列从当前价向历史回推,与真实 provider 的语义一致。Closes #195
可复现测试报告
环境:Windows 11 / Bun 1.4.2(与 CI 固定版本一致)/ 上游 main
8eca7111TDD 证据(新增用例
packages/shared/src/agent/demo-market-data.test.ts)bun test packages/shared/src/agent/demo-market-data.test.ts --isolate失败断言(修复前):
expect(klines.at(-1).close).toBe(quote.lastPrice)→Expected: 189.43 / Received: 190.83expect(klines[0].close).not.toBe(quote.lastPrice)→Expected: not 189.43,即当前价落在了最老一根新增用例覆盖:① 多标的(AAPL/TSLA/NVDA/MSFT)× 多根数(2/30/120)下最新一根精确等于报价;② 最老一根不再是当前价;③ 锁定:升序且相邻间隔恰为 86 400 秒;④ 锁定:
low ≤ min(open, close) ≤ max(open, close) ≤ high且成交量 > 0;⑤ 锁定:limit 仍按文档的 2..400 区间夹取。③④⑤ 在修复前后均通过,证明未连带改动既有行为。周边与全量
bun test packages/shared/src/agent --isolate→ 73 pass / 0 failbun run typecheck→ core / i18n / shared / ui / electron 五个工作区 exit 0bun test packages/shared --isolate在 main 上有 4 项预存在失败(ExperimentService.runExperiment的gitSha、ResearchService×2、langfuse backend×1),已做 A/B 对照:把pi-rpc-client.ts还原为 main 原始字节后重跑同一批文件,失败项与数量逐条一致(52 pass / 4 fail),与本次改动无关;本 PR 只触及demo-market-data.ts,Focused tests 推导到packages/shared未运行的测试:
apps/electron的 e2e(Windows 环境跑不起,见仓库现状)UI 变化
无可见 UI 变化。仅修正 demo 数据集自身的数值一致性(K 线收盘序列),不涉及渲染组件或样式。