Release v2.12.0: Implement single-layer compression enforcement, 256KB plan archive cap with git.libre.audio citations, cold-archived inactive plans, codebase modularity/security/economization (Strategies 1A/2B/3A/4A/5A/6A/7A), and /quant/ spoken voice narration & #lensSelect UI element indicators (Strategies 1B/2A/3A/4A)
This commit is contained in:
1 parent
cc73a57bd8
commit
a066a0d03d
69 files changed
+2334
-619
No files matched your search
@@ -723,6 +723,8 @@ def _open_readonly_catalog(db_path: Path | str | None = None) -> sqlite3.Connect
|
||||
conn = sqlite3.connect(uri, uri=True)
|
||||
conn.row_factory = sqlite3.Row
|
||||
conn.execute("PRAGMA query_only = ON;")
|
||||
conn.execute("PRAGMA temp_store = MEMORY;")
|
||||
conn.execute("PRAGMA cache_size = -8000;")
|
||||
return conn
|
||||
|
||||
|
||||
@@ -881,6 +883,44 @@ def query_timeseries_bars(
|
||||
conn.close()
|
||||
|
||||
|
||||
def ensure_single_layer_gzip_file(gz_path: Path | str) -> dict[str, Any]:
|
||||
"""
|
||||
Inspect `gz_path` and ensure its decompressed stream is compressed strictly once (`1x`).
|
||||
If the decompressed payload itself begins with a gzip (`\\x1f\\x8b`) or xz (`\\xfd7zXZ\\x00`)
|
||||
magic header, iteratively peel outer compression layers in-place until the inner stream
|
||||
is the raw uncompressed payload (e.g., `"SQLite format 3\\x00"` or POSIX `ustar`).
|
||||
"""
|
||||
p = Path(gz_path)
|
||||
if not p.is_file():
|
||||
return {"path": str(p), "peeled_layers": 0, "single_layer_verified": False}
|
||||
peeled = 0
|
||||
while True:
|
||||
with gzip.open(p, "rb") as f_gz:
|
||||
head = f_gz.read(6)
|
||||
if head.startswith(b"\x1f\x8b"):
|
||||
f_gz.seek(0)
|
||||
inner_bytes = f_gz.read()
|
||||
elif head.startswith(b"\xfd7zXZ\x00"):
|
||||
import lzma
|
||||
|
||||
f_gz.seek(0)
|
||||
raw_unwrapped = lzma.decompress(f_gz.read())
|
||||
tmp_p = p.with_suffix(p.suffix + f".peel.{os.getpid()}")
|
||||
with open(tmp_p, "wb") as f_raw:
|
||||
with gzip.GzipFile(filename="", mode="wb", fileobj=f_raw, compresslevel=9, mtime=0) as gz_out:
|
||||
gz_out.write(raw_unwrapped)
|
||||
os.replace(tmp_p, p)
|
||||
peeled += 1
|
||||
continue
|
||||
else:
|
||||
break
|
||||
tmp_p = p.with_suffix(p.suffix + f".peel.{os.getpid()}")
|
||||
tmp_p.write_bytes(inner_bytes)
|
||||
os.replace(tmp_p, p)
|
||||
peeled += 1
|
||||
return {"path": str(p), "peeled_layers": peeled, "single_layer_verified": True}
|
||||
|
||||
|
||||
def _rotate_compressed_archives(base_db_path: Path, rotate_keep: int = 12) -> Path:
|
||||
"""
|
||||
Shift existing `<base_db_path>.{1..K-1}.gz` archives up by 1 and return `<base_db_path>.1.gz`.
|
||||
@@ -893,6 +933,7 @@ def _rotate_compressed_archives(base_db_path: Path, rotate_keep: int = 12) -> Pa
|
||||
src = Path(f"{base_db_path}.{idx}.gz")
|
||||
dst = Path(f"{base_db_path}.{idx + 1}.gz")
|
||||
if src.exists():
|
||||
ensure_single_layer_gzip_file(src)
|
||||
src.replace(dst)
|
||||
return Path(f"{base_db_path}.1.gz")
|
||||
|
||||
@@ -971,6 +1012,7 @@ def truncate_telemetry_db_quiescent(
|
||||
gz_target = _rotate_compressed_archives(t_path, rotate_keep=rotate_keep)
|
||||
with open(snap_tmp, "rb") as f_in, gzip.open(gz_target, "wb", compresslevel=9) as f_out:
|
||||
f_out.write(f_in.read())
|
||||
ensure_single_layer_gzip_file(gz_target)
|
||||
compressed_archive_path = str(gz_target)
|
||||
compressed_archive_bytes = gz_target.stat().st_size
|
||||
finally:
|
||||
@@ -1029,6 +1071,27 @@ def _ensure_telemetry_columns(conn: sqlite3.Connection) -> None:
|
||||
conn.execute("ALTER TABLE api_audit_ringbuffer ADD COLUMN traffic_source TEXT NOT NULL DEFAULT 'internal_test';")
|
||||
|
||||
|
||||
_INITIALIZED_TELEMETRY_INODES: set[tuple[str, int, int]] = set()
|
||||
|
||||
|
||||
def _ensure_telemetry_schema_initialized(conn: sqlite3.Connection, db_path: Path) -> None:
|
||||
try:
|
||||
st = db_path.stat()
|
||||
inode_key = (str(db_path.resolve()), st.st_dev, st.st_ino)
|
||||
except OSError:
|
||||
inode_key = None
|
||||
if inode_key is not None and inode_key in _INITIALIZED_TELEMETRY_INODES and st.st_size > 0:
|
||||
return
|
||||
conn.executescript(TELEMETRY_SCHEMA_SQL)
|
||||
_ensure_telemetry_columns(conn)
|
||||
if inode_key is not None:
|
||||
try:
|
||||
st_after = db_path.stat()
|
||||
_INITIALIZED_TELEMETRY_INODES.add((str(db_path.resolve()), st_after.st_dev, st_after.st_ino))
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
|
||||
def record_api_telemetry(
|
||||
protocol: str,
|
||||
method: str,
|
||||
@@ -1088,8 +1151,7 @@ def record_api_telemetry(
|
||||
conn = sqlite3.connect(str(t_path), timeout=30.0, isolation_level=None)
|
||||
try:
|
||||
conn.execute("PRAGMA busy_timeout = 30000;")
|
||||
conn.executescript(TELEMETRY_SCHEMA_SQL)
|
||||
_ensure_telemetry_columns(conn)
|
||||
_ensure_telemetry_schema_initialized(conn, t_path)
|
||||
conn.execute("BEGIN IMMEDIATE;")
|
||||
try:
|
||||
conn.execute(
|
||||
@@ -1422,8 +1484,10 @@ def run_logrotate_directive(
|
||||
configured_size_str = m_size.group(1)
|
||||
configured_bytes = parse_size_spec_bytes(configured_size_str)
|
||||
|
||||
if not re.search(r"^\s*compress\s*$", txt, flags=re.MULTILINE) or re.search(r"^\s*nocompress\s*$", txt, flags=re.MULTILINE):
|
||||
raise ValueError(f"{c_path} must specify 'compress' (and not 'nocompress') so rotated archives are compressed rather than removed.")
|
||||
if not re.search(r"^\s*nocompress\s*$", txt, flags=re.MULTILINE) or "--compress-archive" not in txt:
|
||||
raise ValueError(
|
||||
f"{c_path} must specify 'nocompress' in the outer logrotate block and '--compress-archive' in prerotate so sqlite_meta.py compresses rotated archives strictly once (1x)."
|
||||
)
|
||||
m_rot = re.search(r"^\s*rotate\s+(\d+)\s*$", txt, flags=re.MULTILINE)
|
||||
rotate_count = int(m_rot.group(1)) if m_rot else 0
|
||||
if rotate_count < 1:
|
||||
|
||||
Reference in new issue
Block a user