Skip to content

fix: preserve persistent agent configuration across Docker namespaces - #3723

Open
alex-furman wants to merge 14 commits into
Abilityai:devfrom
alex-furman:codex/fix-3722-persistent-config
Open

alex-furman wants to merge 14 commits into
Abilityai:devfrom
alex-furman:codex/fix-3722-persistent-config

Conversation

@alex-furman

@alex-furman alex-furman commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #3722.

A containerized backend stages configuration in its own /tmp, but Docker resolves bind sources on the daemon host. Persistent creation can therefore mount missing paths. This change uploads configuration through Docker's archive API into a per-agent volume mounted read-only at /config.

The nullable agent_ownership.config_storage_format field distinguishes legacy agents from new volume-v1 agents. Existing rows stay NULL; no host files are adopted or converted. Recovery requires the exact saved config volume name, config platform, immutable agent owner and matching installation identity before rotating credentials. Creation refuses an unresolved installation identity; this does not change legacy recovery or deletion compatibility. Rename retains the immutable volume base; ordinary recreation retains the read-only mount. Existing configuration volumes produce a named HTTP 409 and are never adopted or overwritten during creation.

Creation settles provisioning and container workers before cleanup. Before container submission it never reclaims a same-name container or Redis state. After submission, unregistered failures use native provenance checks, including lost Docker replies; cancellation preserves a settled daemon conflict. Key rollback deletes only the key minted by that attempt. Registered ownership or an unreadable ownership lookup preserves resources for inspection. Volume cleanup verifies this attempt's exact creation claim and never forces removal.

All generated files, including .env, .mcp.json, template config files and file credentials, are seeds: existing, empty and symlinked workspace files survive restarts. Archive staging uses the caller-validated local image selected for the agent (including custom or pinned images) without an extra pull. The obsolete startup call to an absent configure_agent.py is removed; the server reads agent YAML directly. SQLite and PostgreSQL add the nullable marker. PostgreSQL downgrade refuses to discard populated markers, and a merge revision preserves both published 0099 histories.

Suggested review order: config_volume.py, creation/recovery in crud.py and lifecycle.py, then schema/migrations. Much of the CRUD diff is indentation around staging cleanup.

Current integration 8f263909ac6b7d33f513a6707a2ad8662c27b2d1 targets official dev c8f67cb857086a31f69d1dcc65d360bd94399ba1. The update preserves every published revision ID and parent link, keeps all SQLite entries, renames only this PR's colliding migration filenames, and adds no-op merge revision 0117_merge_config_loop_hygiene. Current upstream lifecycle, endpoint-policy and kind-label changes are retained.

Validation:

  • The configuration-mount regression still fails on unmodified current dev: Docker receives backend-local temporary bind sources. It passes on the candidate.
  • Core configuration/create/recovery/startup/migration batch: 218 passed; slow lifecycle batch: 9 passed; real PostgreSQL unit batch: 15 passed. Adjacent upstream checks: 547 passed, two optional private-submodule skips; a newly merged legacy fixture was corrected and verified in the core batch.
  • Independent review found that a legacy-compatible deletion guard was too permissive for new config recovery. Four regressions fail before the correction. The final config-specific guard passes 163 affected checks plus two strengthened creation-label checks; these overlap earlier batches and are not an additional unique-test total.
  • Nine disposable PostgreSQL upgrade paths, including previously published config history and current upstream head, converge to 0117, repeat idempotently, and preserve synthetic legacy NULL/volume-v1 ownership and valid email records. SQLite existing-install parity passes with ledger health 180/180.
  • All 108 prior PR and 113 official revision/parent pairs remain unchanged; final graph has 118 revisions, unique numeric filenames and one head.
  • Independent full-PR review and targeted re-review of the provenance correction have no unresolved findings. Earlier real Docker archive/read-only mount/startup and cancellation/credential-replay proofs cover unchanged transport behavior; they are reused historical receipts, not newly run full workflows.
  • The first full regression comparison exposed five create-mode golden failures missed by local selection. The issue-scoped fixture repair adds only the intended nullable marker to 12 captured ownership rows, preserving every response and other table field. Golden plus configuration transport checks pass (44); independent repair review is clear.
  • Full upstream CI on this exact head passed, including the full regression comparison: 23 successful checks, five skipped, none pending or failed (November 2).

Limits: these checks do not establish a complete provider-backed HTTP create/recreate workflow. Ephemeral transport and legacy recovery retain their existing behavior. Unreadable ownership needs operator inspection. No production deployment is included.

Journey Impact: extends: J03

