refactor(extensions): centralize validator operation names#2419
Merged
nicoloboschi merged 1 commit intoJun 30, 2026
Merged
Conversation
Add PrecheckOperation, BankReadOperation, and BankWriteOperation StrEnum types for operation validator hook contexts. Use them at every precheck and validate_bank_read/write call site while preserving string comparison compatibility for existing extensions. Tests: - uv run pytest tests/test_extensions.py -q - ./scripts/hooks/lint.sh
243a9b0 to
564975a
Compare
nicoloboschi
approved these changes
Jun 30, 2026
nicoloboschi
left a comment
Collaborator
There was a problem hiding this comment.
Reviewed for backwards compatibility.
The new PrecheckOperation/BankReadOperation/BankWriteOperation StrEnums are fully string-compatible — equality, str(), f-strings, format(), json.dumps, dict-key lookup, set membership, and str methods all behave as the bare string (verified empirically). The context dataclasses do no runtime type enforcement, so existing extensions comparing ctx.operation == "retain" and any not-yet-updated string call sites keep working. Exports are additive only; nothing removed.
Since this is a fork PR, test-api/Core LLM jobs are skipped in CI, so I ran tests/test_extensions.py locally on the PR branch: 42 passed.
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
Centralizes the operation names passed through
precheck,validate_bank_read, andvalidate_bank_writeby addingPrecheckOperation,BankReadOperation, andBankWriteOperationStrEnumtypes. The existingPrecheckContext,BankReadContext, andBankWriteContextcall sites now use enum members instead of scattered string literals.Why this helps
ctx.operationis the main signal anOperationValidatorExtensioncan use for operation-specific authorization and quota checks. Before this change, the allowed values only existed as string literals spread acrossapi/http.py,memory_engine.py, and HTTP route wiring, so extension authors had to search the codebase to discover the full set and could easily miss routes like bank config updates, async maintenance submissions, document/chunk access, file retain, or dry-run extraction.Exported enums give extension authors a single source of truth, better IDE completion, and a clearer review surface when new operation-scoped hooks are added. They also make call sites self-documenting:
BankWriteOperation.UPDATE_BANK_CONFIGandPrecheckOperation.FILES_RETAINcommunicate the hook contract more clearly than raw string literals.Compatibility
The new enums inherit from
str, so existing extensions that comparectx.operationto string values such as"retain","get_bank_stats", or"update_bank_config"continue to work. The compatibility test covers both enum identity checks and legacy string comparison behavior.Tests
uv run pytest tests/test_extensions.py -q./scripts/hooks/lint.sh