Skip to content

fix(sync,mcp,search): resolve account selectors, filter tombstoned FTS rows, and harden search/sync contracts - #263

Closed
saariuslystoned wants to merge 2 commits into
steipete:mainfrom
saariuslystoned:fix/link-insights-web-sync-mcp-and-search-discussion-contracts
Closed

saariuslystoned wants to merge 2 commits into
steipete:mainfrom
saariuslystoned:fix/link-insights-web-sync-mcp-and-search-discussion-contracts

Conversation

@saariuslystoned

@saariuslystoned saariuslystoned commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes account-selector resolution, soft-deleted FTS preflight filtering, reply-metadata exclusion in live search discussions, and sync CLI error/TTL contracts:

  1. src/lib/link-insights.ts & src/lib/web-sync.ts: Reuse the shared findOperationAccount(db, account) resolver from src/lib/account-selection.ts so @handle / username selectors resolve to canonical stored account.id values (acct_primary, acct_studio, etc.) across Link Insights membership queries, web-sync transport mode selection (auto vs xurl), and running-sync job lock keys (getRunningSyncKey).
  2. src/lib/mcp-tools.ts: Filter t.deleted_at is null and t.superseded_at is null in countScopedTweetFtsMatches so soft-deleted or superseded FTS rows do not inflate the MCP_MAX_FTS_MATCHES (1000) preflight check and reject visible search matches.
  3. src/lib/search-discussion.ts: Select t.reply_to_id in collectLiveSearchTweets, exclude rows with Boolean(row.reply_to_id) when originalsOnly is set in liveSearchRowPassesFilters, and fail fast when query.trim() is empty.
  4. src/cli/numeric-options.ts & src/cli/register-sync.ts: Bound --cache-ttl milliseconds conversion (Number.isFinite(number * 1000)) directly in the shared CLI numeric preAction hook (configureNumericOptions) before account selection, and emit structured JSON failure envelopes ({ ok: false, kind, mode, error }) with process.exitCode = 1 on sync timeline, sync likes, and sync bookmarks.

Shipped CLI & Server Behavior Proof (dist/cli/birdclaw.js Base v0.17.0 @ 9895445ba0a2 vs Head @ 678e606)

1. Seed v0.17.0 Archive (9895445ba0a2) with Settings (transport: "bird"), Accounts, 1,001 Soft-Deleted Tombstones, Visible Original + Reply Tweets, Links, Collections, and DMs

$ BIRDCLAW_HOME=/private/tmp/bc-home-base-263 BIRDCLAW_TEST_SEED_DEMO_DATA=1 node /private/tmp/bc-base-v0170/dist/cli/birdclaw.js --json db stats >/dev/null
$ BIRDCLAW_HOME=/private/tmp/bc-home-base-263 node /private/tmp/bc-base-v0170/dist/cli/birdclaw.js --json import x-json /private/tmp/bc-seed-263.jsonl
{
  "imported": 1003,
  "skipped": 0,
  "errors": []
}
$ cp -a /private/tmp/bc-home-base-263/. /private/tmp/bc-home-upg-263/

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

# 2a. Base sync timeline --cache-ttl 1e308 bypasses numeric validation and enters live bird transport
$ PATH="/usr/bin:/bin" BIRDCLAW_HOME=/private/tmp/bc-home-base-263 node /private/tmp/bc-base-v0170/dist/cli/birdclaw.js --json sync timeline --mode bird --cache-ttl 1e308
{"error":"Command failed: /bin/bash -c out=\"$1\"; shift; exec \"$@\" > \"$out\" birdclaw-bird /tmp/birdclaw-bird-GGF80V/stdout.json bird whoami\nbirdclaw-bird: line 0: exec: bird: not found\n"}

# 2b. Base serve: POST /mcp search_tweets fails when 1001 soft-deleted tombstones match
$ curl -sS -X POST http://127.0.0.1:43101/mcp -H "authorization: Bearer <redacted>" -H "content-type: application/json" -d '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"search_tweets","arguments":{"query":"pass11needle"}}}'
{"result":{"content":[{"type":"text","text":"Search matched more than 1000 cached tweets for this account and resource; narrow the search terms."}],"isError":true},"jsonrpc":"2.0","id":1}

# 2c. Base serve: GET /api/search-discussion mode=bird&originalsOnly=true includes reply 1900000000000090002 (no leading @mention)
$ curl -sS "http://127.0.0.1:43101/api/search-discussion?query=pass11needle&source=search&mode=bird&originalsOnly=true" | tr -d ' ' | grep -o '"id":"190000000000009000[12]"' | sort -u
"id":"1900000000000090001"
"id":"1900000000000090002"

# 2d. Base serve: POST /api/sync fails to coalesce @steipete with acct_primary
Base sync job IDs (@steipete vs acct_primary): sameJob=false (sync_timeline_mw8i6aaw_to34y1 vs sync_timeline_mw8i6acq_4muf95)

3. Head (678e606) Shipped CLI & birdclaw serve Pass + v0.17.0 Upgrade Compatibility Proof

