File size: 3,774 Bytes
d739b1b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | // ์คํ ๊ด์ธก ์ค๋ช
๋ฌธ์: /docs/specs/bada-bong-agent-telemetry.md (v0.1.0)
// ๋ณ๋ ฌ ์์๋ ์ธ๋ถ ํจ๊ณผ ์ ์ parent task์ ๋ฌถ์ธ ์์ ๊ธฐ๋ก์ ๋ง๋ค๊ณ ๊ฒฐ๊ณผ์ checkpoint๋ฅผ ํจ๊ป ํ์ ํ๋ค.
// ์ค๋ช
๋ฌธ์: docs/specs/bong-browser-use.md (v1.11.0)
const db = require('../../knowledge-db'), { randomUUID } = require('crypto');
const uncertain = require('../utils/cli-storage-error').isUncertainCliFailure;
const error = code => Object.assign(Error('๋ณ๋ ฌ ์์
์ ์คํ ๊ธฐ๋ก์ ํ์ธํ ๋ค ๊ฐ์ ์คํ์ ๊ฒํ ํ์ธ์.'), { code, retryable: false });
const storage = () => error('WORKFLOW_PARALLEL_STORAGE_FAILED');
function prepare(run, parent, children) {
// ์์ workflow๊ฐ ์๋ ๊ธฐ์กด ๋จ์ ํธ์ถ์๋ ์ ์ฅ์๋ฅผ ์๋ก ๋ง๋ค์ง ์๋๋ค.
if (!run.runData?._badaWorkflowSnapshot) return async (child, execute) => execute();
const parentTaskId = run.nodeTasks?.[parent.id], checkpointNodeId = run.currentNodeId;
const assertActive = () => {
if (run.abortController?.signal.aborted || run.status !== 'running') throw error('WORKFLOW_PARALLEL_RECONCILIATION_REQUIRED');
const row = db.getWorkflowRun(run.runId), task = db.getWorkflowTask(parentTaskId);
if (!row || row.status !== 'running' || row.current_node_id !== checkpointNodeId || !task || task.run_id !== run.runId || task.node_id !== parent.id || task.status !== 'running') throw storage();
};
try {
db.runInTransaction(() => {
assertActive();
// ์ด์ ์์ ์๋๊ฐ ํ๋๋ผ๋ ์์ผ๋ฉด ์ ์ฒด ๊ทธ๋ฃน ์๋ retry๋ก ์ธ๋ถ ํจ๊ณผ๋ฅผ ๋ฐ๋ณตํ์ง ์๋๋ค.
if (db.getWorkflowTasks(run.runId).some(t => children.includes(t.node_id))) throw error('WORKFLOW_PARALLEL_RECONCILIATION_REQUIRED');
});
} catch (err) { throw uncertain(err) ? err : storage(); }
return async (child, execute) => {
const taskId = 'parallel_' + randomUUID(), payload = { ...(child.config || {}), _badaParallel: { version: 1, parentNodeId: parent.id, parentTaskId } };
try {
db.runInTransaction(() => {
assertActive();
if (db.getWorkflowTasks(run.runId).some(t => t.node_id === child.id)) throw error('WORKFLOW_PARALLEL_RECONCILIATION_REQUIRED');
db.enqueueWorkflowTask(taskId, run.runId, child.id, child.config?.agentProfileId || child.config?.agentId || child.type, payload);
db.completeWorkflowTask(taskId, 'running', null, null);
});
} catch (err) { throw uncertain(err) ? err : storage(); }
run.nodeTasks[child.id] = taskId;
try {
require('../services/agent-telemetry-workflow').node(run,child,'running');
const output = await require('./node-context').withNode(run, child.id, taskId, execute);
const present = Object.hasOwn(run.runData, child.id), previous = run.runData[child.id];
try {
db.runInTransaction(() => {
assertActive();
run.runData[child.id] = { status: 'success', output };
db.completeWorkflowTask(taskId, 'completed', output, null);
db.checkpointWorkflowRun(run.runId, 'running', checkpointNodeId, run.runData);
});
} catch (err) {
if (present) run.runData[child.id] = previous; else delete run.runData[child.id];
throw uncertain(err) ? err : storage();
}
require('../services/agent-telemetry-workflow').node(run,child,'completed');
return output;
} catch (err) {
require('../services/agent-telemetry-workflow').node(run,child,run.abortController?.signal.aborted?'cancelled':'failed');
try { db.runInTransaction(() => db.completeWorkflowTask(taskId, 'failed', null, uncertain(err) ? err.code : err.message)); }
catch { throw storage(); }
throw err;
}
};
}
module.exports = { prepare, error };
|