Skip to content

F004: Persistance d'État JSON #6

@pocky

Description

@pocky

Metadata

  • Status: done
  • Phase: 1-MVP
  • Version: v0.1.0
  • Priority: high
  • Estimation: M

Description

Persist workflow execution state to JSON files. Save state after each step completion for crash recovery. Support atomic writes to prevent corruption. Enable workflow resumption from persisted state.

Acceptance Criteria

  • Save state after each step completion
  • Atomic writes (temp file + rename)
  • Load state from file
  • State includes all execution context
  • File locking for concurrent access prevention
  • Implements StateStore port interface

Dependencies

  • Blocked by: F001, F003
  • Unblocks: F013

Impacted Files

internal/infrastructure/store/json_store.go      # NEW
internal/infrastructure/store/json_store_test.go # NEW
internal/application/execution_service.go        # MODIFIED (checkpoint)
internal/domain/ports/store.go                   # EXISTING (interface)
storage/states/

Technical Tasks

  • Define State struct (using existing ExecutionContext)
    • workflow_id, workflow_name, workflow_version
    • status (pending, running, completed, failed)
    • current_state
    • started_at, updated_at, completed_at
    • inputs map
    • states map (per-state results)
  • Implement JSONStore
    • Save(state) with atomic write
    • Load(workflowID)
    • Delete(workflowID)
    • List() for resumable workflows
  • Implement atomic write
    • Write to temp file
    • os.Rename for atomic replace
  • Implement file locking
    • syscall.Flock for exclusive access
  • Implement checkpoint in ExecutionService
    • Checkpoint after each step
    • Checkpoint on completion/failure
  • Write unit tests (14 tests)
  • Write integration tests (1 checkpoint test)

Notes

State file location: storage/states/{workflow-id}.json

Atomic write pattern:

tmpFile := stateFile + ".tmp"
os.WriteFile(tmpFile, data, 0600)
os.Rename(tmpFile, stateFile) // Atomic on POSIX

Implementation Summary

  • JSONStore implements ports.StateStore interface
  • Atomic writes via temp file + os.Rename
  • File locking via syscall.Flock(LOCK_EX)
  • ExecutionService.checkpoint() saves state after each step
  • 14 unit tests + 1 integration test (all passing)

Synced from docs/plans/features/v0.1.0/F004-json-state-persistence.md

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureFeature specificationv0.1.0Version v0.1.0

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions