Skip to content

feat(agent-org): add authoritative Team lifecycle - #824

Open
ShiboSheng wants to merge 5 commits into
developfrom
codex/issue-756-pr1-clean-rebuild
Open

feat(agent-org): add authoritative Team lifecycle#824
ShiboSheng wants to merge 5 commits into
developfrom
codex/issue-756-pr1-clean-rebuild

Conversation

@ShiboSheng

Copy link
Copy Markdown
Collaborator

Problem

Supersedes #781.

Fixes #756.

Agent Org did not have one authoritative, restart-safe lifecycle boundary for a long-lived Team. Initial materialization, quiescence, Run View reads, watchdog recovery, and frontend polling could not yet guarantee that a Team moves safely through Starting -> Running/Idle/Failed, becomes quiet in Idle or Failed, and can later be extended without introducing another state owner.

PR #781 accumulated several later review commits whose scope went beyond PR1. This replacement rebuilds PR1 directly on the latest develop and carries forward only the review fixes explicitly accepted for this slice.

Solution

The branch starts from origin/develop at 8ad1fedea09dd1c4bc101a6a54c48e612466cdaa and contains only these changes:

  • Original PR1 by Shibo Sheng: durable Starting materialization receipts, authoritative lifecycle transitions, centralized quiescence, pure-read Run View, one bounded watchdog, shared frontend polling ownership, and one fail-closed rollout gate.
  • Follow-up by Neonforge: classify permanent launch-recovery failures through stable Store-owned prefixes instead of fragile message substrings.
  • Follow-up by Neonforge: when a late background launch failure arrives after the Team is already Running, preserve the coordinator Session status while retaining the visible error record.
  • Follow-up by Neonforge: centralize the assess-to-CAS-idle protocol, fence the arbitrary-status run creator to test/debug builds, and remove the unused cancelled value from newly created lifecycle DDL.
  • Regression tests by Shibo Sheng: exercise errors emitted by the real Store boundary and the late-failure behavior of a real persisted Running Team/coordinator pair.

The replacement intentionally excludes the other #781 review commits. In particular, it does not add watchdog cursors, Starting retries, stale-intent repair, startup reservation pruning, legacy gate-off passthrough, Idle/Failed deletion, or the cache-hit send-fence probe.

The resulting PR1 boundary remains the design-doc boundary: no Pause/Resume implementation, Archive/Delete implementation, Task FSM rewrite, Writer settings, UserDirectedWork, or Group-send behavior is introduced here.

Potential risks

  • The redesign remains disabled by default and fail-closed. Existing rollout behavior must not be inferred to expose the new lifecycle to normal users yet.
  • Stable error prefixes are now part of the internal launch-recovery classification contract. Future Store error changes must preserve or deliberately replace those prefixes and their tests.
  • A late launch failure for an already Running Team no longer marks its coordinator Session failed. Recovery remains owned by the existing live-Team recovery paths; this PR does not add a new retry owner.
  • Removing cancelled from the CREATE TABLE IF NOT EXISTS constraint affects newly created databases only. Existing databases are intentionally not rewritten or migrated by this PR.
  • Packaged Tauri lifecycle/performance acceptance was completed for the original PR1 in feat(agent-org): add authoritative team lifecycle #781, but it was not repeated after this clean reconstruction and the three selected backend follow-ups. Performance verdict for this rebuilt tip is therefore blocked, not failed, until the project decides whether the prior packaged evidence can be carried forward or should be rerun.

Commit provenance

  • 1db18a176 (original) -> 7beec7907 (rebuilt), authored by Shibo Sheng.
  • 57e7e2c84 (original) -> 49cd4c3c4 (rebuilt), authored by Neonforge.
  • ed309078a (original) -> d4675fb15 (rebuilt), authored by Neonforge.
  • 6b710f58d (original) -> 1e4b4438d (rebuilt), authored by Neonforge.
  • f998e9016, regression tests authored by Shibo Sheng.

Verification

Passed:

  • cargo test -p agent_core starting_store_errors_drive_stable_permanent_failure_classification
  • cargo test -p agent_core late_launch_failure_does_not_fail_a_running_team_coordinator
  • cargo test -p agent_core core::coordination::agent_org_runs::tests — 45 passed.
  • cargo test -p agent_core core::coordination::agent_org_watchdog::tests — 9 passed.
  • cargo test -p agent_core core::session::launch::launch_tests — 10 passed.
  • cargo test -p agent_core core::session::scheduler::tests — 6 passed.
  • cargo test -p agent_core lifecycle::tests — 6 passed.
  • cargo test -p agent_core state::commands::session::org_tasks::tests — 17 passed.
  • cargo test -p org2 agent_org — 1 passed.
  • npm test -- --run src/engines/ChatPanel/InputArea/components/agentOrgRunViewStore.test.ts — 12 passed.
  • cargo clippy -p agent_core -p org2 --all-targets -- -D warnings.
  • rustfmt --edition 2021 --check on the two newly changed test files.
  • git diff --check origin/develop...HEAD.
  • Commit hooks passed, including scoped Agent Core Clippy.

