fix: reclaim cancelFns, TTL idemLocks, cache scope probe, invalidate C1, SSE subscribe order
Close T20-B2/B6/B8/B9/B10 low-risk leaks: map-backed cancel reclaim, idempotency lock TTL in cleanupLoop, sync.Once information_schema probe, InvalidateLayer after chat memory upsert, and Subscribe before SSE headers.
This commit is contained in:
@@ -147,6 +147,8 @@ func (m *ContextManager) RecordTurnMemoryWithVisibility(
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("insert chat memory chunk to db failed: %w", err)
|
||||
}
|
||||
// C1 search cache keys include query text; drop the layer so new chunks are visible.
|
||||
m.Cache().InvalidateLayer(LayerC1Search)
|
||||
return chunkID, nil
|
||||
}
|
||||
|
||||
@@ -184,6 +186,7 @@ func (m *ContextManager) RecordTurnMemoryWithVisibility(
|
||||
m.memoryChunks = append(m.memoryChunks, item)
|
||||
}
|
||||
|
||||
m.Cache().InvalidateLayer(LayerC1Search)
|
||||
return chunkID, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -39,6 +39,10 @@ type ContextManager struct {
|
||||
nextActivityID int64
|
||||
nextMessageID int64
|
||||
nextChunkID int64
|
||||
|
||||
// message scope column probe (information_schema); cached once per manager
|
||||
messageScopeOnce sync.Once
|
||||
messageScopeOK bool
|
||||
}
|
||||
|
||||
// NewContextManager 创建上下文管理器
|
||||
|
||||
@@ -25,14 +25,17 @@ func (m *ContextManager) hasMessageScopeColumns(ctx context.Context) bool {
|
||||
if m == nil || m.pool == nil {
|
||||
return false
|
||||
}
|
||||
var ok bool
|
||||
_ = m.pool.QueryRow(ctx, `
|
||||
SELECT EXISTS (
|
||||
SELECT 1 FROM information_schema.columns
|
||||
WHERE table_schema = 'public' AND table_name = 'chat_messages' AND column_name = 'scope_kind'
|
||||
)
|
||||
`).Scan(&ok)
|
||||
return ok
|
||||
m.messageScopeOnce.Do(func() {
|
||||
var ok bool
|
||||
_ = m.pool.QueryRow(ctx, `
|
||||
SELECT EXISTS (
|
||||
SELECT 1 FROM information_schema.columns
|
||||
WHERE table_schema = 'public' AND table_name = 'chat_messages' AND column_name = 'scope_kind'
|
||||
)
|
||||
`).Scan(&ok)
|
||||
m.messageScopeOK = ok
|
||||
})
|
||||
return m.messageScopeOK
|
||||
}
|
||||
|
||||
func (m *ContextManager) chatMessageSelectColumns(ctx context.Context) string {
|
||||
|
||||
Reference in New Issue
Block a user