Skip to content

fix(agent-org): isolate runtime persistence namespace - #836

Draft
ShiboSheng wants to merge 1 commit into
codex/issue-757-pr2-selected-rebuildfrom
codex/issue-791-pr3-selected-rebuild
Draft

fix(agent-org): isolate runtime persistence namespace#836
ShiboSheng wants to merge 1 commit into
codex/issue-757-pr2-selected-rebuildfrom
codex/issue-791-pr3-selected-rebuild

Conversation

@ShiboSheng

@ShiboSheng ShiboSheng commented Aug 18, 2026

Copy link
Copy Markdown
Collaborator

Problem

Replaces #828.

Fixes #791.

Agent Org's redesigned runtime still shared its private SQLite table names and definitions-file path with older releases. Downgrading could therefore recreate an incompatible legacy schema, and reopening the redesigned build could hit column mismatches before ordinary Rust or CLI Session history loaded.

This is the third PR in the stack: #834 -> #835 -> this PR. It is based directly on codex/issue-757-pr2-selected-rebuild.

Solution

  • Move all 13 Agent Org-owned runtime tables and their indexes into the agent_org_runtime_* namespace.
  • At the existing database initialization barrier, use one BEGIN IMMEDIATE transaction to validate the complete canonical manifest, drop only the exact 13 retired table names, create a fresh canonical namespace when absent, revalidate it, and roll back on any failure.
  • Fail closed for a partial or structurally unknown canonical namespace while preserving unknown tables outside the exact retirement registry.
  • Store redesigned Team definitions only in agent-org-definitions.json; delete agent-orgs.json without parsing or migrating it, and never fall back to the retired path when cleanup fails.
  • Preserve shared Session, CLI, message, turn-intent, Project, Work Item, Routine, and usage data.
  • Preserve activity cancellation with the exact DDL invariant last_activity_outcome IN ('completed', 'failed', 'cancelled') while keeping Team status restricted to starting, running, paused, idle, failed, and archived.
  • Add one minimal DDL test that first accepts last_activity_outcome = 'cancelled' under a valid Team status, then separately proves status = 'cancelled' is rejected by SQLite.

Potential risks

  • The exact 13 retired Agent Org tables and the retired agent-orgs.json file are intentionally deleted. Legacy Agent Org runtime state and legacy custom Team definitions are not recoverable through this change.
  • Downgrading creates an empty legacy Agent Org environment. Returning to this build deletes that temporary legacy environment while retaining the isolated redesigned runtime.
  • Cross-version recovery while a Team is Starting, Running, Paused, or otherwise in flight is unsupported. Running old and new binaries concurrently against the same ORGII_HOME is also unsupported.
  • This PR depends on feat(agent-org): flatten Team definitions and freeze capabilities #835, which depends on feat(agent-org): add authoritative team lifecycle #834, and must not merge before them.
  • The full local automated stack passed, but the packaged cross-version matrix was not rerun. The PR remains Draft.
  • Rollback is to run an older build sequentially; it recreates its own empty legacy tables. The redesigned agent_org_runtime_* tables remain isolated for a later return to the new build.

Verification

Passed on this PR tip:

  • cargo test -p agent_core core::coordination::schema -- --nocapture — 8 passed, including the two-constraint cancellation DDL test. Measured 25 samples: fresh median 4.429 ms, canonical no-op median 2.679 ms, and 13-table cleanup median 3.108 ms.
  • cargo check -p agent_core -p app_paths -p org2 -p session_persistence --all-targets
  • cargo clippy --workspace --all-targets -- -D warnings
  • pnpm run typecheck
  • pnpm run lint — 0 errors; 5 existing unused-value warnings.
  • full frontend Vitest suite — 1,114 files and 8,749 tests passed.
  • cargo test --workspace — complete workspace and doc-test suite passed when rerun outside the restricted sandbox so loopback-port tests could bind.
  • git diff --check origin/develop...HEAD
  • Commit hooks, including scoped Rust Clippy.

Also attempted:

  • cargo fmt --all -- --check reports existing formatting differences in files identical to origin/develop; no changed file in this stack contributes to the output.
  • pnpm run check:circular reports two unresolved raw runtime imports from unchanged reactArtifactDocument.ts; both that file and the checker are byte-identical to origin/develop.

No frontend or wire file changes in this PR layer, so new UI screenshots are not applicable. The packaged cross-version matrix remains not run.

Architecture and performance audit

Architecture review covered compilation, removal of the old fingerprint/reset ownership path, canonical naming, namespace semantics, fail-closed defaults, shared-data boundaries, developer clarity, unchanged wire contracts, initializer parity, and definitions-path resolution.

The runtime cost is startup-only: one SQLite transaction over schema metadata and a fixed 13-name retirement list. There is no new polling, timer, worker, subscription, cache, row scan, or idle/hidden background work. Concurrent same-version initialization is serialized by SQLite and covered by a two-connection test.

Commit provenance

  • Selected source commit b7e24bd1515b058672c2ba8959465214f1ecd968 -> adapted commit fe20ec604902d956b98aa7fab00bdd1469d9f7e3, authored by Shibo Sheng. The adaptation retains the selected stack's local coordinator constant and adds the required DDL constraint test; no other PR fix(agent-org): isolate runtime persistence namespace #828 commit is present.

Move the redesigned Agent Org runtime into the canonical agent_org_runtime_* tables and retire the exact legacy table set atomically on startup. Isolate flat Team definitions at agent-org-definitions.json while preserving ordinary Rust and CLI session data across downgrade and re-upgrade.

Pre-commit hook ran. Total eslint: 0, total circular: 0
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.

1 participant