Skip to content

Self-evolving Context Database for AI Agents. Unify Agent Memory, Knowledge RAG and Skills.

fix(ci): preserve resource failure details and update import tests (#6340)

Zayn Jarvis82882c26e09d
diff --git a/examples/openclaw-plugin/tests/ut/plugin-modules.test.ts b/examples/openclaw-plugin/tests/ut/plugin-modules.test.ts
index 0ee2bc58d..64ad4927b 100644
--- a/examples/openclaw-plugin/tests/ut/plugin-modules.test.ts
+++ b/examples/openclaw-plugin/tests/ut/plugin-modules.test.ts
@@ -377,7 +377,6 @@ describe("plugin module seams", () => {
reason: "project docs",
instruction: "extract API notes",
wait: true,
- timeout: 30,
}, "agent-main")).resolves.toEqual({
content: [{ type: "text", text: "Imported OpenViking resource. viking://resources/project-docs Warnings: kept existing metadata" }],
details: {
@@ -394,14 +393,12 @@ describe("plugin module seams", () => {
reason: "project docs",
instruction: "extract API notes",
wait: true,
- timeout: 30,
}, "agent-main");
await expect(runtime.addSkillOpenViking({
source: "./skills/debugger/SKILL.md",
data: "skill body",
wait: false,
- timeout: 5,
}, "agent-main")).resolves.toEqual({
content: [{ type: "text", text: "Imported OpenViking skill (debugger). viking://user/skills/debugger" }],
details: {
@@ -415,7 +412,6 @@ describe("plugin module seams", () => {
path: "./skills/debugger/SKILL.md",
data: "skill body",
wait: false,
- timeout: 5,
}, "agent-main");
});
@@ -695,7 +691,6 @@ describe("plugin module seams", () => {
source: "https://example.com/docs",
to: "viking://resources/docs",
wait: true,
- timeout: 30,
});
expect(addResource).toHaveBeenCalledWith({
pathOrUrl: "https://example.com/docs",
@@ -704,7 +699,6 @@ describe("plugin module seams", () => {
reason: undefined,
instruction: undefined,
wait: true,
- timeout: 30,
}, "agent-main");
expect(resourceResult.content[0].text).toBe("Imported OpenViking resource. viking://resources/docs Warnings: warn");
expect(resourceResult.details).toMatchObject({ action: "resource_imported", root_uri: "viking://resources/docs" });
@@ -716,7 +710,6 @@ describe("plugin module seams", () => {
path: undefined,
data: "name: demo\n",
wait: undefined,
- timeout: undefined,
}, "agent-main");
expect(skillResult.content[0].text).toBe("Imported OpenViking skill (demo). viking://user/skills/demo");
expect(skillResult.details).toMatchObject({ action: "skill_imported", uri: "viking://user/skills/demo" });
diff --git a/openviking/service/resource_service.py b/openviking/service/resource_service.py
index a607fe7fc..b8c52b6ee 100644
--- a/openviking/service/resource_service.py
+++ b/openviking/service/resource_service.py
@@ -2069,6 +2069,9 @@ class ResourceService:
code = task.result.get("code")
if isinstance(code, str) and code:
failure["code"] = code
+ details = task.result.get("details")
+ if isinstance(details, dict):
+ failure["details"] = details
return failure
async def _execute_resource_ingestion(
diff --git a/openviking/storage/queuefs/add_resource_processor.py b/openviking/storage/queuefs/add_resource_processor.py
index 6085ad1b9..d2c004634 100644
--- a/openviking/storage/queuefs/add_resource_processor.py
+++ b/openviking/storage/queuefs/add_resource_processor.py
@@ -276,13 +276,15 @@ class AddResourceProcessor(DequeueHandlerBase):
error,
)
code = result.get("code")
- failure_result = {"code": code} if isinstance(code, str) and code else None
+ failure_result = {"code": code} if isinstance(code, str) and code else {}
+ if isinstance(result.get("details"), dict):
+ failure_result["details"] = result["details"]
await tracker.fail(
msg.task_id,
error,
account_id=ctx.account_id,
user_id=ctx.user.user_id,
- result=failure_result,
+ result=failure_result or None,
)
await self._record_watch_execution(msg, "failed", error)
terminal = True
@@ -399,14 +401,16 @@ class AddResourceProcessor(DequeueHandlerBase):
str(exc) or type(exc).__name__,
)
failure_result = (
- {"code": exc.code} if isinstance(exc, OpenVikingError) and exc.code else None
+ {"code": exc.code} if isinstance(exc, OpenVikingError) and exc.code else {}
)
+ if isinstance(exc, OpenVikingError) and isinstance(exc.details, dict):
+ failure_result["details"] = exc.details
await tracker.fail(
msg.task_id,
str(exc),
account_id=ctx.account_id,
user_id=ctx.user.user_id,
- result=failure_result,
+ result=failure_result or None,
)
terminal = True
return ProcessResult.failed(str(exc))
diff --git a/tests/service/test_resource_failure_details.py b/tests/service/test_resource_failure_details.py
new file mode 100644
index 000000000..ead45fa1d
--- /dev/null
+++ b/tests/service/test_resource_failure_details.py
@@ -0,0 +1,85 @@
+"""Errors must survive the queue/task boundary without losing their public details."""
+
+import json
+from types import SimpleNamespace
+from unittest.mock import AsyncMock
+
+import pytest
+
+from openviking.server.identity import RequestContext, Role
+from openviking.server.responses import response_from_result
+from openviking.service.resource_service import ResourceService
+from openviking.service.task_domain import TaskRecord, TaskStatus, sanitize_task_result
+from openviking.storage.queuefs.add_resource_msg import AddResourceMsg
+from openviking.storage.queuefs.add_resource_processor import AddResourceProcessor
+from openviking_cli.exceptions import OpenVikingError
+from openviking_cli.session.user_id import UserIdentifier
+
+
[email protected]("raised", [False, True])
+async def test_failed_resource_preserves_details_through_wait_and_http(monkeypatch, raised):
+ monkeypatch.setattr("openviking.service.resource_service.is_git_repo_url", lambda _: False)
+ monkeypatch.setattr("openviking.connector.routing.is_git_repo_url", lambda _: False)
+ details = {"source": "https://example.com/doc", "upstream_status_code": 403}
+ task = TaskRecord(task_id="failure-test", task_type="add_resource")
+
+ async def fail(task_id, error, **kwargs):
+ task.status = TaskStatus.FAILED
+ task.error = error
+ task.result = sanitize_task_result(kwargs["result"])
+
+ tracker = SimpleNamespace(
+ create=AsyncMock(return_value=task),
+ start=AsyncMock(),
+ get_task_auth=AsyncMock(return_value={}),
+ fail=AsyncMock(side_effect=fail),
+ wait=AsyncMock(return_value=task),
+ )
+ monkeypatch.setattr(
+ "openviking.storage.queuefs.add_resource_processor.get_task_tracker", lambda: tracker
+ )
+ monkeypatch.setattr("openviking.service.task_tracker.get_task_tracker", lambda: tracker)
+ service = ResourceService(
+ viking_fs=SimpleNamespace(),
+ resource_processor=SimpleNamespace(),
+ skill_processor=object(),
+ )
+ service.execute_add_resource_job = AsyncMock(
+ side_effect=OpenVikingError("upstream forbidden", code="PERMISSION_DENIED", details=details)
+ if raised
+ else None,
+ return_value={
+ "status": "error",
+ "errors": ["upstream forbidden"],
+ "code": "PERMISSION_DENIED",
+ "details": details,
+ },
+ )
+ processor = AddResourceProcessor(service, "add_resource", service._viking_fs)
+ msg = AddResourceMsg(
+ task_id=task.task_id,
+ root_uri="viking://resources/doc",
+ account_id="acct",
+ user_id="alice",
+ role="user",
+ )
+ await processor._process(msg, {})
+ tracker.fail.assert_awaited_once()
+ assert task.result["details"] == details
+
+ service._prepare_standard_source_plan = AsyncMock(return_value=object())
+ service._enqueue_source_plan = AsyncMock(return_value={"task_id": task.task_id})
+ result = await service.add_resource(
+ path=details["source"],
+ to=msg.root_uri,
+ wait=True,
+ ctx=RequestContext(user=UserIdentifier("acct", "alice"), role=Role.USER),
+ )
+ response = response_from_result(result)
+ assert response.status_code == 403
+ assert json.loads(response.body)["error"] == {
+ "code": "PERMISSION_DENIED",
+ "message": "upstream forbidden",
+ "details": details,
+ }