v0.1.10: add storage-neutral cache lifecycle and task state models#147
v0.1.10: add storage-neutral cache lifecycle and task state models#147rickisba wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e7489ecd52
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| get = row.get if hasattr(row, "get") else lambda key, default=None: getattr(row, key, default) | ||
| kid = _safe_component(get("kid"), "kid") |
There was a problem hiding this comment.
Support sqlite3.Row in legacy mapping
When this helper receives a row directly from the legacy SQLite database, it always rejects it: TextDatabase._connect() configures sqlite3.Row, which has neither .get() nor field attributes, so this fallback returns None for kid even though row["kid"] exists, and _safe_component raises. Handle mapping-style subscription before falling back to attribute access.
Useful? React with 👍 / 👎.
| directory_exists = runtime_directory.is_dir() | ||
| kv_ready = bool(get("kv_ready", False)) | ||
| artifact_state = ArtifactState.READY if kv_ready else ArtifactState.PENDING | ||
| replica_state = ReplicaState.READY if kv_ready and directory_exists else ReplicaState.FAILED |
There was a problem hiding this comment.
Keep unbuilt legacy replicas pending
For every normal text-only row with kv_ready=0, this assigns ReplicaState.FAILED regardless of whether any build or copy has failed. Consumers of this projection will therefore count newly registered or not-yet-built knowledge as failed and receive misleading resource-state visibility; use PENDING when kv_ready is false and reserve FAILED for stale kv_ready=1 metadata whose runtime directory is missing.
AGENTS.md reference: AGENTS.md:L219-L230
Useful? React with 👍 / 👎.
Merge-blocking architecture alignment after the updated #139The state-model implementation is broadly compatible with the updated direction and does not need to be redesigned, but the PR should not merge until its documentation and contract wording make the LMCache ownership boundary unambiguous. Required before merge:
Keep this PR scoped to updated #139. Do not implement the LMCache adapter or #140 protocol here. |
Motivation
Description
core/state_models.py: shared enums (ArtifactState,ReplicaState,DataPlaneTaskState,QueueWorkState), immutable_StateModel,transition_to()that returns a copy plusTransitionResult,InvalidStateTransitionwith structured detail, and deterministicstable_idhelpers; direct field assignment now raises Pydantic frozen-instanceValidationError.kdn_server/legacy_state.pythat: normalizes and validateskid, resolves runtime Replica directory as<kv_root>/<kid>for health checks, rejects path-escaping values, treatskv_rel_diras legacy metadata (validated but not authoritative), emits a machine-readablelegacy_kv_rel_dir_mismatchwarning whenkv_rel_dirdiffers fromkid, and never treatskv_rel_dir="."as making the KV root a valid Replica directory.failed, stable sorted allowed-target output, SQLite layout andmark_kv_readysemantics, and injection/routing logic), and do not alter injection code or manifests.test/test_state_models.py(immutability, idempotency, copy-on-transition, structured terminal rejection) andtest/test_legacy_kv_state_mapping.py(runtime-kid checks, stalekv_rel_dir,.handling, path escape rejection, immutability of projection, and read-only mapping).core.forward_requestlazily import its optionalaiohttpdependency to allow CPU-only state-contract tests to import the package withoutaiohttpinstalled.Testing
python3 -m compileall core kdn_server proxy— completed successfully.pytest -q test/test_state_models.py— passed:7 passed(with unrelated SWIG deprecation warnings).pytest -q test/test_legacy_kv_state_mapping.py— passed:6 passed(with unrelated SWIG deprecation warnings).pytest -q test/test_state_models.py test/test_legacy_kv_state_mapping.py test/test_instance_capability.py test/test_instance_capability_registration.py proxy/resource/test_instance_pool_gpu.py— collection stopped with environment-dependent errors due to missing optional test dependencies, specificallyModuleNotFoundError: No module named 'fastapi'intest/test_instance_capability.pyandtest/test_instance_capability_registration.py(these are unrelated to the new state-model changes).pytest -q --ignore=test/test_kv_injector_reuse.py— collection stopped for the same environment-dependent reasons (missingfastapi) and one pre-existing test that reads a placeholder path raisingFileNotFoundError; these failures are not introduced by this PR.Notes and current status
f491ba96f0494217e9c75cb9c4506948c7060ecccontaining the changes above, and the changed files arecore/__init__.py,core/state_models.py,kdn_server/legacy_state.py,test/test_state_models.py, andtest/test_legacy_kv_state_mapping.py.fatal: unable to access 'https://github.com/AstraNetLab/CacheRoute.git/': CONNECT tunnel failed, response 403), so the remote PR was not updated from this environment; the commit and tests are present locally as reported above.fastapi,aiohttp) could not be completed in this environment; those are environment-dependent and pre-existing outside the scope of the fixes here.Codex Task