fix(taskState): report artifact fallback as unknown evidence

This commit is contained in:
Haitao Pan 2026-06-12 14:08:02 +08:00
parent 35379f2fb0
commit fc6a02ac1a
3 changed files with 31 additions and 17 deletions

15
dist/src/taskState.js vendored
View File

@ -165,9 +165,10 @@ export async function getXWorkmateTaskSnapshot(input) {
: undefined;
if (exported?.artifacts.length) {
return {
success: true,
status: "completed",
taskStatus: "succeeded",
success: false,
status: "unknown",
taskStatus: "unknown",
evidence: "artifacts_present",
mode: "gateway-chat",
mapping,
appThreadKey: mapping?.appThreadKey ?? appThreadKey,
@ -177,7 +178,7 @@ export async function getXWorkmateTaskSnapshot(input) {
task: {
taskId: taskId || runId,
runId,
status: "succeeded",
status: "unknown",
source: "artifact_fallback",
},
expectedArtifactDirs: mapping?.expectedArtifactDirs ?? [],
@ -186,9 +187,11 @@ export async function getXWorkmateTaskSnapshot(input) {
remoteWorkspaceRefKind: exported.remoteWorkspaceRefKind,
scopeKind: exported.scopeKind,
artifacts: exported.artifacts,
constraintSatisfied: exported.constraintSatisfied,
missingRequiredExtensions: exported.missingRequiredExtensions,
warnings: [
...exported.warnings,
`Native OpenClaw task record was unavailable for ${openclawSessionKey}; resolved from task artifacts.`,
`Native OpenClaw task record was unavailable for ${openclawSessionKey}; artifacts are present but task status is unknown.`,
],
artifactCount: exported.artifacts.length,
};
@ -217,6 +220,8 @@ export async function getXWorkmateTaskSnapshot(input) {
remoteWorkspaceRefKind: exported?.remoteWorkspaceRefKind,
scopeKind: exported?.scopeKind,
artifacts: exported?.artifacts ?? [],
constraintSatisfied: exported?.constraintSatisfied,
missingRequiredExtensions: exported?.missingRequiredExtensions,
warnings: exported?.warnings ?? [],
artifactCount: exported?.artifacts.length ?? 0,
};

View File

@ -166,14 +166,14 @@ describe("xworkmate task state mapping", () => {
});
});
it("resolves completed snapshot from task artifacts when native task record is unavailable", async () => {
it("reports unknown evidence from task artifacts when native task record is unavailable", async () => {
const workspaceDir = await createWorkspaceFixture();
const appThreadKey = "draft:sample-task";
const openclawSessionKey = "agent:main:draft:sample-task";
const runId = "turn-sample";
const artifactDir = path.join(workspaceDir, "tasks", "agent_main_draft_sample-task", runId);
await fs.mkdir(artifactDir, { recursive: true });
await fs.writeFile(path.join(artifactDir, "report.md"), "# Report\n", "utf8");
await fs.writeFile(path.join(artifactDir, "series.config.json"), "{}\n", "utf8");
const { api } = createApiFixture({}, { workspaceDir });
await recordXWorkmateSessionMapping({
@ -196,21 +196,25 @@ describe("xworkmate task state mapping", () => {
});
expect(result).toMatchObject({
success: true,
status: "completed",
taskStatus: "succeeded",
success: false,
status: "unknown",
taskStatus: "unknown",
evidence: "artifacts_present",
openclawSessionKey,
runId,
task: {
source: "artifact_fallback",
status: "unknown",
},
artifacts: [
{
relativePath: "report.md",
contentType: "text/markdown",
relativePath: "series.config.json",
contentType: "application/json",
},
],
artifactCount: 1,
});
expect((result.warnings as string[]).some((entry) => entry.includes("task status is unknown"))).toBe(true);
});
it("returns no_native_task_record when neither native task record nor task artifacts exist", async () => {

View File

@ -260,9 +260,10 @@ export async function getXWorkmateTaskSnapshot(input: {
: undefined;
if (exported?.artifacts.length) {
return {
success: true,
status: "completed",
taskStatus: "succeeded",
success: false,
status: "unknown",
taskStatus: "unknown",
evidence: "artifacts_present",
mode: "gateway-chat",
mapping,
appThreadKey: mapping?.appThreadKey ?? appThreadKey,
@ -272,7 +273,7 @@ export async function getXWorkmateTaskSnapshot(input: {
task: {
taskId: taskId || runId,
runId,
status: "succeeded",
status: "unknown",
source: "artifact_fallback",
},
expectedArtifactDirs: mapping?.expectedArtifactDirs ?? [],
@ -281,9 +282,11 @@ export async function getXWorkmateTaskSnapshot(input: {
remoteWorkspaceRefKind: exported.remoteWorkspaceRefKind,
scopeKind: exported.scopeKind,
artifacts: exported.artifacts,
constraintSatisfied: exported.constraintSatisfied,
missingRequiredExtensions: exported.missingRequiredExtensions,
warnings: [
...exported.warnings,
`Native OpenClaw task record was unavailable for ${openclawSessionKey}; resolved from task artifacts.`,
`Native OpenClaw task record was unavailable for ${openclawSessionKey}; artifacts are present but task status is unknown.`,
],
artifactCount: exported.artifacts.length,
};
@ -320,6 +323,8 @@ export async function getXWorkmateTaskSnapshot(input: {
remoteWorkspaceRefKind: exported?.remoteWorkspaceRefKind,
scopeKind: exported?.scopeKind,
artifacts: exported?.artifacts ?? [],
constraintSatisfied: exported?.constraintSatisfied,
missingRequiredExtensions: exported?.missingRequiredExtensions,
warnings: exported?.warnings ?? [],
artifactCount: exported?.artifacts.length ?? 0,
};