feat(resource): implement ResourceHandler sandbox and checkpoint methods #1067

Merged
hamza.khyari merged 1 commit from feature/resource-handler-sandbox into master 2026-03-27 11:08:54 +00:00
Member

Summary

  • Extend the ResourceHandler protocol with four sandbox/lifecycle methods: create_sandbox, create_checkpoint, rollback_to, and project_access
  • Add frozen dataclass result types (SandboxResult, CheckpointResult, RollbackResult, AccessResult) to the handler protocol
  • Implement checkpoint/rollback for GitCheckoutHandler (git tag / git checkout) and FsDirectoryHandler (shutil.copytree snapshot / clear-and-restore)
  • Default create_sandbox delegates to SandboxManager (idempotent — returns existing sandbox on second call)
  • Default project_access delegates to PermissionService (local mode = always permit)
  • 8 Behave scenarios + 2 Robot integration tests covering the full checkpoint -> modify -> rollback cycle

Details

Protocol Extension (protocol.py)

  • SandboxResultsandbox_id, sandbox_path, strategy, created (idempotency flag), message
  • CheckpointResultcheckpoint_id, plan_id, timestamp, snapshot_path, message
  • RollbackResultsuccess, checkpoint_id, restored_files, message
  • AccessResultpermitted, principal, action, scope, reason

Base Handler (_base.py)

  • create_sandbox(): delegates to SandboxManager.get_or_create_sandbox(), checks for existing sandbox first (idempotent)
  • project_access(): delegates to PermissionService.check_permission(), falls back to local-mode permit
  • create_checkpoint() / rollback_to(): raise NotImplementedError (subclasses override)
  • _resolve_strategy_str() helper extracted for DRY strategy resolution

Handler Implementations

  • GitCheckoutHandler: create_checkpoint via git tag checkpoint-{plan_id}-{timestamp}, rollback_to via git checkout {tag} -- . with restored file count from git diff --name-only
  • FsDirectoryHandler: create_checkpoint via shutil.copytree to temp snapshot dir, rollback_to via clear sandbox + copy snapshot back. In-process _checkpoints ClassVar store.
  • DatabaseResourceHandler: inherits NotImplementedError stubs (no savepoint infrastructure exists)

Tests

  • 8 Behave scenarios: sandbox creation (+ idempotency), checkpoint/rollback cycle for FsDirectory and GitCheckout, project_access in local mode, NotImplementedError defaults for Database handler
  • 2 Robot integration tests: full checkpoint -> modify -> rollback cycle on real temp directories and git repos

ISSUES CLOSED: #836

## Summary - Extend the `ResourceHandler` protocol with four sandbox/lifecycle methods: `create_sandbox`, `create_checkpoint`, `rollback_to`, and `project_access` - Add frozen dataclass result types (`SandboxResult`, `CheckpointResult`, `RollbackResult`, `AccessResult`) to the handler protocol - Implement checkpoint/rollback for `GitCheckoutHandler` (git tag / git checkout) and `FsDirectoryHandler` (shutil.copytree snapshot / clear-and-restore) - Default `create_sandbox` delegates to `SandboxManager` (idempotent — returns existing sandbox on second call) - Default `project_access` delegates to `PermissionService` (local mode = always permit) - 8 Behave scenarios + 2 Robot integration tests covering the full checkpoint -> modify -> rollback cycle ## Details ### Protocol Extension (`protocol.py`) - `SandboxResult` — `sandbox_id`, `sandbox_path`, `strategy`, `created` (idempotency flag), `message` - `CheckpointResult` — `checkpoint_id`, `plan_id`, `timestamp`, `snapshot_path`, `message` - `RollbackResult` — `success`, `checkpoint_id`, `restored_files`, `message` - `AccessResult` — `permitted`, `principal`, `action`, `scope`, `reason` ### Base Handler (`_base.py`) - `create_sandbox()`: delegates to `SandboxManager.get_or_create_sandbox()`, checks for existing sandbox first (idempotent) - `project_access()`: delegates to `PermissionService.check_permission()`, falls back to local-mode permit - `create_checkpoint()` / `rollback_to()`: raise `NotImplementedError` (subclasses override) - `_resolve_strategy_str()` helper extracted for DRY strategy resolution ### Handler Implementations - **GitCheckoutHandler**: `create_checkpoint` via `git tag checkpoint-{plan_id}-{timestamp}`, `rollback_to` via `git checkout {tag} -- .` with restored file count from `git diff --name-only` - **FsDirectoryHandler**: `create_checkpoint` via `shutil.copytree` to temp snapshot dir, `rollback_to` via clear sandbox + copy snapshot back. In-process `_checkpoints` ClassVar store. - **DatabaseResourceHandler**: inherits `NotImplementedError` stubs (no savepoint infrastructure exists) ### Tests - 8 Behave scenarios: sandbox creation (+ idempotency), checkpoint/rollback cycle for FsDirectory and GitCheckout, project_access in local mode, NotImplementedError defaults for Database handler - 2 Robot integration tests: full checkpoint -> modify -> rollback cycle on real temp directories and git repos ISSUES CLOSED: #836
hamza.khyari added this to the v3.6.0 milestone 2026-03-19 04:17:07 +00:00
Owner

