Skip to content

Remove legacy client patch flow / self-heal #62

@mateicanavra

Description

@mateicanavra

TL;DR

Remove legacy client-side patch orchestration and "self-heal" helpers. Move retry logic server-side for single source of truth.

Context

During PER-19 extraction work, we identified that use-patch-application.ts contains retryWithValidationErrors logic (lines 114-265) that duplicates server-side capabilities. The server's assistant-service.ts already validates patches, but the client still carries legacy retry orchestration.

Current state:

  • Server validates patches in assistant-service.ts
  • Client has retryWithValidationErrors in extracted use-patch-application.ts
  • Invalid responses surface as UI text but don't trigger server-side repair
  • Dead code and duplicated logic between client and server

Goals

  • Single source of truth for patch generation/validation/retry on server
  • Client reduced to: display + apply + stale/expired handling
  • No loss of current behaviors (retry on invalid, stale detection, apply-time validation)

Plan

  1. Server: add auto-repair loop in assistant-service.ts
    • When buildPatchTransactionFromResponse returns invalid, re-prompt with repair prompt
    • Cap retries (1 pass), surface second invalid as-is with reasons
  2. Server: standardize error payloads
    • Structured errors (type/message/fix) compatible with existing UI
  3. Client: trim legacy orchestration
    • Remove retryWithValidationErrors from use-patch-application.ts
    • Keep UI messaging for invalid/noop/missing-target
    • Retain apply-time stale handling only
  4. Contracts & types
    • Update shared types if repair path adds fields (e.g., attempt: "initial" | "repair")
  5. Tests
    • Unit tests for server repair flow
    • Integration tests for client handling of invalid payloads

Acceptance Criteria

  • Invalid responses trigger exactly one server-side repair attempt
  • Client no longer issues generation-time retries
  • Stale/expired handling still works
  • No unused self-heal helpers in apps/web patch flows
  • Tests cover repair success/fail and client handling

References

  • docs/projects/slides-v0/issues/remove-legacy-client-patch-flow.md
  • apps/web/src/features/slideshow/hooks/use-patch-application.ts
  • packages/api/src/slideshow/assistant-service.ts

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions