Repository navigation
Read the overview and session view from set-based queries - #315
Merged
Merged
Conversation
Batch the per-plan and per-row lookups behind overview, session-view and a plan's status: items, updates, task states, open questions and latest messages are each read once for the whole list. Index the questions asked on an item or by a task, so the open-question read searches only them. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012F3VVE8imqwYs9oBRxHeUd
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.
Objective
overviewandsession-viewread each list's items, open questions, task states and latest messages once for the whole list instead of once per plan or per row, so both meet their performance targets (5 ms and 1 ms). Responses are unchanged.Benchmark on the fixture in
internal/control/bench_test.go(500 items, 1,000 attempts, 20,000 updates, 2,000 receipts;go test ./internal/control -run xxx -bench BenchmarkStore -benchtime 500x, mean per op, same machine):overviewsession-viewplan-detailgetupdatesinboxsay/ one recordGates
./dev test(every required lane)umask 022(see Deviations)internal/control/tx_batch_test.go: each batchedTxaccessor (ItemsByID,UpdatesByID,TaskStatesOfPlans,OwnQuestions,LatestMessages) returns what the per-item lookup it replaces returns, on a real database: items with no question, several questions (resolved, replied, acknowledged, pane-answered), a plan's question held by the task that asked it, blank and Unicode-space bodies, the coordinator's and non-message updates; the SQL blank set equalsstrings.TrimSpace's.internal/control/plans_test.go: each new accessor is an indexed query (updates_asked_item,updates_asked_task,items_plan,updates_item).internal/control/store_test.go: a current database lacking the new indexes gets them on open.internal/controlrun/scope_test.go: the table-scan check, see Deviations.overview,session-view,inbox,plan-viewand benchmark-gate tests pass unchanged.Rulings
Ruling (risk: review): the open-question read gets two partial indexes on
updates(updates_asked_item,updates_asked_task,WHERE requires_reply=1), added through the store'scurrentIndexeson open, with no schema version bump.User notices: nothing;
overviewis faster. The first open of an existing database builds the two indexes, which hold only the questions.Alternative: schema version 8 with a migration, which an older server would refuse to open.
If wrong: another PR drops the indexes (a database keeps unused indexes harmlessly); no record changes.
Ruling (risk: low):
withStatusof one item goes through the batched reads, so a plan read has one code path.Ruling (risk: low): the batched accessors take the set as one JSON array (
json_each), so each is one statement whatever its size.Review
Verdict: APPROVED, no must-fix findings.json_eachaliases: the SQLite plan text names the alias, which a rename would silently break; no other virtual table exists in the schema.TaskStatesOfPlansrepeats a plan's states if the caller lists the plan twice: no caller does, andPlanStatusis unchanged by repeats.internal/control/tx_batch.go(each accessor equals its per-item original, including the blank-body test),internal/control/schema.go(indexes without a version bump),internal/control/plans_test.goandinternal/controlrun/scope_test.go(what counts as a bounded scan).Deviations
currentIndexes(the mechanism that addedattempts_limitedto the current version) instead, as the Rulings entry says.internal/control/plans_test.goandinternal/controlrun/scope_test.gonow accept ajson_eachlist scan and theSCAN (subquery-step over a materialised result as bounded; their inner steps are still checked, and a table scan still fails. No gate threshold, baseline row,//nolintor budget changed../dev testpasses only underumask 022:TestTrustFolderKeepsEverythingElse(internal/harness/claude) andTestEditFileRetriesThenGivesUpOnABusyFile(internal/session) create a file expecting mode 0640 and fail under the shell's umask 0077, identically on untouchedorigin/mainat 87d936f in a scratch checkout, and pass there underumask 022. The lanes ran underumask 022; no code or test was changed for it.🤖 Generated with Claude Code