Day 43 Review — Rebase Required

This PR has merge conflicts with master and cannot be merged in its current state. This is one of 9 Hamza PRs in the resource/LSP domain (v3.5.0-v3.6.0) that all have conflicts. These PRs likely share a common dependency chain and should be rebased sequentially.

@hamza.khyari: Please rebase onto current master. If multiple PRs depend on each other, start with the base PR in the chain and work upward.

Rebase priority: HIGH — these PRs represent significant feature work that is blocked by merge conflicts. Every day they remain conflicted is a day they cannot be reviewed or merged.

**Day 43 Review — Rebase Required** This PR has merge conflicts with `master` and cannot be merged in its current state. This is one of 9 Hamza PRs in the resource/LSP domain (v3.5.0-v3.6.0) that all have conflicts. These PRs likely share a common dependency chain and should be rebased sequentially. @hamza.khyari: Please rebase onto current `master`. If multiple PRs depend on each other, start with the base PR in the chain and work upward. **Rebase priority**: HIGH — these PRs represent significant feature work that is blocked by merge conflicts. Every day they remain conflicted is a day they cannot be reviewed or merged.
freemo approved these changes 2026-03-24 15:29:25 +00:00
Dismissed
freemo left a comment

Review: APPROVED

ResourceHandler sandbox and checkpoint methods implementation. Feature follows project conventions.

## Review: APPROVED ResourceHandler sandbox and checkpoint methods implementation. Feature follows project conventions.
hamza.khyari force-pushed feature/resource-handler-sandbox from e9ed73d148
Some checks failed
CI / lint (pull_request) Successful in 16s
CI / benchmark-publish (pull_request) Has been skipped
CI / quality (pull_request) Successful in 38s
CI / typecheck (pull_request) Successful in 53s
CI / security (pull_request) Successful in 54s
CI / build (pull_request) Successful in 41s
CI / unit_tests (pull_request) Failing after 3m21s
CI / docker (pull_request) Has been skipped
CI / integration_tests (pull_request) Failing after 3m47s
CI / e2e_tests (pull_request) Successful in 3m52s
CI / coverage (pull_request) Failing after 6m54s
CI / benchmark-regression (pull_request) Successful in 37m32s
to f8f85b1bc3
Some checks failed
CI / benchmark-publish (pull_request) Has been skipped
CI / build (pull_request) Successful in 28s
CI / lint (pull_request) Successful in 3m20s
CI / quality (pull_request) Successful in 3m51s
CI / typecheck (pull_request) Successful in 3m56s
CI / security (pull_request) Successful in 4m4s
CI / integration_tests (pull_request) Failing after 4m17s
CI / unit_tests (pull_request) Failing after 4m36s
CI / docker (pull_request) Has been skipped
CI / e2e_tests (pull_request) Successful in 8m27s
CI / benchmark-regression (pull_request) Has been cancelled
CI / coverage (pull_request) Has been cancelled
CI / status-check (pull_request) Has been cancelled
2026-03-25 12:10:01 +00:00
Compare
hamza.khyari dismissed freemo's review 2026-03-25 12:10:01 +00:00
Reason:

New commits pushed, approval review dismissed automatically according to repository settings

