Skip to content

fix(skills): strip YAML-decoded null bytes and rotate unwritable catalog rows - #401

Merged
artempartos merged 2 commits into
developfrom
artempartos/skills-catalog-null-byte
Oct 2, 2026
Merged

artempartos merged 2 commits into
developfrom
artempartos/skills-catalog-null-byte

Conversation

@artempartos

Copy link
Copy Markdown
Contributor

Fixes Sentry PALAD-AI-TEMPORAL-1M: ArgumentError: string contains null byte in Skills::CatalogSync#record_metadata. It has failed every skills_demand_sync_workflow run since 2026-09-28, and it came back after #371 shipped.

Root cause

#371 removes raw NUL bytes from a SKILL.md before parsing it. YAML then puts them back. In double-quoted scalars, the escapes "\0", "\x00" and "\u0000" decode to NUL. !!binary decodes to arbitrary bytes, which need not be valid UTF-8. I checked all four with YAML.safe_load on the production Ruby (4.0.7). An upstream SKILL.md uses one of them in its frontmatter, and pg rejects the bind parameter before the UPDATE is sent.

Why one file stopped the whole sync

Because the write raised, the row was never stamped with description_checked_at. It stayed first in undescribed_first, so every later run died on that row before any row behind it got a turn. The description backfill and the audit pass after it both stalled.

Changes

  1. Skills::SkillMarkdown: safe_yaml passes the parsed tree through scrub_strings. Every string (keys and values, nested) is forced to UTF-8, scrubbed, and has its NUL removed. Doing it in this one place covers every consumer:

    • the catalog's name/description
    • SkillsRegistryService installs
    • the description and frontmatter["title"] from parse(), which manual skills, personal tools and template installs store
  2. Skills::CatalogSync#backfill_metadata: when a row's write raises ActiveRecord::ActiveRecordError or ArgumentError, the row is now:

    • reported through Rails.error with source skills.catalog_backfill. It is forwarded to Sentry with one issue per error class and the registry_id in the context.
    • counted in result.failed
    • stamped, so the queue moves on

    If the stamp fails too, the database itself is the problem and the run still fails.

Tests

  • skill_markdown_test.rb: all three YAML escapes in name, title and description (through name, description and parse), plus a !!binary description containing NUL and \xFF.
  • catalog_sync_test.rb: an unwritable row at the front of the queue is reported, counted and stamped, and the row behind it still gets its description.

I ran each new test against the old code first. All three failed: the markdown tests returned "pdf\u0000-processing", and the sync test raised the production ArgumentError: string contains null byte.

Run locally in an isolated worktree stack: the skills, templates, personal-tools and SkillsRegistryService suites plus sentry_configuration_test all pass, and rubocop and brakeman report nothing. CI is the full-suite check.

After this deploys, the stuck row is written (or stamped) on the next demand sync and the backlog drains by itself.

🤖 Generated with Claude Code

artempartos and others added 2 commits October 2, 2026 12:37
#371 deletes raw NUL from a SKILL.md before parsing, but YAML puts it
back: the double-quoted escapes "\0", "\x00" and "\u0000" decode to NUL,
and `!!binary` decodes to arbitrary bytes that need not be UTF-8. The
catalog backfill then wrote that description and pg refused it with
"string contains null byte".

Scrubbing the parsed tree in one place covers every consumer: the
catalog's name/description, the registry install path, and parse()'s
description and frontmatter title that manual skills and templates store.

Fixes PALAD-AI-TEMPORAL-1M

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
A row whose write raised was never stamped, so it stayed first in
`undescribed_first` and every later run died on it before anything
behind it got a turn. One upstream SKILL.md stopped the description
backfill and the audit pass for four days.

The row is now reported through Rails.error (forwarded to Sentry, one
issue per error class), counted as failed and stamped, so the queue moves
on. If stamping fails too the database itself is the problem and the run
still fails.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
@artempartos
artempartos merged commit 032be4f into develop Oct 2, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant