feat: Add state lifecycle ops#26
Open
so0k wants to merge 11 commits into
Open
Conversation
Contributor
so0k
commented
Dec 9, 2025
- feat: Init lifecycle specs
- chore: initial task generation
- chore: run cross reference validation
- chore: complete setup phase and start foundation
Create initial specs on state lifecycle operations with research and plan
identify inconsistencies and correct them
1. Proto Definitions (grid-asc3.1.1) ✅
- Added 4 lifecycle RPCs: RenameState, TombstoneState, RestoreState,
PurgeState
- Added StateLifecycleStatus enum (ACTIVE, TOMBSTONED)
- Added lifecycle fields to StateInfo and ListStatesRequest
- File: proto/state/v1/state.proto:132-1049
2. Code Generation (grid-asc3.1.2) ✅
- Ran buf generate successfully
- Go and TypeScript code regenerated
3. Auth Actions (grid-asc3.1.3) ✅
- Added 4 action constants: StateRename, StateTombstone, StateRestore,
StatePurge
- Updated ValidateAction() and ExpandWildcard()
- File: cmd/gridapi/internal/auth/actions.go:25-35,166-223
4. State Model (grid-asc3.1.4) ✅
- Added lifecycle fields: Status, TombstonedAt, TombstonedBy,
RetentionDays
- Added helper methods: IsTombstoned(), IsActive(), PurgeEligibleAt(),
IsPurgeEligible()
- File: cmd/gridapi/internal/db/models/state.go:16-160
5. Database Migration (grid-asc3.1.5) ✅
- Created migration 20251208000000_add_lifecycle.go
- Adds 4 columns + 2 indexes with PostgreSQL/SQLite compatibility
- File: cmd/gridapi/internal/migrations/20251208000000_add_lifecycle.go
6. Repository Interface (grid-asc3.1.6) ✅
- Added 6 lifecycle methods to StateRepository interface
- Added error constants: ErrConcurrentModification, ErrNotFound
- File: cmd/gridapi/internal/repository/interface.go:11-67
7. Repository Implementation (grid-asc3.1.7) ✅
- Implemented all 6 lifecycle methods in BunStateRepository
- Includes optimistic locking, status validation, dependent checking
8. Seed Policy Update (grid-di2z) ✅
- Added lifecycle action policies for product-engineer role (scoped to
env=="dev")
- File:
cmd/gridapi/internal/migrations/20251203000000_init_schema.go:385-389
9. Retention Config (grid-v3sy) ✅
- Added RetentionDays field to Config (default: 30 days)
- Added GRID_RETENTION_DAYS env var support
- Files: cmd/gridapi/internal/config/config.go:32-34,174,
cmd/gridapi/cmd/serve.go:96
10. StateService Lifecycle Methods (grid-asc3.2.2) ✅
- Implemented 4 lifecycle methods: RenameState(), TombstoneState(),
RestoreState(), PurgeState()
- Added lifecycle fields to StateSummary and StateInfo types
- Business logic includes:
- Lock validation
- Active dependent checking (FR-011)
- Retention period enforcement
- Optimistic locking for renames
- File: cmd/gridapi/internal/services/state/service.go:26-928
- File: cmd/gridapi/internal/repository/bun_state_repository.go:474-634
Implement state renaming with optimistic locking, tombstone filtering, and comprehensive test coverage. Completes Phase 2 foundational work and US1 rename functionality. Phase 2 - Foundational: - Add tombstone check to HTTP backend middleware (410 Gone) - Implement ListStates tombstone filtering (active by default) - Update repository ListWithFilter to support status filtering User Story 1 - Rename State: - Add RenameState RPC with optimistic locking via updated_at - Authorization: Dynamic label-based permission checking - Handler: Validates locks, checks name uniqueness, handles concurrent mods - SDK: RenameState method with StateReference pattern - CLI: gridctl state rename command with auto-context update - Error mapping: ABORTED code for concurrent modifications Additional Features: - gridctl state list --all flag shows tombstoned states with [DELETED] - FR-012: Prevent adding dependencies to tombstoned states - Lifecycle fields in StateSummary (status, tombstoned_at) Test Coverage: - Integration: Rename happy path, existing name conflict, concurrent requests - Repository: Optimistic locking with ErrConcurrentModification - Repository: Fresh vs stale timestamp handling - Data integrity validation under concurrent load All tests passing. US1 complete. Closes: grid-asc3.2, grid-asc3.3, grid-asc3.4.9, grid-likw, grid-z6k7, grid-9bm0
implement authz, handlers, sdk, cli and integration tests
Implement permanent deletion (purge) of tombstoned states with retention
period enforcement and force override capability.
Core Implementation (7/9 tasks - 78%):
- Authorization: PurgeState authz interceptor with label-scoped
permissions
- Handler: PurgeState Connect RPC with force flag support
- SDK: PurgeState method accepting StateReference and force bool
- CLI: Added --purge and --force flags to `gridctl state delete`
- Tests: 3 integration tests validating all error paths and happy path
Integration Tests (all passing):
- TestPurgeState_ActiveFails: Validates FR-016 (reject purge on active)
- TestPurgeState_WithinRetentionFails: Validates FR-014 (retention
enforced)
- TestPurgeState_ForcePurgeSucceeds: Validates FR-015 (force override)
and FR-017 (logic_id reuse)
Functional Requirements Validated:
- FR-013: Purge only tombstoned states ✓
- FR-014: Retention period enforced (default: 30 days) ✓
- FR-015: Force flag bypasses retention ✓
- FR-016: Reject purge on non-tombstoned states ✓
- FR-017: Logic_id reusable after purge ✓
- FR-019: CLI purge command ✓
Service Layer (from Session 01):
- StateService.PurgeState() with retention check and force override
- Repository Delete() with CASCADE DELETE for outputs and edges
- State model methods: IsTombstoned(), IsPurgeEligible(),
PurgeEligibleAt()
Deferred (slow tests - 2/9 tasks):
- grid-asc3.5.8: Purge past retention (requires 30s wait)
- grid-asc3.5.9: Restore past retention fails (requires 30s wait)
- Tagged with test:slow for manual execution
- Core functionality already validated via force purge tests
Complete Lifecycle: Create → Rename → Tombstone → Restore → Purge ✓
Files modified:
- cmd/gridapi/internal/middleware/authz_interceptor.go
- cmd/gridapi/internal/server/connect_handlers.go
- pkg/sdk/state_client.go
- pkg/sdk/state_types.go
- cmd/gridctl/cmd/state/delete.go
- tests/integration/lifecycle_test.go
Breaking changes: None
Database changes: None (uses existing lifecycle columns)
Build status: All components compile ✓
Test status: All integration tests passing (56.4s) ✓
Closes: grid-asc3.5.1, grid-asc3.5.2, grid-asc3.5.3, grid-asc3.5.4,
grid-asc3.5.5, grid-asc3.5.6, grid-asc3.5.7
Related: grid-asc3 (State Lifecycle Operations)k
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.