fix(ci+sec): idempotent relationship upsert, I2 line drift, inline CWE-22 sanitisers#53
Open
cdeust wants to merge 6 commits into
Open
fix(ci+sec): idempotent relationship upsert, I2 line drift, inline CWE-22 sanitisers#53cdeust wants to merge 6 commits into
cdeust wants to merge 6 commits into
Conversation
…E-22 sanitisers Two CI Test-job failures + 4 CodeQL path-injection alerts. CI: - insert_relationship: plain INSERT collided with uq_relationships_directed on incremental codebase re-analysis (defines/imports/extends edges replay). Now ON CONFLICT (source,target,type) DO UPDATE — keep strongest weight/ confidence, refresh last_reinforced — mirroring staging_resolve_sink. - test_I2_canonical_writer: allow-list line numbers drifted as code was added above the two canonical heat_base writers (477→543 bump_heat_raw, 537→603 update_memories_heat_batch). Updated the pins. Security (CWE-22): - http_file_diff / http_standalone_trace: refactor _under_allowed_root into sanitise-and-return _contained_resolved(p) -> Path|None. Callers now use the validated resolved path for is_dir()/git rev-parse, so the is_relative_to barrier sits inline on the tainted→sink dataflow CodeQL tracks. Behaviour unchanged (boolean wrapper retained); 20 server-helper tests green. Verified against pgvector/pgvector:pg17: codebase-alteration 5/5, invariants + store 57/57, server helpers 20/20. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…eadless authoring The CI Test job hung ~1h on every run since 2026-05-25 (commit 148d5a1) — pre-existing, not introduced by this branch. Two root causes in the consolidate → wiki-maintenance path, both surfaced via faulthandler. 1. Self-deadlock (the CI hang). `_run_purge_axis` ran inside the async consolidate handler yet bridged to wiki_purge via `asyncio.run_coroutine_threadsafe(coro, running_loop).result(timeout=120)`. It scheduled the coroutine on the *same* loop whose thread the synchronous caller had already blocked, so the coroutine could never run and each axis stalled to the 120s timeout. Fix: make the chain async end-to-end (`_run_purge_axis`, `run_wiki_maintenance` → `async def`; consolidate awaits via new `_atimed`). The purge now runs on its owning loop with the correctly-bound psycopg async pool. The dead identical-branch loop detection in `_invoke_wiki_purge` is removed. 2. Subprocess storm (machine-crash family). Headless authoring spawned up to ~38 `claude -p` subprocesses (30 anchor + 8 file-doc) at 180s each, synchronously on the event loop — wedging dev machines and the local test suite (claude is on PATH there; on CI it FileNotFounds fast, which is why CI hung only on cause 1). Gated behind `CORTEX_HEADLESS_AUTHORING` (default OFF) until per-cycle load balancing lands. tests_py/handlers/test_consolidate.py: 9/9 pass in 6m (was hanging ~1h). ruff clean. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…vendored dirs in wiki-drift walk CI Test (Python 3.11) hung because 41 handlers each constructed their own PgMemoryStore, leaking 60+ PG connections (batch timeout 1800s = 30-min stall). A second hang came from wiki-drift walking a stray 154M vendored deps/ tree. - infrastructure/memory_store.py: add process-wide get_shared_store()/ reset_shared_store() cache keyed by backend/url/dim; extract _construct_store(). - handlers/*.py (41): route _get_store() through get_shared_store(...); drop 4 dead MemoryStore imports. - tests_py/conftest.py: _reset_all_singletons calls reset_shared_store() and nulls handler caches via package iteration. - core/wiki_drift.py, core/wiki_coverage.py: prune _SKIP_DIRECTORIES (deps, site-packages) in _file_exists_under walk. Verified: 37 handlers -> 1 store; PG conns peak 16 (was 60+); back to 1 at teardown. pytest tests_py/handlers/ = 378 passed, no hang. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The mechanical pool-leak edit (memory_store.py get_shared_store) and the _SKIP_DIRECTORIES prune (wiki_drift._file_exists_under) left a call and a comprehension that now fit on one line; ruff format --check flagged both, failing CI Lint. Pure whitespace, no behaviour change. Lint was green at bed6393 — these two are the only regression. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The pool-leak rewrite swapped MemoryStore(...) -> get_shared_store(...) but left MemoryStore in wiki_api's lazy in-function import (the one handler with a different import form), so ruff check . failed F401. Removed; get_shared_store is the only symbol used. Full-repo ruff verified with CI's version (0.15.16): 'ruff format --check .' = 703 files already formatted, 'ruff check .' = passed. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes both CI Test-job failures and the open CodeQL/Dependabot security alerts on the default branch.
CI failures (both verified against
pgvector/pgvector:pg17)insert_relationship(pg_store_relationships.py) — made the upsert idempotent withON CONFLICT (source, target, type) DO UPDATE. It was raisingUniqueViolationonuq_relationships_directedduring incremental re-ingest.test_I2_canonical_writer.py) — line pins drifted: 477→543, 537→603.Security
_contained_resolved()helper inhttp_file_diff.pyandhttp_standalone_trace.py, with an inlineis_relative_tocontainment barrier.usedforsecurity=Falsefix landed after the alert was raised; auto-clears). No change.Test plan
ruffclean🤖 Generated with Claude Code