Skip to content

fix(import): skip invalid includes.tweets during x-json import - #270

Merged
steipete merged 3 commits into
steipete:mainfrom
TheAngryPit:cursor/x-json-skip-includes-without-author-be59
Nov 21, 2026
Merged

steipete merged 3 commits into
steipete:mainfrom
TheAngryPit:cursor/x-json-skip-includes-without-author-be59

Conversation

@TheAngryPit

@TheAngryPit TheAngryPit commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

import x-json no longer rejects a whole document when includes.tweets carries a referenced post without a usable author_id. Primary data tweets still go through strict validateTweetRecord; invalid include rows are dropped and counted in a new skippedIncludes field (skipped keeps meaning "primary already imported"), and warnings (always an array) explains which id was skipped and why. Structural problems (includes not an object, includes.tweets not an array) still reject the document.

Why skip instead of persisting with null author

Birdclaw tweet rows assume a numeric X user id for profiles and edges. Storing an include without author_id would either violate existing invariants in ingestTweetPayload or invent placeholder authors. X often omits author expansion on unavailable or partial referenced tweets, so the include is auxiliary context. Dropping it preserves the primary import while leaving referenced_tweets ids on the parent tweet intact.

Verification

Verified against head 37d62ad4e1b488b31d71c38deba1a5bc0fc25eb4 (on top of upstream/main 17b14dfb486c18c4e3eb860875ffcfb66087f48f) with bun 1.4.0-canary.1 (./scripts/bun-canary.sh) and Node v26.10.0 (repo engine floor is >=26.5.1 <27).

Step Bun canary 1.4.0-canary.1 Node v26.10.0
check (format + lint + typecheck) ./scripts/bun-canary.sh run check pass npm run typecheck pass
build ./scripts/bun-canary.sh run build pass npm run build:node pass
tests ./scripts/bun-canary.sh --no-env-file ./scripts/run-vitest.mjs run — 190 files, 2570 tests pass npm run test:node — 190 files, 2570 tests pass

Added failing-first coverage with synthetic fixtures only: primary ok + include missing or non-numeric author_id, mixed valid + invalid includes (valid include still ingested), and structural include errors still rejecting the document.

Changelog

CHANGELOG.md under 0.17.2 – Unreleased.

Real behavior proof

Synthetic X API v2 JSON only (900001 / synth_lab, tweet ids 880012–880017). Each run uses a fresh isolated data root (BIRDCLAW_HOME=$TMP/birdclaw-xjson-proof-<label>, never ~/.birdclaw) and BIRDCLAW_BACKUP_AUTO_SYNC=0. Fixture path: $TMP/synthetic-x-json.json.

Fixture ($TMP/synthetic-x-json.json)

{
  "data": {
    "id": "880012",
    "author_id": "900001",
    "text": "synth quote parent proof",
    "created_at": "2026-03-01T12:00:00.000Z",
    "referenced_tweets": [
      { "type": "quoted", "id": "880013" },
      { "type": "quoted", "id": "880017" }
    ]
  },
  "includes": {
    "users": [
      { "id": "900001", "username": "synth_lab", "name": "Synth Lab" }
    ],
    "tweets": [
      {
        "id": "880013",
        "text": "quoted include without author_id",
        "created_at": "2026-03-01T11:00:00.000Z"
      },
      {
        "id": "880017",
        "author_id": "900001",
        "text": "valid quoted include still stored",
        "created_at": "2026-03-01T10:30:00.000Z"
      }
    ]
  }
}

Shared setup

cd /path/to/birdclaw
export FIXTURE="$TMP/synthetic-x-json.json"
# write fixture JSON to $FIXTURE (see above)
export BIRDCLAW_BACKUP_AUTO_SYNC=0

(a) Before — upstream/main at 17b14df (document rejected)

git checkout 17b14df
./scripts/bun-canary.sh run build

export BIRDCLAW_HOME="$TMP/birdclaw-xjson-proof-before"
rm -rf "$BIRDCLAW_HOME"
mkdir -p "$BIRDCLAW_HOME"

./scripts/bun-canary.sh bin/birdclaw.mjs import x-json "$FIXTURE" --json
echo "exit_code=$?"

./scripts/bun-canary.sh bin/birdclaw.mjs search tweets "synth quote parent proof" --limit 5 --json

import x-json output:

{
  "imported": 0,
  "skipped": 0,
  "errors": [
    {
      "line": 1,
      "message": "Line 1: tweet.author_id must be a non-empty string"
    }
  ]
}
exit_code=1

search tweets output:

[]

