Skip to content

fix(arkor): keeping original error when training entry import fails - #222

Open
ARYAN0-work wants to merge 5 commits into
arkorlab:mainfrom
ARYAN0-work:fix/runner-import-error-context
Open

fix(arkor): keeping original error when training entry import fails#222
ARYAN0-work wants to merge 5 commits into
arkorlab:mainfrom
ARYAN0-work:fix/runner-import-error-context

Conversation

@ARYAN0-work

@ARYAN0-work ARYAN0-work commented Aug 9, 2026

Copy link
Copy Markdown

Summary

This PR addresses #221 issue

  • How i found and investigated the issue

I started by reading issue #221 to understand the reported behavior and the expected behavior. Main problem is that when the training entry exists but its dynamic import fails, the original import error is not preserved with enough context. This makes it harder to understand what went wrong and where the failure happened.

  • How i reproduced the issue

I first reproduced the behavior locally by creating a small temporary test case with a training entry whose import intentionally fails. I then ran:

pnpm --filter arkor test -- src/core/runner.test.ts

The test reproduced the problematic behavior.

image
  • Understanding the repo pattern

Before changing the implementation, I looked through other parts of the repository to understand how errors and error causes are handled elsewhere. I followed the existing patterns for understanding the repo error-handling convention. This helped me identify the appropriate boundary for handling the error: the dynamic import of the training entry itself, without wrapping errors produced later by the Trainer.

  • Implementing the fix

I actually changed the dynamic training-entry import to preserve the original error as the cause while adding contextual information about the failed training entry. I also converted the reproduction into a regression test.

  • Verification

I ran the targeted test again and verified that it passed then i ran the test and got:

26 test files passed, 458 tests passed

image

Overall Changes

  • Preserve the original dynamic import error as cause
  • Add contextual information when loading a training entry fails
  • Add a regression test covering the failure case

This keeps the original debugging info while providing additional context about which training entry failed to load.


Summary by cubic

Preserves the original error when a training entry import fails in arkor and adds the entry path to the top-level error. Previously, import failures lost context; now we include the entry path and append the original error message while keeping it as the cause.

  • Wrap the dynamic import in try/catch and rethrow: "Failed to load training entry: \n" with { cause }.
  • Keep CLI output behavior; the rethrown message now surfaces the root cause without dumping raw stacks.
  • Add a regression test asserting the contextual message, entry path, preserved cause, and inclusion of the underlying "Cannot find module" message.

Written for commit 51b1efe. Summary will update on new commits.

Review in cubic

Summary by CodeRabbit

  • Bug Fixes
    • Improved error messages when a training entry cannot be loaded, including the entry path for easier troubleshooting.
    • Preserved the original import error details, including module-not-found messages, for better diagnosis.
    • Added contextual error handling to make failures during training startup clearer and easier to investigate.

@qodo-code-review

Copy link
Copy Markdown

ⓘ Qodo reviews are paused because your trial has ended. Ask your workspace admin to add credits to resume reviews. Manage billing

@coderabbitai

coderabbitai Bot commented Aug 9, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 08ca7159-bfc1-4eda-b67d-67c2d0d376db

📥 Commits

Reviewing files that changed from the base of the PR and between 4112052 and 51b1efe.

📒 Files selected for processing (2)
  • packages/arkor/src/core/runner.test.ts
  • packages/arkor/src/core/runner.ts

Included review availability: Your plan provides up to 2 included reviews per hour; 0 remain after this review.

📜 Recent review details
⏰ Context from checks skipped due to timeout. (2)
  • GitHub Check: cubic · AI code reviewer
  • GitHub Check: Seer Code Review
🧰 Additional context used
📓 Path-based instructions (9)
packages/arkor/src/**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Preserve Studio CSRF protections: send the token in X-Arkor-Studio-Token for fetch, use studioToken for EventSource, enforce the localhost host-header allow-list, do not configure CORS, and compare tokens with timingSafeEqual.

Files:

  • packages/arkor/src/core/runner.test.ts
  • packages/arkor/src/core/runner.ts
packages/*/src/**/*.test.ts

📄 CodeRabbit inference engine (AGENTS.md)

Add Vitest tests in the same change for SDK, CLI, scaffolder, schema, or other package logic changes; consider an e2e/cli scenario for CLI flow changes.

Files:

  • packages/arkor/src/core/runner.test.ts
