zai-org / zai-org/feedback

[Feature Request] AutoClaw Smart-Recovery: Scope-Aware Validation & Checkpoint Resume

Open
#248 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

priority: P2
Dominant language
No language data
Stars
22
Forks
1
PR merge metrics
No merged PRs in 30d

Description

Feature Request: AutoClaw Smart-Recovery Improvements

πŸ“‹ Summary

Scope-aware replacement validation, checkpoint-based resume with user confirmation, and partial success extraction for AutoClaw agent tasks that fail due to overly broad code modifications.


πŸ” Problem Description

Observed Failure Pattern

When executing complex multi-step tasks (e.g., PPT generation with 25+ slides), AutoClaw agents can make overly broad string replacements that break valid code patterns:

❌ Agent Action: Replace all "inches" occurrences
βœ… Result: Broke valid `.inches` calls on actual `Inches` objects from python-pptx
βœ… Cascade: New bugs introduced β†’ auto-recovery fails β†’ task incomplete
Evidence from Production Failure

Screenshot captured: PPT Generator task showing:

"That replacement was too broad β€” it broke valid .inches calls on actual Inches objects. Let me rewrite the problematic arithmetic patterns properly."

"The task still could not finish after automatic recovery. You can retry, and I'll continue from the existing results without blindly repeating completed actions."

Deliverables produced:

  • build_new_deck.py β€” initial attempt (partial)
  • build_new_deck_v2.py β€” recovery attempt (still partial)
Root Causes Identified
Cause Impact Frequency
Overly broad regex replacements Breaks unrelated code using similar patterns High in python-pptx, reportlab tasks
No scope validation before apply Agent cannot predict side effects of edits Common in subagent-driven development
Blind retry without user input Repeats or compounds previous mistakes ~40% of recovery attempts
No partial extraction on failure Working deliverables trapped in failed session User loses salvageable work

βœ… Proposed Solutions

Feature 1: Scope-Aware Replacement Validator

Description: Before applying any string/regex replacement, validate that changes are scoped correctly.

def validate_replacement(old_code, new_code, pattern, target_scope):
    """
    Validate that a replacement only affects intended scope.
    
    Args:
        old_code: Original source code
        new_code: Modified source code  
        pattern: The regex/string being replaced
        target_scope: List of functions/classes that SHOULD be affected
    
    Returns:
        (is_valid, reason) tuple
    """
    affected = find_affected_symbols(old_code, new_code)
    unintended = [s for s in affected if s not in target_scope]
    
    if unintended:
        return False, f"Replacement would affect {unintended} outside target scope"
    if breaks_type_annotations(new_code):
        return False, "Preserves attribute access patterns (.inches, .width, etc.)"
    if breaks_import_statements(new_code):
        return False, "Modifies import statements indirectly"
    
    return True, "Scope validated"

Behavior:

  • Agent proposes replacement β†’ validator checks scope β†’ warns if too broad
  • Agent must narrow pattern or explicitly confirm override
  • Configurable strictness level (strict/lenient/off)
Feature 2: Checkpoint-Based Resume with Confirmation

Description: Insert explicit save-points during long-running tasks; require user approval before recovery retries.

Checkpoint Triggers:

  • After each major section/phase completion
  • Before any bulk replacement operation
  • After N successful tool calls (configurable, default=10)
  • When token usage exceeds threshold

Resume Flow:

Task Fails at Step 12/25
    ↓
AutoClaw saves checkpoint: "slides_11_complete.pptx"
    ↓
Prompt user:
    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
    β”‚ ⚠️ Task failed at slide 12          β”‚
    β”‚ βœ“ Slides 1-11 saved successfully   β”‚
β”‚                                      β”‚
    β”‚ [Retry from checkpoint]  [Abort]   β”‚
    β”‚ [View error details]   [Edit fix]  β”‚
    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
    ↓
User selects option β†’ AutoClaw continues intelligently
Feature 3: Partial Success Extraction

Description: On task failure, automatically extract and preserve all working deliverables.

Implementation:

extraction_rules:
  - pattern: "*.py"
    action: save_to_deliverables
    condition: syntax_valid
  - pattern: "*.pptx"
    action: save_and_verify
    condition: file_opens_without_error
  - pattern: "*.json"
    action: save_always
    condition: null  # always save config/state files

on_failure:
  - run_tests_on_deliverables
  - generate_failure_report:
      include: [error_log, completed_steps, remaining_steps, suggested_fix]
  - offer_resume_options

User Benefit: Never lose work β€” even failed sessions produce usable artifacts.

Feature 4: Smart Retry Strategy

Description: Instead of blind retry, analyze failure cause and adapt approach.

Decision Matrix:

Failure Type Smart Response
Broad replacement broke code Narrow regex scope; exclude imports/types
Import statement corrupted Restore imports from original; only redo logic
Syntax error in generated code Run linter before next attempt; fix lint errors first
Token limit exceeded Compress context; summarize completed work
External API failure Exponential backoff; switch endpoint if available

🎯 Use Cases

Primary: Document Generation (pptx/docx/pdf)
  • Prevent .inches, .width, .Emu attribute corruption in python-pptx
  • Preserve reportlab dimension calculations
  • Allow partial PPT extraction when later slides fail
Secondary: Full-Stack Development
  • Prevent import statement corruption during refactoring
  • Validate database migration changes don't affect models
  • Extract working endpoints when integration tests fail
Tertiary: Data Processing Pipelines
  • Checkpoint after each ETL stage
  • Recover from transformation errors without re-running extraction
  • Preserve intermediate data artifacts

πŸ“Š Success Metrics

Metric Current State Target State
Task completion rate (complex tasks) ~60% >85%
Recovery success rate ~40% >75%
Work lost on failure 0% salvaged >90% extracted
User intervention required Post-failure manual Pre-retry confirmation
Average retries to success 2-3 blind retries 1 smart retry

πŸ”„ Implementation Priority

Priority Feature Effort Impact
P0 Partial Success Extraction Low High
P0 Smart Retry Strategy Medium High
P1 Checkpoint-Based Resume Medium High
P2 Scope-Aware Validator High Medium

Recommended MVP: Ship P0 features first β€” they provide immediate value with minimal complexity.


πŸ§ͺ Testing Scenarios

  1. PPT Generation Test: Run 25-slide creation; intentionally trigger broad replacement; verify v2 script is extracted
  2. Recovery Resume Test: Fail at step 10; verify checkpoint resume skips steps 1-9
  3. Scope Validation Test: Attempt to replace inches globally; verify warning triggers
  4. Partial Extraction Test: Generate 3 deliverables; fail on 4th; verify first 3 are preserved

πŸ’‘ Additional Context

  • Related Discord Thread: GLM Coding Pro quota/billing discussion (where this failure was reported)
  • Affected Component: AutoClaw agent system / ZCode IDE
  • Reporter Experience: Intermediate user running autopilot skill for document generation
  • Workaround Available: Manual script execution + targeted retry prompt (not intuitive)

Submitted by:
Regards,
Roman (Discord: bignavi_x)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up β€” it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No repository files, tests, or implementation entry points are named. Start by locating the AutoClaw recovery, retry, checkpoint, and deliverable-handling entry points, then scope the work around the proposed P0 features. Use the listed PPT generation, recovery resume, and partial extraction scenarios to define what β€œdone” means.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
ai, devtools
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.