Skip to content

feat(agent-runtime): pass metadata through createThread/ensureThread/createRun#5949

Open
strommmm wants to merge 2 commits into
nextfrom
feat/cha-phase2a-agent-runtime-metadata
Open

feat(agent-runtime): pass metadata through createThread/ensureThread/createRun#5949
strommmm wants to merge 2 commits into
nextfrom
feat/cha-phase2a-agent-runtime-metadata

Conversation

@strommmm
Copy link
Copy Markdown

@strommmm strommmm commented May 12, 2026

createThread support params to set metadata

Summary by CodeRabbit

  • New Features

    • Thread creation now accepts optional metadata that persists on the thread object.
    • Metadata is properly isolated between threads and runs—run metadata no longer overwrites thread metadata.
  • Tests

    • Added comprehensive test suite validating metadata persistence and isolation across all runtime APIs.

Review Change Stack

shidong.wh added 2 commits May 11, 2026 15:30
…createRun

打通业务方调 createRun 时 input.metadata 到 AgentStore.createThread 的全链路
透传。chair-sandbox-ai-use 多 agent 路径依赖此能力把 agentName 写入新建
thread 的 metadata,供后续 resume 时按 thread.metadata 读 agentName。

resume 场景下(threadId 已存在),ensureThread 不覆盖原 thread 的 metadata
(保持一致性)。

5 个 TDD case 覆盖:createThread 写入 / createThread 默认空 metadata /
syncRun 自动建 thread 带 metadata / syncRun resume 不覆盖 / asyncRun 自动
建 thread 带 metadata。

类型新增:CreateThreadOptions、EnsureThreadOptions(位于 @eggjs/tegg-types
的 agent-runtime 子模块),随原 export * 自动导出,无需手动加 index。
Copilot AI review requested due to automatic review settings May 12, 2026 13:02
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 12, 2026

📝 Walkthrough

Walkthrough

AgentRuntime now supports optional metadata at thread creation time via a new CreateThreadOptions interface. The createThread method forwards metadata to the underlying store, while metadata passed during runs is preserved separately without mutating thread metadata.

Changes

Thread Metadata Support

Layer / File(s) Summary
CreateThreadOptions contract
tegg/core/types/src/agent-runtime/AgentRuntime.ts
New CreateThreadOptions interface exports optional metadata?: Record<string, unknown> with JSDoc describing metadata forwarding to thread creation and persistence across run operations.
AgentRuntime metadata forwarding
tegg/core/agent-runtime/src/AgentRuntime.ts
createThread method signature updated to accept optional CreateThreadOptions and forward options?.metadata to store.createThread. Documentation added to ensureThread clarifying threadId reuse and metadata isolation behavior.
Metadata behavior test suite
tegg/core/agent-runtime/test/AgentRuntime.metadata.test.ts
Comprehensive Vitest suite with MockSSEWriter validates metadata persistence in createThread, syncRun, asyncRun, and streamRun, confirming metadata stays at creation level and is not overwritten by subsequent run operations.

Sequence Diagram

sequenceDiagram
  participant Caller
  participant AgentRuntime
  participant AgentStore
  participant ThreadStorage
  
  Caller->>AgentRuntime: createThread(metadata)
  AgentRuntime->>AgentStore: createThread(metadata)
  AgentStore->>ThreadStorage: persist thread with metadata
  ThreadStorage-->>AgentStore: thread created
  AgentStore-->>AgentRuntime: ThreadObject
  AgentRuntime-->>Caller: ThreadObject with metadata
  
  Caller->>AgentRuntime: syncRun(threadId, runMetadata)
  AgentRuntime->>AgentStore: createRun(runMetadata)
  AgentStore->>ThreadStorage: persist run, do not mutate thread metadata
  ThreadStorage-->>AgentStore: run created
  AgentStore-->>AgentRuntime: RunResult with runMetadata
  AgentRuntime-->>Caller: RunResult (thread metadata unchanged)
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 A thread now carries its metadata with care,
Forwarded at birth, forever it'll share,
While runs keep their own in pristine isolation—
Metadata metadata, no contamination! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and specifically summarizes the main change: adding metadata support to thread and run creation methods in the agent-runtime module.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/cha-phase2a-agent-runtime-metadata

Warning

Review ran into problems

🔥 Problems

Timed out fetching pipeline failures after 30000ms

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 12, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.21%. Comparing base (0dec2c9) to head (2bd5212).

Additional details and impacted files
@@           Coverage Diff           @@
##             next    #5949   +/-   ##
=======================================
  Coverage   85.21%   85.21%           
=======================================
  Files         669      669           
  Lines       19304    19304           
  Branches     3787     3787           
=======================================
  Hits        16449    16449           
  Misses       2463     2463           
  Partials      392      392           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR extends the agent runtime thread-creation API to allow attaching persistent metadata to a newly created thread, and adds tests to ensure run metadata is not accidentally copied into thread metadata.

Changes:

  • Add CreateThreadOptions (with metadata) to the agent-runtime type definitions.
  • Update AgentRuntime.createThread() to accept optional metadata and forward it to the store.
  • Add a new Vitest suite covering thread metadata persistence and “no run→thread metadata copying” behavior for sync/async/stream runs.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
tegg/core/types/src/agent-runtime/AgentRuntime.ts Introduces CreateThreadOptions type and documents intended metadata semantics.
tegg/core/agent-runtime/src/AgentRuntime.ts Extends createThread() to accept options and pass metadata into store.createThread().
tegg/core/agent-runtime/test/AgentRuntime.metadata.test.ts Adds tests for thread metadata persistence and ensures run metadata doesn’t mutate/copy to thread metadata.

Comment on lines +92 to +99
/**
* Options for {@link AgentRuntime.createThread}.
*
* `metadata` is forwarded verbatim to {@link AgentStore.createThread} so callers
* can persist additional business semantics on the thread record (e.g. the
* resolved agent name, owning sandbox id, trace id). It is stored once at
* creation time and never overwritten by subsequent runs on the same thread.
*/
Comment on lines +21 to +27
end(): void {
this.closed = true;
}

onClose(): void {
/* noop */
}
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces the ability to provide metadata when creating a thread in the AgentRuntime. It adds the CreateThreadOptions interface, updates the createThread method to accept these options, and ensures that metadata is correctly persisted to the store. Additionally, it includes a new test suite to verify metadata handling across various run types (sync, async, and stream) and confirms that run-specific metadata does not overwrite thread metadata. I have no feedback to provide.

Copy link
Copy Markdown
Contributor

@jerryliang64 jerryliang64 left a comment

Choose a reason for hiding this comment

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

LGTM

@killagu killagu changed the title Feat/cha phase2a agent runtime metadata feat(agent-runtime): pass metadata through createThread/ensureThread/createRun May 12, 2026
Copy link
Copy Markdown
Contributor

@killagu killagu left a comment

Choose a reason for hiding this comment

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

LGTM

@killagu
Copy link
Copy Markdown
Contributor

killagu commented May 12, 2026

eggjs/tegg 也要 pick 下。

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.

4 participants