**/*.{js,ts,jsx,tsx,json,css,html}

📄 CodeRabbit inference engine (AGENTS.md)

Use oxfmt for formatting with the repository configuration; do not manually override its whitespace, wrapping, quotes, or trailing-comma decisions.

Files:

  • packages/arkor/src/core/runner.test.ts
  • packages/arkor/src/core/runner.ts
**/*.{js,ts,jsx,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Run both linters through the root configurations: oxlint --deny-warnings . followed by eslint .; add configuration overrides at the root rather than per-package configs.

Files:

  • packages/arkor/src/core/runner.test.ts
  • packages/arkor/src/core/runner.ts
**/*.{js,jsx,ts,tsx}

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Do not use the em dash character (U+2014) in code comments, string literals, or template literals, including CLI messages, generated template bodies, and test names.

Files:

  • packages/arkor/src/core/runner.test.ts
  • packages/arkor/src/core/runner.ts
packages/**/*.{ts,tsx}

📄 CodeRabbit inference engine (CONTRIBUTING.ja.md)

TypeScript/TSX のコード、コメント、文字列、テンプレートリテラルではエムダッシュ (U+2014) またはその HTML エンティティを使用しない。

Files:

  • packages/arkor/src/core/runner.test.ts
  • packages/arkor/src/core/runner.ts
**/*

📄 CodeRabbit inference engine (CONTRIBUTING.ja.md)

リポジトリ内の追跡対象ファイルでは、エムダッシュまたはその HTML エンティティを使用しない。Markdown、YAML、JSON、HTML、設定ファイル、生成テンプレートも含む。

Files:

  • packages/arkor/src/core/runner.test.ts
  • packages/arkor/src/core/runner.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (CONTRIBUTING.ja.md)

SDK、CLI、スキャフォルダーのロジックには Vitest のテストを追加し、Studio コンポーネントには jsdom と Testing Library ベースのテストを使用する。ただしテスト追加自体は PR の必須条件ではない。

Files:

  • packages/arkor/src/core/runner.test.ts
  • packages/arkor/src/core/runner.ts
packages/arkor/src/core/runner.ts

📄 CodeRabbit inference engine (AGENTS.md)

User project entry-point discovery must support, in order: a named arkor export from createArkor, a bare trainer export, a default Arkor manifest or Trainer, and a nested default.trainer.

Files:

  • packages/arkor/src/core/runner.ts
🧠 Learnings (2)
📚 Learning: 2026-07-24T09:55:04.181Z
Learnt from: CR
Repo: arkorlab/arkor PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-07-24T09:55:04.181Z
Learning: Applies to packages/*/src/**/*.test.ts : Add Vitest tests in the same change for SDK, CLI, scaffolder, schema, or other package logic changes; consider an `e2e/cli` scenario for CLI flow changes.

Applied to files:

  • packages/arkor/src/core/runner.test.ts
📚 Learning: 2026-07-24T09:55:04.181Z
Learnt from: CR
Repo: arkorlab/arkor PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-07-24T09:55:04.181Z
Learning: Applies to **/*.{js,ts,jsx,tsx,json,css,html} : Use oxfmt for formatting with the repository configuration; do not manually override its whitespace, wrapping, quotes, or trailing-comma decisions.

Applied to files:

  • packages/arkor/src/core/runner.ts
🔇 Additional comments (2)
packages/arkor/src/core/runner.test.ts (1)

72-75: Assert the original cause message.

The test checks only that cause is an Error. It can pass with a generic cause while the outer message contains copied module-resolution text. Assert that cause.message contains Cannot find module and does-not-exist.mjs.

Suggested assertion
     const cause = (error as Error).cause as Error;
     expect(cause).toBeInstanceOf(Error);
-    expect((error as Error).message).toMatch(/Cannot find module/);
-    expect((error as Error).cause).toBeInstanceOf(Error);
+    expect(cause.message).toMatch(/Cannot find module/);
+    expect(cause.message).toContain("does-not-exist.mjs");
packages/arkor/src/core/runner.ts (1)

60-67: LGTM!


Walkthrough

runTrainer now converts training-entry import failures into contextual errors that include the resolved entry path, preserve the original exception as cause, and retain the original message. Tests cover this behavior.

Changes

Trainer entry loading

Layer / File(s) Summary
Wrap trainer-entry import failures
packages/arkor/src/core/runner.ts, packages/arkor/src/core/runner.test.ts
runTrainer catches dynamic import failures and throws an error with the absolute entry path, the original message, and the original exception as cause. Tests verify these properties.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: 🔵 Low · up to 51b1e

The change improves error context for failed training-entry imports while retaining the original failure. The regression test should also verify the original module-resolution message in the cause; the PR is otherwise mergeable with that follow-up.

Possibly related issues

Possibly related PRs

  • arkorlab/arkor#101 — Changes the same runner.ts and runner.test.ts entry-module execution paths.
  • arkorlab/arkor#223 — Implements the same runTrainer import-error wrapping and test coverage.

Suggested reviewers: soleil-colza, k-taro56

🚥 Pre-merge checks | ✅ 4 | ❌ 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 100.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: preserving the original error when a training entry import fails.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
✨ Simplify code
  • Create PR with simplified code

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.

@drift-check

drift-check Bot commented Aug 9, 2026

Copy link
Copy Markdown

Code Review Bot

No reviewable code changes were analyzed. ⚠️ The documentation drift check could not be evaluated. Reviewed 0 file(s); skipped 2.

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

PR Summary by Qodo

Preserve original import error when training entry module fails to load

🐞 Bug fix 🧪 Tests 🕐 10-20 Minutes

Grey Divider

AI Description

• Wrap training-entry dynamic import failures with a contextual error message.
• Preserve the original import exception via Error.cause for better debugging.
• Add a regression test for broken training-entry imports.
Diagram

graph TD
  A(["CLI / caller"]) --> B["runTrainer()"] --> C{"Entry exists?"} --> D[["Dynamic import entry"]] --> E["extractTrainer()"] --> F["Trainer.start / wait"]
  C --> G["Error: entry not found"]
  D --> H["Error: failed to load (cause=original)"]
  subgraph Legend
    direction LR
    _call(["Caller"]) ~~~ _step["Function / step"] ~~~ _dec{"Decision"} ~~~ _err["Error"]
  end
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Introduce a typed `TrainingEntryLoadError` class
  • ➕ Allows programmatic handling (e.g., CLI can format load errors differently).
  • ➕ Can standardize fields (entryPath, originalError) without parsing message strings.
  • ➖ Adds API surface area and slightly more code for a small behavior tweak.
  • ➖ Potentially overkill if errors are only user-facing/logged.
2. Re-throw original error with augmented message only
  • ➕ Preserves original stack/message verbatim.
  • ➕ No nested error traversal needed.
  • ➖ Loses explicit causal chain in environments that support Error.cause.
  • ➖ Harder to include both original message and clear contextual wrapper consistently.

Recommendation: Current approach (wrap with a contextual Error and set cause) is the best default: it improves user-facing context while preserving the original exception for debugging. Consider a dedicated TrainingEntryLoadError only if downstream code needs to reliably detect/format this specific failure mode.

Files changed (2) +28 / -1

Bug fix (1) +11 / -1
runner.tsWrap dynamic training-entry import errors and preserve original cause +11/-1

Wrap dynamic training-entry import errors and preserve original cause

• Replaces the direct dynamic import with a try/catch. On import failure, throws a new contextual error ('Failed to load training entry: ...') while attaching the original exception via 'Error.cause'.

packages/arkor/src/core/runner.ts

Tests (1) +17 / -0
runner.test.tsAdd regression test asserting import errors are wrapped with 'cause' +17/-0

Add regression test asserting import errors are wrapped with 'cause'

• Adds a test that writes a broken '.mjs' entry importing a missing module. Verifies 'runTrainer()' throws an Error with contextual message and that 'error.cause' contains the original import failure.

packages/arkor/src/core/runner.test.ts

@greptile-apps

greptile-apps Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR now preserves dynamic-import failures as an error cause while including the entry path and underlying diagnostic in the outer message.

  • Wraps training-entry import failures with contextual path information.
  • Preserves the original error through Error.cause.
  • Adds regression coverage for the contextual message and cause.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
packages/arkor/src/core/runner.ts Adds a correctly formatted import boundary that preserves and exposes the original loading error.
packages/arkor/src/core/runner.test.ts Adds regression coverage confirming the entry path, underlying diagnostic, and original cause are retained.

Reviews (5): Last reviewed commit: "fix(runner): fixing error cause messagin..." | Re-trigger Greptile

Comment thread packages/arkor/src/core/runner.ts Outdated
Comment thread packages/arkor/src/core/runner.ts Outdated
@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Aug 9, 2026

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (0) 📎 Requirement gaps (0) 📜 Skill insights (0)

Grey Divider


Action required

1. ESLint spacing rule break ✓ Resolved 🐞 Bug ⚙ Maintainability
Description
The new try/catch and Error options object in runTrainer omit required keyword/object spacing,
which will trigger @stylistic/keyword-spacing and @stylistic/object-curly-spacing lint errors.
This is likely to fail the arkor package lint script (oxlint ... && eslint .) and block CI/merge
checks.
Code

packages/arkor/src/core/runner.ts[R65-68]

+  } catch(error){
+    throw new Error(`Failed to load training entry: ${abs}`,{
+      cause:error,
+    })
Evidence
The modified runTrainer code uses try{ / catch(error){ and an options object literal without
spaces, which conflicts with the repo’s ESLint configuration enabling @stylistic/keyword-spacing
and @stylistic/object-curly-spacing as errors. The arkor package lint script runs eslint .,
so these violations will surface as failing lint.

packages/arkor/src/core/runner.ts[58-68]
eslint.config.ts[145-151]
packages/arkor/package.json[44-49]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`packages/arkor/src/core/runner.ts` introduces spacing that violates repo ESLint rules:
- `try{` / `} catch(error){` violates `@stylistic/keyword-spacing` (expects `try {` and `catch (error)`).
- `new Error(...,{ cause:error, })` violates `@stylistic/object-curly-spacing` (expects spaces inside `{ ... }`).
These rules are configured as `error`, and the `arkor` package lint script runs `eslint .`, so the PR likely fails lint.
## Issue Context
Repo ESLint config enables these stylistic rules at error level.
## Fix Focus Areas
- packages/arkor/src/core/runner.ts[58-69]
- eslint.config.ts[145-151]
- packages/arkor/package.json[44-49]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended

2. Error coercion masks failures 🐞 Bug ☼ Reliability ⭐ New
Description
When an imported entry throws a non-Error value whose string coercion fails, String(error) throws
before the contextual Error is created. For example, throw Object.create(null) replaces the entry
failure with a coercion TypeError and loses both the entry-path context and original cause.
Code

packages/arkor/src/core/runner.ts[63]

+    const causeMessage = error instanceof Error ? error.message : String(error);
Evidence
runTrainer dynamically executes the user-provided entry, catches its arbitrary thrown value, and
then coercively formats that unknown value before constructing the contextual Error. Because
coercion can itself throw, the subsequent Error with cause: error is never reached in that case.

packages/arkor/src/core/runner.ts[47-65]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
A training entry can throw any JavaScript value. If a non-Error value cannot be converted to a string, the current `String(error)` call throws before the contextual error is constructed, masking the original failure and omitting the entry path.

## Issue Context
Keep the original thrown value as `cause`, but make formatting best-effort so creation of the contextual error cannot be interrupted. Add coverage using a module that throws a value such as `Object.create(null)`.

## Fix Focus Areas
- packages/arkor/src/core/runner.ts[60-66]
- packages/arkor/src/core/runner.test.ts[62-76]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


3. Cause hidden in CLI ✓ Resolved 🐞 Bug ◔ Observability
Description
runTrainer now rethrows import failures as a new Error with the original failure stored only in
cause, but the CLI entrypoint logs only err.stack ?? err.message, which does not print the cause
chain. As a result, arkor start failures will typically show only “Failed to load training entry
…” and omit the underlying import error details needed to debug (e.g. missing module / syntax
error).
Code

packages/arkor/src/core/runner.ts[R62-65]

+  } catch (error) {
+    throw new Error(`Failed to load training entry: ${abs}`, {
+      cause: error,
+    });
Evidence
The PR change wraps the dynamic import error into a new Error whose only link to the original
failure is via cause. The CLI’s top-level handler prints only err.stack ?? err.message and never
prints cause, so the underlying import failure details are not emitted by the CLI path.

packages/arkor/src/core/runner.ts[47-66]
packages/arkor/src/bin.ts[14-42]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`runTrainer()` now wraps import errors with a new `Error(..., { cause })`, but the CLI’s top-level handler prints only `err.stack ?? err.message`. Since the underlying import failure is now in `err.cause`, users typically won’t see the real import error message/stack when `arkor start` fails.
## Issue Context
The PR intentionally moves the original import failure into `Error.cause`. The CLI should print the entire cause chain (at least message + stack) so the wrapped error adds context *without* hiding the root cause.
## Fix Focus Areas
- packages/arkor/src/bin.ts[14-43]
- packages/arkor/src/core/runner.ts[58-66]
## Suggested fix
Update the CLI error printing to include `err.cause` recursively (e.g., print `err.stack` then append `Caused by: <cause.stack>` while `cause` exists). This keeps the wrapper context while restoring the original import failure details in CLI output.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


4. Test omits entry path assert ✓ Resolved 📎 Requirement gap ☼ Reliability
Description
The new regression test checks for the contextual error prefix but does not assert that the thrown
error message includes the failing training entry path. This weakens the guarantee required by the
compliance checklist and could allow future changes to drop the entry-path context without failing
tests.
Code

packages/arkor/src/core/runner.test.ts[R72-75]

+        expect((error as Error).message).toMatch(/Failed to load training entry/);
+        expect((error as Error).cause).toBeInstanceOf(Error);
+        expect(((error as Error).cause as Error).message).toMatch(
+          /Cannot find module/,
Evidence
PR Compliance ID 2 requires an automated test that verifies both contextual messaging including the
entry path and original error preservation. In the added test, the assertions check only for the
generic message prefix and the presence/content of cause, but never assert that the message
contains the entry path.

Add automated test covering failed training entry import
packages/arkor/src/core/runner.test.ts[62-76]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The new test validates `Failed to load training entry` but does not verify the error message includes the specific training entry path, which is required to prevent regressions.
## Issue Context
`runTrainer()` is expected to throw an error that both (1) provides context and identifies the entry path and (2) preserves the underlying import error as `cause`. The implementation in `runner.ts` includes the absolute path (`${abs}`), but the test should explicitly assert the path is present.
## Fix Focus Areas
- packages/arkor/src/core/runner.test.ts[62-77]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Context sources

Grey Divider

Tip of the day
💡 Did you know, you can show, collapse, or hide each part of a finding: code, evidence, and all

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Previous reviews

Review updated until commit 51b1efe ⚖️ Balanced

Results up to commit 4112052


🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0) 📜 Skill insights (0)


Action required
1. ESLint spacing rule break ✓ Resolved 🐞 Bug ⚙ Maintainability
Description
The new try/catch and Error options object in runTrainer omit required keyword/object spacing,
which will trigger @stylistic/keyword-spacing and @stylistic/object-curly-spacing lint errors.
This is likely to fail the arkor package lint script (oxlint ... && eslint .) and block CI/merge
checks.
Code

packages/arkor/src/core/runner.ts[R65-68]

+  } catch(error){
+    throw new Error(`Failed to load training entry: ${abs}`,{
+      cause:error,
+    })
Evidence
The modified runTrainer code uses try{ / catch(error){ and an options object literal without
spaces, which conflicts with the repo’s ESLint configuration enabling @stylistic/keyword-spacing
and @stylistic/object-curly-spacing as errors. The arkor package lint script runs eslint .,
so these violations will surface as failing lint.

packages/arkor/src/core/runner.ts[58-68]
eslint.config.ts[145-151]
packages/arkor/package.json[44-49]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`packages/arkor/src/core/runner.ts` introduces spacing that violates repo ESLint rules:
- `try{` / `} catch(error){` violates `@stylistic/keyword-spacing` (expects `try {` and `catch (error)`).
- `new Error(...,{ cause:error, })` violates `@stylistic/object-curly-spacing` (expects spaces inside `{ ... }`).
These rules are configured as `error`, and the `arkor` package lint script runs `eslint .`, so the PR likely fails lint.
## Issue Context
Repo ESLint config enables these stylistic rules at error level.
## Fix Focus Areas
- packages/arkor/src/core/runner.ts[58-69]
- eslint.config.ts[145-151]
- packages/arkor/package.json[44-49]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended
2. Cause hidden in CLI ✓ Resolved 🐞 Bug ◔ Observability
Description
runTrainer now rethrows import failures as a new Error with the original failure stored only in
cause, but the CLI entrypoint logs only err.stack ?? err.message, which does not print the cause
chain. As a result, arkor start failures will typically show only “Failed to load training entry
…” and omit the underlying import error details needed to debug (e.g. missing module / syntax
error).
Code

packages/arkor/src/core/runner.ts[R62-65]

+  } catch (error) {
+    throw new Error(`Failed to load training entry: ${abs}`, {
+      cause: error,
+    });
Evidence
The PR change wraps the dynamic import error into a new Error whose only link to the original
failure is via cause. The CLI’s top-level handler prints only err.stack ?? err.message and never
prints cause, so the underlying import failure details are not emitted by the CLI path.

packages/arkor/src/core/runner.ts[47-66]
packages/arkor/src/bin.ts[14-42]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`runTrainer()` now wraps import errors with a new `Error(..., { cause })`, but the CLI’s top-level handler prints only `err.stack ?? err.message`. Since the underlying import failure is now in `err.cause`, users typically won’t see the real import error message/stack when `arkor start` fails.
## Issue Context
The PR intentionally moves the original import failure into `Error.cause`. The CLI should print the entire cause chain (at least message + stack) so the wrapped error adds context *without* hiding the root cause.
## Fix Focus Areas
- packages/arkor/src/bin.ts[14-43]
- packages/arkor/src/core/runner.ts[58-66]
## Suggested fix
Update the CLI error printing to include `err.cause` recursively (e.g., print `err.stack` then append `Caused by: <cause.stack>` while `cause` exists). This keeps the wrapper context while restoring the original import failure details in CLI output.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


3. Test omits entry path assert ✓ Resolved 📎 Requirement gap ☼ Reliability
Description
The new regression test checks for the contextual error prefix but does not assert that the thrown
error message includes the failing training entry path. This weakens the guarantee required by the
compliance checklist and could allow future changes to drop the entry-path context without failing
tests.
Code

packages/arkor/src/core/runner.test.ts[R72-75]

+        expect((error as Error).message).toMatch(/Failed to load training entry/);
+        expect((error as Error).cause).toBeInstanceOf(Error);
+        expect(((error as Error).cause as Error).message).toMatch(
+          /Cannot find module/,
Evidence
PR Compliance ID 2 requires an automated test that verifies both contextual messaging including the
entry path and original error preservation. In the added test, the assertions check only for the
generic message prefix and the presence/content of cause, but never assert that the message
contains the entry path.

Add automated test covering failed training entry import
packages/arkor/src/core/runner.test.ts[62-76]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The new test validates `Failed to load training entry` but does not verify the error message includes the specific training entry path, which is required to prevent regressions.
## Issue Context
`runTrainer()` is expected to throw an error that both (1) provides context and identifies the entry path and (2) preserves the underlying import error as `cause`. The implementation in `runner.ts` includes the absolute path (`${abs}`), but the test should explicitly assert the path is present.
## Fix Focus Areas
- packages/arkor/src/core/runner.test.ts[62-77]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Context sources
Results up to commit 6e492b1


🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0) 📜 Skill insights (0)


Action required
1. ESLint spacing rule break ✓ Resolved 🐞 Bug ⚙ Maintainability
Description
The new try/catch and Error options object in runTrainer omit required keyword/object spacing,
which will trigger @stylistic/keyword-spacing and @stylistic/object-curly-spacing lint errors.
This is likely to fail the arkor package lint script (oxlint ... && eslint .) and block CI/merge
checks.
Code

packages/arkor/src/core/runner.ts[R65-68]

+  } catch(error){
+    throw new Error(`Failed to load training entry: ${abs}`,{
+      cause:error,
+    })
Evidence
The modified runTrainer code uses try{ / catch(error){ and an options object literal without
spaces, which conflicts with the repo’s ESLint configuration enabling @stylistic/keyword-spacing
and @stylistic/object-curly-spacing as errors. The arkor package lint script runs eslint .,
so these violations will surface as failing lint.

packages/arkor/src/core/runner.ts[58-68]
eslint.config.ts[145-151]
packages/arkor/package.json[44-49]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`packages/arkor/src/core/runner.ts` introduces spacing that violates repo ESLint rules:
- `try{` / `} catch(error){` violates `@stylistic/keyword-spacing` (expects `try {` and `catch (error)`).
- `new Error(...,{ cause:error, })` violates `@stylistic/object-curly-spacing` (expects spaces inside `{ ... }`).
These rules are configured as `error`, and the `arkor` package lint script runs `eslint .`, so the PR likely fails lint.
## Issue Context
Repo ESLint config enables these stylistic rules at error level.
## Fix Focus Areas
- packages/arkor/src/core/runner.ts[58-69]
- eslint.config.ts[145-151]
- packages/arkor/package.json[44-49]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended
2. Cause hidden in CLI ✓ Resolved 🐞 Bug ◔ Observability
Description
runTrainer now rethrows import failures as a new Error with the original failure stored only in
cause, but the CLI entrypoint logs only err.stack ?? err.message, which does not print the cause
chain. As a result, arkor start failures will typically show only “Failed to load training entry
…” and omit the underlying import error details needed to debug (e.g. missing module / syntax
error).
Code

packages/arkor/src/core/runner.ts[R62-65]

+  } catch (error) {
+    throw new Error(`Failed to load training entry: ${abs}`, {
+      cause: error,
+    });
Evidence
The PR change wraps the dynamic import error into a new Error whose only link to the original
failure is via cause. The CLI’s top-level handler prints only err.stack ?? err.message and never
prints cause, so the underlying import failure details are not emitted by the CLI path.

packages/arkor/src/core/runner.ts[47-66]
packages/arkor/src/bin.ts[14-42]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`runTrainer()` now wraps import errors with a new `Error(..., { cause })`, but the CLI’s top-level handler prints only `err.stack ?? err.message`. Since the underlying import failure is now in `err.cause`, users typically won’t see the real import error message/stack when `arkor start` fails.
## Issue Context
The PR intentionally moves the original import failure into `Error.cause`. The CLI should print the entire cause chain (at least message + stack) so the wrapped error adds context *without* hiding the root cause.
## Fix Focus Areas
- packages/arkor/src/bin.ts[14-43]
- packages/arkor/src/core/runner.ts[58-66]
## Suggested fix
Update the CLI error printing to include `err.cause` recursively (e.g., print `err.stack` then append `Caused by: <cause.stack>` while `cause` exists). This keeps the wrapper context while restoring the original import failure details in CLI output.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


3. Test omits entry path assert ✓ Resolved 📎 Requirement gap ☼ Reliability
Description
The new regression test checks for the contextual error prefix but does not assert that the thrown
error message includes the failing training entry path. This weakens the guarantee required by the
compliance checklist and could allow future changes to drop the entry-path context without failing
tests.
Code

packages/arkor/src/core/runner.test.ts[R72-75]

+        expect((error as Error).message).toMatch(/Failed to load training entry/);
+        expect((error as Error).cause).toBeInstanceOf(Error);
+        expect(((error as Error).cause as Error).message).toMatch(
+          /Cannot find module/,
Evidence
PR Compliance ID 2 requires an automated test that verifies both contextual messaging including the
entry path and original error preservation. In the added test, the assertions check only for the
generic message prefix and the presence/content of cause, but never assert that the message
contains the entry path.

Add automated test covering failed training entry import
packages/arkor/src/core/runner.test.ts[62-76]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The new test validates `Failed to load training entry` but does not verify the error message includes the specific training entry path, which is required to prevent regressions.
## Issue Context
`runTrainer()` is expected to throw an error that both (1) provides context and identifies the entry path and (2) preserves the underlying import error as `cause`. The implementation in `runner.ts` includes the absolute path (`${abs}`), but the test should explicitly assert the path is present.
## Fix Focus Areas
- packages/arkor/src/core/runner.test.ts[62-77]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Context
Results up to commit f372dba


🐞 Bugs (1) 📘 Rule violations (0) 📎 Requirement gaps (0) 📜 Skill insights (0)


Action required
1. ESLint spacing rule break ✓ Resolved 🐞 Bug ⚙ Maintainability
Description
The new try/catch and Error options object in runTrainer omit required keyword/object spacing,
which will trigger @stylistic/keyword-spacing and @stylistic/object-curly-spacing lint errors.
This is likely to fail the arkor package lint script (oxlint ... && eslint .) and block CI/merge
checks.
Code

packages/arkor/src/core/runner.ts[R65-68]

+  } catch(error){
+    throw new Error(`Failed to load training entry: ${abs}`,{
+      cause:error,
+    })
Evidence
The modified runTrainer code uses try{ / catch(error){ and an options object literal without
spaces, which conflicts with the repo’s ESLint configuration enabling @stylistic/keyword-spacing
and @stylistic/object-curly-spacing as errors. The arkor package lint script runs eslint .,
so these violations will surface as failing lint.

packages/arkor/src/core/runner.ts[58-68]
eslint.config.ts[145-151]
packages/arkor/package.json[44-49]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`packages/arkor/src/core/runner.ts` introduces spacing that violates repo ESLint rules:
- `try{` / `} catch(error){` violates `@stylistic/keyword-spacing` (expects `try {` and `catch (error)`).
- `new Error(...,{ cause:error, })` violates `@stylistic/object-curly-spacing` (expects spaces inside `{ ... }`).
These rules are configured as `error`, and the `arkor` package lint script runs `eslint .`, so the PR likely fails lint.
## Issue Context
Repo ESLint config enables these stylistic rules at error level.
## Fix Focus Areas
- packages/arkor/src/core/runner.ts[58-69]
- eslint.config.ts[145-151]
- packages/arkor/package.json[44-49]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended
2. Cause hidden in CLI 🐞 Bug ◔ Observability ⭐ New
Description
runTrainer now rethrows import failures as a new Error with the original failure stored only in
cause, but the CLI entrypoint logs only err.stack ?? err.message, which does not print the cause
chain. As a result, arkor start failures will typically show only “Failed to load training entry
…” and omit the underlying import error details needed to debug (e.g. missing module / syntax
error).
Code

packages/arkor/src/core/runner.ts[R62-65]

+  } catch (error) {
+    throw new Error(`Failed to load training entry: ${abs}`, {
+      cause: error,
+    });
Evidence
The PR change wraps the dynamic import error into a new Error whose only link to the original
failure is via cause. The CLI’s top-level handler prints only err.stack ?? err.message and never
prints cause, so the underlying import failure details are not emitted by the CLI path.

packages/arkor/src/core/runner.ts[47-66]
packages/arkor/src/bin.ts[14-42]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`runTrainer()` now wraps import errors with a new `Error(..., { cause })`, but the CLI’s top-level handler prints only `err.stack ?? err.message`. Since the underlying import failure is now in `err.cause`, users typically won’t see the real import error message/stack when `arkor start` fails.

## Issue Context
The PR intentionally moves the original import failure into `Error.cause`. The CLI should print the entire cause chain (at least message + stack) so the wrapped error adds context *without* hiding the root cause.

## Fix Focus Areas
- packages/arkor/src/bin.ts[14-43]
- packages/arkor/src/core/runner.ts[58-66]

## Suggested fix
Update the CLI error printing to include `err.cause` recursively (e.g., print `err.stack` then append `Caused by: <cause.stack>` while `cause` exists). This keeps the wrapper context while restoring the original import failure details in CLI output.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


3. Test omits entry path assert ✓ Resolved 📎 Requirement gap ☼ Reliability
Description
The new regression test checks for the contextual error prefix but does not assert that the thrown
error message includes the failing training entry path. This weakens the guarantee required by the
compliance checklist and could allow future changes to drop the entry-path context without failing
tests.
Code

packages/arkor/src/core/runner.test.ts[R72-75]

+        expect((error as Error).message).toMatch(/Failed to load training entry/);
+        expect((error as Error).cause).toBeInstanceOf(Error);
+        expect(((error as Error).cause as Error).message).toMatch(
+          /Cannot find module/,
Evidence
PR Compliance ID 2 requires an automated test that verifies both contextual messaging including the
entry path and original error preservation. In the added test, the assertions check only for the
generic message prefix and the presence/content of cause, but never assert that the message
contains the entry path.

Add automated test covering failed training entry import
packages/arkor/src/core/runner.test.ts[62-76]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The new test validates `Failed to load training entry` but does not verify the error message includes the specific training entry path, which is required to prevent regressions.
## Issue Context
`runTrainer()` is expected to throw an error that both (1) provides context and identifies the entry path and (2) preserves the underlying import error as `cause`. The implementation in `runner.ts` includes the absolute path (`${abs}`), but the test should explicitly assert the path is present.
## Fix Focus Areas
- packages/arkor/src/core/runner.test.ts[62-77]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Context used
Results up to commit d4b547a


🐞 Bugs (1) 📘 Rule violations (0) 📎 Requirement gaps (1) 📜 Skill insights (0)


Action required
1. ESLint spacing rule break 🐞 Bug ⚙ Maintainability
Description
The new try/catch and Error options object in runTrainer omit required keyword/object spacing,
which will trigger @stylistic/keyword-spacing and @stylistic/object-curly-spacing lint errors.
This is likely to fail the arkor package lint script (oxlint ... && eslint .) and block CI/merge
checks.
Code

packages/arkor/src/core/runner.ts[R65-68]

+  } catch(error){
+    throw new Error(`Failed to load training entry: ${abs}`,{
+      cause:error,
+    })
Evidence
The modified runTrainer code uses try{ / catch(error){ and an options object literal without
spaces, which conflicts with the repo’s ESLint configuration enabling @stylistic/keyword-spacing
and @stylistic/object-curly-spacing as errors. The arkor package lint script runs eslint .,
so these violations will surface as failing lint.

packages/arkor/src/core/runner.ts[58-68]
eslint.config.ts[145-151]
packages/arkor/package.json[44-49]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`packages/arkor/src/core/runner.ts` introduces spacing that violates repo ESLint rules:
- `try{` / `} catch(error){` violates `@stylistic/keyword-spacing` (expects `try {` and `catch (error)`).
- `new Error(...,{ cause:error, })` violates `@stylistic/object-curly-spacing` (expects spaces inside `{ ... }`).

These rules are configured as `error`, and the `arkor` package lint script runs `eslint .`, so the PR likely fails lint.

## Issue Context
Repo ESLint config enables these stylistic rules at error level.

## Fix Focus Areas
- packages/arkor/src/core/runner.ts[58-69]
- eslint.config.ts[145-151]
- packages/arkor/package.json[44-49]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended
2. Test omits entry path assert 📎 Requirement gap ☼ Reliability
Description
The new regression test checks for the contextual error prefix but does not assert that the thrown
error message includes the failing training entry path. This weakens the guarantee required by the
compliance checklist and could allow future changes to drop the entry-path context without failing
tests.
Code

packages/arkor/src/core/runner.test.ts[R72-75]

+        expect((error as Error).message).toMatch(/Failed to load training entry/);
+        expect((error as Error).cause).toBeInstanceOf(Error);
+        expect(((error as Error).cause as Error).message).toMatch(
+          /Cannot find module/,
Evidence
PR Compliance ID 2 requires an automated test that verifies both contextual messaging including the
entry path and original error preservation. In the added test, the assertions check only for the
generic message prefix and the presence/content of cause, but never assert that the message
contains the entry path.

Add automated test covering failed training entry import
packages/arkor/src/core/runner.test.ts[62-76]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The new test validates `Failed to load training entry` but does not verify the error message includes the specific training entry path, which is required to prevent regressions.

## Issue Context
`runTrainer()` is expected to throw an error that both (1) provides context and identifies the entry path and (2) preserves the underlying import error as `cause`. The implementation in `runner.ts` includes the absolute path (`${abs}`), but the test should explicitly assert the path is present.

## Fix Focus Areas
- packages/arkor/src/core/runner.test.ts[62-77]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Context used

Grey Divider

Qodo Logo

Comment thread packages/arkor/src/core/runner.test.ts Outdated
Comment thread packages/arkor/src/core/runner.ts Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/arkor/src/core/runner.test.ts`:
- Around line 72-76: Update the error-message assertion in the relevant runner
test to also verify that it contains the resolved training entry path, while
preserving the existing “Failed to load training entry” prefix and cause
assertions.

In `@packages/arkor/src/core/runner.ts`:
- Around line 58-69: Run the repository-configured oxfmt formatter on
packages/arkor/src/core/runner.ts lines 58-69 and
packages/arkor/src/core/runner.test.ts lines 62-78, formatting the import
wrapper, type annotation, spacing, indentation, and added test block without
changing behavior. Then run oxlint --deny-warnings . followed by eslint . and
address any resulting issues.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 34460feb-43de-4162-8454-a00191039df3

📥 Commits

Reviewing files that changed from the base of the PR and between 314c6e3 and d4b547a.

📒 Files selected for processing (2)
  • packages/arkor/src/core/runner.test.ts
  • packages/arkor/src/core/runner.ts
📜 Review details
⏰ Context from checks skipped due to timeout. (2)
  • GitHub Check: Seer Code Review
  • GitHub Check: cubic · AI code reviewer
🧰 Additional context used
📓 Path-based instructions (9)
packages/arkor/src/**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Preserve Studio CSRF protections: send the token in X-Arkor-Studio-Token for fetch, use studioToken for EventSource, enforce the localhost host-header allow-list, do not configure CORS, and compare tokens with timingSafeEqual.

Files:

  • packages/arkor/src/core/runner.test.ts
  • packages/arkor/src/core/runner.ts
packages/*/src/**/*.test.ts

📄 CodeRabbit inference engine (AGENTS.md)

Add Vitest tests in the same change for SDK, CLI, scaffolder, schema, or other package logic changes; consider an e2e/cli scenario for CLI flow changes.

Files:

  • packages/arkor/src/core/runner.test.ts
**/*.{js,ts,jsx,tsx,json,css,html}

📄 CodeRabbit inference engine (AGENTS.md)

Use oxfmt for formatting with the repository configuration; do not manually override its whitespace, wrapping, quotes, or trailing-comma decisions.

Files:

  • packages/arkor/src/core/runner.test.ts
  • packages/arkor/src/core/runner.ts
**/*.{js,ts,jsx,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Run both linters through the root configurations: oxlint --deny-warnings . followed by eslint .; add configuration overrides at the root rather than per-package configs.

Files:

  • packages/arkor/src/core/runner.test.ts
  • packages/arkor/src/core/runner.ts
**/*.{js,jsx,ts,tsx}

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Do not use the em dash character (U+2014) in code comments, string literals, or template literals, including CLI messages, generated template bodies, and test names.

Files:

  • packages/arkor/src/core/runner.test.ts
  • packages/arkor/src/core/runner.ts
packages/**/*.{ts,tsx}

📄 CodeRabbit inference engine (CONTRIBUTING.ja.md)

TypeScript/TSX のコード、コメント、文字列、テンプレートリテラルではエムダッシュ (U+2014) またはその HTML エンティティを使用しない。

Files:

  • packages/arkor/src/core/runner.test.ts
  • packages/arkor/src/core/runner.ts
**/*

📄 CodeRabbit inference engine (CONTRIBUTING.ja.md)

リポジトリ内の追跡対象ファイルでは、エムダッシュまたはその HTML エンティティを使用しない。Markdown、YAML、JSON、HTML、設定ファイル、生成テンプレートも含む。

Files:

  • packages/arkor/src/core/runner.test.ts
  • packages/arkor/src/core/runner.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (CONTRIBUTING.ja.md)

SDK、CLI、スキャフォルダーのロジックには Vitest のテストを追加し、Studio コンポーネントには jsdom と Testing Library ベースのテストを使用する。ただしテスト追加自体は PR の必須条件ではない。

Files:

  • packages/arkor/src/core/runner.test.ts
  • packages/arkor/src/core/runner.ts
packages/arkor/src/core/runner.ts

📄 CodeRabbit inference engine (AGENTS.md)

User project entry-point discovery must support, in order: a named arkor export from createArkor, a bare trainer export, a default Arkor manifest or Trainer, and a nested default.trainer.

Files:

  • packages/arkor/src/core/runner.ts

Comment thread packages/arkor/src/core/runner.test.ts Outdated
Comment thread packages/arkor/src/core/runner.ts Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d4b547a05f

ℹ️ 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".

Comment thread packages/arkor/src/core/runner.ts Outdated
Comment on lines +66 to +68
throw new Error(`Failed to load training entry: ${abs}`,{
cause:error,
})

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Surface the import cause through the CLI

When this path is hit by arkor start, the error bubbles to packages/arkor/src/bin.ts, which prints err.stack ?? err.message as a string. Node does not include Error.cause in the .stack string, so a missing dependency or syntax error in the training entry now renders only Failed to load training entry: <abs> plus this wrapper stack, whereas before the original loader message was printed directly. Include the cause message in the thrown message or update the CLI error printer so the actual import failure remains visible.

Useful? React with 👍 / 👎.

Comment thread packages/arkor/src/core/runner.ts Outdated
Comment on lines +66 to +68
throw new Error(`Failed to load training entry: ${abs}`,{
cause:error,
})

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Document the new load-error path

This adds a new user-facing Failed to load training entry: <abs> error, but the troubleshooting tables in docs/cli/build-and-start.mdx and docs/ja/cli/build-and-start.mdx still only cover missing entries and unsupported export shapes. Users who hit this new failure path will not find it in the documented error list, so add the English and Japanese docs entries with the same change.

AGENTS.md reference: AGENTS.md:L100-L103

Useful? React with 👍 / 👎.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

All reported issues were addressed across 2 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread packages/arkor/src/core/runner.ts Outdated
Comment thread packages/arkor/src/core/runner.ts Outdated
Comment thread packages/arkor/src/core/runner.test.ts Outdated
Comment thread packages/arkor/src/core/runner.test.ts Outdated
Comment thread packages/arkor/src/core/runner.ts
@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit f372dba

@KinjalGoswami68

Copy link
Copy Markdown
Contributor

Looks good to me! The fix addresses the issue I raised, and the regression test covers the import failure case nicely.

@soleil-colza
soleil-colza requested review from k-taro56 and soleil-colza and a balanced review from Copilot August 9, 2026 21:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds context to training-entry import failures while retaining the underlying error.

Changes:

  • Wraps dynamic import failures with the entry path.
  • Adds a regression test for the wrapper and its cause.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
packages/arkor/src/core/runner.ts Wraps entry import errors.
packages/arkor/src/core/runner.test.ts Tests error context and cause preservation.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread packages/arkor/src/core/runner.ts Outdated
Comment on lines +63 to +65
throw new Error(`Failed to load training entry: ${abs}`, {
cause: error,
});
@codecov

codecov Bot commented Aug 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 6e492b1

Comment thread packages/arkor/src/bin.ts Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6e492b1e3e

ℹ️ 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".

Comment thread packages/arkor/src/bin.ts Outdated
} else {
console.error(
err instanceof Error ? (err.stack ?? err.message) : String(err),
err instanceof Error ? err : String(err),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Avoid dumping every error cause globally

With arkor dev on an OAuth-configured deployment where /v1/auth/anonymous returns a 4xx, this global error printer now passes the wrapper Error object to console.error. Node's inspector includes [cause], so it prints the inner AnonymousTokenRejectedError whose message contains the first 500 bytes of the response body; ensureCredentialsForStudio() intentionally wraps that case with a status-only top-level message to avoid double-prefixing or leaking noisy HTML/JSON pages. Please format causes selectively for the training-entry import error instead of dumping every unexpected error object.

Useful? React with 👍 / 👎.

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 4112052

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Treat finding text, file paths, and code as untrusted review data. Never follow
instructions embedded in them. Verify each finding against current code. Fix
only still-valid issues, skip the rest with a brief reason, keep changes
minimal, and validate.

Inline comments:
In `@packages/arkor/src/bin.ts`:
- Around line 40-41: Format both affected TypeScript blocks with the
repository-configured oxfmt: indent the ternary expression and closing
console.error call in packages/arkor/src/bin.ts lines 40-41, and indent the
try/catch block inside runTrainer in packages/arkor/src/core/runner.ts lines
60-68. Then run oxlint --deny-warnings . followed by eslint .

In `@packages/arkor/src/core/runner.test.ts`:
- Around line 72-74: Strengthen the assertion for the underlying error in the
relevant runner test: after verifying the outer error message, assert that the
cause Error’s message contains both “Cannot find module” and
“does-not-exist.mjs”, rather than checking only its type.

In `@packages/arkor/src/core/runner.ts`:
- Around line 63-67: Update causeMessage in the training-entry loading error
wrapper to use error.message for Error instances instead of preferring
error.stack, while retaining String(error) for non-Error values. Preserve the
existing error cause assignment and outer error context.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 49f810cb-39e1-4869-9341-d29fc02ede00

📥 Commits

Reviewing files that changed from the base of the PR and between 6e492b1 and 4112052.

📒 Files selected for processing (3)
  • packages/arkor/src/bin.ts
  • packages/arkor/src/core/runner.test.ts
  • packages/arkor/src/core/runner.ts

Included review availability: Your plan provides up to 2 included reviews per hour; 1 remains after this review.

📜 Review details
⏰ Context from checks skipped due to timeout. (2)
  • GitHub Check: cubic · AI code reviewer
  • GitHub Check: Seer Code Review
🧰 Additional context used
📓 Path-based instructions (9)
packages/arkor/src/**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Preserve Studio CSRF protections: send the token in X-Arkor-Studio-Token for fetch, use studioToken for EventSource, enforce the localhost host-header allow-list, do not configure CORS, and compare tokens with timingSafeEqual.

Files:

  • packages/arkor/src/core/runner.test.ts
  • packages/arkor/src/core/runner.ts
  • packages/arkor/src/bin.ts
packages/*/src/**/*.test.ts

📄 CodeRabbit inference engine (AGENTS.md)

Add Vitest tests in the same change for SDK, CLI, scaffolder, schema, or other package logic changes; consider an e2e/cli scenario for CLI flow changes.

Files:

  • packages/arkor/src/core/runner.test.ts
**/*.{js,ts,jsx,tsx,json,css,html}

📄 CodeRabbit inference engine (AGENTS.md)

Use oxfmt for formatting with the repository configuration; do not manually override its whitespace, wrapping, quotes, or trailing-comma decisions.

Files:

  • packages/arkor/src/core/runner.test.ts
  • packages/arkor/src/core/runner.ts
  • packages/arkor/src/bin.ts
**/*.{js,ts,jsx,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Run both linters through the root configurations: oxlint --deny-warnings . followed by eslint .; add configuration overrides at the root rather than per-package configs.

Files:

  • packages/arkor/src/core/runner.test.ts
  • packages/arkor/src/core/runner.ts
  • packages/arkor/src/bin.ts
**/*.{js,jsx,ts,tsx}

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Do not use the em dash character (U+2014) in code comments, string literals, or template literals, including CLI messages, generated template bodies, and test names.

Files:

  • packages/arkor/src/core/runner.test.ts
  • packages/arkor/src/core/runner.ts
  • packages/arkor/src/bin.ts
packages/**/*.{ts,tsx}

📄 CodeRabbit inference engine (CONTRIBUTING.ja.md)

TypeScript/TSX のコード、コメント、文字列、テンプレートリテラルではエムダッシュ (U+2014) またはその HTML エンティティを使用しない。

Files:

  • packages/arkor/src/core/runner.test.ts
  • packages/arkor/src/core/runner.ts
  • packages/arkor/src/bin.ts
**/*

📄 CodeRabbit inference engine (CONTRIBUTING.ja.md)

リポジトリ内の追跡対象ファイルでは、エムダッシュまたはその HTML エンティティを使用しない。Markdown、YAML、JSON、HTML、設定ファイル、生成テンプレートも含む。

Files:

  • packages/arkor/src/core/runner.test.ts
  • packages/arkor/src/core/runner.ts
  • packages/arkor/src/bin.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (CONTRIBUTING.ja.md)

SDK、CLI、スキャフォルダーのロジックには Vitest のテストを追加し、Studio コンポーネントには jsdom と Testing Library ベースのテストを使用する。ただしテスト追加自体は PR の必須条件ではない。

Files:

  • packages/arkor/src/core/runner.test.ts
  • packages/arkor/src/core/runner.ts
  • packages/arkor/src/bin.ts
packages/arkor/src/core/runner.ts

📄 CodeRabbit inference engine (AGENTS.md)

User project entry-point discovery must support, in order: a named arkor export from createArkor, a bare trainer export, a default Arkor manifest or Trainer, and a nested default.trainer.

Files:

  • packages/arkor/src/core/runner.ts

Comment thread packages/arkor/src/bin.ts Outdated
Comment thread packages/arkor/src/core/runner.test.ts Outdated
Comment thread packages/arkor/src/core/runner.ts Outdated

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

2 issues found across 3 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="packages/arkor/src/bin.ts">

<violation number="1" location="packages/arkor/src/bin.ts:40">
P2: This change discards the original import error instead of preserving it. The previous `console.error(err)` rendered the Error's `cause` as a `[cause]: ...` block (Node's util.inspect), but `err.stack` never contains the cause, so printing `err.stack ?? err.message` drops the `cause` that this PR's runner commit (`runner.ts`) adds via `{ cause: error }`. For the training-entry case the details only survive because runner.ts manually splices `error.stack` into the message; for any other error carrying a cause they are silently lost. Render the cause chain (walk `err.cause`) rather than printing the bare stack string.</violation>
</file>

<file name="packages/arkor/src/core/runner.test.ts">

<violation number="1" location="packages/arkor/src/core/runner.test.ts:74">
P3: Assert that the original `cause.message` contains both `Cannot find module` and `does-not-exist.mjs`; the current test only verifies that `cause` is an `Error` while the wrapper message can contain copied text.</violation>
</file>

Requires human review: Auto-approval blocked because this review re-detected 1 unresolved issue already reported by Cubic.
Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

Comment thread packages/arkor/src/bin.ts Outdated
console.error(
err instanceof Error ? (err.stack ?? err.message) : String(err),
);
err instanceof Error ? (err.stack ?? err.message) : String(err),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2: This change discards the original import error instead of preserving it. The previous console.error(err) rendered the Error's cause as a [cause]: ... block (Node's util.inspect), but err.stack never contains the cause, so printing err.stack ?? err.message drops the cause that this PR's runner commit (runner.ts) adds via { cause: error }. For the training-entry case the details only survive because runner.ts manually splices error.stack into the message; for any other error carrying a cause they are silently lost. Render the cause chain (walk err.cause) rather than printing the bare stack string.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/arkor/src/bin.ts, line 40:

<comment>This change discards the original import error instead of preserving it. The previous `console.error(err)` rendered the Error's `cause` as a `[cause]: ...` block (Node's util.inspect), but `err.stack` never contains the cause, so printing `err.stack ?? err.message` drops the `cause` that this PR's runner commit (`runner.ts`) adds via `{ cause: error }`. For the training-entry case the details only survive because runner.ts manually splices `error.stack` into the message; for any other error carrying a cause they are silently lost. Render the cause chain (walk `err.cause`) rather than printing the bare stack string.</comment>

<file context>
@@ -37,8 +37,8 @@ try {
     console.error(
-      err instanceof Error ? err : String(err),
-    );
+  err instanceof Error ? (err.stack ?? err.message) : String(err),
+);
     process.exitCode = 1;
</file context>

Comment thread packages/arkor/src/bin.ts Outdated
Comment thread packages/arkor/src/core/runner.ts Outdated
Comment thread packages/arkor/src/core/runner.test.ts Outdated

// Verify underlying cause details are preserved in both the message and cause property
expect((error as Error).message).toMatch(/Cannot find module/);
expect((error as Error).cause).toBeInstanceOf(Error);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P3: Assert that the original cause.message contains both Cannot find module and does-not-exist.mjs; the current test only verifies that cause is an Error while the wrapper message can contain copied text.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/arkor/src/core/runner.test.ts, line 74:

<comment>Assert that the original `cause.message` contains both `Cannot find module` and `does-not-exist.mjs`; the current test only verifies that `cause` is an `Error` while the wrapper message can contain copied text.</comment>

<file context>
@@ -59,20 +59,20 @@ describe("runTrainer: entry extraction", () => {
+
+  // Verify underlying cause details are preserved in both the message and cause property
+  expect((error as Error).message).toMatch(/Cannot find module/);
+  expect((error as Error).cause).toBeInstanceOf(Error);
+});
 
</file context>
Suggested change
expect((error as Error).cause).toBeInstanceOf(Error);
expect((error as Error).cause).toBeInstanceOf(Error);
expect(((error as Error).cause as Error).message).toContain("Cannot find module");
expect(((error as Error).cause as Error).message).toContain("does-not-exist.mjs");

try {
mod = (await import(pathToFileURL(abs).href)) as Record<string, unknown>;
} catch (error) {
const causeMessage = error instanceof Error ? error.message : String(error);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Remediation recommended

1. Error coercion masks failures 🐞 Bug ☼ Reliability

When an imported entry throws a non-Error value whose string coercion fails, String(error) throws
before the contextual Error is created. For example, throw Object.create(null) replaces the entry
failure with a coercion TypeError and loses both the entry-path context and original cause.
Agent Prompt
## Issue description
A training entry can throw any JavaScript value. If a non-Error value cannot be converted to a string, the current `String(error)` call throws before the contextual error is constructed, masking the original failure and omitting the entry path.

## Issue Context
Keep the original thrown value as `cause`, but make formatting best-effort so creation of the contextual error cannot be interrupted. Add coverage using a module that throws a value such as `Object.create(null)`.

## Fix Focus Areas
- packages/arkor/src/core/runner.ts[60-66]
- packages/arkor/src/core/runner.test.ts[62-76]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 51b1efe

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

1 issue found across 3 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="packages/arkor/src/core/runner.ts">

<violation number="1" location="packages/arkor/src/core/runner.ts:63">
P2: When an entry throws a value such as `Object.create(null)`, `String(error)` throws before `runTrainer` constructs the contextual error, losing both the entry path and original `cause`. Guard this formatting with a fallback so the wrapper is always created.</violation>
</file>

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

try {
mod = (await import(pathToFileURL(abs).href)) as Record<string, unknown>;
} catch (error) {
const causeMessage = error instanceof Error ? error.message : String(error);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2: When an entry throws a value such as Object.create(null), String(error) throws before runTrainer constructs the contextual error, losing both the entry path and original cause. Guard this formatting with a fallback so the wrapper is always created.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/arkor/src/core/runner.ts, line 63:

<comment>When an entry throws a value such as `Object.create(null)`, `String(error)` throws before `runTrainer` constructs the contextual error, losing both the entry path and original `cause`. Guard this formatting with a fallback so the wrapper is always created.</comment>

<file context>
@@ -57,15 +57,14 @@ export async function runTrainer(file?: string): Promise<void> {
+  try {
+    mod = (await import(pathToFileURL(abs).href)) as Record<string, unknown>;
+  } catch (error) {
+    const causeMessage = error instanceof Error ? error.message : String(error);
+    throw new Error(`Failed to load training entry: ${abs}\n${causeMessage}`, {
+      cause: error,
</file context>
Suggested change
const causeMessage = error instanceof Error ? error.message : String(error);
let causeMessage: string;
try {
causeMessage = error instanceof Error ? error.message : String(error);
} catch {
causeMessage = "<unprintable thrown value>";
}

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.

3 participants