Skip to content

fix(search): reject tokenless FTS widening, scope search dms by account, and guard empty author filters - #258

Closed
saariuslystoned wants to merge 1 commit into
steipete:mainfrom
saariuslystoned:fix/search-tokenless-queries-and-account-scope
Closed

saariuslystoned wants to merge 1 commit into
steipete:mainfrom
saariuslystoned:fix/search-tokenless-queries-and-account-scope

Conversation

@saariuslystoned

@saariuslystoned saariuslystoned commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Prevents non-empty tokenless searches and empty author selectors from widening results to unfiltered rows, and extends per-operation account selection to search dms:

  1. src/lib/timeline-read-model.ts: Track hasUnmatchableText when a non-blank search string produces no FTS tokens after stripping from: selectors, and preserve explicit empty --author / from:@ / from: selectors as "" instead of falling back to undefined so unmatchable searches return [].
  2. src/lib/dm-read-model.ts & src/lib/link-index.ts: Return [] when a non-blank search query produces no FTS tokens (listDmConversations) or no URL/word terms (searchLinks), while keeping absent/blank queries unfiltered.
  3. src/cli/register-search.ts: Add --account <username> to search dms <query> and forward options.account to enrichDmItems so DM search honors both configured accounts.default and explicit --account overrides via the shared configureOperationAccountSelection preAction hook.

Shipped CLI Behavior Proof (dist/cli/birdclaw.js Base v0.17.0 @ 9895445ba0a2 vs Head @ 2357d10abc89)

1. Seed v0.17.0 Archive (9895445ba0a2) with Settings (accounts.default: "@steipete"), Accounts, Tweets, Collections, Links, and DMs

$ cat /private/tmp/bc-home-base-258/config.json
{
  "accounts": { "default": "@steipete" }
}
$ BIRDCLAW_HOME=/private/tmp/bc-home-base-258 BIRDCLAW_TEST_SEED_DEMO_DATA=1 node /private/tmp/bc-base-v0170/dist/cli/birdclaw.js --json db stats >/dev/null
$ cp -a /private/tmp/bc-home-base-258/. /private/tmp/bc-home-upg-258/

2. Base (v0.17.0 @ 9895445ba0a2) Shipped CLI Failures

# 2a. Base search tweets "!!!" drops tokenless filter and returns unfiltered timeline rows
$ BIRDCLAW_HOME=/private/tmp/bc-home-base-258 node /private/tmp/bc-base-v0170/dist/cli/birdclaw.js --json search tweets "!!!"
{"count":3,"ids":["tweet_001","tweet_003","tweet_002"]}

# 2b. Base search tweets "local-first" --author "@" drops empty author filter and returns matching text rows
$ BIRDCLAW_HOME=/private/tmp/bc-home-base-258 node /private/tmp/bc-base-v0170/dist/cli/birdclaw.js --json search tweets "local-first" --author "@"
{"count":1,"ids":["tweet_001"]}

# 2c. Base search links "!!!" drops tokenless filter and returns all indexed links
$ BIRDCLAW_HOME=/private/tmp/bc-home-base-258 node /private/tmp/bc-base-v0170/dist/cli/birdclaw.js --json search links "!!!"
{"count":3,"urls":["https://t.co/local","https://t.co/survey","https://t.co/video"]}

# 2d. Base search dms "!!!" drops tokenless filter, ignores configured default account (@steipete -> acct_primary), and rejects --account
$ BIRDCLAW_HOME=/private/tmp/bc-home-base-258 node /private/tmp/bc-base-v0170/dist/cli/birdclaw.js --json search dms "!!!"
{"count":4,"accounts":["acct_primary","acct_studio"]}
$ BIRDCLAW_HOME=/private/tmp/bc-home-base-258 node /private/tmp/bc-base-v0170/dist/cli/birdclaw.js --json search dms "ship" --account acct_studio
{"error":"error: unknown option '--account'"}

3. Head (2357d10abc89) Shipped CLI Pass & v0.17.0 Upgrade Compatibility Proof