Mutation: the named-volume creation regression fails on unmodified current official dev and passes on this integration. Existing migration invariants reproduce duplicate filenames and multiple heads before reconciliation. Earlier cancellation/credential regression evidence covers unchanged paths; published migration histories are preserved rather than rewritten.

@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

✅ Nightly unit-suite clean when this PR is merged into dev, all 3 seeds (head_sha: 637bd99b106d2ee598573229c7fdac7bb4e5d8db).

@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

⚠️ Alembic head fork if this PR is merged into dev.

dev has advanced since this PR's checks last ran. GitHub recomputes the merge ref when the base moves but does not re-trigger workflows, so a green schema-parity here can describe a base that no longer exists (#2533).

scripts/ci/check_alembic_heads.py against dev + this PR, merged in memory
alembic-heads: FAIL — src/backend/migrations/versions resolves to 2 heads across 132 revision(s); exactly 1 is required.
  • 0117_merge_config_loop_hygiene  (0117_merge_config_loop_hygiene.py)
  • 0126_schedule_email_results  (0126_schedule_email_results.py)

They fork at: 0112_loop_runs_stale_duplicates  (0112_loop_runs_stale_duplicates.py)

`alembic upgrade head` is singular and resolves its target BEFORE applying anything,
so this graph applies ZERO revisions — every revision since the fork stops arriving,
not only the one that forked. Fix by chaining the newer revision off the real head,
or — if the forked revision may already be applied somewhere — by adding a merge
revision (`alembic merge -m "…" <head-a> <head-b>`), whose tuple `down_revision`
converges the line from any starting state. See Architectural Invariant #3.
alembic-heads: src/backend/enterprise/backend/migrations/versions — version directory absent (submodule not initialised) — skipped.

Evaluated on the version line only — this PR also conflicts with dev in 4 unrelated file(s), which do not change this verdict but must be resolved before merge:

src/backend/db/agents.py
src/backend/services/agent_service/crud.py
tests/unit/fixtures/ent695_create_mode_golden.json
tests/unit/test_1484_create_agent_characterization.py

Fix: rechain this PR's revision off 0126_schedule_email_results (the current dev head), or — if the forked revision may already be applied somewhere — add a merge revision (alembic merge -m "…" 0117_merge_config_loop_hygiene 0126_schedule_email_results), whose tuple down_revision converges the line from any starting state. See Architectural Invariant #3.

