Skip to content

Add self-improving retries for effect generation with versioned prompt templates#359

Open
smcga wants to merge 1 commit intomainfrom
codex/implement-self-improvement-protocol-for-failed-effects
Open

Add self-improving retries for effect generation with versioned prompt templates#359
smcga wants to merge 1 commit intomainfrom
codex/implement-self-improvement-protocol-for-failed-effects

Conversation

@smcga
Copy link
Copy Markdown
Owner

@smcga smcga commented Apr 8, 2026

Motivation

  • Improve observability and robustness of model-generated effect creation by recording failed attempts and enabling automatic, bounded self-improvement of the generator prompt template.
  • Allow prompt template updates at runtime (with version history) so operators can inspect and evolve the system prompt over time.
  • Reduce friction for users by automatically retrying generation after a failure and surface concise status/attempt information in the UI.

Description

  • Introduced a KV-backed prompt-template store and versioning under effects:generate:prompt-template and a failure log stream effects:generate:failure-logs, with sanitization and seeding logic (new types and helpers in api/effects.ts).
  • Reworked server generation flow (POST /api/effects?action=generate) to run a bounded self-improvement loop (configurable constant MAX_SELF_IMPROVEMENT_ATTEMPTS = 5) that: logs failures, requests a prompt-template tweak from the model, appends the new template as a version, and retries generation; includes a leak-guard to prevent copying user idea text into templates.
  • Persisted failure diagnostics (timestamp, requestId, exact template text used, full model response, user-visible error, attempt index) to KV via effects:generate:failure-logs and surface self-improvement metadata in API JSON responses under selfImprovement.
  • Added requestResponsesApi / requestPromptTemplateImprovement helpers to centralize calls to the Responses API and to request prompt-template improvements.
  • Updated client plumbing (src/effectIdeas.ts) and UI (src/main.ts) to propagate and display selfImprovement metadata, remove the manual retry dependence, show clearer busy/error copy, and display attempt counters in the busy/error modal; removed retry-button click wiring.
  • Added/updated tests to cover the new behavior and persisted artifacts (api/effects.test.ts, src/effectIdeas.test.ts), and updated README.md to document the prompt-template KV key and failure-log stream.

Testing

  • Ran unit tests: npm test -- api/effects.test.ts src/effectIdeas.test.ts src/style.test.ts and all tests passed (42 tests, all green).
  • Added tests that assert: self-improvement metadata appears in API responses, prompt-template store is updated (effects:generate:prompt-template), failure logs are appended (effects:generate:failure-logs), and the client surfaces attempt info; these tests passed as part of the run.
  • Verified existing generation/monitoring tests still pass after changes.

Codex Task

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 8, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
codexperimental Ready Ready Preview, Comment Apr 8, 2026 11:27pm

Request Review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant