Skip to content

fix(agent-org): converge durable task finality - #1309

Open
ShiboSheng wants to merge 1 commit into
fix/issue-765-group-activity-formatter-memoryfrom
codex/agent-org-durable-finality
Open

fix(agent-org): converge durable task finality#1309
ShiboSheng wants to merge 1 commit into
fix/issue-765-group-activity-formatter-memoryfrom
codex/agent-org-durable-finality

Conversation

@ShiboSheng

Copy link
Copy Markdown
Collaborator

Problem

Agent Org's durable Task ledger could fail to converge even when the visible work looked finished:

  • an old Task-bound Inbox delivery could admit a sibling execution Turn for the same Task;
  • deterministic authority/provenance conflicts could remain running instead of reaching a terminal state;
  • terminal Task mutations did not always settle the exact Inbox/materialization in the same transaction;
  • Coordinator-authored graph changes could leave its observed revision stale and miss the final completion recheck;
  • Task UI cancellation proved only the target cancellation, not an episode-level user scope-removal decision that dependent work and completion could verify;
  • on the initial Coordinator Turn, the first task_list against a revision-0 empty board could be mistaken for a repeated no-progress read and end the Turn before any Task existed.

This is PR 1 from the Agent Org consolidation plan (P0-1, P0-2, P0-3, P0-4, and P0-9), stacked directly on the current head of #1224.

Solution

  • Add an additive agent_org_finality persistence owner with companion tables for execution authority, terminal delivery settlement, Coordinator recheck receipts, scope-removal receipts, and idempotent legacy-state reconciliation.
  • Claim one durable live execution authority per Task activation generation and reject sibling execution before it can become valid work.
  • Route Task complete/fail/cancel/replace/reassign paths through transaction-scoped settlement so only deliveries bound to the exact Task/generation stop blocking or rematerializing.
  • Classify deterministic assistant-persistence authority failures at their owning boundary; only bounded transient database failures are retried.
  • Advance exact Coordinator Turn revision context from committed mutations and persist one completion-relevant recheck receipt without relaxing certificate validation.
  • Record UI scope removal as a user-event/request-bound receipt, expose cancellation for every non-terminal Task, and require downstream closure to cite the same durable decision.
  • Let only the saved initial Coordinator Turn read a revision-0, zero-Task, uncertified board without entering waiting_for_org_event; the existing repeat-read guard remains unchanged after work is materialized.

No existing runtime table is rewritten. The new finality schema is additive and initialized in the existing database transaction. No polling, per-Team timer, or unbounded in-memory registry is introduced.

Potential risks

  • The highest correctness risk is settling a legitimate delivery or rejecting a legitimate continuation. Settlement and execution claims therefore require exact Run, Task, generation, Turn, and receipt bindings, with concurrent and rollback tests.
  • Additive companion tables remain in an existing user database after rollback. An older build can ignore them; rollback should disable/revert the new writer paths, not delete finality history.
  • The initial empty-board exception deliberately does not persist a one-shot flag. Repeated task_list calls in the same untouched initial Turn can still read the empty board until the model creates work. Later Turns, nonzero revisions, existing Tasks, and certified Runs do not receive the exception.
  • Restart reconciliation in this PR only repairs PR1 ledger invariants. Full cross-process redispatch/doorbell recovery and SQLite WAL lifecycle remain intentionally deferred to PR3.
  • The UI change reuses the existing cancellation control and dialog rather than adding a new visual system. No screenshot is attached because layout and styling are unchanged; the meaningful change is which non-terminal Task states expose the action and the persisted receipt behind it.

Verification

  • git diff --check — passed.
  • Changed Rust files: rustfmt --edition 2021 --check — passed.
  • pnpm typecheck — passed.
  • pnpm lint — passed with zero warnings.
  • pnpm check:circular — passed; no circular dependencies across 6,426 modules.
  • pnpm test -- src/engines/ChatPanel/InputArea/components/AgentOrgTaskPanel.test.ts — 26 passed.
  • cd src-tauri && cargo check --workspace --all-targets — passed.
  • cd src-tauri && cargo clippy --workspace --all-targets -- -D warnings — passed.
  • cd src-tauri && cargo test -p agent_core — 3,454 passed, 0 failed, 3 explicitly ignored stress tests.
  • cd src-tauri && cargo fmt --all -- --check — repository-wide check remains blocked by pre-existing formatting differences in untouched crates; the changed Rust files pass the focused check above, and no unrelated formatting was applied.
  • BuildFast packaged-app real-provider acceptance with the configured codexharry GPT-5.6 Luna account — one clean end-to-end natural-language run inspected the empty Task board, created work, advanced the revision, completed the work, and issued the final certificate without a user nudge.
  • A second real-provider run reached list_dir → task_list(empty) → task_create and proved the targeted initial-board path; its later browser portion is excluded from product evidence because an older test instance still owned port 4173 and all app instances shared the global orgii browser session.
  • User manual packaged-app acceptance — subsequent Flappy Bird and Snake Agent Org runs launched normally, used the browser successfully, and continued/completed after natural-language follow-ups.

Architecture and performance review

  • Ownership: execution authority, settlement, scope closure, Coordinator recheck, and repair are split into focused modules behind one finality facade; Task writers call the facade instead of duplicating SQL.
  • Compatibility: schema changes are additive; wire changes only add the optional scope-removal receipt.
  • Initialization: fresh and existing databases create the companion schema through the same initialization transaction.
  • Runtime cost: no new polling, timers, subscriptions, caches, or per-Session background work; retry remains bounded to transient persistence errors.
  • Performance verdict: pass for the changed PR1 runtime surface. Long-running recovery/watchdog and WAL lifecycle work are out of scope and remain assigned to PR3.

Centralize task execution authority, terminal delivery settlement, scope-removal receipts, coordinator revision rechecks, and restart reconciliation. Allow the initial Coordinator Turn to inspect an empty task board before the no-progress gate applies.

Verification:
- git diff --check (passed)
- changed Rust files: rustfmt --check (passed)
- pnpm typecheck (passed)
- pnpm lint (passed)
- pnpm check:circular (passed; 6426 modules)
- pnpm test -- src/engines/ChatPanel/InputArea/components/AgentOrgTaskPanel.test.ts (26 passed)
- cargo check --workspace --all-targets (passed)
- cargo clippy --workspace --all-targets -- -D warnings (passed)
- cargo test -p agent_core (3454 passed; 3 ignored)

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