Skip to content

feat(tegg): [1/3] add agent-runtime package with OSS-backed store#5818

Closed
jerryliang64 wants to merge 15 commits intoeggjs:nextfrom
jerryliang64:feat/pr1-agent-store
Closed

feat(tegg): [1/3] add agent-runtime package with OSS-backed store#5818
jerryliang64 wants to merge 15 commits intoeggjs:nextfrom
jerryliang64:feat/pr1-agent-store

Conversation

@jerryliang64
Copy link
Copy Markdown
Contributor

@jerryliang64 jerryliang64 commented Mar 1, 2026

Summary

  • Add @eggjs/agent-runtime package under tegg/core/agent-runtime/
  • Self-contained types: AgentObjectType, RunStatus, InputMessage, MessageObject, AgentRunConfig, ThreadRecord, RunRecord
  • AgentStore interface for thread/run CRUD operations
  • ObjectStorageClient abstraction for pluggable storage backends
  • OSSObjectStorageClient adapter for Alibaba Cloud OSS (oss-client)
  • OSSAgentStore implementation with prefix-based key namespace isolation
  • Error types: AgentNotFoundError (404), AgentConflictError (409)
  • 16 unit tests using inline MapStorageClient (no external dependencies)

Test plan

  • pnpm --filter @eggjs/agent-runtime run typecheck passes
  • pnpm --filter @eggjs/agent-runtime run test — 16 tests passing
  • CI passes

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • New agent-runtime package offering persistent storage for threads and runs, a pluggable object-storage client API, utility helpers for IDs/timestamps, and clear not-found/conflict error types.
  • Tests

    • Extensive unit tests covering storage behavior, message/run lifecycle, prefix isolation, object-storage client integration, and utilities.
  • Chores

    • Workspace and TypeScript project configuration added for the new package.

Stacked PRs

