fix(brain): address spec review findings

- Move BrainForget DB lookup inside circuit breaker for consistency
- Check ensureCollection() PUT response for Qdrant errors
- Wrap remember() in DB::transaction for atomicity
- Align migration confidence default to 0.8 (matches PHP default)

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Snider 2026-03-03 09:45:05 +00:00
parent eeb6927d8f
commit 2c6a095a0e
3 changed files with 25 additions and 18 deletions

View file

@ -73,19 +73,18 @@ class BrainForget extends AgentTool
}
$reason = $this->optionalString($args, 'reason', null, 500);
// Verify memory exists and belongs to this workspace
$memory = BrainMemory::where('id', $id)
->where('workspace_id', $workspaceId)
->first();
if (! $memory) {
return $this->error("Memory '{$id}' not found in this workspace");
}
$agentId = $context['agent_id'] ?? $context['session_id'] ?? 'anonymous';
return $this->withCircuitBreaker('brain', function () use ($id, $memory, $reason, $agentId) {
return $this->withCircuitBreaker('brain', function () use ($id, $workspaceId, $reason, $agentId) {
// Verify memory exists and belongs to this workspace
$memory = BrainMemory::where('id', $id)
->where('workspace_id', $workspaceId)
->first();
if (! $memory) {
return $this->error("Memory '{$id}' not found in this workspace");
}
Log::info('OpenBrain: memory forgotten', [
'id' => $id,
'type' => $memory->type,

View file

@ -27,7 +27,7 @@ return new class extends Migration
$table->text('content');
$table->json('tags')->nullable();
$table->string('project', 128)->nullable()->index();
$table->float('confidence')->default(1.0);
$table->float('confidence')->default(0.8);
$table->uuid('supersedes_id')->nullable();
$table->timestamp('expires_at')->nullable();
$table->timestamps();

View file

@ -5,6 +5,7 @@ declare(strict_types=1);
namespace Core\Mod\Agentic\Services;
use Core\Mod\Agentic\Models\BrainMemory;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
@ -63,12 +64,14 @@ class BrainService
]);
$payload['vector'] = $vector;
$this->qdrantUpsert([$payload]);
DB::transaction(function () use ($payload, $memory) {
$this->qdrantUpsert([$payload]);
if ($memory->supersedes_id) {
$this->qdrantDelete([$memory->supersedes_id]);
BrainMemory::where('id', $memory->supersedes_id)->delete();
}
if ($memory->supersedes_id) {
BrainMemory::where('id', $memory->supersedes_id)->delete();
$this->qdrantDelete([$memory->supersedes_id]);
}
});
}
/**
@ -139,13 +142,18 @@ class BrainService
->get("{$this->qdrantUrl}/collections/{$this->collection}");
if ($response->status() === 404) {
Http::timeout(10)
$createResponse = Http::timeout(10)
->put("{$this->qdrantUrl}/collections/{$this->collection}", [
'vectors' => [
'size' => self::VECTOR_DIMENSION,
'distance' => 'Cosine',
],
]);
if (! $createResponse->successful()) {
throw new \RuntimeException("Qdrant collection creation failed: {$createResponse->status()}");
}
Log::info("OpenBrain: created Qdrant collection '{$this->collection}'");
}
}