coding-agents: gitLogIsCurrent's documentTags fallback full-text-scans the bank (q= matches original_text) and times out at 15 s on large repos

Open
#7,214 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
68/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
postgresql, python

Research direction

Start in hindsight-integrations/coding-agents at gitLogIsCurrent() and trace its documentTags fallback and listDocuments paging. Compare the suggested source:git-log tag lookup with the current q search; the issue reports the former returns the needed tags in about 95 ms. Confirm the fallback still identifies gitlog:<repo> without fetching document bodies, then check the existing documentTags test.

Written by the indexing model from the issue text.

Description

integration:coding-agents
Bug Description

In hindsight-integrations/coding-agents, gitLogIsCurrent() falls back to HindsightClient.documentTags("gitlog:<repo>") whenever the gitlog-head:<HEAD> tag lookup misses, which in an active repository is most session starts. documentTags pages GET /documents?q=gitlog:<repo>&limit=100. On the server, q is a substring search over both id and original_text ((id ILIKE '%…%' OR original_text ILIKE '%…%'), with no index on the text), so every call detoasts and scans the full text of every document in the bank.

In a bank holding a few thousand source:git documents (full diffs), that request never fits the client's 15 s timeout. The fallback then returns undefined and the session only loses the "git in sync / catching up" note, so the wait buys nothing. Meanwhile:

  • the first turn waits on it (session start is awaited before the first prompt), and
  • the server keeps scanning after the client gives up, so each session start costs the database seconds of full-text scanning.
Steps to Reproduce
  1. Use a bank with ~2,400 source:git documents (~600 MB of stored diff text) plus its gitlog:<repo> document.
  2. Commit once, so local HEAD differs from the stored gitlog-head: tag.
  3. Start a session (any harness's session-start hook).
Expected Behavior

The freshness check reads one known document's tags in well under a second.

Actual Behavior

Measured against a stock 1.3.0 server with plugin 0.9.1 (latest; main has the same code):

Request Result
GET /documents?tags=gitlog-head:<HEAD>&tags_match=all_strict 96–98 ms, no hit (HEAD moved)
GET /documents?q=gitlog:<repo>&limit=100&offset=0 timeout at 15,012 ms, every session start
The same q count step, run on its own in Postgres (EXPLAIN ANALYZE) 8,442 ms; the page query repeats the scan
GET /documents?tags=source:git-log&tags_match=all_strict&limit=100 94–95 ms, total=1, returns gitlog:<repo> with its tags
GET /documents/gitlog:<repo> 142–432 ms, 197 KB body, includes tags

In our logs, session starts in that repository took ~20–26 s, most of it this one request.

Suggested fix

Keep the "no document body" intent of documentTags (per its test, "reads one document's tags from the id-filtered listing, not the full document"), but make the listing actually narrow server-side. Either:

  1. Client only: look the gitlog document up by the tag it already carries: listDocuments?tags=source:git-log&tags_match=all_strict, then pick id === "gitlog:<repo>" (one document per repository, so a bank shared by several repositories returns only a handful). Measured above at ~95 ms.
  2. Server: offer an exact-id filter on the document listing (for example ids= or q_fields=id), so an id lookup is a primary-key hit and never a text scan.

(1) needs no server change, and its paging logic can stay as it is.

Version

Plugin @vectorize-io/hindsight-coding-agents 0.9.1, server 1.3.0.

Dominant language
Python
Stars
45.2k
Forks
5.9k
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from vectorize-io/hindsight

All issues in vectorize-io/hindsight

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.