Skip to content

perf(hooks,storage): scope PreToolUse protected-branch scan to repo#499

Merged
NagyVikt merged 1 commit intomainfrom
agent/claude/scope-listtasks-pretooluse-2026-05-08-20-02
May 8, 2026
Merged

perf(hooks,storage): scope PreToolUse protected-branch scan to repo#499
NagyVikt merged 1 commit intomainfrom
agent/claude/scope-listtasks-pretooluse-2026-05-08-20-02

Conversation

@NagyVikt
Copy link
Copy Markdown
Collaborator

@NagyVikt NagyVikt commented May 8, 2026

Summary

  • protectedLiveClaimConflict in the PreToolUse hot-path hook used listTasks(1_000_000) then linearly filtered by repo_root + isProtectedBranch(branch). With the task table growing into the thousands across agents, this dominated p95 latency and violated the <150ms hook-handler budget.
  • Added Storage.listProtectedBranchTasksByRepo(repoRoot) — a single index-backed query against the existing UNIQUE(repo_root, branch) constraint on tasks. No new migration needed.
  • Replaced the unbounded scan at packages/hooks/src/handlers/pre-tool-use.ts:436. Defensive resolve() and isProtectedBranch() JS-side checks stay in place so storage path inconsistencies still get filtered.
  • ALL_TASKS_LIMIT constant removed (was only used at the replaced site).

The diff also picks up automatic biome formatting on three @colony/core files that #498 left over the column-wrap threshold (no behavior change). Without those, pnpm lint fails on this branch.

Test plan

  • pnpm --filter @colony/storage test — 117 passed (+1 new: listProtectedBranchTasksByRepo returns only tasks on protected branches at the given repo)
  • pnpm --filter @colony/hooks test — 189 passed
  • pnpm typecheck — clean
  • pnpm lint — clean

🤖 Generated with Claude Code

`protectedLiveClaimConflict` used `listTasks(1_000_000)` to find
protected-branch claim conflicts on every editor tool call, then linearly
filtered by repo_root and isProtectedBranch. With the task table growing
into the thousands, this dominated p95 latency on the hot path and
violated the <150ms hook-handler budget.

Added `Storage.listProtectedBranchTasksByRepo(repoRoot)`, a single
index-backed query against the existing `UNIQUE(repo_root, branch)`
constraint on `tasks`. Replaced the unbounded scan with the new method.
Defensive `resolve()` and `isProtectedBranch()` checks remain inside the
loop so storage path inconsistencies still get filtered.

Also picks up automatic biome formatting on three @colony/core files
that #498 left over the column wrap threshold; behavior unchanged.

Verification:
- pnpm --filter @colony/storage test (117 passed, +1 new)
- pnpm --filter @colony/hooks test (189 passed)
- pnpm typecheck (clean)
- pnpm lint (clean)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@NagyVikt NagyVikt merged commit 3898ff3 into main May 8, 2026
1 of 3 checks 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