hamza.khyari force-pushed feature/resource-handler-sandbox from f8f85b1bc3
Some checks failed
CI / benchmark-publish (pull_request) Has been skipped
CI / build (pull_request) Successful in 28s
CI / lint (pull_request) Successful in 3m20s
CI / quality (pull_request) Successful in 3m51s
CI / typecheck (pull_request) Successful in 3m56s
CI / security (pull_request) Successful in 4m4s
CI / integration_tests (pull_request) Failing after 4m17s
CI / unit_tests (pull_request) Failing after 4m36s
CI / docker (pull_request) Has been skipped
CI / e2e_tests (pull_request) Successful in 8m27s
CI / benchmark-regression (pull_request) Has been cancelled
CI / coverage (pull_request) Has been cancelled
CI / status-check (pull_request) Has been cancelled
to c7518a265e
Some checks failed
CI / benchmark-publish (pull_request) Has been skipped
CI / build (pull_request) Successful in 16s
CI / unit_tests (pull_request) Failing after 2m39s
CI / integration_tests (pull_request) Failing after 2m43s
CI / lint (pull_request) Successful in 3m32s
CI / typecheck (pull_request) Successful in 3m48s
CI / quality (pull_request) Successful in 4m0s
CI / security (pull_request) Successful in 4m3s
CI / docker (pull_request) Has been skipped
CI / e2e_tests (pull_request) Successful in 8m13s
CI / coverage (pull_request) Successful in 9m58s
CI / status-check (pull_request) Failing after 5s
CI / benchmark-regression (pull_request) Successful in 50m12s
2026-03-25 12:25:15 +00:00
Compare
hamza.khyari force-pushed feature/resource-handler-sandbox from c7518a265e
Some checks failed
CI / benchmark-publish (pull_request) Has been skipped
CI / build (pull_request) Successful in 16s
CI / unit_tests (pull_request) Failing after 2m39s
CI / integration_tests (pull_request) Failing after 2m43s
CI / lint (pull_request) Successful in 3m32s
CI / typecheck (pull_request) Successful in 3m48s
CI / quality (pull_request) Successful in 4m0s
CI / security (pull_request) Successful in 4m3s
CI / docker (pull_request) Has been skipped
CI / e2e_tests (pull_request) Successful in 8m13s
CI / coverage (pull_request) Successful in 9m58s
CI / status-check (pull_request) Failing after 5s
CI / benchmark-regression (pull_request) Successful in 50m12s
to 8b1a2add0d
Some checks failed
CI / benchmark-publish (pull_request) Has been skipped
CI / build (pull_request) Successful in 22s
CI / lint (pull_request) Successful in 3m20s
CI / quality (pull_request) Successful in 3m41s
CI / typecheck (pull_request) Successful in 3m57s
CI / security (pull_request) Successful in 4m6s
CI / unit_tests (pull_request) Failing after 3m44s
CI / docker (pull_request) Has been skipped
CI / integration_tests (pull_request) Successful in 7m22s
CI / e2e_tests (pull_request) Successful in 10m49s
CI / coverage (pull_request) Successful in 12m47s
CI / status-check (pull_request) Failing after 4s
CI / benchmark-regression (pull_request) Successful in 55m44s
2026-03-26 12:03:00 +00:00
Compare
hamza.khyari force-pushed feature/resource-handler-sandbox from 8b1a2add0d
Some checks failed
CI / benchmark-publish (pull_request) Has been skipped
CI / build (pull_request) Successful in 22s
CI / lint (pull_request) Successful in 3m20s
CI / quality (pull_request) Successful in 3m41s
CI / typecheck (pull_request) Successful in 3m57s
CI / security (pull_request) Successful in 4m6s
CI / unit_tests (pull_request) Failing after 3m44s
CI / docker (pull_request) Has been skipped
CI / integration_tests (pull_request) Successful in 7m22s
CI / e2e_tests (pull_request) Successful in 10m49s
CI / coverage (pull_request) Successful in 12m47s
CI / status-check (pull_request) Failing after 4s
CI / benchmark-regression (pull_request) Successful in 55m44s
to 7bb77aee5c
All checks were successful
CI / build (pull_request) Successful in 14s
CI / lint (pull_request) Successful in 4m3s
CI / quality (pull_request) Successful in 4m1s
CI / typecheck (pull_request) Successful in 4m30s
CI / security (pull_request) Successful in 5m12s
CI / unit_tests (pull_request) Successful in 8m45s
CI / integration_tests (pull_request) Successful in 8m43s
CI / docker (pull_request) Successful in 1m13s
CI / e2e_tests (pull_request) Successful in 13m7s
CI / coverage (pull_request) Successful in 12m43s
CI / status-check (pull_request) Successful in 1s
CI / benchmark-publish (pull_request) Has been skipped
CI / benchmark-regression (pull_request) Successful in 1h9m12s
2026-03-27 10:50:18 +00:00
Compare
hamza.khyari deleted branch feature/resource-handler-sandbox 2026-03-27 11:09:13 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
cleveragents/cleveragents-core!1067
No description provided.