Skip to content

refactor(storage): centralize safe persisted identifier validation - #4931

Merged
me2seeks merged 1 commit into
apache:mainfrom
seekskyworld:refactor/4926-storage-safe-id
Sep 8, 2026
Merged

me2seeks merged 1 commit into
apache:mainfrom
seekskyworld:refactor/4926-storage-safe-id

Conversation

@seekskyworld

Copy link
Copy Markdown
Contributor

Fixes #4926

Summary

  • add a storage-local safe persisted identifier predicate and asserter
  • migrate runtime event, interaction, session bundle, session copy, and Goal authority boundaries
  • preserve caller-specific trimming, errors, and owner-id semantics
  • add 1/128 boundary and invalid-value regression coverage

Motivation

The same persisted identifier grammar was implemented in several storage authorities. Centralizing the grammar prevents future policy changes from leaving one persistence boundary weaker or accepting a different set of values.

Validation

  • npm --workspace @maka/core run build
  • npm --workspace @maka/storage run build
  • node --test packages/storage/dist/tests/storage-id.test.js packages/storage/dist/tests/session-bundle-policy.test.js packages/storage/dist/tests/session-copy-cleanup.test.js packages/storage/dist/tests/goal-authority.test.js packages/storage/dist/tests/client-capability-session-grant-store.test.js packages/storage/dist/tests/sqlite-core-execution-store.test.js (40/40)
  • npx biome check on changed storage sources and tests

@github-actions github-actions Bot added the effort/S Under 100 readable lines label Sep 6, 2026
@seekskyworld
seekskyworld force-pushed the refactor/4926-storage-safe-id branch from 267f1a9 to e666677 Compare September 6, 2026 19:24

@Astro-Han Astro-Han left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reviewed this PR at head e666677f (7 files, +92/−8) against base 2310035a.

What the change does: adds one storage-local safe persisted-identifier module (storage-id.ts) with an isSafeStorageId type guard (unknown → string) and an assertSafeStorageId assertion over the shared /^[A-Za-z0-9_-]{1,128}$/ grammar, and migrates the five boundaries that previously implemented the same rule independently: runtime-event-invariants.ts, interaction-store.ts, session-bundle-policy.ts, session-copy-cleanup.ts, and goal-authority.ts.

Behavior equivalence (checked per call site):

  • interaction-store.ts already combined a typeof check with the pattern; the guard folds both into one call with identical outcomes.
  • session-copy-cleanup.ts keeps its caller-specific trim-then-validate order.
  • goal-authority.ts keeps its caller-specific TypeError message; session-bundle-policy.ts keeps its SessionBundleExportError contract.
  • The test covers both length boundaries (1 and 128), the charset, and rejections for empty, overlong, whitespace, path, punctuation, and non-string values, plus the assertion message.

Scope: #4926 explicitly leaves provider-specific external session identifiers and the independently evolving agent-run-store / message-admission-store paths out of this change, so the partial consolidation is by design, not a gap. One recorded P3: those remaining storage paths may still hold their own identifier checks; they should be folded in when the broader #1404 consolidation lands.

Gates: CI on this exact head is green (including the epoch guard and architecture checks); no protocol or epoch files are touched; no review is bound to the current head.

Not verified: I did not run the suites locally (CI on the exact head covers the storage suite; the author reports 40/40 passing).

No P0–P2 findings. This is a refactor; I am not approving — the merge decision belongs to humans.


Automated review notice: This comment was posted by an automated review agent operated by Astro-Han. It is not an independent human review and does not replace one.

@me2seeks me2seeks left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review by OpenAI Codex, operated by me2seeks, at e666677f56ea4adaa6818fbe40ac619ca94ec68c. This is an automated technical assessment, not an independent human review. Approval is submitted at the operator's explicit direction.

No actionable findings. Compared all five migrated boundaries: ASCII grammar and length limits are shared, while session-copy trimming, Interaction decode source, bundle error class and Goal TypeError text remain at their owners. Existing isRuntimeStorageSafeId callers still need that named boundary. Both exact-source storage-id tests passed.

  1. Optimal for the actual problem: Yes; the change addresses the defect at its existing owner.
  2. Production code that can be deleted: The five grammar copies are removed. No additional in-scope deletion; #4926 explicitly excludes provider-specific ids and independently evolving admission/run stores.
  3. Low-quality tests that can be deleted or replaced: None identified.
  4. Deeper refactor: No deeper refactor is needed.
  5. Ready to merge: Content is ready; merge remains conditional on current required checks and conflict state.
  6. Residual risks / verification: Focused exact-source tests passed. Reviewed production consumers and error/normalization contracts; full SQLite and bundle suites were not rerun locally. No protected-area effect identified in this diff.

@me2seeks
me2seeks merged commit 6974c47 into apache:main Sep 8, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

effort/S Under 100 readable lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor(storage): centralize safe persisted identifier validation

3 participants