diff --git a/src/shared/types/agent-memory.ts b/src/shared/types/agent-memory.ts index 735e2445f9..70e18cd654 100644 --- a/src/shared/types/agent-memory.ts +++ b/src/shared/types/agent-memory.ts @@ -104,7 +104,7 @@ export const AGENT_MEMORY_AUTO_CONTENT_MAX_CHARS = 2_000 export const AGENT_MEMORY_DIRECTIVE_CONTENT_MAX_CHARS = 2_000 export const AGENT_MEMORY_DIRECTIVE_TOPIC_MAX_CHARS = 512 export const AGENT_MEMORY_DIRECTIVE_CJK_TOPIC_MIN_VISIBLE_CHARS = 2 -export const AGENT_MEMORY_ACTIVE_DIRECTIVE_MAX_COUNT = 64 +export const AGENT_MEMORY_ACTIVE_DIRECTIVE_MAX_COUNT = 128 export const AGENT_MEMORY_SCOPE_ID_MAX_CHARS = 256 export const AGENT_MEMORY_AGENT_ID_PATTERN = /^[a-zA-Z0-9_-]{1,128}$/ diff --git a/test/main/memory/agentMemoryDirectiveTable.test.ts b/test/main/memory/agentMemoryDirectiveTable.test.ts index e037cd93da..14986f36ca 100644 --- a/test/main/memory/agentMemoryDirectiveTable.test.ts +++ b/test/main/memory/agentMemoryDirectiveTable.test.ts @@ -184,7 +184,7 @@ describeIfSqlite('AgentMemoryDirectiveTable', () => { ORDER BY updated_at DESC, id ASC LIMIT ?` ) - .all('b', 64) as Array<{ detail: string }> + .all('b', AGENT_MEMORY_ACTIVE_DIRECTIVE_MAX_COUNT) as Array<{ detail: string }> expect(queryPlan.map((row) => row.detail).join('\n')).toContain( 'idx_agent_memory_directive_status_v1' ) @@ -236,12 +236,12 @@ describeIfSqlite('AgentMemoryDirectiveTable', () => { } }) - it('keeps active directives bounded without blocking updates or later approvals', () => { + it('allows approval past the former 64-directive limit and enforces the new capacity', () => { const db = new DatabaseCtor(':memory:') try { const table = new AgentMemoryDirectiveTableCtor(db) table.createTable() - for (let index = 0; index < AGENT_MEMORY_ACTIVE_DIRECTIVE_MAX_COUNT; index += 1) { + const createActive = (index: number) => { expect( table.upsertExplicitDirective( writeInput( @@ -251,6 +251,18 @@ describeIfSqlite('AgentMemoryDirectiveTable', () => { ).action ).toBe('created') } + for (let index = 0; index < 64; index += 1) createActive(index) + + table.insertDerivedDirectiveDraft( + writeInput( + { kind: 'instruction', content: 'Next instruction after upgrade' }, + { id: 'after-upgrade', source: 'derived_suggestion', status: 'draft' } + ) + ) + expect(table.transitionDirective('a', 'after-upgrade', 'draft', 'active', 2_000).action).toBe( + 'transitioned' + ) + for (let index = 65; index < 128; index += 1) createActive(index) expect( table.upsertExplicitDirective( diff --git a/test/main/memory/directiveService.test.ts b/test/main/memory/directiveService.test.ts index cd9351c762..f3164f08e9 100644 --- a/test/main/memory/directiveService.test.ts +++ b/test/main/memory/directiveService.test.ts @@ -190,7 +190,7 @@ describe('DirectiveService', () => { ).toMatchObject({ normalizedTopic: '工作' }) }) - it('returns typed capacity results for explicit creation and draft approval', () => { + it('bounds request tokens and rejects new activations at storage capacity', () => { const { presenter } = makePresenter({ memoryEnabled: true }) for (let index = 0; index < AGENT_MEMORY_ACTIVE_DIRECTIVE_MAX_COUNT; index += 1) { expect( @@ -200,6 +200,13 @@ describe('DirectiveService', () => { }) ).not.toBeNull() } + const { content, manifest } = presenter.buildDirectiveContribution('a', 2_000) + expect(content).toBeTruthy() + expect(manifest?.tokenBudget).toBe(512) + expect(manifest!.estimatedTokens).toBeLessThanOrEqual(512) + expect(manifest!.selected.length + manifest!.dropped.length).toBe(128) + expect(manifest!.dropped.length).toBeGreaterThan(0) + const draft = presenter.suggestDirective('a', { kind: 'instruction', content: 'Pending approval'