# 3a. Head search tweets "!!!" and "from:@" return [] instead of unfiltered rows
$ BIRDCLAW_HOME=/private/tmp/bc-home-upg-258 node /private/tmp/bc-head-258/dist/cli/birdclaw.js --json search tweets "!!!"
[]
$ BIRDCLAW_HOME=/private/tmp/bc-home-upg-258 node /private/tmp/bc-head-258/dist/cli/birdclaw.js --json search tweets "from:@"
[]

# 3b. Head search tweets "local-first" --author "@" returns [] instead of dropping empty author filter
$ BIRDCLAW_HOME=/private/tmp/bc-home-upg-258 node /private/tmp/bc-head-258/dist/cli/birdclaw.js --json search tweets "local-first" --author "@"
[]

# 3c. Head search links "!!!" returns [] instead of all links
$ BIRDCLAW_HOME=/private/tmp/bc-home-upg-258 node /private/tmp/bc-head-258/dist/cli/birdclaw.js --json search links "!!!"
[]

# 3d. Head search dms "!!!" returns [], honors configured default (@steipete -> acct_primary), and supports explicit --account override
$ BIRDCLAW_HOME=/private/tmp/bc-home-upg-258 node /private/tmp/bc-head-258/dist/cli/birdclaw.js --json search dms "!!!"
[]
$ BIRDCLAW_HOME=/private/tmp/bc-home-upg-258 node /private/tmp/bc-head-258/dist/cli/birdclaw.js --json search dms "a"
Default (@steipete -> acct_primary): {"count":2,"accounts":["acct_primary"]}
$ BIRDCLAW_HOME=/private/tmp/bc-home-upg-258 node /private/tmp/bc-head-258/dist/cli/birdclaw.js --json search dms "a" --account acct_studio
Explicit (--account acct_studio): {"count":1,"accounts":["acct_studio"]}

# 3e. v0.17.0 -> Head data-model & settings compatibility
$ BIRDCLAW_HOME=/private/tmp/bc-home-upg-258 node /private/tmp/bc-head-258/dist/cli/birdclaw.js --json db stats
{
  "paths": {
    "rootDir": "/private/tmp/bc-home-upg-258",
    "dbPath": "/private/tmp/bc-home-upg-258/birdclaw.sqlite",
    "configPath": "/private/tmp/bc-home-upg-258/config.json"
  },
  "stats": {
    "home": 4,
    "mentions": 2,
    "dms": 4,
    "needsReply": 2,
    "inbox": 4
  }
}
$ BIRDCLAW_HOME=/private/tmp/bc-home-upg-258 node /private/tmp/bc-head-258/dist/cli/birdclaw.js --json backup export --repo /private/tmp/bc-repo-258
$ BIRDCLAW_HOME=/private/tmp/bc-home-upg-258 node /private/tmp/bc-head-258/dist/cli/birdclaw.js --json backup validate /private/tmp/bc-repo-258
{
  "ok": true,
  "errors": [],
  "counts": {
    "accounts": 2,
    "collections_bookmarks": 2,
    "collections_likes": 3,
    "dm_messages": 8,
    "dm_conversations": 4,
    "link_occurrences": 3,
    "url_expansions": 3,
    "profiles": 6,
    "timeline_edges_home": 4,
    "timeline_edges_mention": 2,
    "tweets": 6
  }
}

Verification

  • node ./scripts/run-vitest.mjs run src/lib/query-models.test.ts src/lib/link-index.test.ts src/cli/search-account.test.ts: 99 passed

Known gaps

GitHub Actions CI has not run on this head. The workflow is waiting for a maintainer to approve it. The verification above is local: unit tests and the shipped CLI against a local archive, not a live X account.

☁️

@clawsweeper

clawsweeper Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal priority bug or improvement with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 8, 2026
@clawsweeper

clawsweeper Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

Codex review: ready, awaiting a maintainer decision.

What this changes

This PR prevents tokenless searches and empty author selectors from returning unrelated rows and adds account selection to DM search.

