bindings

Documents the CPython C-API binding layer for the strata JSON extension module.

Updated Nov 20, 2025
One-click install
npx skills add https://github.com/PrimeLab-Foundation/strata --skill bindings-primelab-foundation
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: bindings
Source: https://github.com/PrimeLab-Foundation/strata/tree/main/docs/bindings
Command: npx skills add https://github.com/PrimeLab-Foundation/strata --skill bindings-primelab-foundation

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Working on strata's CPython C-API bindings without this context risks reintroducing known bugs (like the cycle_policy init mismatch), breaking CPython-internal invariants, or regressing the measured performance optimizations in the loads/dumps hot paths. ## Core Features & Use Cases - Binding architecture map: Documents every file under src/strata/bindings/ and python/strata/, including the KeyCache, speculative key matching, and per-thread builder leases. - Known bugs and dead code: Records the cycle_policy initialization bug, dead branches in python_document.cpp, and unregistered functions so they are not reproduced. - CPython internals audit list: Enumerates version-sensitive internals (_PyDict_SetItem_KnownHash, _PyDict_NewPresized, dict entry layouts) that must be re-verified on each new CPython release. - Use Case: Before modifying src/strata/bindings/python_dumps.cpp, load this Skill to learn that the raw dict walk is runtime-proved via probe_layout() and that cold-path members must not be refactored into free functions. ## Quick Start Load the bindings skill before editing any file under src/strata/bindings/ or python/strata/ so the documented invariants and known bugs guide the change.

Frequently Asked Questions about bindings

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I safely modify the strata CPython binding layer?

Load this Skill before touching src/strata/bindings/ or python/strata/. It documents the file map, thread-local state design, and invariants such as wrapping every exported function in STRATA_CPP_TRY/CATCH and never releasing the GIL.

What CPython internals does the strata extension depend on?

The bindings use _PyDict_SetItem_KnownHash, _PyDict_NewPresized, PyUnstable_Long_IsCompact/CompactValue, PyUnicode_IS_COMPACT_ASCII, and the internal dict keys-table layouts. These must be audited on every new CPython version, with the raw dict walk gated to 3.11-3.14.

Why does the raw dict walk need a runtime proof?

The walk reads CPython's internal dict entry arrays directly, which are version-sensitive. probe_layout() builds witness dicts and compares raw walks against PyDict_Next at import; any mismatch disables that layout's fast path and falls back to PyDict_Next with identical output.

What is the cycle_policy bug in the strata bindings?

The previous implementation seeded the config map with "warn" without calling the setter, while g_cycle_policy started as Ignore, so reported and actual behavior disagreed until the first config.set. The fix seeds both consistently to "warn" and reads live policy variables.

Does the strata extension release the GIL during parsing?

No, the GIL is never released; all file I/O and parsing hold it. Instead, PyGcPause disables GC around bulk build and serialize operations, and thread safety comes from thread-local buffers, builders, and policy state.