{"record":{"id":"dcdf27070a92375b","repo":"sipeed/picoclaw","slug":"apply-draft-failed","errorCode":null,"errorMessage":"apply draft failed","messagePattern":"apply draft failed","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/evolution/runtime.go","lineNumber":22,"sourceCode":"\t\"context\"\n\t\"crypto/sha1\"\n\t\"encoding/hex\"\n\t\"errors\"\n\t\"fmt\"\n\t\"os\"\n\t\"path/filepath\"\n\t\"sort\"\n\t\"strings\"\n\t\"sync\"\n\t\"time\"\n\t\"unicode/utf8\"\n\n\t\"github.com/sipeed/picoclaw/pkg/config\"\n\t\"github.com/sipeed/picoclaw/pkg/logger\"\n\t\"github.com/sipeed/picoclaw/pkg/skills\"\n)\n\nvar ErrApplyDraftFailed = errors.New(\"apply draft failed\")\n\ntype RuntimeOptions struct {\n\tConfig              config.EvolutionConfig\n\tNow                 func() time.Time\n\tStore               *Store\n\tOrganizer           *Organizer\n\tPatternClusterer    PatternClusterer\n\tSuccessJudge        SuccessJudge\n\tSkillsRecaller      *SkillsRecaller\n\tDraftGenerator      DraftGenerator\n\tGeneratorFactory    func(workspace string) DraftGenerator\n\tSuccessJudgeFactory func(workspace string) SuccessJudge\n\tApplier             *Applier\n\tApplierFactory      func(workspace string) *Applier\n}\n\ntype Runtime struct {\n\tcfg                 config.EvolutionConfig","sourceCodeStart":4,"sourceCodeEnd":40,"githubUrl":"https://github.com/sipeed/picoclaw/blob/49183d7e8daed0dba89ddbb6fcb60089401d9680/pkg/evolution/runtime.go#L4-L40","documentation":"Umbrella error from the evolution Runtime's apply step (applyCandidateDraft): the draft failed to apply via applier.applyDraftWithRollback, or post-apply persistence (SaveDrafts / SaveAppliedProfile) failed even after rollback was attempted. The real cause is appended with %v and often errors.Join-ed with audit/save errors; the draft is marked DraftStatusQuarantined and the reason is appended to draft.ScanFindings (\"apply failed: ...\").","triggerScenarios":"Runtime evolution run where the generated SkillDraft fails to write/scan against workspace skill files, the evolution store file is unwritable or corrupt, or the post-apply profile save fails after files changed (triggering rollback, whose error is joined too).","commonSituations":"Workspace skills directory read-only or skill file missing for an update draft (TargetSkillName not found); $PICOCLAW_HOME store on a full disk or with wrong ownership; draft content produced by the generator rejected by the apply-time scan; concurrent runs writing the store.","solutions":["Read the joined error chain and draft.ScanFindings — the tail after 'apply draft failed:' names the actual cause (apply error, save error, or rollback error)","Verify the workspace skills directory is writable and that draft.TargetSkillName exists for update/change drafts","Check the evolution store under PICOCLAW_HOME: permissions, disk space, no concurrent gateway instances (see pid file singleton)","The failed draft is quarantined automatically and skipped by later runs — fix the root cause, then regenerate/re-run the evolution run instead of retrying the same quarantined draft"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// before triggering an evolution run\nif err := checkWorkspaceWritable(workspaceSkillsDir); err != nil { return err }\nif err := store.Load(); err != nil { return err } // store must be readable","typeGuard":"func isApplyDraftFailed(err error) bool {\n    return errors.Is(err, evolution.ErrApplyDraftFailed)\n}","tryCatchPattern":"draft, err := rt.RunEvolution(ctx) // or the apply entry point\nif err != nil {\n    if errors.Is(err, evolution.ErrApplyDraftFailed) {\n        // inspect draft.ScanFindings for 'apply failed: ...'; draft is quarantined,\n        // so fix the root cause and start a new run — do not retry the same draft\n    }\n    return err\n}","preventionTips":["Keep the workspace skills directory and PICOCLAW_HOME store writable by the gateway user","Run one evolution cycle at a time (the PID-file singleton also guards this)","Monitor draft.Status == quarantined counts as an early signal of apply problems"],"tags":["evolution","skills","persistence","rollback"],"backgroundTag":null,"analyzedSha":"49183d7e8daed0dba89ddbb6fcb60089401d9680","analyzedAt":"2026-08-15T21:55:41.315Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}