Push the fix and schema-parity re-checks it against the merge ref immediately; this comment clears on the next push to dev touching src/backend/migrations/versions/**.

Advisory — this check does not block merge. · head_sha: 8f263909ac6b7d33f513a6707a2ad8662c27b2d1 · run

@vybe

vybe commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

merge-train: held back from today's train. Thanks for this; the config-volume transport is well built, and the tests drive the real create path. One finding needs your call before it can ride.

Blocking: the ent#313 failed-create cleanup is skipped for persistent agents on most failures. In crud.py (head 65f0fe689, around lines 3938-3945 and 3987), container_outcome_known = status in (400, 409). A read timeout, a Docker 500, a 404 or any plain exception counts as "uncertain", and preserve then skips everything: container reclaim, MCP key revocation, agent_git_config rollback and config-volume removal. A 60-second read timeout in containers.run is exactly the field case ent#313 fixed. Its _reclaim_failed_creation_container already handles it safely: it checks for a name conflict, the absence of an ownership row and the trinity.created provenance. Skipping it brings back a running container with no ownership row and a live, unrevoked key. Suggested direction: route "uncertain" through the existing provenance-gated reclaim rather than retaining everything. test_3722_unknown_container_outcome_retains_config_and_key would change with it.

Also worth addressing:

Migration fork: dev has since merged 0099_agent_peer_skill_grants off the same parent. The tables are disjoint, so re-parenting onto it and renumbering, plus keeping both MIGRATIONS entries, is all that is needed. We can do that part at merge time if you prefer.

@vybe vybe added the status-needs-fix PR has an unaddressed review/validation finding; cleared by the author's next push (#2815) label Oct 17, 2026
@alex-furman

Copy link
Copy Markdown
Contributor Author

@vybe Addressed in bfe19cb4f and 45da3d472:

  • Unregistered failures now use the existing provenance-gated reclaim. Cancellation preserves the settled Docker conflict; failures before container submission cannot reclaim a concurrent winner, and rollback revokes only this attempt's minted key.
  • All generated credential/configuration files are seed-only, including .mcp.json and mutable file credentials. Restart/recovery preserves existing values, empty files and symlinks.
  • The archive helper uses the agent's validated, selected local image, including pinned/custom images, without an additional pull.
  • Existing configuration volumes return named HTTP 409; the absent configurator call is removed.
  • The migration merge retains both published 0099 histories and both SQLite entries.

Validation includes failing-before regressions, 168 affected checks on the final corrections, independent re-review, actual Docker archive/startup checks, and PostgreSQL upgrades from base and either 0099 branch. Full provider-backed HTTP create/recovery acceptance is still unverified; the description records the boundaries.

Please re-review the updated head when convenient.

@alex-furman

Copy link
Copy Markdown
Contributor Author

@vybe Following up with the latest integration and regression evidence. Your cleanup, credential overwrite, helper-image and conflict-handling concerns are addressed, as detailed above.

The updated head (637bd99b106d) also reconciles the subsequent dev migration changes while preserving published migration IDs and both SQLite entries. PostgreSQL upgrade checks cover five starting states, including both previously published branches. We also corrected the startup-order regression test to check the actual credential-seeding operation after the upstream script changed.

The final full regression run reports 27,959 passed, 86 skipped, and zero failures or new regressions: https://github.com/Abilityai/trinity/actions/runs/39342293085/job/118373898459

The PR description records the validation and its limits; full provider-backed HTTP create/recovery acceptance remains unverified. Could you take another look when convenient and let us know whether anything else is needed for the merge train?

@alex-furman

Copy link
Copy Markdown
Contributor Author

@vybe Following up after integrating current dev in 5b75ef861. The migration conflicts are resolved while preserving published revision histories, and your previously raised concerns remain addressed. We completed independent re-review, 458 affected tests, and seven PostgreSQL upgrade-path checks. The current regression comparison also passes.

Could you re-review this for the merge train? Please let us know if anything else is needed from our side. The PR description records the validation limits, including the unverified full provider-backed HTTP create/recovery workflow.

@vybe

vybe commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

merge-train (2026-11-04): re-validated at 8f263909a, and this is close. Thanks for your patience on the re-review. The cleanup blocker from 10-17 is closed: I ran read timeout, Docker 500, 404 and a plain exception through the real create_agent_internal, with mocked Docker, and reclaim, key revocation, git-config rollback and volume removal all behaved. Restoring the old defect turns 6 tests red. The .mcp.json overwrite, helper image, named 409 and configure_agent.py points are closed too.

Two things to fix before it can ride:

  1. Flatten the migrations (Alembic now has two heads against dev). dev's head is 0115_access_requests_requester_identity, and 0117_merge_config_loop_hygiene forks at 0112, so upgrade head fails on PostgreSQL 16 with Multiple head revisions. Your tables are disjoint from dev's 0113 to 0115. Those fork revisions were never applied to a deployment, so please replace them rather than add another merge rung:
    • Delete the five fork revision files.
    • Add 0116_agent_config_storage_format with down_revision = "0115_access_requests_requester_identity", same DDL and the guarded downgrade.
    • Remove the ladder tests in tests/unit/test_3722_config_storage_format.py, including the get_heads() == [0117…] assertion, which any later dev migration would break.
    • Move the SQLite entry to the tail of migrations.py. Re-stamp any database of yours that is at the old ids. If dev gains a revision first, parent on its new head.
  2. Pin the generated-seed hand-off. At crud.py:3860, replacing seed_dir with None leaves all 23 create-path test files green, and so does dropping and not config_volume_name at crud.py:2550. Either mutation would silently stop generated .env, .mcp.json and file credentials reaching the volume. No create_agent_internal test uses a template that generates files. Please add one that asserts the seed directory reaches create_config_volume and that no /generated-creds bind appears.

Also worth fixing, not blocking on their own:

  • A lost Docker reply at config_volume.py:133 or :143 leaks the volume. The second also leaves an unstarted helper that the sweep cannot clear, so that name answers 409 until someone runs docker rm. I reproduced both against real Docker.
  • Non-local allowlisted base images no longer auto-pull at config_volume.py:142, and fail with a generic 500. Please say in the PR whether that is intended.
  • The doc addition belongs in docs/memory/architecture/agent-lifecycle.md, not in the core architecture.md.
  • Older base images ignore the seed path, so this needs a release note and a base-image rebuild.

A fork push cannot clear status-needs-fix, so please comment here when this is pushed and it will be lifted by hand. Lane C also needs a real create run on a rebuilt image before merge, which your description already flags as unverified.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status-needs-fix PR has an unaddressed review/validation finding; cleared by the author's next push (#2815)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants