[Backend] Custom Steps Enhancement - Usage Tracking #38

Closed
opened 2026-02-07 22:49:38 +00:00 by chihlasm · 1 comment
chihlasm commented 2026-02-07 22:49:38 +00:00 (Migrated from github.com)

Enhance session custom_steps JSONB field to track step library usage and enable future save session as tree feature.

Design Document: docs/plans/2026-02-07-foundational-schema-design.md (Part 2)

JSONB Enhancement (No Migration Required)

Add optional fields to custom_steps array for tracking:

  • source: ad-hoc | step-library | forked-tree
  • source_step_id: UUID if from library
  • inserted_at: ISO datetime
  • inserted_after_node_id: tree node ID

Pydantic Schema Update

Add fields to CustomStepSchema with defaults for backward compatibility

Usage Tracking Logic

When engineer inserts library step into session:

  1. Add to custom_steps with full metadata
  2. Create StepUsageLog entry immediately
  3. Increment StepLibrary.usage_count
  4. Multiple insertions create multiple log entries

Step Library Reference Handling

  • Deleted steps: source_step_id remains (orphaned UUID)
  • No FK constraint (data in JSONB)
  • Analytics can count historical usage

Acceptance Criteria

  • CustomStepSchema updated with new fields
  • Old sessions load without error (backward compat)
  • Insert from library creates StepUsageLog entry
  • usage_count incremented correctly
  • Multiple insertions counted separately
  • source_step_id preserved after step deletion
  • Ad-hoc steps default to source=ad-hoc

Related: Issues #4-#7 partial, foundational schema work

Enhance session custom_steps JSONB field to track step library usage and enable future save session as tree feature. Design Document: docs/plans/2026-02-07-foundational-schema-design.md (Part 2) JSONB Enhancement (No Migration Required) Add optional fields to custom_steps array for tracking: - source: ad-hoc | step-library | forked-tree - source_step_id: UUID if from library - inserted_at: ISO datetime - inserted_after_node_id: tree node ID Pydantic Schema Update Add fields to CustomStepSchema with defaults for backward compatibility Usage Tracking Logic When engineer inserts library step into session: 1. Add to custom_steps with full metadata 2. Create StepUsageLog entry immediately 3. Increment StepLibrary.usage_count 4. Multiple insertions create multiple log entries Step Library Reference Handling - Deleted steps: source_step_id remains (orphaned UUID) - No FK constraint (data in JSONB) - Analytics can count historical usage Acceptance Criteria - CustomStepSchema updated with new fields - Old sessions load without error (backward compat) - Insert from library creates StepUsageLog entry - usage_count incremented correctly - Multiple insertions counted separately - source_step_id preserved after step deletion - Ad-hoc steps default to source=ad-hoc Related: Issues #4-#7 partial, foundational schema work
chihlasm commented 2026-02-08 00:40:54 +00:00 (Migrated from github.com)

Completed in PR #39. CustomStepSchema updated with source (ad-hoc/step-library/forked-tree), source_step_id, inserted_at, and inserted_after_node_id fields. Backward compatible with existing session JSONB data.

Completed in PR #39. `CustomStepSchema` updated with `source` (ad-hoc/step-library/forked-tree), `source_step_id`, `inserted_at`, and `inserted_after_node_id` fields. Backward compatible with existing session JSONB data.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: chihlasm/resolutionflow#38