Skip to content

fix(moderation,import,backup): validate explicit moderation transport, x-json metrics, and backup schema/shard bounds - #262

Closed
saariuslystoned wants to merge 1 commit into
steipete:mainfrom
saariuslystoned:fix/moderation-transport-xjson-and-backup-validation
Closed

saariuslystoned wants to merge 1 commit into
steipete:mainfrom
saariuslystoned:fix/moderation-transport-xjson-and-backup-validation

Conversation

@saariuslystoned

@saariuslystoned saariuslystoned commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Hardens CLI moderation transport validation, x-json public-metric validation, and backup manifest/shard validation bounds:

  1. src/cli-moderation.ts & src/cli/register-moderation.ts: Validate explicit --transport values (auto, bird, xurl) before resolving account state or invoking live bird/xurl CLI transports; reject unsupported values (--transport must be auto, bird, or xurl).
  2. src/lib/x-json-import.ts: Validate tweet.public_metrics.* and user.public_metrics.* as non-negative safe integers (Number.isInteger(value) && value >= 0) so negative or fractional counts cannot clobber existing stored metrics during import x-json.
  3. src/lib/backup.ts: Validate maxShardBytes before creating destination backup directories in exportBackupUnlockedEffect, and require Number.isInteger(parsed.schemaVersion) in readManifestEffect so fractional schema versions (e.g. 1.5) are rejected.

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

1. Seed v0.17.0 Archive (9895445ba0a2) with Settings, Accounts, Tweets, Collections, and DMs

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

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

# 2a. Base blocks add --transport bogus accepts invalid transport and falls through to live xurl transport
$ PATH="/usr/bin:/bin" BIRDCLAW_HOME=/tmp/bc-home-base-262 node /tmp/bc-base-262/dist/cli/birdclaw.js --json blocks add @spammer --transport bogus
{"error":"spawn xurl ENOENT"}

# 2b. Base import x-json accepts negative like_count (-5) and clobbers stored v0.17.0 metric (42 -> -5)
$ BIRDCLAW_HOME=/tmp/bc-home-base-262 node /tmp/bc-base-262/dist/cli/birdclaw.js --json import x-json /tmp/bc-input-262/corrupt-metrics.jsonl
{
  "imported": 0,
  "skipped": 1,
  "errors": []
}
$ BIRDCLAW_HOME=/tmp/bc-home-base-262 node /tmp/bc-base-262/dist/cli/birdclaw.js --json search tweets "Baseline"
[
  {
    "id": "1900000000000000001",
    "text": "Baseline v0.17.0 post",
    "likeCount": -5
  }
]

# 2c. Base backup validate accepts non-integer schemaVersion 1.5
$ BIRDCLAW_HOME=/tmp/bc-home-base-262 node /tmp/bc-base-262/dist/cli/birdclaw.js --json backup validate /tmp/bc-input-262/repo-base
{
  "ok": true,
  "errors": [],
  "counts": {
    "accounts": 3,
    "collections_bookmarks": 2,
    "collections_likes": 3,
    "dm_messages": 8,
    "dm_conversations": 4,
    "tweets": 7
  }
}

3. Head (dd7c6fd8d4b4) Shipped CLI Pass & v0.17.0 Archive Upgrade Compatibility Proof

# 3a. Head blocks add --transport bogus fails fast before auth/transport
$ PATH="/usr/bin:/bin" BIRDCLAW_HOME=/tmp/bc-home-upg-262 node /tmp/bc-head-262/dist/cli/birdclaw.js --json blocks add @spammer --transport bogus
{"error":"--transport must be auto, bird, or xurl"}

