Skip to content

fix: index filing_document by accession, and clear stale setup env keys - #406

Open
sroussey wants to merge 1 commit into
claude/elegant-fermi-brwjz1from
claude/intelligent-lovelace-uojhge-kb-index
Open

sroussey wants to merge 1 commit into
claude/elegant-fermi-brwjz1from
claude/intelligent-lovelace-uojhge-kb-index

Conversation

@sroussey

Copy link
Copy Markdown
Contributor

Summary

Two fixes on top of claude/elegant-fermi-brwjz1.

filing_document read by accession was a full table scan. ConvertFilingDocumentTask now reads every row of its submission by accession_number alone, before it replaces its own rows. It has to read across CIKs, because the co-filer check (factsAlreadyCurrent) looks at rows filed under other CIKs, so narrowing the query to {cik, accession_number} isn't an option. The primary key (cik, accession_number, doc_file) starts with cik, and none of the existing indexes starts with accession_number. So every conversion scanned the whole table, and a re-conversion sweep cost grew quadratically. This PR adds an ["accession_number"] index.

sec setup left old wizard keys in process.env. InitApplyTask set the keys for the new answers but never removed old ones. Say a first setup in a process used SEC_PG_URL and a second one switched to host/port/user. The old URL stayed set and took precedence, so setupAllDatabases built the tables in the old database. The new applyEnvConfig(env, config) in envFile.ts sets each key in WIZARD_ENV_KEYS from envEntriesFor(config) and deletes any key that has no entry. process.env now matches what .env.local holds.

Tests

  • New src/task/document/filingDocumentByAccession.sqlite.test.ts:
    • checks the query plan uses an index (SEARCH ... USING INDEX). This fails without the index and passes with it.
    • checks the accession query returns every co-filer's rows.
  • src/cli/groups/init.test.ts: new applyEnvConfig cases:
    • switching from a URL to host/port/user removes SEC_PG_URL
    • switching back to SQLite leaves no SEC_PG_* keys
    • the env matches the written file
  • bunx vitest run src/config src/cli/groups src/task/kb src/task/document: 229 passed, 6 skipped. bun run typecheck, bun run lint and bun run format-check pass.

Generated by Claude Code

A conversion reads every co-filer's filing_document rows by accession
alone; the primary key leads with cik, so that read scanned the whole
table on every conversion. Add an accession_number index.

InitApplyTask set process.env from the new wizard answers but never
removed owned keys the answers left unset, so a SEC_PG_URL from an
earlier run in the same process outranked the host/port/user just
chosen. process.env now mirrors envEntriesFor exactly.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015q4aqYR4rAGcnHCooSqJ4s
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.

2 participants