# 3a. Head sync timeline --cache-ttl 1e308 rejected in shared numeric hook before account/transport
$ PATH="/usr/bin:/bin" BIRDCLAW_HOME=/private/tmp/bc-home-upg-263 node /private/tmp/bc-head-263/dist/cli/birdclaw.js --json sync timeline --mode bird --cache-ttl 1e308
{"error":"--cache-ttl must be a non-negative finite number"}

# 3b. Head sync timeline --mode bird emits structured JSON failure envelope
$ PATH="/usr/bin:/bin" BIRDCLAW_HOME=/private/tmp/bc-home-upg-263 node /private/tmp/bc-head-263/dist/cli/birdclaw.js --json sync timeline --mode bird
{
  "ok": false,
  "kind": "timeline",
  "mode": "bird",
  "error": "Command failed: /bin/bash -c out=\"$1\"; shift; exec \"$@\" > \"$out\" birdclaw-bird /tmp/birdclaw-bird-1uDJ51/stdout.json bird whoami\nbirdclaw-bird: line 0: exec: bird: not found\n"
}

# 3c. Head serve: POST /mcp search_tweets excludes 1001 soft-deleted tombstones and returns visible tweets
$ curl -sS -X POST http://127.0.0.1:43102/mcp -H "authorization: Bearer <redacted>" -H "content-type: application/json" -d '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"search_tweets","arguments":{"query":"pass11needle"}}}'
{"isError":false,"count":2,"ids":["1900000000000090002","1900000000000090001"]}

# 3d. Head serve: GET /api/search-discussion mode=bird&originalsOnly=true excludes reply 1900000000000090002
$ curl -sS "http://127.0.0.1:43102/api/search-discussion?query=pass11needle&source=search&mode=bird&originalsOnly=true" | tr -d ' ' | grep -o '"id":"190000000000009000[12]"' | sort -u
"id":"1900000000000090001"

# 3e. Head serve: POST /api/sync coalesces @steipete and acct_primary via findOperationAccount
Head sync job IDs (@steipete vs acct_primary): sameJob=true (sync_timeline_mw8i6dvm_jwp7yq vs sync_timeline_mw8i6dvm_jwp7yq)

# 3f. Links @handle resolution via findOperationAccount & v0.17.0 -> Head data-model/settings compatibility
Links occurrences (acct_primary vs @steipete): { acct_primary: 3, "@steipete": 3, match: true }
$ BIRDCLAW_HOME=/private/tmp/bc-home-upg-263 node /private/tmp/bc-head-263/dist/cli/birdclaw.js --json db stats
{
  "paths": {
    "rootDir": "/private/tmp/bc-home-upg-263",
    "dbPath": "/private/tmp/bc-home-upg-263/birdclaw.sqlite",
    "configPath": "/private/tmp/bc-home-upg-263/config.json"
  },
  "stats": {
    "home": 6,
    "mentions": 2,
    "dms": 4,
    "needsReply": 2,
    "inbox": 4
  }
}
$ BIRDCLAW_HOME=/private/tmp/bc-home-upg-263 node /private/tmp/bc-head-263/dist/cli/birdclaw.js --json backup export --repo /private/tmp/bc-repo-263
$ BIRDCLAW_HOME=/private/tmp/bc-home-upg-263 node /private/tmp/bc-head-263/dist/cli/birdclaw.js --json backup validate /private/tmp/bc-repo-263
{
  "ok": true,
  "errors": [],
  "counts": {
    "accounts": 3,
    "collections_bookmarks": 2,
    "collections_likes": 3,
    "dm_messages": 8,
    "dm_conversations": 4,
    "link_occurrences": 3,
    "url_expansions": 3,
    "profile_snapshots": 3,
    "profiles": 7,
    "timeline_edges_home": 1007,
    "timeline_edges_mention": 2,
    "timeline_edges_search": 2,
    "tweet_revisions": 1003,
    "tweets": 1009
  }
}

Verification

  • node ./scripts/run-vitest.mjs run src/lib/web-sync.test.ts src/lib/account-selection.test.ts src/lib/live-sync-engine.test.ts src/cli.test.ts src/cli/sync-contract.test.ts src/lib/link-insights.test.ts src/lib/mcp-tools.test.ts src/lib/search-discussion.test.ts: 236 passed (8 files)

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-environment 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. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 8, 2026
@clawsweeper

clawsweeper Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

Codex review: needs maintainer review before merge.

What this changes

This PR fixes account-alias handling, hidden-tweet search counts, original-only discussion filtering, and sync CLI validation and errors.

Example: MCP search for pass11needle matches 1,001 deleted tweets and two visible tweets.

  • Before: Deleted matches inflate the account-scoped count and reject the search.
  • After: The search returns the two visible tweets.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Useful contract repairs with supplied shipped-entry-point evidence, focused regression coverage, and both previous findings resolved.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The PR body records built-CLI and running-server base/head output for TTL rejection, sync failure envelopes, MCP tombstone filtering, discussion reply exclusion, alias coalescing, and matching Links counts on a copied v0.17.0 archive; the inspected Discuss screenshots add no changed-behavior coverage.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Account aliases can lose Links results or choose a different sync path, hidden tweets can reject valid MCP searches, and replies can appear in original-only discussions.