Example: Run birdclaw search dms "!!!" against the populated demo archive.

  • Before: The search returns four conversations across acct_primary and acct_studio.
  • After: The search returns [].

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Focused code and supplied CLI upgrade evidence support the implementation; readiness remains capped by the unresolved product decision.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): The updated body demonstrates the changed read models through dist/cli/birdclaw.js at the reviewed head, comparing tokenless and empty-author searches with v0.17.0 and showing configured and explicit DM account selection on a copied archive; this addresses the previous review's runtime-proof request.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Needs a maintainer decision · Fix scope: Complete
User problem: Malformed searches can return unrelated cached records, and DM search cannot select an account or honor its configured default.
Reason: The corrections have clear value, but they deliberately replace tested fallback behavior and add a CLI option that activates configured-account behavior.

Merge readiness

⏳ Ready, awaiting maintainer decision

Keep open: this PR provides useful search corrections with no concrete introduced defect found, but replacing tested behavior and extending account defaults still needs an owner decision.

Priority: P2
Reviewed head: 2357d10abc898806e344756356b091e4036eae58
Owner decision: Required. See Decision needed.

Decision needed

  • Question: Should nonempty tokenless searches replace the tested browsing fallback with empty results, and should DM search gain --account and begin honoring accounts.default?
  • Recommendation: Approve the proposed search behavior: Accept empty results for nonempty unmatchable searches and extend the existing account-selection mechanism to DM search.
  • Why: The changed behavior is clearly explained and demonstrated, but the former fallback is explicitly tested and no owner has approved this PR's direction; a configured account will now narrow DM results or reject an unknown selector.

Before merge

None.

Findings

None.

Agent review details

How this fits together

CLI, web, and MCP consumers pass search text and filters to shared SQLite read models, which return matching cached tweets, conversations, and links.

flowchart TD
  A[CLI search commands] --> B[Operation account selection]
  B --> C[Shared search read models]
  D[Web and MCP consumers] --> C
  C --> E[SQLite archive and indexes]
  E --> F[Filtered results]
Loading

Technical review

Best possible solution:

Keep the focused implementation in the existing search owners if the owner approves its search and account-default semantics.

Do we have a high-confidence way to reproduce the issue?

Current-main source shows dropped tokenless filters, fallback from empty authors, and no DM-search account option; the contributor also supplies matching base/head CLI output, which this read-only review did not rerun.

Is this the best way to solve the issue?

The implementation is narrow, preserves blank browsing and valid author precedence, and reuses account selection; its changed product contract needs owner approval.

AGENTS.md: not found in the target repository.

Codex review notes: model internal, reasoning medium; reviewed against 9895445ba0a2.