(No rows in tweets; primary 880012 was not ingested.)


(b) After — 37d62ad via shipped CLI (bin/birdclaw.mjs)

Bun canary (primary lane):

git checkout 37d62ad
./scripts/bun-canary.sh run build

export BIRDCLAW_HOME="$TMP/birdclaw-xjson-proof-after-bun"
rm -rf "$BIRDCLAW_HOME"
mkdir -p "$BIRDCLAW_HOME"

./scripts/bun-canary.sh bin/birdclaw.mjs import x-json "$FIXTURE" --json
echo "exit_code=$?"

Output:

{
  "imported": 1,
  "skipped": 0,
  "skippedIncludes": 1,
  "errors": [],
  "warnings": [
    "Skipped includes.tweets 880013: tweet.author_id must be a non-empty string"
  ]
}
exit_code=0

Node ≥26.5.1 (same commit, build:node + bin/birdclaw.mjs):

./scripts/bun-canary.sh run build:node
export BIRDCLAW_HOME="$TMP/birdclaw-xjson-proof-after-node"
rm -rf "$BIRDCLAW_HOME"
mkdir -p "$BIRDCLAW_HOME"

node bin/birdclaw.mjs import x-json "$FIXTURE" --json

Output (Node v26.10.0): identical JSON to Bun run above (imported 1, skippedIncludes 1, warning names 880013, errors []).


(c) After — lookup: primary stored, quote id retained, valid include ingested

From the Bun after run (BIRDCLAW_HOME=$TMP/birdclaw-xjson-proof-after-bun):

./scripts/bun-canary.sh bin/birdclaw.mjs search tweets "synth quote parent proof" --limit 5 --json

Output (trimmed):

[
  {
    "id": "880012",
    "text": "synth quote parent proof",
    "accountId": "public",
    "kind": "home"
  }
]
./scripts/bun-canary.sh bin/birdclaw.mjs show tweet 880012 --json

Output (trimmed): tweet 880012 is present (text matches fixture); quotedTweet is null in this read path when the quoted body was skipped.

Quote reference on disk (same DB, synthetic ids only):

node -e "
const { DatabaseSync } = require('node:sqlite');
const db = new DatabaseSync(process.env.BIRDCLAW_HOME + '/birdclaw.sqlite');
console.log(JSON.stringify(
  db.prepare('select id, quoted_tweet_id from tweets where id in (?, ?, ?) order by id')
    .all('880012','880013','880017')
));
"

Output:

[
  { "id": "880012", "quoted_tweet_id": "880013" },
  { "id": "880017", "quoted_tweet_id": null }
]

Interpretation: primary 880012 imported; quoted_tweet_id still points at 880013; valid include 880017 ingested; 880013 skipped (no row).

X API exports can attach referenced tweets without author_id when the
author expansion is missing. Rejecting the whole document dropped valid
primary data rows. Strict validation remains on data tweets; unusable
includes.tweets entries are skipped, counted in skipped, and reported
via warnings so x-json-issues imports still close when errors is empty.

Co-authored-by: Vitor Cepeda Lopes <vitor@vitorcepedalopes.com>
@clawsweeper

clawsweeper Bot commented Nov 18, 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.

Always return warnings and skippedIncludes on x-json import results,
preserve empty includes objects when the key is present, and expand
tests for mixed includes, structural rejections, and include omission.

Verification (bun canary + Node 26.10.0): check/build pass; 190 test
files / 2570 tests pass.

Co-authored-by: Vitor Cepeda Lopes <vitor@vitorcepedalopes.com>
@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 18, 2026
@clawsweeper

clawsweeper Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Codex review: ready, awaiting a maintainer decision.

What this changes

This PR skips invalid included tweet objects with warnings and separate counts while retaining strict primary-tweet validation.

Example: Import primary tweet 880012 alongside included tweet 880013 without author_id and valid included tweet 880017.

  • Before: The whole document fails validation and no tweets are imported.
  • After: Tweet 880012 and valid include 880017 are stored, the quote reference to 880013 survives, and skippedIncludes reports 1.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The previous proof blocker is resolved and the patch has no actionable correctness findings; readiness remains capped by the unresolved acceptance-policy decision.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The updated body records bin/birdclaw.mjs importing the synthetic mixed-include fixture at the reviewed head on Bun and Node, followed by search and SQLite results confirming primary visibility, retained quote identity, and valid-include persistence.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Preference · Worth it: Needs a maintainer decision · Fix scope: Complete