Reason: The changes restore existing account, visibility, filtering, and CLI contracts without introducing settings or expanding the public API.

Merge readiness

✅ Ready for maintainer review

Keep this PR open for landing: both previous findings are resolved, and the reviewed patch has no remaining concrete blockers.

Priority: P2
Reviewed head: 678e6061ce4a1344e299c264ac1a9df87f2aac9f

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: Runtime output shows base failures and head success; execution of the added regression tests against the base was not shown.
Agent review details

How this fits together

CLI and web requests invoke account-aware sync owners; Links, discussion, and MCP readers retrieve content from the shared SQLite archive.

flowchart TD
 CLI[Sync CLI] --> Sync[Live sync owners]
 Web[Web sync dispatcher] --> Sync
 Sync --> DB[SQLite archive]
 DB --> Links[Link insights]
 DB --> Discussion[Search discussion]
 DB --> MCP[Read-only MCP tools]
Loading

Technical review

Best possible solution:

Land the focused contract repairs using the existing account resolver, numeric hook, and archive readers.

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

Current-main source establishes the failing selector, tombstone-count, metadata-reply, and TTL paths; contributor-supplied runtime output corroborates them, and no target code was executed during this review.

Is this the best way to solve the issue?

The revision repairs the existing owners directly, preserves account membership and transport checks, and resolves the previous competing-selector and validation concerns.

AGENTS.md: not found in the target repository.

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

Provenance checked

  • Account selectors and web-sync dispatch keeps the original intent (refactor: remove duplicate query and account seams #128: Centralize account resolution across callers; feat: expand bird sync support and add auto transport preference #231 preserves transport preference and identity checks.)
  • CLI numeric validation keeps the original intent (b5ae7e0: Validate numeric options before account selection and command work while preserving fractional cache lifetimes.)
  • Sync CLI failure output keeps the original intent (3174150: The CLI/web unification carried these command actions; the new envelopes follow the existing sibling sync-command pattern.)
  • Links account membership keeps the original intent (3b72f11: Scope Links context through account-owned DMs, timeline edges, and collections.)
  • MCP visible-match preflight keeps the original intent (ef95137: Bound account-scoped MCP search work; the tombstone contract separately hides deleted and superseded rows from active views.)
  • Live discussion context keeps the original intent (3c8fae1: Use returned live tweet IDs for discussion context while applying requested filters.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

  • Reviewed introduction and resolved findings: The pinned diff uses findOperationAccount for sync identity and places milliseconds-overflow validation in configureNumericOptions; the competing selector parser and action-level TTL validator from the previous revision are removed. (src/lib/web-sync.ts:305, 678e6061ce4a)
  • Current-main contracts: The documented account contract accepts usernames and stored IDs, and numeric validation precedes account selection. Current main still compares raw web-sync selectors and lacks the TTL conversion bound. (docs/cli.md:147, 9895445ba0a2)
  • Shipped behavior and existing archive proof: The updated PR body supplies base/head CLI and running-server output for overflowing TTLs, structured sync failures, tombstoned MCP matches, metadata replies, and alias job coalescing; it also reports matching Links counts and successful backup validation after opening a copied v0.17.0 archive. (678e6061ce4a)
  • Security boundaries preserved: MCP still passes its server-selected literal account to the final reader and retains candidate limits; web requests retain their request guard, and Bird sync retains account verification before fetching. (src/lib/mcp-tools.ts:420, 678e6061ce4a)
  • Prior product intent: refactor: remove duplicate query and account seams #128 centralizes account resolution; feat(cli): add local record reads and validate numeric options #192 establishes early numeric validation; fix: retain archive tweet tombstones #107 retains tombstones while hiding them from active views. This revision respects those contracts. (3c173a7e706a)
  • History scope and local limitation: Path history identifies Peter Steinberger across the original readers and major refactors, and Travis Fischer on recent transport selection. Some deeper content searches and account-selection blame failed because historical blobs were unavailable; introduction claims are limited to verified hunks and supplied provenance. (src/lib/web-sync.ts:116, 9895445ba0a2)

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 and regression coverage Production +98/-34 lines; tests +406/-1 lines The larger test share covers account membership paths, tombstone states, discussion replies, sync failures, and early TTL rejection.

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove rating: 🧂 unranked krab: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: 📣 needs proof: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: These are bounded archive-search and sync contract defects without evidence of an urgent runtime outage.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • 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-08T23:41:38.574Z sha a4030ec :: needs real behavior proof before merge. :: [P1] Use the shared account resolver for sync job identity | [P1] Keep TTL validation in the existing CLI numeric owner

Reviewed November 8, 2026, 7:13 PM ET / November 9, 2026, 00:13 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. proof: sufficient Contributor real behavior proof is sufficient. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. 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 MCP tombstone filtering, original-only discussion filtering, sync errors/TTL bounds, and account-normalized web sync locks 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

P2 Normal priority bug or improvement with limited blast radius. proof: sufficient Contributor real behavior proof is sufficient. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants