Repository navigation
feat(agent-core-v2): attach Kimi request metadata - #4830
Conversation
|
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
commit: |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 13f713003e
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| request: this.protocolRegistry.request(model, params), | ||
| request: provider?.requestMetadata === true | ||
| ? request.with({ | ||
| endpoint: { headers: requestMetadataHeaders(this.requestMetadata.resolve(overrides.source)) }, |
There was a problem hiding this comment.
Preserve the configured metadata header
When a Kimi provider already sets X-Msh-Client-Metadata through the documented providers.*.custom_headers option, this later .with() deep-merge replaces that value with the generated JSON because the new value wins on a same-named header. Before this commit, the protocol request retained the configured header assembled in ProtocolAdapterRegistry; after upgrading, gateway routing, signing, or correlation data using this header is silently discarded with no escape hatch. Preserve an explicit configured value, or reject/reserve the key with a migration path instead of silently overriding it.
AGENTS.md reference: AGENTS.md:L110-L112
Useful? React with 👍 / 👎.
| this.activeTurn = { | ||
| turnId: input.turnId, | ||
| turnTrigger: input.continuation === 'retry' ? 'swarm_retry' : turnTriggerOf(origin), | ||
| stepReason: input.continuation === 'resume' && input.step() > 1 ? 'tool_results' : 'turn_start', |
There was a problem hiding this comment.
Mark the first resumed follow-up as tool results
When a process resumes an interrupted turn after its first LLM step, the restored turn carries step === 1, and the loop creates this execution before incrementing it to step 2. Consequently, this > 1 check labels the resumed request turn_start even though it consumes the completed or synthesized-aborted tool results; this misclassifies Kimi requests for sessions resumed after a crash during the first tool execution. A resumed turn with any prior step (input.step() > 0) should use tool_results.
Useful? React with 👍 / 👎.
| const next: AgentRequestAttribution = { | ||
| ...current, | ||
| userInputId: parent.userInputId ?? current.userInputId, | ||
| parentRequestId: parent.activeRequestId ?? current.parentRequestId, |
There was a problem hiding this comment.
Clear stale parent IDs on a fresh dispatch
When a previously used subagent is dispatched again and the new parent request has no request ID, this nullish fallback retains the subagent's parent ID from its earlier run. Absent request IDs are supported, so a resumed subagent using Kimi can then be logged as a descendant of an unrelated previous parent request. A fresh dispatch should store the current parent's activeRequestId directly, including clearing the field when it is undefined.
Useful? React with 👍 / 👎.
13f7130 to
5a2c66b
Compare
Port MoonshotAI#4901, MoonshotAI#4909 and MoonshotAI#4911: complete the task before asserting a zero-timeout wait sees the completed snapshot, restore the instructions reload spy after the failure assertion, poll the search index until it is ready before asserting the page, and run remote-session git probes through a host process that refuses gh. Record MoonshotAI#4840 as equivalent (the refresh path already rebuilds from the effective binding here) and pin it with a regression case, record MoonshotAI#4883 as ported with the compaction profile already present, and record MoonshotAI#4830 as blocked on the absent loop requester/request-attribution layering. Clear the generated-bundle, release-sync and working-notes rows with their applicable verdicts.
Requirement or Bug
分析 Kimi Code 的模型请求时,服务端日志只有 HTTP 请求本身,无法区分请求来自哪种 Agent、这一轮为什么开始、这一步为什么发出,以及它属于哪一次用户输入。本 PR 将 #4753 的语义应用到最新 main:声明了
requestMetadata的 provider 在模型请求上附带X-Msh-Client-Metadata,供请求日志关联。目前只有 Kimi 声明该能力。Bug Reproduction Steps
N/A
Root Cause
N/A
Code Changes
归因由
RequestMetadataTracker与 Session 级ISessionRequestAttributionService完成。AgentLoopRequestFactory.resolveRequest()在统一装配点通过现有endpoint.headers附加 header,AgentLoopRequestObserver.setRequestId()统一上报当前 Turn 的 request ID;是否附带由 provider definition 上的requestMetadata: true决定。Core Loop、SessionMetadata、SubagentService 和各工具不需要透传归因参数。头里是一份 JSON:
agent_role来自IAgentScopeContext.meta,映射为main、btw、tower_worker、swarm_member、subagent、other。turn_trigger来自TurnPrompt.origin。压缩请求发生在 Turn 内时沿用当前 trigger,idle/compact归为user。step_reason由 Turn 事件决定:收到TurnPrompt为turn_start,首步 retry/recovery 保持该值;收到TurnStepCompleted后为tool_results;full compaction 为compact。user_input_id记录真实用户发出的 prompt ID,后续 cron、background task、goal continuation 和 idle 压缩沿用。子 Agent 在实时派发或 fork 时继承父值,主 Agent 可从 Wire 历史恢复。parent_request_id只在符合条件的子 Agent 上有值,实时 subagent spawn/resume 时采样父 Agent 当时的 active request ID;swarm retry 和 tower inbox 不重新采样,纯 replay、/init和/btw不带。\uXXXX,保证 header 是合法 HTTP ByteString;无值的可选字段省略。阅读顺序:
agent/loop/requestMetadata.ts(映射与事件折叠)、session/requestAttribution/(跨 Agent 归因)、agent/loop/requester.ts(统一 header 装配)、agent/loop/requestObservation.ts(request ID 上报)。Behavior Changes and Affected Users
providerType === 'kimi'的模型请求 HTTP headersX-Msh-Client-Metadataagent_role、turn_trigger、step_reason,以及有值时的user_input_id、parent_request_id。仅声明requestMetadata的 Kimi 协议发送step_reason为compact;idle 压缩的turn_trigger为user,并沿用上一轮user_input_idrequestMetadata的 provider 不受影响验证:
@moonshot-ai/agent-core-v2typecheck 与 build 通过;根pnpm run lint为 0 errors。本变更不改变 CLI 用户可见行为,按
gen-changesets规则不需要 changeset;不需要文档更新。Checklist
/approve).gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.