Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/shared/types/agent-memory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}$/
Expand Down
18 changes: 15 additions & 3 deletions test/main/memory/agentMemoryDirectiveTable.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
)
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand Down
9 changes: 8 additions & 1 deletion test/main/memory/directiveService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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'
Expand Down