Repository navigation
Write the Codex async question cursor only when it moves - #8171
Merged
Merged
Conversation
The experimental_thread.events handler ran about once per second per streaming Codex thread and wrote the unchanged cursor to plugin kv on every run. Each write is an upsert on the main database. Write the cursor only when a new event row moved it.
alexburlis
added a commit
to alexburlis/omnyo
that referenced
this pull request
Nov 26, 2026
Record the upstream PRs, revisions, contributors, and Omnyo integration commits for merge d2a24ac in docs/upstream-credits.md. Original-PR: get-bb/bb#7663 Original-Commit: get-bb/bb@1737a03 Original-Author: rufi Original-PR: get-bb/bb#8055 Original-Commit: get-bb/bb@651ae20 Original-Author: Jake Lancaster Original-PR: get-bb/bb#8075 Original-Commit: get-bb/bb@511e1ed Original-Author: Jake Lancaster Original-Co-Author: Michael Yong Original-Co-Author: Claude Opus 5.5 Original-PR: get-bb/bb#8096 Original-Commit: get-bb/bb@775090b Original-Author: Michael Yong Original-Co-Author: Claude Opus 5.5 Original-PR: get-bb/bb#8145 Original-Commit: get-bb/bb@8de6711 Original-Commit: get-bb/bb@0d3db49 Original-Commit: get-bb/bb@92d3a76 Original-Commit: get-bb/bb@6705422 Original-Author: Michael Yong Original-Co-Author: Claude Opus 5.5 Original-PR: get-bb/bb#8171 Original-Commit: get-bb/bb@b56ed04 Original-Author: Jake Lancaster Original-PR: get-bb/bb#8238 Original-Commit: get-bb/bb@2a9a142 Original-Author: SawyerHood Original-PR: get-bb/bb#8247 Original-Commit: get-bb/bb@ba4ae22 Original-Author: Salem Original-Co-Author: Claude Opus 5.5 Original-PR: get-bb/bb#8259 Original-Commit: get-bb/bb@96f40a9 Original-Author: SawyerHood Original-PR: get-bb/bb#8263 Original-Commit: get-bb/bb@141e40a Original-Author: mk Original-PR: get-bb/bb#8266 Original-Commit: get-bb/bb@84e20e9 Original-Author: ILIA GOLUBEV
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Human comments
What was wrong
readNewQuestionsinplugins/provider-codex/src/async-questions.tsruns on everyexperimental_thread.events, which the server fires once per second per thread while the thread receives events (plugin-thread-events.ts). It ended with an unconditionalbb.storage.kv.set(cursorKey(threadId), cursor)(async-questions.ts). The cursor moves only when a newthread/extensionState/updatedrow exists, so almost every call wrote the value it had just read. Plugins run in the server process, andkv.setcallssetPluginKvValuesynchronously: oneINSERT ... ON CONFLICT DO UPDATEonplugin_kvin the main database (plugin-api.ts, plugin-storage.ts). So each streaming Codex thread caused one write transaction per second that changed nothing. I confirmed the call pattern with a test against the unfixed code (two notifications with no new rows give two writes of cursor 0) and measured the per-tick database cost before changing anything.What changed
readNewQuestionskeeps the cursor it read and callskv.setonly when the cursor moved forward.Math.maxover row sequences), and when it did not move, the skipped write would have stored the value already inplugin_kv. The next run reads the same cursor either way.Deviation from the issue's second question: the
threads.events.listloopback call stays. The event payload carries only the thread's latest sequence and the list is filtered to extension-state rows, so the plugin cannot know if a new question exists without the call. To skip it, the plugin would have to store the last scanned sequence, which brings back a write on every tick. An in-memory high-water mark would almost never skip, because the event fires only after new events were appended.How you verified
New test "writes the cursor only when a new event row moved it", on the unfixed code:
With the fix:
Tests 6 passed (6).Per-tick database work, measured with
getPluginKvValueandsetPluginKvValuefrom@bb/dbon a file database built withcreateConnectionandmigrate(WAL,synchronous = NORMAL, as in production). 50 cursor keys, 20,000 ticks per round, 3 rounds:pnpm exec turbo run typecheck test lint lint:type-aware --filter=bb-plugin-provider-codex: 11 of 11 tasks pass, 626 tests in 49 files.Fixes #8170