Repository navigation
Conversation
2 tasks done
AndriiPasternak31
force-pushed
the
AndriiPasternak31/reset-preserve-state
branch
from
April 19, 2026 13:25
b6269f2 to
15e9be7
Compare
Contributor
Author
|
Rebased onto Used the approach documented in the PR description: Conflicts resolved:
12 commits on top of |
AndriiPasternak31
marked this pull request as ready for review
April 19, 2026 13:26
Add two pure-function primitives that the reset-preserve-state routine will compose: - `build_snapshot(home_dir, paths)` walks /home/developer, selects files matching any allowlist glob (S4 persistent-state patterns), and returns a tar blob plus the list of captured paths. Traversal/absolute patterns in the allowlist are silently skipped. - `restore_from_tar(home_dir, tar_bytes, paths)` extracts a tar back into /home/developer, enforcing the same allowlist and rejecting entries whose names are absolute or contain `..` segments. Returns (restored, skipped) so the caller can audit. Both are wrapped by thin FastAPI endpoints (`/api/agent-server/snapshot`, `/api/agent-server/restore`). The snapshot endpoint optionally writes a copy to `.trinity/backup/<dir>/snapshot.tar` when `backup_dir` is given. The restore endpoint accepts a JSON-encoded `paths` form field so the allowlist is explicit in every call. Tests follow the project convention (see `test_git_pull_branch.py`, `test_persistent_state_reader.py`): mirror the pure functions host-side and drift-detect via a source-match assertion. 10 tests cover empty allowlist no-ops, the S4 default patterns, path-traversal rejection on both sides, and round-trip snapshot→restore. Refs Abilityai#381 Part of Abilityai#384 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…ai#384) Compose the snapshot + restore primitives into the recovery operation the git-improvements proposal calls out as §S3. The routine: 1. Reads the persistent-state allowlist via `_read_persistent_state()` from Abilityai#383 / S4 — does NOT reimplement the reader. 2. Snapshots every matching file to `.trinity/backup/<iso-ts>/` with a manifest, so the destructive reset is always recoverable from inside the container even if the push later fails. 3. `git fetch origin main` + `git reset --hard origin/main` to adopt the template baseline. 4. Overlays the snapshot back to restore instance-specific state. 5. Commits `Adopt main baseline, preserve state` — the exact message §S3 specifies. 6. `git push --force-with-lease origin HEAD:<working-branch>` — the lease keeps this safe against the P5 clobber scenario even though the broader --force swap belongs to Abilityai#382 / S7. Two guardrails live in this layer: - `no_git_config` — refuse if `.git` is missing or no origin remote. - `no_remote_main` — refuse if origin doesn't have main. Both surface as HTTP 409 with an `X-Conflict-Type` header so the backend can map them to operator-readable messages. The "agent currently running a task" guardrail sits in the backend layer (next commit) because this server has no view of the activity service. Tests (6 new): drift-detect the compose routine's signature; cover the two guardrails; pin the empty-allowlist-is-safe-no-op invariant; exercise the full snapshot→reset→overlay→commit happy path; verify the push step uses --force-with-lease. All tests drive a real tmpdir with a bare-origin fixture reproducing the parallel-history scenario from the proposal. Refs Abilityai#381 Part of Abilityai#384 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…rd (S3, Abilityai#384) Backend surface for the recovery operation added to the agent-server in the previous commit: - `services/git_service.py::reset_to_main_preserve_state(agent_name)` proxies `POST /api/agents/{name}/git/reset-to-main-preserve-state` to the agent-server endpoint, and adds one guard that can only live at this layer: reject if the agent currently has in-progress activities (chat, schedule, tool-call, collaboration). The activity service is a backend-only view, so the agent-server cannot check this itself. - `routers/git.py` adds the `POST .../git/reset-to-main-preserve-state` endpoint, scoped to `OwnedAgentByName` so only the agent's owner or an admin can trigger a destructive reset. Normalises the service's error dict into HTTP responses: - 409 `X-Conflict-Type: agent_busy | no_git_config | no_remote_main` - 500 for unexpected agent-server failures (push_failed, etc.) - 200 with `{success: true, snapshot_dir, files_preserved, commit_sha, working_branch}` on success. Tests (4 new, 10 total with the agent-server ones): mock the activity service and httpx client to verify the guard short-circuits before any HTTP call, the happy-path proxy call shape, conflict-header surfacing, and the unexpected-status → proxy_failed fallback. The helper in `_load_git_service` installs mocks directly in sys.modules (rather than using patch.dict) so the function's lazy import of `services.activity_service` still resolves to the mock at call time. Refs Abilityai#381 Part of Abilityai#384 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
In-repo mirror of /tmp/trinity-repro/s3_fix_verified.sh. Pure git + bash — no Trinity stack, no Python, no network. Lets anyone confirm the shell-level mechanics of reset-preserve-state still work after a refactor without bringing up Docker. Reproduces the parallel-history scenario from the proposal (same commit title, different SHAs, upstream advances with a conflicting change) and asserts the remote `trinity/demo/abc` ends with origin/main's baseline plus the worker's workspace state and the spec's exact commit message. Refs Abilityai#381 Part of Abilityai#384 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…#384) Opt-in integration test that hits the endpoint on a running Trinity stack. Skipped unless TRINITY_API_URL / TRINITY_TEST_TOKEN / TRINITY_GIT_TEST_AGENT are set — so CI and the default pytest run don't need Docker or a pre-configured test agent. Asserts the response falls in the defined contract surface — either a 200 with snapshot_dir/commit_sha/working_branch, or a 409 with an X-Conflict-Type header in the known set (agent_busy, no_git_config, no_remote_main). Anything else indicates a regression. A second test verifies that unauthenticated requests are rejected before any git work happens. Refs Abilityai#381 Part of Abilityai#384 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…lityai#384) - architecture.md: new "Git Recovery" section with the endpoint row and its three 409 X-Conflict-Type variants. - feature-flows/github-sync.md: revision-history entry for S3 covering the agent-server primitives, the compose routine, the allowlist consumer contract from S4, and the test matrix. Refs Abilityai#381 Part of Abilityai#384 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…i#384) Ruff doesn't recognise flake8-wemake-python-styleguide codes and emitted a warning. The lazy import is intentional (explained in the comment) and ruff's own rules don't flag it, so no suppression is needed. Refs Abilityai#384 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…ai#384) Addresses two mypy --strict errors introduced by the new compose routine: - `_git` now returns `subprocess.CompletedProcess[str]` (text=True). - `reset_to_main_preserve_state_impl` returns `dict[str, object]` instead of a bare `dict`. Rest of agent_server/routers/git.py remains untyped (140 pre-existing strict errors out of scope for Abilityai#384). Refs Abilityai#384 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…nts (Abilityai#384) One-line row in the Entry Points table so the top-of-file index reflects the new recovery endpoint alongside pull/sync/status/config. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…ityai#384) Document the new recovery operation as its own section in the existing GitHub Sync flow (rather than a standalone file — S3 is an enhancement to the sync feature, not a separate system). Covers: - Purpose (parallel-history deadlock and why pull/force aren't safe) - Full API contract with all three 409 X-Conflict-Type variants - Sequence diagram showing the backend agent-busy guard + agent-server compose routine (snapshot → fetch → reset → overlay → commit → push) - Five guardrails in execution order - Primitives table mapping each helper to its source file - Code reference map (tests, regression script, integration test) - Explicit non-goals (UI, auto-sync, branch-ownership) with the PRs that own them Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…lityai#384) One-line entry under Recent Updates pointing at the github-sync.md flow where the full S3 recovery operation is documented. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…yai#384) New requirement §11.3 with status, description, key features, endpoint, and flow-doc link. Sits under "GitHub Integration" alongside Sync and Repository Initialization. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…ilityai#384) Project index JSON gains the new feature slug under features.implemented; bumps last_updated to 2026-04-18. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
vybe
force-pushed
the
AndriiPasternak31/reset-preserve-state
branch
from
April 22, 2026 09:09
15e9be7 to
e46f58a
Compare
9 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Ships §S3 of the git-improvements proposal — a first-class recovery path for
agents stuck in the parallel-history deadlock (P2/P3). Consumes the
persistent-state allowlist primitive from #383 / PR #394 (S4) rather than
reimplementing it.
POST /api/agents/{name}/git/reset-to-main-preserve-state(owner-only). Guardrail: refuses with 409
agent_busyif the agentcurrently has in-progress activities (activity service check).
routers/snapshot.pywithPOST /api/agent-server/snapshot(tarball response; optional.trinity/backup/<ts>/copy) andPOST /api/agent-server/restore(multipart with JSON-array
paths). Both pure functions(
build_snapshot,restore_from_tar) reject traversal / absolutepaths.
agent_server/routers/git.py:_read_persistent_state()(S4)..trinity/backup/<iso-ts>/with manifest.git fetch origin main+git reset --hard origin/main.Adopt main baseline, preserve state.git push --force-with-lease origin HEAD:<working-branch>.Guardrails: 409
no_git_config/no_remote_main.existing S4 tests). Plus
tests/git-sync/s3_reset_preserve.shreproducing the proposal's pure-git regression from
/tmp/trinity-repro/s3_fix_verified.sh. Opt-in integration test intests/test_reset_preserve_state_integration.py.The UI wiring (third modal button) belongs to #385 / PR #395 and is
intentionally out of scope here.
Stacking
Stacked on #394 (S4, issue #383). Marked draft until #394 merges.
Once it does, rebase onto
upstream/mainwithgit rebase --onto upstream/main <S4-head-sha> AndriiPasternak31/reset-preserve-stateand flip out of draft.
Test plan
pytest tests/unit/test_reset_preserve_state_*.py→ 20 passedpytest tests/unit/test_persistent_state_*.py tests/unit/test_git_pull_branch.py→ 23 passed (no S4 regressions)./tests/git-sync/s3_reset_preserve.sh→S3 pure-git regression: OKruff checkon edited files → 0 new errors (4 pre-existing F841s untouched)mypy --stricton the new compose routine → 0 new errorscd src/mcp-server && npm run build→ tsc exit 0TRINITY_API_URL/TRINITY_TEST_TOKEN/TRINITY_GIT_TEST_AGENTCloses #384
Refs #381
🤖 Generated with Claude Code