After turn/start was appended, nothing guaranteed a matching turn/end: a throw from a boundary emit (agent/turn-start, agent/step-start, the normal-path agent/turn-end) escaped runTurn, and the outer runLoop backstop logged an error but never appended turn/end — leaving an unbalanced turn that replay, telemetry, and the invariants plugin all assume is impossible. runTurn is restructured around idempotent finalizers that satisfy the four traps a naive finally would hit: - closeStep()/closeTurn(emit) are guarded (stepOpen/turnEnded) so they run at most once; the agent/step-end and agent/error emits are contained so a throwing listener can't strand the turn open. - failTurn() records the single error event + reason and emits agent/error exactly once (errorReported guard) — no double-logging when the outer catch also runs (e.g. a step error followed by a throwing turn-end listener). - the catch closes an open step BEFORE turn/end (invariants reject turn/end while a step is open), and rethrows ONLY pre-turn throws (turnStarted false), where no turn/end is owed, so the backstop still nets them. - disposal precedence: reason stays disposed only when disposed AND no error was reported; otherwise the error reason wins. Tests (with the invariants plugin loaded as a balance oracle): throwing turn-start (one error, one turn/end, no step), throwing step-start (step/end before turn/end), throwing agent/error on a step-error path (balanced, loop survives), disposal mid-turn (reason disposed, no error event), a pre-turn turn/start-append throw (rethrown to the backstop, no turn/end owed), and a step error + throwing turn-end listener (error logged exactly once). Verified all six fail against a simulated finalizer bypass. dsh-invariants added as an agent-loop devDependency (test-only oracle; no package cycle).
43 lines
1.1 KiB
JSON
43 lines
1.1 KiB
JSON
{
|
|
"name": "@deepseek-ai/dsh-agent-loop",
|
|
"description": "The concrete agent loop plugin for the DeepSeek Harness",
|
|
"version": "0.0.1",
|
|
"private": true,
|
|
"type": "module",
|
|
"main": "lib/index.js",
|
|
"types": "lib/index.d.ts",
|
|
"exports": {
|
|
".": {
|
|
"types": "./lib/index.d.ts",
|
|
"default": "./lib/index.js"
|
|
},
|
|
"./src/*": "./src/*",
|
|
"./package.json": "./package.json"
|
|
},
|
|
"files": [
|
|
"lib",
|
|
"src"
|
|
],
|
|
"license": "BSD-3-Clause",
|
|
"peerDependencies": {
|
|
"@deepseek-ai/dsh-agent": "^0.0.1",
|
|
"@deepseek-ai/dsh-llm": "^0.0.1",
|
|
"@deepseek-ai/dsh-session": "^0.0.1",
|
|
"@deepseek-ai/dsh-system-prompt": "^0.0.1",
|
|
"@deepseek-ai/dsh-tools": "^0.0.1",
|
|
"cordis": "^4.0.0-rc.6"
|
|
},
|
|
"dependencies": {
|
|
"schemastery": "^3.18.0"
|
|
},
|
|
"devDependencies": {
|
|
"@deepseek-ai/dsh-agent": "^0.0.1",
|
|
"@deepseek-ai/dsh-invariants": "^0.0.1",
|
|
"@deepseek-ai/dsh-llm": "^0.0.1",
|
|
"@deepseek-ai/dsh-session": "^0.0.1",
|
|
"@deepseek-ai/dsh-system-prompt": "^0.0.1",
|
|
"@deepseek-ai/dsh-tools": "^0.0.1",
|
|
"cordis": "^4.0.0-rc.6"
|
|
}
|
|
}
|