Skip to content

refactor(public-safety): centralize compact identifier shapes - #5351

Open
karenchuu wants to merge 1 commit into
loopx-project:mainfrom
karenchuu:karenchuu/compact-identifier-shapes-owner
Open

karenchuu wants to merge 1 commit into
loopx-project:mainfrom
karenchuu:karenchuu/compact-identifier-shapes-owner

Conversation

@karenchuu

Copy link
Copy Markdown
Contributor

Summary

Centralizes the identical compact public-safe reference, compact token, and module-qualified surface regular expressions in loopx/public_safe_text.py. Reward Memory, Semantic Preference, Decision Context, and Material Lifecycle retain their existing field-level behavior and error messages while consuming the shared compiled patterns.

Also adds a focused ownership regression test that verifies the listed consumers share the owner objects (is, not ==) and no longer restate the literals.

Delivery brief

  • Goal/source: remove demonstrated duplicated identifier/surface-shape decisions across the named capability contracts.
  • Current gap: three shape rules were independently compiled in 12 modules, so a one-character edit in any one of them would silently drift the others.
  • Observable result: each migrated consumer aliases the canonical compiled pattern; validation semantics remain unchanged.
  • Owning boundary: loopx/public_safe_text.py owns syntax shapes only, while callers retain contract-specific field names, thresholds, policy and diagnostics.

Relationship to #5350 and #5296

This replaces #5350, which carried the same content from a different account; #5350 is closed with a pointer here.

Rebased onto a7e6b826a. Two files conflict on the way because #5296 landed between the original branch point and this base: decision_context/packets.py and material_lifecycle/_validation.py no longer carry _LOCAL_PATH_RE (that check now goes through find_public_safe_local_path). Resolution kept #5296's owner call and its explanatory comments verbatim, and removed only the duplicated _TOKEN_RE literal in favour of the shared import. Both files keep a net line delta of 0, which is what preserves the two project_registry_io census sites recorded for _validation.py.

Validation

  • pytest -q tests/control_plane/test_compact_identifier_shape_owner.py — 3 passed.
  • pytest -q tests/architecture --ignore=tests/architecture/test_semantic_production.py — 1009 passed / 0 failed (2m21s); tests/architecture/test_semantic_production.py separately — 34 passed.
  • pytest -q tests/architecture/test_project_registry_io_census.py — 7 passed (needs the typescript dev dependency installed; run from a tree with node_modules).
  • pytest -q tests/capabilities tests/test_decision_context_material.py plus the new guard — 1831 passed / 9 failed / 42 skipped (4m15s). All 9 failures are in tests/capabilities/test_repository_change_window.py, which spawns the loopx console script; they reproduce identically (9 failed / 8 passed) on an unmodified worktree at a7e6b826a under the same interpreter and PATH, so they are an environment artifact of this machine and not a regression from this change.
  • examples/semantic-vocabulary-drift-smoke.py — ok. Measured counts are byte-identical between the unmodified base and this head (multi_value_twins=8/8, same_runtime_forks=11/11, conflicting_values=16/16, schema_version_same_runtime_forks=2/2), so no budget anchor moves: the three shapes were never registered as twins, and removing the duplicates does not by itself lower a budget.
  • python -m ruff check on all 14 changed files — all checks passed; python -m mypy (no arguments, as CI runs it) — Success: no issues found in 19 source files; git diff --check — clean.
  • loopx check --scan-path over public_safe_text.py, the four capability packages and the new guard — errors=0, public boundary scan clean: 77 files.
  • loopx canary premerge with the 14 changed files listed explicitly — selected=10 executed=10 failures=0 advisory_failures=0.
  • Disclosure: this run reused an already-installed local virtualenv interpreter and a node_modules symlink from another worktree (after diffing package.json dependencies and devDependencies field by field, identical) instead of a fresh uv sync --extra test, and pointed PYTHONPATH at this tree. The commands above are what actually ran, with PYTHONPATH and PATH (Node 22.23.2) set that way.

Scope

  • Changed surfaces: shared public-safe shape owner; Reward Memory, Semantic Preference, Decision Context, and Material Lifecycle Python contract validation.
  • No frontend, CLI, permission, persistence, default-off, or authority behavior changes.
  • Future-facing refactor pass: applied; this removes duplicate shape authority without changing validation behavior.
  • Not in scope: chat_action_store.py / chat_actions.py / goals/deletion_service.py each compile the same ^[A-Za-z0-9._:-]{1,200}$, and global_risks.py / global_todos.py / summary_all.py each restate the same SCHEMA_VERSION value. Those are separate owners with different contract lifetimes and are left for their own PRs rather than folded in here.

Signed-off-by: karenchuu <25980598+karenchuu@users.noreply.github.com>

This branch has not been deployed

No deployments
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