This is part of a 3-PR series (review in order):

  1. This PR (feat(tegg): [1/3] add agent-runtime package with OSS-backed store #5818) — Store layer (AgentStore + OSSAgentStore)
  2. feat(tegg): [2/3] add AgentRuntime with sync/async/stream execution modes #5819 — Runtime (AgentRuntime + MessageConverter + RunBuilder)
  3. feat(tegg): [3/3] add @AgentController decorator with plugin integration #5820 — Decorator (@AgentController + Plugin integration)

Add @eggjs/agent-runtime package providing an AgentStore interface and
ObjectStorageClient abstraction for persistent agent state management.

- Self-contained types (AgentObjectType, RunStatus, InputMessage, etc.)
- AgentStore interface for thread/run CRUD operations
- ObjectStorageClient interface for pluggable storage backends
- OSSObjectStorageClient adapter for Alibaba Cloud OSS (oss-client)
- OSSAgentStore implementation with prefix-based key isolation
- Error types: AgentNotFoundError (404), AgentConflictError (409)
- Full test coverage using inline MapStorageClient

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a new agent runtime package designed to manage agent-related data, such as threads and runs, with a flexible storage abstraction. It enables the use of Alibaba Cloud OSS as a backend for persistent storage, providing a scalable and robust solution for handling agent state. The changes lay the groundwork for integrating advanced agent capabilities within the Egg.js tegg framework, ensuring data integrity and proper error handling.

Highlights

  • New Package Introduction: A new package, @eggjs/agent-runtime, has been added under tegg/core/agent-runtime/ to provide agent runtime functionalities.
  • Core Type Definitions: Self-contained types for AgentObjectType, RunStatus, InputMessage, MessageObject, AgentRunConfig, ThreadRecord, and RunRecord have been defined to structure agent-related data.
  • AgentStore Interface: An AgentStore interface has been introduced to standardize CRUD operations for agent threads and runs.
  • Pluggable Object Storage: An ObjectStorageClient abstraction has been created to allow for pluggable storage backends, along with an OSSObjectStorageClient adapter for Alibaba Cloud OSS.
  • OSSAgentStore Implementation: An OSSAgentStore implementation has been provided, utilizing the ObjectStorageClient with prefix-based key namespace isolation for managing agent data in OSS.
  • Custom Error Types: New error types, AgentNotFoundError (404) and AgentConflictError (409), have been added for specific agent runtime scenarios.
  • Comprehensive Unit Tests: Sixteen unit tests have been included for the OSSAgentStore using an inline MapStorageClient to ensure functionality without external dependencies.
Changelog
  • pnpm-lock.yaml
    • Added oss-client dependency to the catalog.
    • Included mime@3.0.0, xml2js@0.6.2, and xmlbuilder@11.0.1 as new package dependencies.
    • Defined dependencies and devDependencies for the new tegg/core/agent-runtime package.
  • pnpm-workspace.yaml
    • Added oss-client to the catalog section.
  • tegg/core/agent-runtime/package.json
    • Added a new package definition for @eggjs/agent-runtime with metadata, scripts, and dependencies.
  • tegg/core/agent-runtime/src/AgentStore.ts
    • Defined AgentObjectType and RunStatus constants and types.
    • Introduced interfaces for InputMessage, MessageObject, AgentRunConfig, ThreadRecord, and RunRecord.
    • Created the AgentStore interface for thread and run management operations.
  • tegg/core/agent-runtime/src/OSSAgentStore.ts
    • Implemented the OSSAgentStore class, providing concrete implementations for AgentStore methods using an ObjectStorageClient.
    • Included logic for creating, retrieving, appending, and updating thread and run records, with prefix-based key management.
  • tegg/core/agent-runtime/src/OSSObjectStorageClient.ts
    • Implemented the OSSObjectStorageClient class, adapting the ObjectStorageClient interface to interact with Alibaba Cloud OSS using oss-client.
  • tegg/core/agent-runtime/src/ObjectStorageClient.ts
    • Defined the ObjectStorageClient interface for abstracting object storage operations.
  • tegg/core/agent-runtime/src/errors.ts
    • Defined custom error classes AgentNotFoundError and AgentConflictError with HTTP status codes.
  • tegg/core/agent-runtime/src/index.ts
    • Exported all public modules from the agent-runtime package.
  • tegg/core/agent-runtime/src/utils.ts
    • Added utility functions nowUnix for current Unix timestamp and newMsgId for generating new message IDs.
  • tegg/core/agent-runtime/test/OSSAgentStore.test.ts
    • Added unit tests for OSSAgentStore covering thread and run creation, retrieval, updates, message appending, error handling, and prefix isolation.
  • tegg/core/agent-runtime/tsconfig.json
    • Added a tsconfig.json file extending the root configuration for the new package.
  • tegg/core/agent-runtime/vitest.config.ts
    • Added a vitest.config.ts file for the new package's test configuration.
  • tsconfig.json
    • Updated the root tsconfig.json to include the new ./tegg/core/agent-runtime path in the project references.
Activity
  • The author has confirmed that pnpm --filter @eggjs/agent-runtime run typecheck passes.
  • The author has confirmed that pnpm --filter @eggjs/agent-runtime run test shows 16 tests passing locally.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 1, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds a new tegg/core/agent-runtime package: typed AgentStore and ObjectStorageClient interfaces, OSS-backed implementations (OSSAgentStore, OSSObjectStorageClient), error types, utilities, comprehensive tests, package manifest, workspace/tsconfig references, and Vitest config. (26 words)

Changes

Cohort / File(s) Summary
Workspace & Manifests
pnpm-workspace.yaml, tsconfig.json
Adds oss-client: ^2.5.1 to workspace catalog and registers ./tegg/core/agent-runtime as a TS project reference.
Package Manifest
tegg/core/agent-runtime/package.json
New package manifest with metadata, exports, Node engine, scripts, dependency on oss-client, and publish mappings.
Core API Types
tegg/core/agent-runtime/src/AgentStore.ts, tegg/core/agent-runtime/src/ObjectStorageClient.ts
Introduces AgentStore API surface, DTOs/record types, and a generic ObjectStorageClient interface.
OSS Implementations
tegg/core/agent-runtime/src/OSSObjectStorageClient.ts, tegg/core/agent-runtime/src/OSSAgentStore.ts
Adds OSSObjectStorageClient wrapper and OSSAgentStore implementation using JSON serialization, key prefixing, UUID timestamps/IDs, and non-atomic read-modify-write caveats.
Errors, Utils & Barrel
tegg/core/agent-runtime/src/errors.ts, tegg/core/agent-runtime/src/utils.ts, tegg/core/agent-runtime/src/index.ts
Adds AgentNotFoundError/AgentConflictError, nowUnix/newMsgId helpers, and a barrel file re-exporting the package API.
Tests & Test Helpers
tegg/core/agent-runtime/test/*
Comprehensive unit tests for OSSAgentStore, OSSObjectStorageClient, errors, and utils; includes in-memory MapStorageClient mock and oss-client mocking to validate lifecycles, prefix isolation, and error cases.
Tooling Config
tegg/core/agent-runtime/tsconfig.json, tegg/core/agent-runtime/vitest.config.ts
Adds package-local tsconfig (extends root) and a Vitest project config for workspace testing.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Store as OSSAgentStore
    participant OSS as OSSObjectStorageClient
    Client->>Store: createThread(metadata)
    Store->>OSS: put("prefix/thread/{threadId}", JSON(threadRecord))
    OSS-->>Store: OK
    Client->>Store: createRun(input, threadId, config)
    Store->>OSS: put("prefix/run/{runId}", JSON(runRecord))
    OSS-->>Store: OK
    Client->>Store: appendMessages(threadId, messages)
    Store->>OSS: get("prefix/thread/{threadId}")
    OSS-->>Store: JSON(threadRecord)
    Store->>OSS: put("prefix/thread/{threadId}", JSON(updatedThreadRecord))
    OSS-->>Store: OK
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested reviewers

  • fengmk2

Poem

🐇 I hopped in code with paws that write,
Threads and runs tucked in the byte,
Keys hum soft, IDs spin and glow,
Prefix fences keep the flow,
A tiny runtime springs to light!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding a new @eggjs/agent-runtime package with OSS-backed storage implementation.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


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 Mar 1, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.29%. Comparing base (f64b818) to head (7a7cfee).
⚠️ Report is 1 commits behind head on next.

Additional details and impacted files
@@            Coverage Diff             @@
##             next    #5818      +/-   ##
==========================================
+ Coverage   85.23%   85.29%   +0.06%     
==========================================
  Files         650      655       +5     
  Lines       12522    12591      +69     
  Branches     1435     1447      +12     
==========================================
+ Hits        10673    10740      +67     
- Misses       1729     1731       +2     
  Partials      120      120              

☔ 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

@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 new @eggjs/agent-runtime package, which provides a store abstraction for agent threads and runs, with an initial implementation backed by Aliyun OSS. The code is well-structured with clear separation of concerns between the store logic, storage client interface, and the OSS-specific implementation.

My review focuses on improving the robustness and correctness of the new package. Key feedback points include:

  • Relaxing the strict Node.js engine requirement in package.json for better compatibility.
  • Adding data validation after parsing JSON from the object store to prevent runtime errors from malformed data.
  • Addressing potential race conditions in update operations (appendMessages and updateRun) by using atomic/conditional writes.
  • Improving the type safety of error handling in the OSSObjectStorageClient.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (3)
tegg/core/agent-runtime/src/index.ts (1)

6-6: Consider whether utils should be part of the public API.

Re-exporting utils.ts exposes internal utilities like nowUnix() as part of the package's public surface. If these are intended only for internal use, consider either:

  • Removing this export from the barrel
  • Keeping them unexported and importing directly within the package

If consumers need these utilities, this export is fine.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tegg/core/agent-runtime/src/index.ts` at line 6, The barrel file currently
re-exports internal utilities via the line exporting './utils.ts', which exposes
functions like nowUnix() publicly; decide whether they should be internal and if
so remove that export from the barrel (keep utils.ts imports internal to modules
that need them) or explicitly mark/rename and document them if they must remain
public; update the export line in index.ts accordingly and adjust any internal
imports that previously relied on the barrel to import directly from
'./utils.ts' (or alternatively add explicit named exports for only the intended
public symbols).
tegg/core/agent-runtime/src/OSSAgentStore.ts (1)

60-64: Read-modify-write pattern lacks atomicity guarantees.

Both appendMessages and updateRun use a get-then-put pattern that can lose concurrent updates. If two calls to appendMessages happen simultaneously, one message set may be lost.

This is an inherent limitation when using object storage without conditional writes (ETags/versioning). Consider documenting this behavior, or if OSS supports conditional puts, implementing optimistic concurrency control.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tegg/core/agent-runtime/src/OSSAgentStore.ts` around lines 60 - 64, The
read-modify-write in appendMessages (and similarly updateRun) can lose
concurrent updates; either document this limitation or implement optimistic
concurrency: modify appendMessages to read the thread via getThread(), capture a
version/ETag (or a lastModified field) from the stored object, merge messages,
then use a conditional put (client.put with an If-Match/expected ETag or OSS
conditional put API) or a compare-and-swap loop with retries to ensure the put
fails if the stored version changed; if the OSS client has no conditional-put
support, add retry-on-conflict by re-reading and merging up to N attempts or add
explicit documentation in OSSAgentStore that concurrent updates are not atomic.
Ensure you reference and change the methods appendMessages, updateRun,
getThread, threadKey and the use of client.put accordingly.
tegg/core/agent-runtime/test/OSSAgentStore.test.ts (1)

39-40: Timestamp assertions may be fragile under clock drift.

The assertions thread.created_at <= Math.floor(Date.now() / 1000) could theoretically fail if the test execution spans a second boundary or under clock adjustments. This is a minor concern since it's unlikely in practice, but you could make it more robust by capturing the timestamp before the operation.

 it('should create a thread', async () => {
+  const beforeCreate = Math.floor(Date.now() / 1000);
   const thread = await store.createThread();
   assert(thread.id.startsWith('thread_'));
   assert.equal(thread.object, 'thread');
   assert(Array.isArray(thread.messages));
   assert.equal(thread.messages.length, 0);
   assert(typeof thread.created_at === 'number');
-  assert(thread.created_at <= Math.floor(Date.now() / 1000));
+  assert(thread.created_at >= beforeCreate && thread.created_at <= Math.floor(Date.now() / 1000));
 });

Also applies to: 107-108

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tegg/core/agent-runtime/test/OSSAgentStore.test.ts` around lines 39 - 40,
Capture the current timestamp immediately before creating the thread (e.g.,
const before = Math.floor(Date.now() / 1000)) and again immediately after (const
after = Math.floor(Date.now() / 1000)), then replace the fragile assertion on
thread.created_at with a range check like thread.created_at >= before &&
thread.created_at <= after; update both occurrences that assert
thread.created_at (the checks around thread.created_at in OSSAgentStore.test.ts)
to use this before/after range so the test is robust against clock boundaries.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@tegg/core/agent-runtime/tsconfig.json`:
- Around line 1-3: Add "emitDecoratorMetadata": true under a "compilerOptions"
object in this package tsconfig so tegg DI can infer types; if "compilerOptions"
is not present, create it and set "emitDecoratorMetadata": true (and ensure
"experimentalDecorators": true is enabled or inherited). Update the JSON in the
tsconfig that currently only extends "../../../tsconfig.json" to include these
compilerOptions while keeping the existing extends entry.

---

Nitpick comments:
In `@tegg/core/agent-runtime/src/index.ts`:
- Line 6: The barrel file currently re-exports internal utilities via the line
exporting './utils.ts', which exposes functions like nowUnix() publicly; decide
whether they should be internal and if so remove that export from the barrel
(keep utils.ts imports internal to modules that need them) or explicitly
mark/rename and document them if they must remain public; update the export line
in index.ts accordingly and adjust any internal imports that previously relied
on the barrel to import directly from './utils.ts' (or alternatively add
explicit named exports for only the intended public symbols).

In `@tegg/core/agent-runtime/src/OSSAgentStore.ts`:
- Around line 60-64: The read-modify-write in appendMessages (and similarly
updateRun) can lose concurrent updates; either document this limitation or
implement optimistic concurrency: modify appendMessages to read the thread via
getThread(), capture a version/ETag (or a lastModified field) from the stored
object, merge messages, then use a conditional put (client.put with an
If-Match/expected ETag or OSS conditional put API) or a compare-and-swap loop
with retries to ensure the put fails if the stored version changed; if the OSS
client has no conditional-put support, add retry-on-conflict by re-reading and
merging up to N attempts or add explicit documentation in OSSAgentStore that
concurrent updates are not atomic. Ensure you reference and change the methods
appendMessages, updateRun, getThread, threadKey and the use of client.put
accordingly.

In `@tegg/core/agent-runtime/test/OSSAgentStore.test.ts`:
- Around line 39-40: Capture the current timestamp immediately before creating
the thread (e.g., const before = Math.floor(Date.now() / 1000)) and again
immediately after (const after = Math.floor(Date.now() / 1000)), then replace
the fragile assertion on thread.created_at with a range check like
thread.created_at >= before && thread.created_at <= after; update both
occurrences that assert thread.created_at (the checks around thread.created_at
in OSSAgentStore.test.ts) to use this before/after range so the test is robust
against clock boundaries.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f64b818 and ba98a44.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (13)
  • pnpm-workspace.yaml
  • tegg/core/agent-runtime/package.json
  • tegg/core/agent-runtime/src/AgentStore.ts
  • tegg/core/agent-runtime/src/OSSAgentStore.ts
  • tegg/core/agent-runtime/src/OSSObjectStorageClient.ts
  • tegg/core/agent-runtime/src/ObjectStorageClient.ts
  • tegg/core/agent-runtime/src/errors.ts
  • tegg/core/agent-runtime/src/index.ts
  • tegg/core/agent-runtime/src/utils.ts
  • tegg/core/agent-runtime/test/OSSAgentStore.test.ts
  • tegg/core/agent-runtime/tsconfig.json
  • tegg/core/agent-runtime/vitest.config.ts
  • tsconfig.json

Verify Buffer encoding on put, content decoding on get (Buffer and
non-Buffer paths), null content handling, NoSuchKey → null mapping,
and re-throw of unexpected errors.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@tegg/core/agent-runtime/test/OSSObjectStorageClient.test.ts`:
- Line 5: Update the ESM import specifier to use the compiled .js extension:
replace the import of OSSObjectStorageClient from
'../src/OSSObjectStorageClient.ts' with '../src/OSSObjectStorageClient.js' so
that the test file imports the runtime JS module (referencing the
OSSObjectStorageClient export/class in the test) and satisfies the project
tsconfig verbatimModuleSyntax requirement.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ba98a44 and 5cca3e0.

📒 Files selected for processing (1)
  • tegg/core/agent-runtime/test/OSSObjectStorageClient.test.ts

- Use safer NoSuchKey error check with type narrowing
- Add race condition comments to appendMessages/updateRun
- Add test coverage for AgentConflictError, newMsgId, init/destroy

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@tegg/core/agent-runtime/src/OSSObjectStorageClient.ts`:
- Line 3: Replace all local ESM import extensions from ".ts" to ".js" in this
package: update the import statement in OSSObjectStorageClient.ts (the import of
ObjectStorageClient) and the corresponding imports/exports referenced in
OSSAgentStore.ts and the package index (and any test files) so they import
"./ObjectStorageClient.js", "./OSSAgentStore.js", etc.; ensure all module
specifiers in functions/classes referenced (e.g., ObjectStorageClient,
OSSAgentStore, and the index.ts export entries) are changed consistently to use
.js so the ESM loader resolves local modules correctly.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5cca3e0 and 63a7c88.

📒 Files selected for processing (5)
  • tegg/core/agent-runtime/src/OSSAgentStore.ts
  • tegg/core/agent-runtime/src/OSSObjectStorageClient.ts
  • tegg/core/agent-runtime/test/OSSAgentStore.test.ts
  • tegg/core/agent-runtime/test/errors.test.ts
  • tegg/core/agent-runtime/test/utils.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • tegg/core/agent-runtime/src/OSSAgentStore.ts

jerryliang64 and others added 5 commits March 2, 2026 00:33
… test helper

The oxlint type-aware checker reports TS2339 because MapStorageClient
did not declare the optional init/destroy methods from ObjectStorageClient,
causing type errors when tests assign vi.fn() to them.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…SAgentStore

Mark appendMessages and updateRun as follow-up items for atomic
operations (e.g. ETag-based conditional writes) in multi-writer scenarios.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Split thread storage into metadata (JSON) + messages (JSONL) to leverage
the OSS AppendObject API for O(1) message writes instead of
read-modify-write. This avoids reading the entire thread on every
appendMessages call, which is much more efficient for long conversations.

- Add optional append() to ObjectStorageClient interface
- Implement append() in OSSObjectStorageClient with position cache
  and HEAD-based fallback for stale cache self-healing
- Refactor OSSAgentStore: threads/{id}.json → threads/{id}/meta.json
  + threads/{id}/messages.jsonl
- Fall back to get-concat-put when client has no append()
- Add tests for incremental append, fallback path, and edge cases

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add mock tests for OSSObjectStorageClient.append (position cache,
  PositionNotEqualToLength HEAD fallback, error propagation)
- Add TODO(PR2) comments for newMsgId and AgentConflictError
- Add JSDoc to ThreadRecord.messages explaining storage separation
- Remove redundant type assertions in OSSAgentStore tests

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…istency

Follow tegg convention where utility files use PascalCase
(e.g., ObjectUtils.ts, TimerUtil.ts, NameUtil.ts).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
jerryliang64 and others added 2 commits March 3, 2026 10:44
…nstructing internally

Follow IoC/DI principle: external SDK clients should be injected by the
caller, not constructed inside the class. This improves testability and
decouples OSSObjectStorageClient from OSS configuration details.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Match the original tegg coding convention established by the original
authors, using standard TypeScript enum declarations.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@socket-security
Copy link
Copy Markdown

socket-security bot commented Mar 3, 2026

Warning

Review the following alerts detected in dependencies.

According to your organization's Security Policy, it is recommended to resolve "Warn" alerts. Learn more about Socket for GitHub.

Action Severity Alert  (click "▶" to expand/collapse)
Warn High
Obfuscated code: npm entities is 91.0% likely obfuscated

Confidence: 0.91

Location: Package overview

From: pnpm-lock.yamlnpm/entities@4.5.0

ℹ Read more on: This package | This alert | What is obfuscated code?

Next steps: Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support@socket.dev.

Suggestion: Packages should not obfuscate their code. Consider not using packages with obfuscated code.

Mark the package as acceptable risk. To ignore this alert only in this pull request, reply with the comment @SocketSecurity ignore npm/entities@4.5.0. You can also ignore all packages with @SocketSecurity ignore-all. To ignore an alert for all future pull requests, use Socket's Dashboard to change the triage state of this alert.

View full report

@jerryliang64 jerryliang64 force-pushed the feat/pr1-agent-store branch from 9cb6f66 to 22513fc Compare March 3, 2026 15:46
… compliance

Replace `export enum` with `as const` + type extraction pattern to fix
TS1294 errors under `erasableSyntaxOnly: true`. This aligns with the
established convention in tegg/core/types/src/core-decorator/enum/.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@jerryliang64
Copy link
Copy Markdown
Contributor Author

针对 @killagu 的 review comments 统一回复:

1. prefix 拼接 (OSSAgentStore.ts:64)

会检查 prefix 后面一定有 / 吗?

已修复。构造函数中增加了 normalize 逻辑:非空 prefix 如果不以 / 结尾会自动补上,并加了测试用例验证 prefix: 'myapp'prefix: 'myapp/' 行为一致。不使用 path.join 是因为 OSS key 不是文件系统路径,且 path.join 在 Windows 上会用 \ 分隔符。

2. OSS 对象应该外部传入 (OSSObjectStorageClient.ts:42)

oss 对象应该是外部传入,而不是自己构造

当前已经是外部注入的:constructor(client: OSSObject),调用方构造好 OSSObject 后传入。

3. append 的 position 问题 (OSSObjectStorageClient.ts:79)

如果是知道 key 存在但是 position 不存在是否应该去检查 position?现在这样可能会出现覆盖问题。这个 api 不安全。

OSS AppendObject API 本身是安全的——position 不匹配时会返回 PositionNotEqualToLength 错误,不会覆盖数据。当前代码的处理逻辑是:

  1. 先用缓存的 position(新 key 默认 0)尝试 append
  2. 如果 position 不匹配(进程重启/其他 writer),捕获错误后 HEAD 获取实际 size,再 retry

所以不存在覆盖问题。唯一的风险是两个 writer 同时 append 同一个 key 时可能丢数据(HEAD 之后另一个 writer 又 append 了),但这属于 last-write-wins 的固有限制,注释中已说明。如果需要多 writer 安全,应该用数据库 store。

jerryliang64 and others added 2 commits March 4, 2026 14:36
Prefix without trailing slash (e.g. 'myapp') would produce malformed
keys like 'myappthreads/...'. Now the constructor ensures non-empty
prefixes always end with '/'.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
cnpmcore master upgraded oxlint-tsgolint from ^0.14.2 to ^0.15.0,
resolving the ERESOLVE conflict with oxlint@1.51.0.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Move type definitions (AgentStore, ObjectStorageClient, errors) from
@eggjs/agent-runtime to @eggjs/tegg-types/agent-runtime for centralized
type management. Implementation code (OSSAgentStore, OSSObjectStorageClient,
AgentStoreUtils) stays in agent-runtime. The agent-runtime package re-exports
all types from tegg-types for backward compatibility.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown

@akitaSummer akitaSummer left a comment

Choose a reason for hiding this comment

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

1

@socket-security
Copy link
Copy Markdown

socket-security bot commented Mar 5, 2026

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedhusky@​9.1.71001006280100
Addedmri@​1.2.010010010080100
Addedcross-spawn@​7.0.6991009780100
Addedjs-yaml@​4.1.19810010081100
Addedglobby@​11.1.09910010087100
Addedtypescript@​5.9.31001009010090
Addedzod@​4.3.610010010093100

View full report

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
gxkl pushed a commit that referenced this pull request Mar 5, 2026
)

sync from: #5818

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

## Release Notes

* **New Features**
* Introduced a new agent runtime module for managing agent threads and
runs with persistent storage capabilities.
* Added thread creation and run lifecycle operations with metadata and
conversation history management.
* Implemented error handling for missing resources and conflicting
operations.

* **Tests**
* Added comprehensive test suites for agent runtime components and
storage functionality.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
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