Skip to content

Reset-preserve-state operation (S3) #384

Closed

Description

@vybe

Summary

New endpoint to adopt latest upstream (main) while preserving agent-specific state files.

Context

Problem P2/P3: When parallel history exists, both UI options ("Pull First" / "Force Push") make things worse. The only valid recovery is: adopt main as baseline, overlay workspace state, push to working branch. Currently requires SSH access.

Acceptance Criteria

New endpoint

  • POST /api/agents/{name}/git/reset-to-main-preserve-state
  • Backend proxies to agent server

Guardrails

  • ALWAYS snapshot persistent-state files to .trinity/backup/<timestamp>/ before reset
  • Create tar archive downloadable via Files panel
  • Refuse if agent has no git config
  • Refuse if agent is currently running a task (check activity service)

Agent-server implementation

  • New endpoint proxied from backend
  • Uses S4's _reset_preserving_persistent_state() subroutine
  • Commits "Adopt main baseline, preserve state"
  • Pushes with --force-with-lease

New agent-server primitives

  • POST /api/agent-server/snapshot?paths=... — returns tarball of matched files
  • POST /api/agent-server/restore — restore from tarball with path allowlist

Response

{
  "success": true,
  "files_preserved": ["workspace/decisions.csv", ".trinity/config.yaml", ...],
  "commit_sha": "abc123",
  "backup_path": ".trinity/backup/2026-04-18T..."
}

Technical Notes

Depends on #383 (S4 persistent state allowlist).

Files to modify:

  • src/backend/routers/git.py — new endpoint
  • src/backend/services/git_service.py — proxy logic
  • docker/base-image/agent_server/routers/git.py — implementation
  • docker/base-image/agent_server/routers/files.py — snapshot/restore primitives

Part of Epic #381

Activity

  1. added
    priority-p1
    type-feature
    on Apr 18, 2026
  2. 42 remaining items

  3. added 4 commits that reference this issue on Apr 22, 2026
  4. added
    complexity-medium
    theme-reliability
    on Jun 3, 2026
  5. added a commit that references this issue on Sep 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    complexity-mediumpriority-p1theme-reliabilitytype-feature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions