Skip to content

Read the overview and session view from set-based queries - #315

Merged
dinoderek merged 1 commit into
mainfrom
task/engine-414
Nov 23, 2026
Merged

dinoderek merged 1 commit into
mainfrom
task/engine-414

Conversation

@dinoderek

Copy link
Copy Markdown
Owner

Objective

overview and session-view read 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):

Operation Target Before After
overview < 5 ms 9.996 ms 2.28 ms
session-view < 1 ms 1.616 ms 0.58 ms
plan-detail < 5 ms 2.184 ms 1.11 ms
get < 1 ms 0.071 ms 0.061 ms
updates < 1 ms 0.137 ms 0.14 ms
inbox < 5 ms 0.747 ms 0.76 ms
write say / one record < 5 ms 0.285 / 0.112 ms 0.30 / 0.10 ms

Gates

Lane Result Evidence
./dev test (every required lane) PASS head 323efa6: format, vet, lint, unit, coverage, file-length, imports, versions, docs-check, harness-names all PASS, run with umask 022 (see Deviations)
  • New or changed tests:
    • internal/control/tx_batch_test.go: each batched Tx accessor (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 equals strings.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.
    • The existing overview, session-view, inbox, plan-view and benchmark-gate tests pass unchanged.
  • Not run, with reason: none

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's currentIndexes on open, with no schema version bump.
User notices: nothing; overview is 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): withStatus of 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

  • Fresh reviewer: claude-opus-5-5 (Claude Code); round 1 Verdict: APPROVED, no must-fix findings.
  • Declined findings (all optional):
    • Narrow the plan-scan allowance to json_each aliases: the SQLite plan text names the alias, which a rename would silently break; no other virtual table exists in the schema.
    • TaskStatesOfPlans repeats a plan's states if the caller lists the plan twice: no caller does, and PlanStatus is unchanged by repeats.
  • Applied: the index decision is recorded under Deviations.
  • Review hard: 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.go and internal/controlrun/scope_test.go (what counts as a bounded scan).

Deviations

  • The card asks for a schema change as a new schema version; the two indexes use currentIndexes (the mechanism that added attempts_limited to the current version) instead, as the Rulings entry says.
  • The table-scan checks in internal/control/plans_test.go and internal/controlrun/scope_test.go now accept a json_each list scan and the SCAN (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, //nolint or budget changed.
  • On this host ./dev test passes only under umask 022: TestTrustFolderKeepsEverythingElse (internal/harness/claude) and TestEditFileRetriesThenGivesUpOnABusyFile (internal/session) create a file expecting mode 0640 and fail under the shell's umask 0077, identically on untouched origin/main at 87d936f in a scratch checkout, and pass there under umask 022. The lanes ran under umask 022; no code or test was changed for it.

🤖 Generated with Claude Code

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
@dinoderek
dinoderek merged commit cee47fe into main Nov 23, 2026
1 check passed
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