Skip to content

fix: enforce whois account/read-only and live-search input contracts - #264

Closed
saariuslystoned wants to merge 1 commit into
steipete:mainfrom
saariuslystoned:fix/whois-tweet-search-live-and-import-contracts
Closed

saariuslystoned wants to merge 1 commit into
steipete:mainfrom
saariuslystoned:fix/whois-tweet-search-live-and-import-contracts

Conversation

@saariuslystoned

@saariuslystoned saariuslystoned commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Hardens account resolution, read-only deployment isolation, and live-search input/Effect validation across src/lib/whois.ts, src/lib/identity-search-index.ts, and src/lib/tweet-search-live.ts:

  1. whois & identity_search_index account resolution, non-negative Effect input validation (--limit 0 preserved), and read-only deployment isolation (src/lib/whois.ts, src/lib/identity-search-index.ts):
    • ensureIdentitySearchIndexForDmProfiles and findProfileEvidenceConversationIds previously bound the raw account string directly against c.account_id = ?, missing handle selectors (@studio, studio, padded/case variants) unless identity_search_index was already populated. Both now resolve explicit selectors via findOperationAccount(db, account) (returning { profiles: 0, entries: 0 } / [] for unknown selectors while preserving "all" and undefined behavior), and runWhoisEffect passes the canonicalized account selector to downstream DM and timeline queries.
    • runWhoisEffect validates options.limit and options.context as non-negative safe integers (>= 0) inside trySync so programmatic callers receive invalid numeric errors in the Effect failure channel (Effect.either) while preserving the documented and tested --limit 0 contract (docs/search.md:10, #132).
    • When isReadOnlyDeployment() (BIRDCLAW_DEPLOYMENT_READ_ONLY=1) is active, runWhoisEffect, ensureIdentitySearchIndexForDmProfiles, and syncIdentitySearchIndexForProfileIds read existing identity rows and profile metadata via getReadDb() and skip identity_search_index writes as well as default live profile resolution and URL expansion cache writes (profileResolution === undefined, urlExpansions: []), instead of failing with attempt to write a readonly database.
  2. Live tweet search Effect failure channel & strict calendar/range validation (src/lib/tweet-search-live.ts):
    • Moves normalizeLimit(limit), normalizeMaxPages(maxPages), and mode validation ("auto" | "bird" | "xurl" | "local") inside trySync in syncTweetSearchEffect so invalid inputs fail in the Effect error channel rather than throwing synchronously before the Effect executes or silently falling through to live auto search.
    • Requires positive safe integers in normalizeLimit and normalizeMaxPages instead of silently truncating fractional numbers.
    • Validates calendar dates in normalizeTime (rejecting impossible calendar dates like 2026-02-30, hour 24, or trailing junk) and rejects inverted ranges where normalizedSince > normalizedUntil (--since must be before or equal to --until).

Real Shipped-CLI (dist/cli/birdclaw.js) Base-Fail -> Head-Pass & v0.17.0 Upgrade Verification

1. Shipped CLI whois under BIRDCLAW_DEPLOYMENT_READ_ONLY=1 (Default Enrichment Options & Prebuilt Index)

  • Base (9895445ba0a2 v0.17.0): Fails immediately with attempt to write a readonly database when whois runs with default options under BIRDCLAW_DEPLOYMENT_READ_ONLY=1:
    $ BIRDCLAW_HOME="$tmp_root/home-ro-base" BIRDCLAW_CONFIG=/dev/null BIRDCLAW_BACKUP_AUTO_SYNC=0 BIRDCLAW_DEPLOYMENT_READ_ONLY=1 \
        node dist/cli/birdclaw.js whois "indexneedle" --json
    {"error":"attempt to write a readonly database"}
    # exit code 1
    
  • Head (18d4de3041f3) — Unindexed Archive with Default Enrichment Options: Succeeds with exit 0 and writes 0 rows:
    $ BIRDCLAW_HOME="$tmp_root/home-ro-head" BIRDCLAW_CONFIG=/dev/null BIRDCLAW_BACKUP_AUTO_SYNC=0 BIRDCLAW_DEPLOYMENT_READ_ONLY=1 \
        node dist/cli/birdclaw.js whois "indexneedle" --json
    {
      "query": "indexneedle",
      "candidates": [],
      "relatedTweets": [],
      "urlExpansions": []
    }
    # exit code 0; HEAD identity_search_index rows written under READ_ONLY=1: 0
    
  • Head (18d4de3041f3) — Prebuilt Archive under BIRDCLAW_DEPLOYMENT_READ_ONLY=1 with Default Enrichment (resolveProfiles=true, expandUrls=true) and --refresh-profile-cache --refresh-url-cache: Reads existing identity_search_index evidence for --account "@studio", suppresses default live profile resolution (profileResolution omitted) and URL expansion (urlExpansions: [] despite https://t.co/demo in bio), and leaves birdclaw.sqlite byte-for-byte unchanged (sha256=a9a7c14225a253ff76e3466310ff52a57ad0b7f8ef711d6a1f79bd4954b8fdb8):
    $ sha256sum "$tmp_root/home/birdclaw.sqlite"
    a9a7c14225a253ff76e3466310ff52a57ad0b7f8ef711d6a1f79bd4954b8fdb8  /tmp/birdclaw-264-v2-prebuilt.tQaExp/home/birdclaw.sqlite
    
    $ BIRDCLAW_HOME="$tmp_root/home" BIRDCLAW_CONFIG=/dev/null BIRDCLAW_BACKUP_AUTO_SYNC=0 BIRDCLAW_DEPLOYMENT_READ_ONLY=1 \
        node dist/cli/birdclaw.js whois "indexneedle" --account "@studio" --refresh-profile-cache --refresh-url-cache --json
    {
      "query": "indexneedle",
      "candidates": [
        {
          "conversation": {
            "id": "dm_studio",
            "accountId": "acct_studio",
            "accountHandle": "@studio",
            "title": "Studio Friend",
            "inboxKind": "accepted",
            "isMessageRequest": false,
            "lastMessageAt": "2026-05-02T00:00:00.000Z",
            "lastMessagePreview": "",
            "unreadCount": 0,
            "needsReply": false,
            "influenceScore": 49,
            "influenceLabel": "emerging",
            "participant": {
              "id": "profile_studio",
              "handle": "studio_friend",
              "displayName": "Studio Friend",
              "bio": "indexneedle https://t.co/demo",
              "followersCount": 100,
              "followingCount": 0,
              "avatarHue": 120,
              "entities": {},
              "createdAt": "2026-01-01T00:00:00.000Z"
            }
          },
          "confidence": 60,
          "category": "other",
          "reasons": [
            "resolved profile",
            "profile matches query"
          ],
          "profileEvidence": [
            {
              "kind": "profile_bio",
              "value": "indexneedle https://t.co/demo",
              "source": "profile"
            }
          ],
          "evidence": []
        }
      ],
      "relatedTweets": [],
      "urlExpansions": []
    }
    
    $ sha256sum "$tmp_root/home/birdclaw.sqlite"
    a9a7c14225a253ff76e3466310ff52a57ad0b7f8ef711d6a1f79bd4954b8fdb8  /tmp/birdclaw-264-v2-prebuilt.tQaExp/home/birdclaw.sqlite
    

2. Shipped CLI whois --limit 0 (Preserved Non-Negative Zero-Limit Contract)

  • Head (18d4de3041f3): Preserves --limit 0 compatibility (docs/search.md:10, #132) end-to-end through the real runWhois implementation:
    $ BIRDCLAW_HOME="$tmp_root/home-head" BIRDCLAW_CONFIG=/dev/null BIRDCLAW_BACKUP_AUTO_SYNC=0 \
        node dist/cli/birdclaw.js whois "indexneedle" --limit 0 --json
    {
      "query": "indexneedle",
      "candidates": [],
      "relatedTweets": [],
      "urlExpansions": [],
      "profileResolution": [
        {
          "profileId": "profile_studio",
          "externalUserId": null,
          "status": "miss",
          "source": "local"
        },
        {
          "profileId": "profile_user_42",
          "externalUserId": "42",
          "status": "hit",
          "source": "local",
          "profile": {
            "id": "profile_user_42",
            "handle": "aditya",
            "displayName": "Aditya",
            "bio": "indexneedle",
            "followersCount": 5000,
            "followingCount": 0,
            "avatarHue": 210,
            "entities": {},
            "createdAt": "2020-01-01T00:00:00.000Z"
          }
        }
      ]
    }
    

3. Shipped CLI Live-Search Calendar & Chronological Range Validation (discuss --source search)

  • Base (9895445ba0a2 v0.17.0): Accepts impossible date 2026-02-30 (rolling it over to March 2) and inverted window --since 2026-11-08 --until 2026-11-01, proceeding directly to spawn the bird transport subprocess:
    $ BIRDCLAW_HOME="$tmp_root/home-base" BIRDCLAW_CONFIG=/dev/null BIRDCLAW_BACKUP_AUTO_SYNC=0 OPENAI_API_KEY="sk-test-offline" \
        node dist/cli/birdclaw.js discuss "indexneedle" --source search --mode bird --since "2026-02-30" --json
    {"error":"Live tweet search failed via bird: Command failed: /bin/bash -c out=\"$1\"; shift; exec \"$@\" > \"$out\" birdclaw-bird /tmp/birdclaw-bird-IVC0EP/stdout.json bird search indexneedle -n 100 --all --max-pages 200 --json-full\nbirdclaw-bird: line 1: exec: bird: not found\n"}
    
    $ BIRDCLAW_HOME="$tmp_root/home-base" BIRDCLAW_CONFIG=/dev/null BIRDCLAW_BACKUP_AUTO_SYNC=0 OPENAI_API_KEY="sk-test-offline" \
        node dist/cli/birdclaw.js discuss "indexneedle" --source search --mode bird --since "2026-11-08" --until "2026-11-01" --json
    {"error":"Live tweet search failed via bird: Command failed: /bin/bash -c out=\"$1\"; shift; exec \"$@\" > \"$out\" birdclaw-bird /tmp/birdclaw-bird-1zhekg/stdout.json bird search indexneedle -n 100 --all --max-pages 200 --json-full\nbirdclaw-bird: line 1: exec: bird: not found\n"}
    
  • Head (18d4de3041f3): Rejects both invalid date inputs deterministically before touching the database or spawning any live transport subprocess:
    $ BIRDCLAW_HOME="$tmp_root/home-head" BIRDCLAW_CONFIG=/dev/null BIRDCLAW_BACKUP_AUTO_SYNC=0 OPENAI_API_KEY="sk-test-offline" \
        node dist/cli/birdclaw.js discuss "indexneedle" --source search --mode bird --since "2026-02-30" --json
    {"error":"--since must be a valid date"}
    
    $ BIRDCLAW_HOME="$tmp_root/home-head" BIRDCLAW_CONFIG=/dev/null BIRDCLAW_BACKUP_AUTO_SYNC=0 OPENAI_API_KEY="sk-test-offline" \
        node dist/cli/birdclaw.js discuss "indexneedle" --source search --mode bird --since "2026-11-08" --until "2026-11-01" --json
    {"error":"--since must be before or equal to --until"}
    

4. v0.17.0-Seeded Archive Upgrade & backup export / backup validate Verification

$ BIRDCLAW_HOME="$tmp_root/home-head" BIRDCLAW_CONFIG=/dev/null BIRDCLAW_BACKUP_AUTO_SYNC=0 \
    node dist/cli/birdclaw.js backup export --repo "$tmp_root/backup-repo"
{
  "ok": true,
  "repoPath": "/tmp/birdclaw-264-final.IGrCGm/backup-repo",
  "manifest": {
    "app": "birdclaw",
    "schemaVersion": 8,
    "generatedAt": "2026-11-09T04:49:52.865Z",
    "counts": {
      "accounts": 2,
      "dm_conversations": 2,
      "profiles": 2
    },
    "files": [
      {
        "path": "data/accounts.jsonl",
        "rows": 2,
        "sha256": "14e735c406fa4857419eda903de31b7986dfcef7ad45dca143fb598debade5ff",
        "bytes": 317
      },
      {
        "path": "data/dms/conversations.jsonl",
        "rows": 2,
        "sha256": "9eecc9c842dd7f0cb167c222e9917de9a5fb902ee52aa8cf141091df2df98fd0",
        "bytes": 424
      },
      {
        "path": "data/profiles.jsonl",
        "rows": 2,
        "sha256": "8e1a5d7e9383c8e356c87825b73e19a16e0e99e1e4f0945b3d4e2125d6fcae4f",
        "bytes": 646
      }
    ],
    "backupHash": "25ad6ecead6d94a3066e6260ebd86d1bda25e18dc688bbcd980b7ca4b4781f80"
  },
  "validation": {
    "ok": true,
    "repoPath": "/tmp/birdclaw-264-final.IGrCGm/backup-repo",
    "counts": {
      "accounts": 2,
      "dm_conversations": 2,
      "profiles": 2
    },
    "backupHash": "25ad6ecead6d94a3066e6260ebd86d1bda25e18dc688bbcd980b7ca4b4781f80",
    "errors": []
  }
}

$ BIRDCLAW_HOME="$tmp_root/home-head" BIRDCLAW_CONFIG=/dev/null BIRDCLAW_BACKUP_AUTO_SYNC=0 \
    node dist/cli/birdclaw.js backup validate "$tmp_root/backup-repo"
{
  "ok": true,
  "repoPath": "/tmp/birdclaw-264-final.IGrCGm/backup-repo",
  "counts": {
    "accounts": 2,
    "dm_conversations": 2,
    "profiles": 2
  },
  "backupHash": "25ad6ecead6d94a3066e6260ebd86d1bda25e18dc688bbcd980b7ca4b4781f80",
  "errors": []
}

5. Focused Base-RED -> Fix-GREEN & Full Suite Verification

  • Base-RED (9895445ba0a2): 44 failed | 35 passed (79) across src/lib/whois.test.ts (22 failed) and src/lib/tweet-search-live.test.ts (22 failed).
  • Fix-GREEN (18d4de3041f3): 79 passed (79) (2 test files), format:check + lint + typecheck clean (0 warnings and 0 errors).

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 9, 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. P2 Normal priority bug or improvement with limited blast radius. merge-risk: 🚨 compatibility 🚨 Merging this PR could break existing users, config, migrations, defaults, or upgrades. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. 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. labels Nov 9, 2026
@clawsweeper

clawsweeper Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

Codex review: needs maintainer review before merge.

What this changes

The PR resolves whois account selectors, prevents read-only enrichment writes, and validates whois and live-search inputs through Effect failures.

Example: Run whois "indexneedle" --account "@studio" against a prebuilt archive with BIRDCLAW_DEPLOYMENT_READ_ONLY=1.

  • Before: Whois fails with an attempted read-only database write.
  • After: Whois returns the cached dm_studio candidate without changing the database or running enrichment.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) Focused repairs have supplied production-entry evidence and stable-archive compatibility coverage; the earlier zero-limit blocker is resolved.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): Current-head shipped-CLI output exercises whois with default enrichment on unindexed and prebuilt read-only archives, @studio selection, zero limits, and early invalid-date/range rejection; an unchanged database hash supports write suppression. The inspected screenshots show unrelated archive pages and do not contribute proof.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Whois can miss handle-scoped identity evidence or fail on read-only archives, while invalid live-search inputs can escape typed validation or reach transports.
Reason: The changes restore existing account-selection and read-only behavior and improve invalid-input handling without adding configuration or a parallel implementation.

Merge readiness

✅ Ready for maintainer review

This PR repairs current account-selection, read-only lookup, and input-validation defects. The prior zero-limit finding is resolved, and no actionable blocker remains.

Priority: P2
Reviewed head: 18d4de3041f3e31b32086bd10d5e15e21c3d922a

Before merge

None.

Findings

None.

Agent review details

How this fits together

CLI commands call Effect-based identity and live-search services, which resolve account selectors, query SQLite archives, and optionally invoke enrichment or search transports.

flowchart TD
CLI[CLI commands] --> Validation[Effect input validation]
Validation --> Whois[Whois service]
Validation --> Search[Live search service]
Whois --> Accounts[Shared account resolver]
Accounts --> Archive[SQLite archive]
Whois --> Archive
Search --> Transport[Bird or xurl transport]
Transport --> Archive
Loading

Technical review

Best possible solution:

Land the focused repairs while retaining the existing zero-limit, account-scope, and read-only contracts.

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

Current-main source binds unresolved selectors and attempts whois index writes in read-only mode; supplied base CLI traces confirm the read-only failure and acceptance of invalid date windows.

Is this the best way to solve the issue?

The patch uses existing account, database, and Effect owners, preserves supported zero limits, and rejects malformed inputs before live-search database access or transport execution.

AGENTS.md: not found in the target repository.

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

Provenance checked

  • Account-scoped identity indexing keeps the original intent (730c67d: Identity indexing supports cached profile-evidence ranking; later account-selection work established the shared selector resolver.)
  • Whois index writes and enrichment changes intended behavior with a stated reason (730c67d: Indexing enriches writable identity lookup; skipping writes and live enrichment in read-only deployments follows the current documented deployment contract.)
  • Effect failure handling keeps the original intent (refactor: migrate core IO to Effect #35: Core IO migrated to Effect while preserving Promise-compatible public wrappers.)
  • Live-search date normalization changes intended behavior with a stated reason (919f658: Time bounds enabled deeper live analysis; the PR explains strict calendar validation and chronological range rejection.)
  • Whois zero-limit compatibility keeps the original intent (fix(search): validate --limit before binding it into SQL #132: The merged validation repair deliberately preserved zero and existing numeric spellings, with explicit owner confirmation.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

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.

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove status: 📣 needs proof: Current PR status label is status: 👀 ready for maintainer look.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.
  • remove merge-risk: 🚨 compatibility: Current PR review selected no merge-risk labels.

Label justifications:

  • P2: The PR fixes bounded archive lookup failures and invalid-input handling without evidence of an urgent widespread regression.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • 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-09T05:03:57.655Z sha 863a662 :: needs real behavior proof before merge. :: [P2] Preserve the supported zero whois limit

Reviewed November 9, 2026, 12:14 AM ET / 05:14 UTC (Revision 2).

@saariuslystoned
saariuslystoned force-pushed the fix/whois-tweet-search-live-and-import-contracts branch from 863a662 to 18d4de3 Compare November 9, 2026 05:09
@saariuslystoned saariuslystoned changed the title fix: enforce whois account/read-only, live-search input, and import failure guards fix: enforce whois account/read-only and live-search input contracts Nov 9, 2026
@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 proof: sufficient Contributor real behavior proof is sufficient. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. merge-risk: 🚨 compatibility 🚨 Merging this PR could break existing users, config, migrations, defaults, or upgrades. 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 account-scoped read-only whois and strict live-search validation 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: 🦞 diamond lobster Very strong PR readiness with only minor 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