people_find reads every interaction per matched Person and builds rows past the page #86

Closed
opened 2026-11-04 14:11:30 +00:00 by svc-svd-writer · 3 comments
Collaborator

This was generated by AI during triage.

What happens

people_find gets slower as the store collects interactions. On the #49 pair store (rc.9, 401 Persons) it took about 100 ms at 21,600 interactions. At 168,000 interactions it took 27–30 s, even for a query that matches nothing. The I01 run saw nine probe calls in a row exceed their 10 s client timeout, from 2026-11-04T14:04:27Z.

Cause

Two defects in src/people_mind_mcp/views.py, confirmed on a read-only copy of the pair store:

  1. interactions has no index on person_id. The only index is interactions_once. LAST_INTERACTION (SELECT MAX(date) FROM interactions WHERE person_id = ?, views.py:29) and RECENT (views.py:48) read the whole table for each Person.
  2. find (views.py:133) calls default_row for every match before _paged selects one page (views.py:183). In hybrid mode, the matches are every Person with a semantic score of 0.55 or more (config.py:110), so one call can build hundreds or thousands of rows to return 20.

Measured on the store copy (native arm64; the pair container runs amd64 under emulation, which is about 10 times slower):

Step Time
Lexical find, no rows built 2 ms
LAST_INTERACTION, one Person, 168,000 interactions 6.2 ms
default_row for all 401 Persons 2.6 s

