feat(agent-org): add transactional turn context and member FIFO - #841
Draft
ShiboSheng wants to merge 2 commits into
Draft
feat(agent-org): add transactional turn context and member FIFO#841ShiboSheng wants to merge 2 commits into
ShiboSheng wants to merge 2 commits into
Conversation
Persist a typed context for every Agent Org turn and allocate Member dispatches from a single per-run/member FIFO in the same immediate transaction as the base Turn Intent. Wire Starting and Coordinator Root admission, keep ordinary SDE turns context-free, and fail closed before persisting legacy Member group/inbox work that lacks typed authority. Use one strict current-schema manifest and isolated legacy cleanup without adding a second runtime or scheduler. Refs: #758 Pre-commit hook ran. Total eslint: 5, total circular: 0
Accept only an empty Agent Org runtime namespace or the exact current 15-table manifest. Remove the obsolete 13-table manifest branch, upgrade-only schema builder, logging, and test. Keep strict corruption checks and supported legacy namespace cleanup unchanged. Refs: #758 Pre-commit hook ran. Total eslint: 5, total circular: 0
ShiboSheng
force-pushed
the
codex/issue-758-turn-context-fifo
branch
from
August 19, 2026 17:15
569045e to
32565bd
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Fixes #758
Agent Org turns currently persist a generic Turn Intent, but they do not have one canonical durable record that says which run, participant, turn kind, authority source, and activation episode own that turn. That leaves later Task, direct-member, group, and inbox producers without a trustworthy identity boundary, and it makes Member ordering vulnerable to per-source queues or half-written state.
PR3 needs to establish that ownership boundary without implementing the later PR4–PR10 product features, without adding a second runtime, and without making ordinary SDE sessions depend on Agent Org context storage.
Solution
agent_org_runtime_turn_contextstable with strict row-shape checks, exhaustive typed decoding, source identity, activation/actor versioning, and one context per Agent Org Turn Intent.(org_run_id, member_id)dispatch allocator. Task execution and every future user-directed Member source share the same monotonically increasing FIFO; Coordinator Root turns never consume a Member sequence.BEGIN IMMEDIATEtransaction. Exact replay returns the existing identity and sequence; partial pairs, mismatched replay, unknown members, wrong sessions, and invalid authority fail closed without a repair guess or second allocation.org_run_id IS NULL; run Agent Org recovery only after its schema is initialized, preserving typed initial Root recovery and isolating contextless historical rows.cancelledas the authoritative terminal outcome when user Stop or Force Send interrupts a turn.This PR is intentionally stacked on #836 (
codex/issue-791-pr3-selected-rebuild) so its diff contains only PR3.Potential risks
agent_org_runtime_*schema now rejects startup instead of being guessed or upgraded. Recovery is to restore a backup or use a fresh namespace; do not hand-edit the tables.BEGIN IMMEDIATEwriter transaction. The 50-connection mixed-source test passed, and packaged-app active/idle measurements showed no new timer, poll, context query, or memory staircase.PR3 -> official v1.2.6 -> PR3UI test is blocked by fix(agent-org): [11/11] harden full-stack upgrade and rollback compatibility #840 because v1.2.6 cannot read the newer WorkStationmemberstab cache. PR3 does not modify that cache or PR825. Before the old UI failed, and after returning to PR3, the 15 runtime tables and key Agent Org business fingerprints remained intact. The complete cross-version UI matrix remains unverified until fix(agent-org): [11/11] harden full-stack upgrade and rollback compatibility #840.Verification
Automated checks ran on source tree
e8ea88f767abed22f57fc7a4f43205b610e2b08d, now published as32565bdaefd2bc9d051b8f4cfcb6d5923b27d0e9after a commit-message-only Husky rewrite:cargo test -p agent_core core::coordination::agent_org_turn_contexts -- --nocapture— 8 passed, including strict replay, transaction rollback, delete cascade, shared FIFO, and 50 concurrent connections.cargo test -p agent_core core::coordination::schema -- --nocapture— 8 passed, including fresh/current-only manifest, corruption rejection, atomic legacy cleanup, concurrency, and schema-init timing.cargo test -p agent_core state::commands::session::message -- --nocapture— 21 passed, including steering/Force Send separation and authoritative cancellation.cargo test -p agent_core agent_org -- --nocapture --test-threads=1— 232 passed.cargo test -p session_persistence turn_intents -- --nocapture— 13 passed, including ordinary SDE recovery with no context schema dependency.cargo check --workspace --all-targets— passed.cargo clippy -p agent_core -p session_persistence -p org2 --all-targets -- -D warnings— passed.rustfmt --edition 2021 --check <12 changed Rust files>— passed.git diff --check fe20ec604902d956b98aa7fab00bdd1469d9f7e3...HEAD— passed.cargo fmt --all -- --check— not clean because seven pre-existing, unchanged files have formatting drift; those unrelated files were deliberately not reformatted in this PR.Packaged-app real-machine verification:
/private/tmp/ORG2-PR3-758-no-pr828-upgrade.app, executable SHA-256dc282e927a3c5eab7d5ad4f9180ea15c1d53dc970e8d789f5a01d029de578bc4.quick_check=ok, the exact 15 runtime tables, 50 contexts, zero active Turn Intents, and zero ordinary-SDE contexts. Coordinator contexts had null dispatch/sequence fields and created no allocator row.Screenshots are not attached because PR3 has no new visible UI. The acceptance evidence is the production UI side effects correlated with SQLite, logs, Command+5, restart fingerprints, and performance samples.