User problem: A valid primary tweet cannot be imported when auxiliary included content lacks required fields.
Reason: The demonstrated recovery is useful, but successful partial imports change the deliberately shipped document-validation contract.

Merge readiness

⏳ Ready, awaiting maintainer decision

This PR has useful, demonstrated behavior and no actionable correctness findings; an owner still needs to approve changing included-tweet validation failures into successful partial imports.

Priority: P2
Reviewed head: 37d62ad4e1b488b31d71c38deba1a5bc0fc25eb4
Owner decision: Required. See Decision needed.

Decision needed

  • Question: Should every validation failure in an included tweet object permit a successful partial import, or should the exception cover only unusable author_id values?
  • Recommendation: Approve auxiliary-record partial success: Accept the current policy because invalid included objects remain outside storage and each omission is reported separately.
  • Why: The patch catches all validateTweetRecord failures, including malformed entities, metrics, and timestamps, while the shipped contract rejects invalid documents; the contributor explains the author_id case but no owner has approved the broader policy.

Before merge

None.

Findings

None.

Agent review details

How this fits together

The offline x-json CLI validates saved X API responses before passing normalized tweets to shared transactional SQLite ingestion and search indexing.

flowchart LR
A[Saved JSON or JSONL] --> B[x-json CLI]
B --> C[Validate primary tweets]
C --> D[Filter included tweets]
D --> E[Shared transactional ingestion]
D --> F[Counts and warnings]
E --> G[SQLite and search index]
Loading

Technical review

Best possible solution:

Keep filtering at the existing importer boundary, with an owner-approved policy for which included-tweet failures permit partial success.

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

Current-main source deterministically rejects the supplied missing-author include, and contributor-provided CLI output demonstrates that failure; no target code was run during this read-only review.

Is this the best way to solve the issue?

Filtering auxiliary records before shared ingestion preserves storage invariants and solves the demonstrated case, subject to approval of the broader acceptance policy.

AGENTS.md: not found in the target repository.

Codex review notes: model internal, reasoning medium; reviewed against 17b14dfb486c.

Provenance checked

  • Included-tweet validation and document acceptance changes intended behavior with a stated reason (d1b619a: The original importer validated documents before transactional ingestion so malformed records became line-scoped failures without partial document writes.)
  • Validation of stored metric inputs keeps the original intent (ff12a9b: The later validation repair rejects invalid counts before they can overwrite stored data; skipped included records still cannot reach ingestion.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit ff12a9b adds src/lib/x-json-import.ts:113 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: ff12a9b1096a; files: src/lib/x-json-import.ts)
  • Vitor Cepeda Lopes: Raw commit d1b619a adds src/lib/x-json-import.ts:356 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: d1b619a03b76; files: src/lib/x-json-import.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
Implementation and regression coverage Production +72/-10 lines; tests +271/-11 lines The added coverage exercises missing and invalid authors, mixed includes, preserved references, and structural rejection using the existing SQLite setup.

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster 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: This improves a bounded offline import workflow without evidence of an urgent regression.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster 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-18T02:32:41.558Z sha 37d62ad :: needs real behavior proof before merge. :: none

Reviewed November 18, 2026, 4:19 AM ET / 09:19 UTC (Revision 2).

Copy link
Copy Markdown
Contributor Author

Added real behavior proof to the PR body (shipped CLI, synthetic fixture, before on 17b14df vs after on 37d62ad, bun canary + node 26.10.0).

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added 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. labels Nov 18, 2026
@steipete

Copy link
Copy Markdown
Owner

Extended the fix to null, scalar, and array entries in includes.tweets; these now increment skippedIncludes and produce a warning while preserving primary tweets. Invalid container shapes and primary records remain errors.

Verified failing-first with four synthetic cases, then all 71 import tests passed. Format/lint/typecheck and the production build passed on Linux through Crabbox. Independent Codex review found no remaining actionable P0–P2 findings. No paid X requests were made. Waiting for CI at the updated head before landing.

@steipete
steipete merged commit 29eae2c into steipete:main Nov 21, 2026
5 checks passed
@steipete

Copy link
Copy Markdown
Owner

Merged as 29eae2c after the updated head passed Bun primary, Node 26 compatibility, installed npm-package smoke, Playwright production-server checks, and GitGuardian: https://github.com/steipete/birdclaw/actions/runs/44852044558

The Linux gate also passed all 71 focused import tests, format/lint/typecheck, and production build. Synthetic regressions cover null, scalar, and array include rows as well as missing/invalid author IDs. Primary validation and malformed-container errors remain strict; no paid X requests were used.

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: 🦐 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.

3 participants