Live store (rc.9, read-only, during the #338 rebuild): 3,939 Persons, 93,714 interactions, LAST_INTERACTION 8.3 ms per Person. If most Persons pass the semantic threshold, the worst case is about 33 s per people_find call. A live call was not timed.

What to change

  • Add a schema migration: CREATE INDEX interactions_person_date ON interactions(person_id, date). Follow the migration pattern in src/people_mind_mcp/store.py (MIGRATIONS, SCHEMA_VERSION); the next user_version is 10.
  • In find, page the ranked matches first, then build default_row only for the rows on the selected page. Keep the footer total: it is the count of all matches, not of the page.

Acceptance

  • EXPLAIN QUERY PLAN for LAST_INTERACTION and RECENT names the new index.
  • A test builds a store with many matches and asserts that find calls default_row at most limit times per call.
  • The find output is unchanged for existing tests, including the footer total and the next cursor.
  • A store at user_version 9 migrates to 10 in place, and the migration test covers it.
  • On the #49 pair store at 168,000 interactions, people_find answers in under 1 s.

Out of scope

  • related builds no default rows, so it needs no change.
  • No change to ranking, scores, or the semantic threshold.

Blocks

#10: the Grok re-run uses people_find, and a call that takes about 30 s fails the client's timeout.

Filed under: operator word "yes, file it that way" sha256:df2e44592f44

> *This was generated by AI during triage.* ## What happens `people_find` gets slower as the store collects interactions. On the #49 pair store (rc.9, 401 Persons) it took about 100 ms at 21,600 interactions. At 168,000 interactions it took 27–30 s, even for a query that matches nothing. The I01 run saw nine probe calls in a row exceed their 10 s client timeout, from 2026-11-04T14:04:27Z. ## Cause Two defects in `src/people_mind_mcp/views.py`, confirmed on a read-only copy of the pair store: 1. `interactions` has no index on `person_id`. The only index is `interactions_once`. `LAST_INTERACTION` (`SELECT MAX(date) FROM interactions WHERE person_id = ?`, `views.py:29`) and `RECENT` (`views.py:48`) read the whole table for each Person. 2. `find` (`views.py:133`) calls `default_row` for every match before `_paged` selects one page (`views.py:183`). In hybrid mode, the matches are every Person with a semantic score of 0.55 or more (`config.py:110`), so one call can build hundreds or thousands of rows to return 20. Measured on the store copy (native arm64; the pair container runs amd64 under emulation, which is about 10 times slower): | Step | Time | | --- | --- | | Lexical `find`, no rows built | 2 ms | | `LAST_INTERACTION`, one Person, 168,000 interactions | 6.2 ms | | `default_row` for all 401 Persons | 2.6 s | Live store (rc.9, read-only, during the #338 rebuild): 3,939 Persons, 93,714 interactions, `LAST_INTERACTION` 8.3 ms per Person. If most Persons pass the semantic threshold, the worst case is about 33 s per `people_find` call. A live call was not timed. ## What to change - Add a schema migration: `CREATE INDEX interactions_person_date ON interactions(person_id, date)`. Follow the migration pattern in `src/people_mind_mcp/store.py` (`MIGRATIONS`, `SCHEMA_VERSION`); the next `user_version` is 10. - In `find`, page the ranked matches first, then build `default_row` only for the rows on the selected page. Keep the footer total: it is the count of all matches, not of the page. ## Acceptance - `EXPLAIN QUERY PLAN` for `LAST_INTERACTION` and `RECENT` names the new index. - A test builds a store with many matches and asserts that `find` calls `default_row` at most `limit` times per call. - The `find` output is unchanged for existing tests, including the footer total and the next cursor. - A store at `user_version` 9 migrates to 10 in place, and the migration test covers it. - On the #49 pair store at 168,000 interactions, `people_find` answers in under 1 s. ## Out of scope - `related` builds no default rows, so it needs no change. - No change to ranking, scores, or the semantic threshold. ## Blocks #10: the Grok re-run uses `people_find`, and a call that takes about 30 s fails the client's timeout. Filed under: operator word "yes, file it that way" sha256:df2e44592f44
Author
Collaborator

⏸ SVD architect gate: dev/people-mind-mcp#86 people-find-reads-every-interaction-per-matched-person-and-b

Status: CLEAN after 0 rework round(s) · 0 blocking defect(s) · 0 lens(es) INCONCLUSIVE (could not run) · 0 lens(es) DEGRADED (deterministic denial) · complexity substrate · dispatch effort high

Run: 20261104T142905Z-db82f6ef

Held because: CLEAN but 2 open risk(s) (2 verification) — HOLD-ALL parks everything. The risks, verbatim:

Open risks:

  1. The '<1 s on the #49 pair store at 168,000 interactions' criterion can only be checked live. Check: after the pair deploy, confirm peoplemind check reports store=ok schema=10. Then time three people_find calls over MCP: a name that matches nothing, a broad common name, and an email. Each must answer in under 1 s; the issue's baseline was 27-30 s. [verification]
  2. The tests/test_deploy.py literal bump (schema=9 to schema=10 at :295 and :328) is not run in CI, because .woodpecker/validation.yaml leaves make test-integration host-only. Check: on a host with podman or docker, run make test-integration and confirm test_litestream_restore_passes_check passes rather than failing with live-store-timeout. [verification]

Change: Schema 10 goes in the post-v6 upgrade block of store.py open_writer (store.py:162-172), not in MIGRATIONS. MIGRATIONS covers only versions 1-6, so appending a seventh entry would apply it at the wrong version. Add a constant INDEXES = ("CREATE INDEX IF NOT EXISTS interactions_person_date ON interactions(person_id, date)",), mirroring the UPGRADES shape (store.py:19-24). Run it after the UPGRADES loop. Replace SCHEMA_9 with SCHEMA_10 = "PRAGMA user_version=10" and set SCHEMA_VERSION = 10. IF NOT EXISTS keeps the #69 concurrent-writer path and the version-marker heal paths idempotent. In views.find (views.py:182-183), page the (pid, reason) matches with rows.page first (rows.py:49-54), build default_row only for the selected page, then join row(...) with the footer. The total and next_cursor are unchanged because page counts len(matches). Keep _paged for related and recent. Raise every schema-9 literal (test_identity:528, test_mailpeer:607/628/663, test_embed:64, test_config_cli:119, test_deploy:295/328, README:177) and add a README:141 rollback sentence.

Files: src/people_mind_mcp/store.py · src/people_mind_mcp/views.py · tests/test_identity.py · tests/test_embed.py · tests/test_mailpeer.py · tests/test_config_cli.py · tests/test_deploy.py · README.md

Decision: accept the 2 open risk(s) above and dispatch this spec (svd:go), or park (svd:skip) / re-spec (svd:respec)?

Your call (when this issue is held at the gate via svd:hold):

  • add label svd:go — approve; Half-B dispatch accepts exactly this spec (open risks accepted)
  • add label svd:fire beside svd:go — approve AND authorise the Half-B fire from the phone; never on its own
  • add label svd:skip — park it; dispatch refuses it and the issue stays for a human
  • add label svd:respec — discard this spec; the next Half-A run re-produces it with this record as prior-attempt context

Spec: /Users/piers/.local/state/exhaust/groupthink/specs/2026-11-04-people-find-reads-every-interaction-per-matched-person-and-b.md — next: codex-svd dispatch --args '<same-json>' --approved-spec-path /Users/piers/.local/state/exhaust/groupthink/specs/2026-11-04-people-find-reads-every-interaction-per-matched-person-and-b.md

### ⏸ SVD architect gate: dev/people-mind-mcp#86 people-find-reads-every-interaction-per-matched-person-and-b **Status:** CLEAN after 0 rework round(s) · 0 blocking defect(s) · 0 lens(es) INCONCLUSIVE (could not run) · 0 lens(es) DEGRADED (deterministic denial) · complexity `substrate` · dispatch effort `high` **Run:** `20261104T142905Z-db82f6ef` **Held because:** CLEAN but 2 open risk(s) (2 verification) — HOLD-ALL parks everything. The risks, verbatim: **Open risks:** 1. The '<1 s on the #49 pair store at 168,000 interactions' criterion can only be checked live. Check: after the pair deploy, confirm peoplemind check reports store=ok schema=10. Then time three people_find calls over MCP: a name that matches nothing, a broad common name, and an email. Each must answer in under 1 s; the issue's baseline was 27-30 s. [verification] 2. The tests/test_deploy.py literal bump (schema=9 to schema=10 at :295 and :328) is not run in CI, because .woodpecker/validation.yaml leaves make test-integration host-only. Check: on a host with podman or docker, run make test-integration and confirm test_litestream_restore_passes_check passes rather than failing with live-store-timeout. [verification] **Change:** Schema 10 goes in the post-v6 upgrade block of store.py open_writer (store.py:162-172), not in MIGRATIONS. MIGRATIONS covers only versions 1-6, so appending a seventh entry would apply it at the wrong version. Add a constant INDEXES = ("CREATE INDEX IF NOT EXISTS interactions_person_date ON interactions(person_id, date)",), mirroring the UPGRADES shape (store.py:19-24). Run it after the UPGRADES loop. Replace SCHEMA_9 with SCHEMA_10 = "PRAGMA user_version=10" and set SCHEMA_VERSION = 10. IF NOT EXISTS keeps the #69 concurrent-writer path and the version-marker heal paths idempotent. In views.find (views.py:182-183), page the (pid, reason) matches with rows.page first (rows.py:49-54), build default_row only for the selected page, then join row(...) with the footer. The total and next_cursor are unchanged because page counts len(matches). Keep _paged for related and recent. Raise every schema-9 literal (test_identity:528, test_mailpeer:607/628/663, test_embed:64, test_config_cli:119, test_deploy:295/328, README:177) and add a README:141 rollback sentence. **Files:** `src/people_mind_mcp/store.py` · `src/people_mind_mcp/views.py` · `tests/test_identity.py` · `tests/test_embed.py` · `tests/test_mailpeer.py` · `tests/test_config_cli.py` · `tests/test_deploy.py` · `README.md` **Decision:** accept the 2 open risk(s) above and dispatch this spec (`svd:go`), or park (`svd:skip`) / re-spec (`svd:respec`)? **Your call** (when this issue is held at the gate via `svd:hold`): - add label `svd:go` — approve; Half-B dispatch accepts exactly this spec (open risks accepted) - add label `svd:fire` **beside** `svd:go` — approve AND authorise the Half-B fire from the phone; never on its own - add label `svd:skip` — park it; dispatch refuses it and the issue stays for a human - add label `svd:respec` — discard this spec; the next Half-A run re-produces it with this record as prior-attempt context <sub>Spec: `/Users/piers/.local/state/exhaust/groupthink/specs/2026-11-04-people-find-reads-every-interaction-per-matched-person-and-b.md` — next: `codex-svd dispatch --args '<same-json>' --approved-spec-path /Users/piers/.local/state/exhaust/groupthink/specs/2026-11-04-people-find-reads-every-interaction-per-matched-person-and-b.md`</sub>
Author
Collaborator

spec-verify-dispatch Half B for dev/people-mind-mcp#86 people-find-reads-every-interaction-per-matched-person-and-b completed integration verify.

  • PR: #88
  • Branch: feat/svd-dev-people-mind-mcp-86-people-find-reads-every-inter-31b0c2dc
  • Commit: 63d066cfe8
  • Build: none
  • Test: green
  • Reader audit clean: True
  • Spec fidelity: True
  • Ready for merge: True
  • Check ci/woodpecker/pr/validation: green https://ci.groupthink.asia/repos/73/pipeline/52/1
  • Checks: required ci/woodpecker/pr/validation resolved pass by CI-wait poll
  • Warning: Container integration tests (tests/test_deploy.py schema=10 literals) are not run in CI; the architect runs make test-integration on a host with a container engine before merge.
  • Warning: Live post-deploy verification of people_find latency (<1 s on the 168,000-interaction pair store) remains open.
  • Warning: Schema 10 is a rollback hazard: older binaries refuse a schema-10 store.
  • CI wait: ci/woodpecker/pr/validation -> pass
  • Decision: review the PR and merge? (codex-svd ship --run-id 20261104T201458Z-31b0c2dc --confirm-merge)
spec-verify-dispatch Half B for dev/people-mind-mcp#86 people-find-reads-every-interaction-per-matched-person-and-b completed integration verify. - PR: https://git.groupthink.asia/dev/people-mind-mcp/pulls/88 - Branch: feat/svd-dev-people-mind-mcp-86-people-find-reads-every-inter-31b0c2dc - Commit: 63d066cfe8136088273b70bd327edf6647304d81 - Build: none - Test: green - Reader audit clean: True - Spec fidelity: True - Ready for merge: True - Check ci/woodpecker/pr/validation: green https://ci.groupthink.asia/repos/73/pipeline/52/1 - Checks: required ci/woodpecker/pr/validation resolved pass by CI-wait poll - Warning: Container integration tests (tests/test_deploy.py schema=10 literals) are not run in CI; the architect runs make test-integration on a host with a container engine before merge. - Warning: Live post-deploy verification of people_find latency (<1 s on the 168,000-interaction pair store) remains open. - Warning: Schema 10 is a rollback hazard: older binaries refuse a schema-10 store. - CI wait: ci/woodpecker/pr/validation -> pass - Decision: review the PR and merge? (`codex-svd ship --run-id 20261104T201458Z-31b0c2dc --confirm-merge`)
svc-svd-writer 2026-11-04 20:29:36 +00:00
  • closed this issue
  • removed the
    svd:go
    label
Author
Collaborator

This was generated by AI during triage.

Live check on 0.1.0-rc.10 (piers store, 2026-11-04)

rc.10 carries PR #88 (61febb4). The pod rolled at 21:34:30Z (starbase/iac#340, sha256:caf5c3f3cd71…). All three containers are ready, with 0 restarts. The checks are read-only.

  • peoplemind check: store=ok schema=10 persons=3939 organisations=1516 tombstones=0.
  • PRAGMA user_version: 10. The index interactions_person_date is present.
  • EXPLAIN QUERY PLAN for LAST_INTERACTION: SEARCH interactions USING COVERING INDEX interactions_person_date (person_id=?).
  • The store has 93,705 interactions.

views.find timings, run in the api container against the live store. Each call is timed once after a warm-up call, with limit 20:

Query Mode Rows Time
A name that matches nothing lexical 0 22.9 ms
A name that matches nothing hybrid 20 107.7 ms
The most common first name lexical 20 53.5 ms
The most common first name hybrid 20 164.6 ms
An Owner email lexical 1 2.7 ms
An Owner email hybrid 1 2.5 ms

Every call is under the 1 s target. Before the change, the estimate for this store was about 33 s in the worst case.

The Grok re-run on #10 used people_find over MCP at 22:05Z to 22:07Z. All four people_find calls returned code=ok. The api log does not record call times.

Open Risk 1: met on the live store at 93,705 interactions. It is not yet measured on the #49 pair store at 168,000 interactions; the next #49 run covers that.

Open Risk 2 (make test-integration for the schema-10 literals in tests/test_deploy.py): this check does not cover it.

> *This was generated by AI during triage.* ## Live check on 0.1.0-rc.10 (piers store, 2026-11-04) rc.10 carries PR #88 (`61febb4`). The pod rolled at 21:34:30Z (starbase/iac#340, `sha256:caf5c3f3cd71…`). All three containers are ready, with 0 restarts. The checks are read-only. - `peoplemind check`: `store=ok schema=10 persons=3939 organisations=1516 tombstones=0`. - `PRAGMA user_version`: 10. The index `interactions_person_date` is present. - `EXPLAIN QUERY PLAN` for `LAST_INTERACTION`: `SEARCH interactions USING COVERING INDEX interactions_person_date (person_id=?)`. - The store has 93,705 interactions. `views.find` timings, run in the api container against the live store. Each call is timed once after a warm-up call, with `limit` 20: | Query | Mode | Rows | Time | | --- | --- | --- | --- | | A name that matches nothing | lexical | 0 | 22.9 ms | | A name that matches nothing | hybrid | 20 | 107.7 ms | | The most common first name | lexical | 20 | 53.5 ms | | The most common first name | hybrid | 20 | 164.6 ms | | An Owner email | lexical | 1 | 2.7 ms | | An Owner email | hybrid | 1 | 2.5 ms | Every call is under the 1 s target. Before the change, the estimate for this store was about 33 s in the worst case. The Grok re-run on #10 used `people_find` over MCP at 22:05Z to 22:07Z. All four `people_find` calls returned `code=ok`. The api log does not record call times. **Open Risk 1:** met on the live store at 93,705 interactions. It is not yet measured on the #49 pair store at 168,000 interactions; the next #49 run covers that. **Open Risk 2** (`make test-integration` for the schema-10 literals in `tests/test_deploy.py`): this check does not cover it.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
dev/people-mind-mcp#86
No description provided.