🌊 The original agent harness. Deploy intelligent multi-player swarms, coordinate autonomous workflows, and build conversational AI systems. Features adaptive memory, self-learning intelligence, federation, vector RAG integration, and native Claude Code / Codex / Hermes and many more Integrated
TypeScript agentic-aiagentic-frameworkagentic-workflowagentsai-agentsai-assistantai-skillsautonomous-agentsclaudecodexdsh-pluginharnessmcp-servermulti-agentmulti-agent-systemsnpmskillsswarmswarm-intelligencetypescript
fix(ruflo-mods): reset per-session state on session.end(reason: clear), not session.start (#3795)
Dragan Spiridonovc486e0ec269c
diff --git a/plugins/ruflo-mods/hooks/cost/index.ts b/plugins/ruflo-mods/hooks/cost/index.tsindex 8b9406a1da..bd94e1b2ce 100644--- a/plugins/ruflo-mods/hooks/cost/index.ts+++ b/plugins/ruflo-mods/hooks/cost/index.ts@@ -17,9 +17,11 @@ export function registerCost(on: On, state: ModState, options: ModOptions) {state.budget = { level: 'OK', limit }let announced: BudgetLevel = 'OK' // the highest rung told this session; a fall and a second rise stay quiet- // The budget is per session, and /clear starts a new one in the same process- // with its cost counted from zero: the ladder and the hard stop start over.- on('session.start', { surface: /^[\s\S]*$/ }, ($, e, next) => {+ // The budget is per session. /clear ends one (session.end, reason clear; no+ // session.start follows) and the process goes on with the next one's cost+ // counted from zero, so the ladder and the hard stop start over. Registered+ // after the rollup, which records this session's rung before this runs.+ on('session.end', { reason: /^clear$/ }, ($, e, next) => {announced = 'OK'state.budget = { level: 'OK', limit }return next(e)diff --git a/plugins/ruflo-mods/hooks/rollup/index.ts b/plugins/ruflo-mods/hooks/rollup/index.tsindex 2f139c5664..74531f5e01 100644--- a/plugins/ruflo-mods/hooks/rollup/index.ts+++ b/plugins/ruflo-mods/hooks/rollup/index.ts@@ -36,8 +36,6 @@ export function registerRollup(on: On, state: ModState) {r.enabled = trueon('session.start', { surface: /^[\s\S]*$/ }, async ($, e, next) => {- // /clear ends one session and starts the next in the same process: each gets its own record.- Object.assign(r, { tools: 0, denied: 0, spawns: 0, rung: 'OK', written: false, base: { routed: state.routed, tightened: state.tightened } })const result = await next(e)try {r.recent = readLedger(await $.store.get(LEDGER))@@ -83,6 +81,9 @@ export function registerRollup(on: On, state: ModState) {// an unwritable ledger only means this session has no record}}+ // /clear ends this session and the process goes on with the next (no+ // session.start fires for it): the next session gets its own counters and record.+ if (e.reason === 'clear') Object.assign(r, { tools: 0, denied: 0, spawns: 0, rung: 'OK', written: false, base: { routed: state.routed, tightened: state.tightened } })return next(e)}).catch(($, e, next) => next(e))}diff --git a/plugins/ruflo-mods/tests/cost.test.ts b/plugins/ruflo-mods/tests/cost.test.tsindex a2ea3ee0b9..25851c75b7 100644--- a/plugins/ruflo-mods/tests/cost.test.ts+++ b/plugins/ruflo-mods/tests/cost.test.ts@@ -33,19 +33,34 @@ describe('cost', () => {on('ui.toast', ($, e) => (toasts.push(e.text), { value: undefined }))on('session.measure', ($, e) => ({ changed: e.changed }))on('agent.spawn', () => ({ model: 'sonnet' }))+ on('session.end', () => ({ sessionId: 's' }) as never)const spawn = () =>$.agent.spawn({ prompt: 'p', description: 'd', subagentType: 'coder' } as Parameters<typeof $.agent.spawn>[0])await $.session.start(START)await $.session.measure(measure(2.4))expect((await spawn()).deny).toMatch(/costHardStop/)- // The engine counts the new session's cost from zero after /clear (measured live on 2.1.289).- await $.session.start({ ...START, source: 'clear' } as never)+ // /clear: session.end with reason clear and no session.start (engine contract); the next+ // session's cost is counted from zero (measured live on 2.1.289).+ await $.session.end({ reason: 'clear', sessionId: 's', resume: { id: 's' } } as never)expect(await spawn()).toEqual({ model: 'sonnet' })await $.session.measure(measure(1.1))expect(toasts.map(t => t.split(':')[0])).toEqual(['ruflo budget HARD_STOP', 'ruflo budget INFO'])})+ test('only /clear restarts the ladder: another session end keeps the hard stop', { options: { costBudgetUsd: 2, costHardStop: true } }, async ($, on) => {+ world(on)+ on('session.measure', ($, e) => ({ changed: e.changed }))+ on('agent.spawn', () => ({ model: 'sonnet' }))+ on('session.end', () => ({ sessionId: 's' }) as never)+ const spawn = () =>+ $.agent.spawn({ prompt: 'p', description: 'd', subagentType: 'coder' } as Parameters<typeof $.agent.spawn>[0])+ await $.session.start(START)+ await $.session.measure(measure(2.4))+ await $.session.end({ reason: 'other', sessionId: 's', resume: { id: 's' } } as never)+ expect((await spawn()).deny).toMatch(/costHardStop/)+ })+test('a rung announced once stays quiet when cost falls and rises again', { options: { costBudgetUsd: 2 } }, async ($, on) => {world(on)const toasts: string[] = []diff --git a/plugins/ruflo-mods/tests/rollup.test.ts b/plugins/ruflo-mods/tests/rollup.test.tsindex 6b756c97bb..b14e609843 100644--- a/plugins/ruflo-mods/tests/rollup.test.ts+++ b/plugins/ruflo-mods/tests/rollup.test.ts@@ -118,8 +118,8 @@ describe('sessionRollup option (ADR-451 item 6)', () => {const s = store(on)await $.session.start(START)await $.tool.call({ tool: 'Read', file_path: 'a' } as never)+ // As the engine runs /clear: session.end with reason clear, then the next session's work; no session.start.await $.session.end({ ...(END as object), reason: 'clear' } as never)- await $.session.start({ ...START, source: 'clear' } as never)for (const f of ['b', 'c', 'd']) await $.tool.call({ tool: 'Read', file_path: f } as never)await $.session.end(END)expect((s.kv.get('sessionRollup') as Rollup[]).map(r => r.tools)).toEqual([1, 3])