Skip to content

Fix/sparse stream block index#46

Merged
CrazyBoyM merged 2 commits intoshareAI-lab:mainfrom
Gui-Yue:fix/sparse-stream-block-index
Mar 29, 2026
Merged

Fix/sparse stream block index#46
CrazyBoyM merged 2 commits intoshareAI-lab:mainfrom
Gui-Yue:fix/sparse-stream-block-index

Conversation

@Gui-Yue
Copy link
Copy Markdown
Contributor

@Gui-Yue Gui-Yue commented Mar 29, 2026

Summary

修复 Agent.runStep() 对稀疏 streamed block index 的处理问题,并将 OpenAIProvider.stream() 的 block index 规范化为连续且互不冲突的本地索引。

Motivation / Context

Agent.runStep() 会直接按 chunk.index 写入assistantBlocks[chunk.index]。当 provider 输出稀疏 index 时,会生成稀疏数组,后续传入 splitThinkBlocksIfNeeded() 时可能触发: TypeError: Cannot read properties of undefined (reading 'type')本 PR 一方面在 core 层修复该运行时问题,另一方面同步修正 OpenAIProvider.stream() 当前已知的稀疏 / 冲突 index 行为。

Type of Change

  • Bug fix
  • Feature
  • Refactor
  • Docs
  • Test
  • Chore / Build

Scope / Modules

  • core (agent / events / pool / room / scheduler)
  • infra (db / provider / sandbox / store)
  • tools (fs / bash / mcp / skills / task)
  • skills
  • examples
  • docs (en / zh-CN)
  • tests
  • other: ___

Public API

  • Exports changed in src/index.ts
  • No public API change

Breaking Changes

  • Yes , and attach report(include necessity) and transition plan
  • No

Testing

  • npm run test:unit(required)
  • npm run test:integration(if needed)
  • npm run test:e2e(if needed)

Impact / Risk

风险较低。

本次行为调整包括:

  • Agent 在 streamed assistant blocks 进入后处理前,先压缩为稠密数组。
  • splitThinkBlocksIfNeeded() 增加对空值的防御处理。
  • OpenAIProvider.stream() 改为对 text、reasoning、tool_use 分配本地连续
    索引,避免稀疏数组和 index 冲突。

兼容性说明:

  • 无 public API 变化。
  • 不涉及文档和示例更新。
  • 不改变已有 streamed 内容语义,只修正内部 block 组装过程。

Checklist

  • Docs updated if needed
  • Examples updated if needed
  • New feature includes related tests and docs
  • Tests follow tests/README.md structure
  • Docs follow docs/en + docs/zh-CN format rules
  • No secrets or tokens committed
  • No dist/ changes (unless release)
  • Only one lockfile updated for the package manager used

@CrazyBoyM CrazyBoyM merged commit 0dcf203 into shareAI-lab:main Mar 29, 2026
8 checks passed
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.

2 participants