docling-studio/document-parser/domain
Pier-Jean Malandrino ff0b795b6d feat(#202): introduce Document lifecycle state machine
Adds a first-class lifecycle state to every document, distinct from
AnalysisJob.status. The lifecycle describes the document as a whole and
is the foundation for the doc-centric pivot in 0.6.0.

Domain
- DocumentLifecycleState enum (Uploaded/Parsed/Chunked/Ingested/Stale/Failed)
- Document.lifecycle_state and lifecycle_state_at fields
- Document.transition_to() validates against a transition table
  (domain/lifecycle.py) and returns a DocumentLifecycleChanged event
- InvalidLifecycleTransitionError on disallowed transitions

Persistence
- ALTER TABLE documents to add the two columns (default 'Uploaded')
- New index idx_documents_lifecycle_state for filter perf
- _COLUMN_MIGRATIONS refactored to support multiple tables
- _POST_MIGRATION_DDL list for indexes on freshly-added columns
- SqliteDocumentRepository.update_lifecycle()

Services
- AnalysisService drives transitions on parse / chunk / re-chunk / fail
  via _transition_document(); idempotent and resilient (logs WARN and
  continues if a stale state is somehow encountered)

API
- DocumentResponse exposes lifecycleState + lifecycleStateAt
  (additive — existing 'status' field kept for backwards compat)

Frontend
- Document type extended with lifecycleState and lifecycleStateAt
- DocumentLifecycleState union literal mirroring the backend enum

Tests
- 24 new tests in test_lifecycle.py covering transitions, idempotency,
  invariant preservation, and event emission
- test_repos.py: round-trip + every-enum-value check + update_lifecycle
- test_chunking.py: rechunk path now mocks document_repo correctly

Refs #202
2026-05-05 09:38:39 +02:00
..
__init__.py Radical architecture change, migration to a more lightweight 2026-03-17 16:06:27 +01:00
events.py feat(#202): introduce Document lifecycle state machine 2026-05-05 09:38:39 +02:00
exceptions.py feat(#202): introduce Document lifecycle state machine 2026-05-05 09:38:39 +02:00
lifecycle.py feat(#202): introduce Document lifecycle state machine 2026-05-05 09:38:39 +02:00
models.py feat(#202): introduce Document lifecycle state machine 2026-05-05 09:38:39 +02:00
ports.py feat(#202): introduce Document lifecycle state machine 2026-05-05 09:38:39 +02:00
services.py fix(arch): inject repositories and extract domain logic 2026-04-10 11:44:33 +02:00
value_objects.py feat(#202): introduce Document lifecycle state machine 2026-05-05 09:38:39 +02:00
vector_schema.py feat(domain): add VectorStore port and SearchResult value object 2026-04-10 20:40:17 +02:00