# 3b. Head import x-json rejects negative metric (-5) and preserves v0.17.0 tweet likeCount=42
$ BIRDCLAW_HOME=/tmp/bc-home-upg-262 node /tmp/bc-head-262/dist/cli/birdclaw.js --json import x-json /tmp/bc-input-262/corrupt-metrics.jsonl
{
  "imported": 0,
  "skipped": 0,
  "errors": [
    {
      "line": 1,
      "message": "Line 1: tweet.public_metrics.like_count must be a non-negative integer"
    }
  ]
}
$ BIRDCLAW_HOME=/tmp/bc-home-upg-262 node /tmp/bc-head-262/dist/cli/birdclaw.js --json search tweets "Baseline"
[
  {
    "id": "1900000000000000001",
    "text": "Baseline v0.17.0 post",
    "likeCount": 42
  }
]

# 3c. Head backup validate rejects non-integer schemaVersion 1.5
$ BIRDCLAW_HOME=/tmp/bc-home-upg-262 node /tmp/bc-head-262/dist/cli/birdclaw.js --json backup validate /tmp/bc-input-262/repo-base
{
  "ok": false,
  "repoPath": "/tmp/bc-input-262/repo-base",
  "files": [],
  "counts": {},
  "backupHash": "",
  "errors": [
    "Unsupported backup schema version 1.5"
  ]
}

# 3d. v0.17.0 -> Head data-model compatibility (settings, accounts, tweets, collections, DMs, backup export & validate)
$ BIRDCLAW_HOME=/tmp/bc-home-upg-262 node /tmp/bc-head-262/dist/cli/birdclaw.js --json db stats
{
  "paths": {
    "rootDir": "/tmp/bc-home-upg-262",
    "dbPath": "/tmp/bc-home-upg-262/birdclaw.sqlite",
    "configPath": "/tmp/bc-home-upg-262/config.json"
  },
  "stats": {
    "home": 5,
    "mentions": 2,
    "dms": 4,
    "needsReply": 2,
    "inbox": 4
  }
}
$ BIRDCLAW_HOME=/tmp/bc-home-upg-262 node /tmp/bc-head-262/dist/cli/birdclaw.js --json backup export --repo /tmp/bc-input-262/repo-head
$ BIRDCLAW_HOME=/tmp/bc-home-upg-262 node /tmp/bc-head-262/dist/cli/birdclaw.js --json backup validate /tmp/bc-input-262/repo-head
{
  "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": 1,
    "profiles": 7,
    "timeline_edges_home": 5,
    "timeline_edges_mention": 2,
    "tweet_revisions": 1,
    "tweets": 7
  }
}

Verification

  • pnpm test src/cli-moderation.test.ts src/cli/moderation-contract.test.ts src/lib/x-json-import.test.ts src/lib/backup.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.

☁️

…, x-json metrics, and backup schema/shard bounds
@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 rejects unsupported moderation transports, negative or fractional imported metrics, and malformed backup versions, and validates shard limits earlier.

Example: Import tweet 1900000000000000001 with like_count -5 when its stored count is 42.

  • Before: The import accepts -5 and replaces the stored count.
  • After: The document receives a validation error and the stored count remains 42.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Useful, focused repairs with shipped CLI evidence and existing-state compatibility support; functional test results are contributor-reported rather than independently executed here.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): The PR body records the built CLI on v0.17.0 and the reviewed head exercising invalid transport rejection, negative-count rejection with stored count 42 preserved, fractional manifest rejection, and valid backup export and validation using a copied stable-release archive. The internal shard-limit ordering has focused regression coverage and no CLI override. The prepared Discuss screenshots belong to predecessor transport work and add no proof for this PR.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Malformed explicit inputs can invoke an unintended moderation transport, overwrite valid archive metrics, or enter backup processing before rejection.
Reason: The repairs enforce existing transport choices and count/version invariants while retaining valid defaults and compatibility.

Merge readiness

✅ Ready for maintainer review

Keep open: this PR repairs validation defects present in v0.17.0, and the new CLI evidence resolves the earlier proof hold; no blocking correctness or security finding remains.

Priority: P2
Reviewed head: dd7c6fd8d4b4e2703bc08d5afde4769bdf4d40c9

Before merge

None.

Findings

None.

Agent review details

How this fits together

CLI arguments, saved X API JSON, and backup manifests enter existing validators before moderation transports, transactional SQLite ingestion, or backup processing.