cargo fmt --all -- --check was also attempted. It reports pre-existing formatting differences in three untouched files already present on origin/develop: render_inline_canvas.rs, ui_metadata_tests.rs, and turn_window.rs. Those unrelated files are not changed in this PR; the two files added by the replacement test commit pass direct rustfmt --check.

No new packaged build or UI recording was produced for this reconstruction. The meaningful new verification is at the Store, launch-recovery, lifecycle, watchdog, Tauri command, and shared polling-store boundaries.

ShiboSheng and others added 5 commits August 16, 2026 23:15
Establish durable Starting materialization receipts and a centralized quiescence boundary so Working teams enter Idle only from committed facts. Keep Run View pure-read, bound the global watchdog, and stop frontend polling for hidden or non-pollable teams behind one fail-closed rollout gate.

Verification:
- cargo clippy --all-targets -- -D warnings
- Packaged Tauri Command+5 foreground, hidden, and restore lifecycle passed
- Run View refresh left the isolated database byte-identical

Pre-commit hook ran. Total eslint: 0, total circular: 0
launch_org.rs classified permanent identity failures with
.contains("identity mismatch") / .contains("Session identity"), but the
store emits 'materialization session mismatch for ...' and 'materialized
Session ... is missing for ...' — neither matched, so a permanently wrong
identity was retried forever instead of failing Starting.

Replace substring matching with stable machine prefixes defined next to
the error construction in AgentOrgRunStore:

- MATERIALIZATION_IDENTITY_MISMATCH_PREFIX now stamps all three permanent
  identity failures in mark_materialization_succeeded and the certified-row
  revalidation in finish_starting;
- STARTING_INPUT_CERTIFICATE_ERROR_PREFIX stamps the two permanent
  initial-input certificate failures in finish_starting;
- is_materialization_identity_mismatch_error() /
  is_permanent_finish_starting_error() are the only classification points.

Sweep of substring classifications introduced by this PR:
- launch_org.rs materialization receipt classification -> typed helper;
- launch/mod.rs both finish_starting sites (background launch + startup
  recovery) -> is_permanent_finish_starting_error();
- launch/mod.rs initial-input payload decode classification -> shared
  prefix constants + is_permanent_initial_input_payload_error(), used by
  both the constructor and the classifier.

Pre-commit hook ran. Total eslint: 0, total circular: 0
handle_background_launch_failure discarded fail_starting's Ok(false)
(returned when the run already left Starting) and then marked the
coordinator session failed anyway — a Running team with a failed
coordinator session row, and a log that claimed the run was marked failed
when it was not.

When fail_starting reports no transition, the handler now reloads the
actual run status and logs error-level with that status, stating
explicitly that the run status was left unchanged. For a Running run the
coordinator session status is also left untouched (the watchdog and the
initial-dispatch recovery own retries for a live team); the launch error
is still broadcast and persisted to the transcript so the failure stays
visible. Non-Running outcomes keep the previous behavior.

Pre-commit hook ran. Total eslint: 0, total circular: 0
Hygiene batch from the PR 781 audit:

- The copy-pasted assess-quiescence -> extract generation/work_revision ->
  try_transition_working_to_idle block (4 sites: scheduler post-intent
  reconcile, lifecycle turn finalization, plan-approval follow-up,
  watchdog terminal candidate) is hoisted into
  AgentOrgRunStore::try_reconcile_to_idle() so the certificate protocol
  cannot drift per caller.

- AgentOrgRunStore::create is production-dead (launch goes exclusively
  through create_starting) but is needed by unit tests and the
  #![cfg(debug_assertions)] /test endpoints, which seed arbitrary-status
  runs create_starting cannot express (no coordinator identity, non-
  Starting statuses, NULL root). Gate it #[cfg(any(test,
  debug_assertions))] — present exactly where its consumers exist,
  absent from release binaries.

- Drop 'cancelled' from the last_activity_outcome CHECK: no code path
  reads or writes that value ('failed' via fail_starting and 'completed'
  via the idle CAS are the only writers). CREATE TABLE IF NOT EXISTS
  leaves existing databases untouched; PR 799 above regenerates its DDL
  manifest from the binary. The DDL string is edited minimally, no
  reformatting.

Pre-commit hook ran. Total eslint: 0, total circular: 0
Exercise Store-emitted permanent Starting errors and protect a Running team's coordinator Session from late launch-failure handling.

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.

feat(agent-org): [1/10] add authoritative Team lifecycle, Idle, and a quiet watchdog

2 participants