Skip to content

fix(seed): converge the Cornelius flag on a 409 only when the agent exists (#1790) - #1837

Merged
vybe merged 1 commit into
devfrom
fix/1790-cornelius-volume-conflict-409
Jul 28, 2026
Merged

vybe merged 1 commit into
devfrom
fix/1790-cornelius-volume-conflict-409

Conversation

@dolho

@dolho dolho commented Jul 28, 2026 •

Copy link
Copy Markdown
Contributor

What

The Cornelius seeder converged its durable cornelius_seeded flag on any 409 from the create path. Now it converges only when something actually claims the name.

Related to #1790

Why it mattered

Three of the create path's 409s mean nothing was created:

409 source Meaning Old handling
_check_name_availability → "Agent already exists" genuinely there (race backstop) converge ✅
_guard_leftover_workspace_volume (#1667) unclaimed leftover volume — refused converge ❌
is_volume_base_reserved (#1664) volumes owned by a renamed agent — refused converge ❌
FORK_DESTINATION_IN_USE destination repo bound — refused converge ❌

On the bottom three the flag suppressed every later attempt, so the install stayed permanently Cornelius-less while reporting seeded — and system_seed_service.ensure_first_run_seeded() then read the install as not-fresh. Recovery meant hand-editing system_settings.

Reachable via the ordinary "start over": docker compose down -v destroys the DB but not the agent volumes (not compose-managed), so re-setup hits the leftover agent-cornelius-workspace.

Approach

Verify by fact, not by status code. On a 409 the handler asks whether anything claims the name; converges only then, otherwise leaves the flag unset, returns create_blocked, logs the cause, and the next boot retries. The common blocker is reclaimed unattended by the #1581 orphan-volume sweep, so the retry converges with no operator action.

Two deliberate choices worth reviewing:

  • Shared predicate, not a typed exception. The issue suggested typing the bug: agent creation silently reuses a pre-existing Docker volume of the same name (get-then-create, no adopt/refuse decision) #1667 refusal. Instead the existence check inside _check_name_availability is extracted as crud.agent_name_is_taken and reused by the seeder. That covers every non-existence 409 — including the two the issue didn't name and any added later — and it keeps detail a plain string, so no 409 response shape changes for the UI. Sharing beats copying here: a duplicated predicate would drift the moment a new claim source lands in the create path.
  • The probe fails toward retry. If the check itself errors we report absent. The errors aren't symmetric: a wrong "absent" costs one redundant create attempt that 409s again next boot; a wrong "present" burns the durable flag and is unrecoverable without editing the DB. That asymmetry is the bug.

Precedent: lifecycle.py (#1809) already handles a Docker 409 the same way — catch, then confirm the container is really there before adopting.

Note one preserved behaviour: a container-only leftover with no ownership row still counts as taken, because that's what the create path itself refuses on. It converges as before.

Verification

$ pytest tests/unit/test_ent107_cornelius_seed.py -q
18 passed

New cases, run against the pre-fix handler (fix stashed, tests kept) — both fail, so they pin the actual defect:

FAILED test_409_with_no_agent_does_not_burn_flag
FAILED test_409_presence_probe_failure_fails_toward_retry
2 failed, 16 passed

Full unit suite:

4993 passed, 16 skipped, 4 failed

All 4 failures are pre-existing and environmental — ModuleNotFoundError: No module named 'tzdata' (test_1472) and 3 in test_admin_email_login.py — reproduced identically on an untouched checkout at the same commit. Crud-adjacent files (test_1484, test_1664, test_1581, test_fork_to_own, test_1646) pass 144/144, covering the predicate extraction.

Not done: no operator-queue alert for a blocked seed. Retry + an ERROR log naming the cause is the fix for the reported defect; an alert is a separate call.

🤖 Generated with Claude Code

Fixes #1790

…xists (#1790)

The seeder read any HTTP 409 from create_agent_internal as "Cornelius already
exists" and durably set cornelius_seeded=true. But the create path raises 409
for several conditions under which NOTHING was created — a leftover unclaimed
workspace volume (#1667), volumes still owned by a renamed agent (#1664), a
fork destination already bound. On those, the flag suppressed every later
attempt, so the install stayed permanently Cornelius-less while reporting that
it had seeded, and system_seed_service then read the install as not-fresh.

The reachable path is the ordinary "let me start over": `docker compose down -v`
destroys the DB but NOT the agent volumes (they are not compose-managed), so the
next setup hits the leftover agent-cornelius-workspace, 409s, and burns the flag.
Recovery required hand-editing system_settings.

Verify by fact, not by status code: on a 409 the handler now re-checks whether
anything actually claims the name and converges only then; otherwise it leaves
the flag unset, returns create_blocked, and logs the cause, so the next boot
retries. The usual blocker is reclaimed unattended by the #1581 orphan-volume
sweep, so the retry converges without intervention.

The predicate is the create path's own — `_check_name_availability`'s existence
check, extracted as `crud.agent_name_is_taken` and shared rather than re-derived,
so the two cannot drift when a claim source is added. This is deliberately
broader than typing the one #1667 refusal: every present and future non-existence
409 is handled, since the seeder now asks the question it actually cares about.
Mirrors the fact-based 409 handling already used for Docker name conflicts in
lifecycle.py (#1809). The probe fails toward retry — a wrong "absent" costs one
redundant create attempt, a wrong "present" is the unrecoverable direction.

Tests: 3 new cases in the ent107 suite (409-with-no-agent leaves the flag unset;
probe failure fails toward retry; the shared predicate reads every claim source),
plus the existing 409-convergence case tightened to assert presence. Verified
failing 2/2 against the pre-fix handler. Full unit suite: 4993 passed, 4
pre-existing environmental failures (missing tzdata, admin-email-login)
reproduced identically on an untouched checkout.

Related to #1790
@github-actions

Copy link
Copy Markdown

⚠️ Nightly unit-suite check skipped — merge conflict against dev.

Resolve by running git merge dev locally and pushing the result. The next nightly run will re-test once the conflict is gone.

@vybe vybe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Validated via /validate-pr: shared claim predicate (no drift), fail-toward-retry asymmetry is right, regression tests named to #1790 cover both 409 branches + probe failure + all claim sources, feature-flow doc updated. Approving.

@vybe
vybe merged commit ce9ce32 into dev Jul 28, 2026
22 checks passed
pull Bot pushed a commit to bryanwills/trinity that referenced this pull request Jul 28, 2026
…xists (Abilityai#1790) (Abilityai#1837)

The seeder read any HTTP 409 from create_agent_internal as "Cornelius already
exists" and durably set cornelius_seeded=true. But the create path raises 409
for several conditions under which NOTHING was created — a leftover unclaimed
workspace volume (Abilityai#1667), volumes still owned by a renamed agent (Abilityai#1664), a
fork destination already bound. On those, the flag suppressed every later
attempt, so the install stayed permanently Cornelius-less while reporting that
it had seeded, and system_seed_service then read the install as not-fresh.

The reachable path is the ordinary "let me start over": `docker compose down -v`
destroys the DB but NOT the agent volumes (they are not compose-managed), so the
next setup hits the leftover agent-cornelius-workspace, 409s, and burns the flag.
Recovery required hand-editing system_settings.

Verify by fact, not by status code: on a 409 the handler now re-checks whether
anything actually claims the name and converges only then; otherwise it leaves
the flag unset, returns create_blocked, and logs the cause, so the next boot
retries. The usual blocker is reclaimed unattended by the Abilityai#1581 orphan-volume
sweep, so the retry converges without intervention.

The predicate is the create path's own — `_check_name_availability`'s existence
check, extracted as `crud.agent_name_is_taken` and shared rather than re-derived,
so the two cannot drift when a claim source is added. This is deliberately
broader than typing the one Abilityai#1667 refusal: every present and future non-existence
409 is handled, since the seeder now asks the question it actually cares about.
Mirrors the fact-based 409 handling already used for Docker name conflicts in
lifecycle.py (Abilityai#1809). The probe fails toward retry — a wrong "absent" costs one
redundant create attempt, a wrong "present" is the unrecoverable direction.

Tests: 3 new cases in the ent107 suite (409-with-no-agent leaves the flag unset;
probe failure fails toward retry; the shared predicate reads every claim source),
plus the existing 409-convergence case tightened to assert presence. Verified
failing 2/2 against the pre-fix handler. Full unit suite: 4993 passed, 4
pre-existing environmental failures (missing tzdata, admin-email-login)
reproduced identically on an untouched checkout.

Related to Abilityai#1790
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants