Skip to content

[Fix] Brain backfills delay recent task context - #1356

Draft
mrubens wants to merge 2 commits into
developfrom
codex/brain-newest-tasks-first
Draft

[Fix] Brain backfills delay recent task context#1356
mrubens wants to merge 2 commits into
developfrom
codex/brain-newest-tasks-first

Conversation

@mrubens

@mrubens mrubens commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

​Opened on behalf of @mrubens. View the task or mention @roomote for follow-up asks.

What changed

  • Persist each task run's completion time on its Brain memory outbox event.
  • Claim active events through a partial index ordered by completion time and descending run ID, while preserving atomic FOR UPDATE SKIP LOCKED claims and stale-processing recovery.
  • Backfill priority timestamps for existing outbox rows during migration and populate them through completion, agent-summary, and historical-backfill enqueue paths.
  • Cover newest-first ordering, deterministic ties, and timestamp propagation with real-database tests.

Why this change was made

Historical events can share effectively identical outbox creation times. Joining and sorting the full pending backlog for every small claim made recent context expensive to prioritize during a large Brain backfill.

Impact

Recent completed tasks become available to Brain first without repeatedly joining and sorting the historical backlog. The queue keeps its existing concurrency and retry behavior, and the migration safely initializes priority metadata for events already waiting to drain.

@roomote-community

roomote-community Bot commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

No code issues found. See task

  • packages/db/src/lib/brain.ts - Claims use persisted completion priority and a matching active-queue index instead of joining and sorting the full pending backfill.

Reviewed 6c0389d

Comment thread packages/db/src/lib/brain.ts Outdated
@roomote-community roomote-community Bot changed the title [Fix] Prioritize recent tasks during Brain backfill [Fix] Brain backfills delay recent task context Aug 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant