fix: harden pyright strict-mode follow-up regressions#336
Draft
fix: harden pyright strict-mode follow-up regressions#336
Conversation
Restore the assistant and audit contracts that drifted during the pyright strict migration and harden Optional datetime sorting so it is actually safe at runtime. What this changes: - keep assistant session pagination cursors nullable instead of coercing missing cursors to datetime.min - preserve nullable tool_call_id values in SSE and persisted assistant tool metadata instead of emitting empty strings - require a real approval_id for approval SSE events instead of silently serializing an empty string - register audit worker task names in the Task enum and stop hiding them behind cast(Task, "...") - centralize Optional datetime fallback logic in a UTC-aware helper and use it in the strict-mode sort paths that previously mixed None, naive datetimes, and aware datetimes Why: - fixes the runtime sort crash risk in ai_models_service and the same latent aware-vs-naive issue in adjacent strict-mode sort sites - restores pre-migration API and wire semantics for nullable pagination and tool approval fields - makes the Task typing honest instead of masking enum gaps with casts - adds focused regression coverage for the touched safety paths
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
Follow-up to #325.
This PR fixes a small set of runtime and contract regressions that surfaced after the backend-wide Pyright strict migration, while keeping the strict baseline intact.
What changed
datetime.mintool_call_idvalues in assistant SSE and persisted tool metadata instead of serializing empty stringsapproval_idfor approval SSE events instead of silently emitting""Taskenum and replacecast(Task, "...")with real enum membersNone, naive datetimes, and aware datetimesWhy
PR #325 made the backend globally strict, but a few pyright-driven fallbacks changed runtime behavior:
previous_cursorfromnullto0001-01-01T00:00:00created_atsort path could still crash at runtime, and the straightforwarddatetime.minfallback is not safe when real timestamps are timezone-awareThis PR restores the original API semantics where appropriate and hardens the datetime fallback so it is correct at runtime.
Testing
Targeted verification run in the devcontainer:
cd /workspace && set -a && . backend/.env && set +a && cd backend && python -m pytest -q tests/unittests/ai_models/test_ai_models_service.py tests/unittests/spaces/test_space.py tests/unittests/assistants/test_assistant_router.py tests/unittests/questions/test_questions_repo.py tests/unittests/worker/test_worker.py tests/unit/test_assistant_protocol.py tests/unit/test_audit_async.pycd /workspace && set -a && . backend/.env && set +a && cd backend && python -m pytest -q tests/unittests/sessions/test_protocol.py tests/unit/test_conversations_tool_approval_contract.py tests/unit/test_tool_approval_manager.py tests/unit/test_completion_service_streaming.py tests/unit/test_export_job_manager.py tests/integration/audit/test_audit_worker.py tests/integration/test_tool_approval_endpoint.pycd /workspace/backend && ./scripts/run_pyright_in_devcontainer.sh src/intric/ai_models/ai_models_service.py src/intric/assistants/api/assistant_router.py src/intric/assistants/api/assistant_protocol.py src/intric/assistants/assistant_service.py src/intric/jobs/job_models.py src/intric/api/audit/routes.py src/intric/audit/application/audit_service.py src/intric/main/datetime_utils.py src/intric/spaces/space.py src/intric/spaces/space_service.py src/intric/completion_models/application/completion_model_crud_service.py src/intric/transcription_models/domain/transcription_model_service.py src/intric/transcription_models/application/transcription_model_crud_service.py src/intric/group_chat/presentation/assemblers/group_chat_assembler.pyNotes