flowchart TD
 A[Moderation arguments] --> B[CLI and action validation]
 B --> C[Account checks and transports]
 D[Saved X JSON] --> E[Import validation]
 E --> F[SQLite ingestion]
 G[Backup options and manifests] --> H[Backup validation and export]
Loading

Technical review

Best possible solution:

Land the focused validation repairs in the existing owners while preserving valid inputs, archive formats, and transport preferences.

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

The base source exposes all reported validation paths, and the contributor supplies v0.17.0 CLI failures followed by corrected output on the reviewed head; no target code was executed during this review.

Is this the best way to solve the issue?

The patch repairs existing validation owners without adding machinery; the PR body's safe-integer wording overstates Number.isInteger, which enforces integrality without a safe-integer upper bound.

AGENTS.md: not found in the target repository.

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

Provenance checked

  • Moderation CLI validation and transport selection keeps the original intent (3174150: The CLI refactor separated command registration from application wiring; later transport-preference work kept explicit valid modes authoritative.)
  • X JSON metric validation keeps the original intent (Add birdclaw import x-json for saved X API v2 tweet JSON #252: Validate saved documents before transactional ingestion and preserve existing metadata when fields are omitted.)
  • Backup shard-limit validation order keeps the original intent (f05944c: Split oversized JSONL shards deterministically and validate a positive safe-integer byte limit; later hardening added staged publication.)
  • Supported backup schema versions keeps the original intent (0ff0317: Accept supported legacy backup versions and adapt their data during import; the new integer check retains that supported range.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

  • Verified introduced patch: The pinned diff adds validation in existing owners without changing valid defaults, persisted schemas, dependencies, or workflows. (dd7c6fd8d4b4)
  • Shipped CLI behavior and upgrade evidence: The current PR body supplies base-versus-head CLI output for invalid transport rejection, negative metrics preserving likeCount 42, fractional backup-version rejection, and successful export and validation of an archive copied from v0.17.0. (dd7c6fd8d4b4)
  • Existing transport contract: Configuration documents explicit transport precedence and the three supported modes; the repair preserves the preference and fallback behavior established by feat: expand bird sync support and add auto transport preference #231. (docs/configuration.md:110, b22ced0110ce)
  • Importer contract and history: The importer introduced in Add birdclaw import x-json for saved X API v2 tweet JSON #252 validates documents before transactional ingestion and preserves omitted metadata; the new count checks retain those boundaries. (src/lib/x-json-import.ts:102, d1b619a03b76)
  • Backup compatibility boundary: The patch retains the existing supported integer version range and shard normalizer; only malformed versions and validation ordering change, while staged publication from fix: harden profile and backup synchronization #125 remains intact. (src/lib/backup.ts:2885, 0ff0317c9afe)
  • Validation and inspection limits: The exact head has a successful GitGuardian check; no functional CI run is listed. Tests were inspected but not run during this read-only review. Some historical blobs were unavailable with lazy fetching disabled; supplied provenance and readable history covered the changed contracts. (dd7c6fd8d4b4)

Likely related people:

  • Peter Steinberger: Raw commit 131f6a1 adds src/lib/backup.ts:2787 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 131f6a1a7074; files: src/lib/backup.ts)
  • Vitor Cepeda Lopes: Raw commit d1b619a adds src/lib/x-json-import.ts:108 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
Production and regression coverage Production +47/-16 lines; tests +300/-1 lines The test growth covers command aliases, valid transport preservation, rejected imports preserving stored rows, and backup validation before side effects.

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: The repair prevents malformed explicit inputs from selecting unintended transports or corrupting imported counts, with limited blast radius.
  • 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-08T22:03:25.033Z sha dd7c6fd :: needs real behavior proof before merge. :: none

Reviewed November 8, 2026, 6:50 PM ET / 23:50 UTC (Revision 2).

@saariuslystoned

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 8, 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 8, 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 moderation transport validation, non-negative safe imported metrics, and backup input 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: 🐚 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