Provenance checked

  • Tokenless tweet and DM searches changes intended behavior with a stated reason (406b7bf: Sanitize text into quoted FTS terms to avoid query syntax errors, with an explicit punctuation-only DM browsing test.)
  • Empty author selectors changes intended behavior with a stated reason (feat: filter local tweet search by author #226: Implement documented author filtering through shared parsing while retaining explicit-author precedence and MCP bounds.)
  • Tokenless link queries changes intended behavior with a stated reason (3f0deca: Search indexed links and linked text with literal URL-friendly terms; the patch preserves that tokenizer while rejecting nonblank queries with no terms.)
  • DM command account selection keeps the original intent (feat: add per-operation account selection #105: Provide reversible per-operation account selection with explicit overrides without changing stored account identity.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

  • Verified introduced change: The pinned patch keeps filtering in existing read models and reuses the CLI account-selection hook; the current main branch retains the previous behavior. (2357d10abc89)
  • Explicit existing fallback contract: Main explicitly tests punctuation-only DM search as unfiltered browsing; the sanitization commit introduced that expectation to accompany quoted FTS token handling. (src/lib/query-models.test.ts:549, 406b7bf74c8a)
  • Account-selection direction: feat: add per-operation account selection #105 established reversible per-operation account selection; docs/configuration.md says commands exposing --account honor accounts.default, so adding this option also changes existing configured DM searches. (src/cli/command-context.ts:61, 9895445ba0a2)
  • Author-filter intent: feat: filter local tweet search by author #226 established shared author parsing, case-insensitive handles, and explicit-author precedence; this PR preserves valid selectors while making empty selectors match nothing. (src/lib/timeline-read-model.ts:657, 00516d77eadd)
  • Updated runtime and upgrade evidence: The complete current PR body supplies shipped-CLI base/head output for tokenless searches, empty authors, configured accounts, and explicit overrides, followed by successful archive statistics and backup validation after copying a v0.17.0 home. (2357d10abc89)
  • Discussion and current review state: The contributor requested re-review after adding evidence; no owner approval or submitted review is recorded, and the sole reported check, GitGuardian Security Checks, passed for the reviewed head. (2357d10abc89)

Likely related people:

  • Emanuel Ferm: Raw commit 00516d7 adds src/lib/timeline-read-model.ts:661 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 00516d77eadd; files: src/lib/timeline-read-model.ts)

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Review metrics

Metric Value Why it matters
Production versus test changes Production +23/-8; tests +278/-22 The small production change reuses existing owners; regression coverage exercises SQL plans, account precedence, empty selectors, and preserved blank browsing.

Labels

Label changes:

  • add merge-risk: 🚨 compatibility: The patch replaces an explicitly tested fallback and makes existing accounts.default settings affect DM search, potentially narrowing results or rejecting an unknown account.
  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: ⏳ waiting on maintainer: Only explicit maintainer approvals or decisions remain; merge is still blocked.
  • remove rating: 🧂 unranked krab: Current PR rating is rating: 🦐 gold shrimp, so this older rating label is no longer current.
  • remove status: 📣 needs proof: Current PR status label is status: ⏳ waiting on maintainer.

Label justifications:

  • P2: Search correctness and account selection have limited impact in an advanced local CLI workflow.
  • merge-risk: 🚨 compatibility: The patch replaces an explicitly tested fallback and makes existing accounts.default settings affect DM search, potentially narrowing results or rejecting an unknown account.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: ⏳ waiting on maintainer: Only explicit maintainer approvals or decisions remain; merge is still blocked.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (1 earlier review cycle)
  • reviewed 2026-11-08T21:06:54.473Z sha 2357d10 :: needs real behavior proof before merge. :: none

Reviewed November 8, 2026, 7:16 PM ET / November 9, 2026, 00:16 UTC (Revision 2).

@saariuslystoned

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. merge-risk: 🚨 compatibility 🚨 Merging this PR could break existing users, config, migrations, defaults, or upgrades. proof: sufficient Contributor real behavior proof is sufficient. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on maintainer Only explicit maintainer approvals or decisions remain; merge is still blocked. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 9, 2026
steipete added a commit that referenced this pull request Nov 14, 2026
Consolidate verified fixes from #257, #258, #259, #260, #261, #262, #263, #264, and #265. Repair account selection, cache restoration, search bounds, input validation, and read-only analysis while preserving existing account and data-safety contracts. Also reject unsafe Git indexes before backup publication and keep recovery snapshots private.

Co-authored-by: Bobby Bones <saariuscrypto@gmail.com>
Co-authored-by: sm0ky <smokyproductcompany@gmail.com>
@steipete

Copy link
Copy Markdown
Owner

Thanks for the fixes. I reproduced the reported defects against v0.17.0 and consolidated tokenless and empty-author search bounds plus account-scoped DM search into #266, now landed. The overlapping cache ingestion changes from #257 and #261 are included once.

The consolidation preserves contributor credit in the changelog and squash commit. Synthetic regressions, independent P0–P2 review, and exact-head CI cover the result; no paid X requests were used. Closing this PR as superseded by the landed consolidation.

@steipete steipete closed this Nov 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 compatibility 🚨 Merging this PR could break existing users, config, migrations, defaults, or upgrades. P2 Normal priority bug or improvement with limited blast radius. proof: sufficient Contributor real behavior proof is sufficient. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on maintainer Only explicit maintainer approvals or decisions remain; merge is still blocked.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants