Skip to content

fix(session): exclude orphan org members from native pages - #804

Open
ShiboSheng wants to merge 2 commits into
fix/issue-840-startup-compatibilityfrom
fix/issue-803-orphan-coordinator-pagination
Open

fix(session): exclude orphan org members from native pages#804
ShiboSheng wants to merge 2 commits into
fix/issue-840-startup-compatibilityfrom
fix/issue-803-orphan-coordinator-pagination

Conversation

@ShiboSheng

@ShiboSheng ShiboSheng commented Aug 14, 2026

Copy link
Copy Markdown
Collaborator

Problem

Fixes #803.

The session sidebar paginates each native stream before rendering it. PR #1190 already fixes the standalone SDE stream so rows marked with org_member_id cannot consume that stream's page capacity unless they are represented as a persisted Agent Org root. The remaining gap was the global pinned-native stream: it accepted every pinned, top-level native row before applying the cursor and LIMIT.

Historical coordinator/member rows can retain org_member_id after their Agent Org runtime run is gone. Those orphan rows are not valid standalone sessions or valid Agent Org roots, but the pinned query let them displace real pinned SDE, OS, Human, and CLI sessions.

The completed Agent Org stack also remained hidden in ordinary release builds because both the frontend bundle and Rust runtime defaulted the rollout gate off. This top-stack commit makes the completed product available by default while preserving an explicit environment opt-out.

The authoritative session source is agent_sessions. A membership-marked row is a valid root only when agent_org_runtime_runs.root_session_id points to it.

Solution

  • Stack this PR directly on PR fix(startup): isolate cross-version persistence #1190 (fix/issue-840-startup-compatibility) and keep its standalone-stream fix unchanged.
  • Filter pinned native rows before cursor ordering and page capacity. Rows without org_member_id remain eligible; membership-marked rows require a matching persisted runtime run.
  • Preserve valid pinned coordinator roots and the existing cross-store pinned order.
  • Clarify the persisted field contract: a coordinator root keeps its primary SDE session type while carrying the coordinator member id.
  • Add regression coverage for first-page capacity, continuation cursors, second-page exhaustion, valid-root annotation, cross-store ordering, and indexed query plans.
  • Default ORGII_AGENT_ORG_REDESIGN to 1 in ordinary frontend bundles, while preserving explicit 0.
  • Default the Rust rollout gate on when the variable is absent; explicit values remain fail-closed unless they are exactly 1.
  • Keep unit-test and WebDriver builds force-enabled, and add regression coverage for default-on and explicit opt-out behavior.

The pagination portion remains a read-path invariant fix. The rollout activation changes only build/runtime defaults; neither change modifies schemas, migrations, writers, RPC/wire formats, frontend filters, or persisted historical data.

Potential risks

  • Any pinned row that carries org_member_id but has no persisted runtime run will now be hidden. This is intentional: such a row violates the native-sidebar domain invariant and must not consume page capacity.
  • Valid coordinator roots depend on agent_org_runtime_runs.root_session_id. Regression tests explicitly prove those roots remain visible and annotated.
  • Historical orphan rows remain in SQLite. No destructive cleanup or migration is performed; rollback is a normal revert of this commit with no data recovery step.
  • The added correlated membership probe runs once per bounded candidate row. Query-plan tests and a read-only real-database plan both show the existing sidebar index and root-session covering index are used.
  • This PR depends on PR fix(startup): isolate cross-version persistence #1190 (fix/issue-840-startup-compatibility) and must be reviewed and merged as its child in the stack.
  • The PR fix(startup): isolate cross-version persistence #1190 base rejects legacy databases with a partial Agent Org runtime schema. That inherited startup contract is outside this PR's scope; true-machine verification used a complete 33/33 runtime schema copied into an isolated profile.
  • Agent Org now ships enabled by default. Operators can set ORGII_AGENT_ORG_REDESIGN=0 to disable it; rollback is either that environment override or reverting the activation commit. Malformed explicit values remain disabled on both frontend and backend.
  • macOS packaged-app behavior was exercised. Other platforms were covered by Rust boundary tests and static checks, but not by a packaged UI run.

Verification

  • node --test scripts/dev/webpack-config-light.test.cjs — 6 passed, including default-on, explicit opt-out, and WebDriver force-enable cases.
  • TAURI_CONFIG='{"bundle":{"externalBin":[]}}' cargo +1.98.0 test -p agent_core production_gate_defaults_enabled_and_explicit_values_fail_closed — 1 passed.
  • TAURI_CONFIG='{"bundle":{"externalBin":[]}}' cargo +1.98.0 clippy -p agent_core --all-targets -- -D warnings — passed.
  • rustfmt --edition 2021 --check crates/agent-core/src/core/coordination/agent_org_runs/rollout.rs and Prettier on the changed test file — passed.
  • cargo test --manifest-path src-tauri/Cargo.toml -p agent_core core::session::persistence::sidebar::tests -- --nocapture — 4 passed, 0 failed.
  • cargo test --manifest-path src-tauri/Cargo.toml -p org2 native_sidebar -- --nocapture — 5 passed, 0 failed.
  • rustfmt --edition 2021 --check src-tauri/src/agent_sessions/session_directory/aggregation/native_sidebar.rs src-tauri/crates/agent-core/src/core/session/persistence/crud/record.rs — passed.
  • git diff --check — passed.
  • cargo check --manifest-path src-tauri/Cargo.toml -p agent_core -p org2 --all-targets — passed.
  • cargo clippy --manifest-path src-tauri/Cargo.toml -p agent_core -p org2 --all-targets -- -D warnings — passed. Cargo only reported the existing future-incompatibility notice for block v0.1.6.
  • cargo fmt --manifest-path src-tauri/Cargo.toml --all -- --check — not clean because PR fix(startup): isolate cross-version persistence #1190 already contains unrelated rustfmt differences; both files changed by this PR pass rustfmt independently.
  • Read-only real database check — found 42 historical orphan top-level SDE rows. Under the old predicate, 27 of the first 51 rows were orphans; the fixed predicate returned a full 51-row eligible page. EXPLAIN QUERY PLAN used idx_agent_sessions_sidebar and idx_agent_org_runtime_runs_root_session.
  • ORGII_AGENT_ORG_REDESIGN=1 pnpm run tauri:build:fast — passed and produced src-tauri/target/dev-build/bundle/macos/ORG2.app. Executable SHA-256: 5715ce2ecf55491aa206b501d65f3b146ecc50a26298833b2daee567d89a8dca.
  • Packaged-app true-machine test with an isolated profile — seeded 51 rows: 27 orphan rows and 24 eligible rows. The initial UI showed 10 valid pinned and 10 valid standalone rows with Load more; two Load more actions revealed all 12 valid pinned rows and all 12 valid unpinned/root rows, then removed the control. No orphan label appeared, while both valid roots remained visible.
  • Packaged-app restart — normal Command-Q shutdown preserved PRAGMA quick_check = ok; reopening returned the same bounded first page and Load more state.
  • Idle packaged-app samples — 0.0% CPU in three samples and approximately 158 MiB RSS. No session-sidebar RPC, database-open, or panic errors appeared in the isolated backend/frontend logs. The isolated run did show unrelated updater-network and code-editor WebSocket warnings.
  • Pre-commit hook — scoped clippy passed for agent_core and org2; no TypeScript files were staged.

No screenshot is attached because this changes query membership and page capacity, not visual layout. The rendered macOS sidebar was exercised through Computer Use with explicit row and control assertions.

@Harry19081 Harry19081 added bug Something isn't working sessions Sessions, history, replay, sidebar, workspace, or worktrees cloud-collaboration Cloud sync, organizations, channels, or collaboration labels Aug 23, 2026
@ShiboSheng
ShiboSheng force-pushed the fix/issue-803-orphan-coordinator-pagination branch from c9ef9ba to e65d3cf Compare September 1, 2026 12:49
@ShiboSheng
ShiboSheng changed the base branch from develop to fix/issue-840-startup-compatibility September 1, 2026 12:51
@ShiboSheng
ShiboSheng force-pushed the fix/issue-803-orphan-coordinator-pagination branch from e65d3cf to be06028 Compare September 1, 2026 17:00
@ShiboSheng
ShiboSheng force-pushed the fix/issue-803-orphan-coordinator-pagination branch from be06028 to ba56cdb Compare September 1, 2026 19:15
@ShiboSheng
ShiboSheng marked this pull request as ready for review September 1, 2026 20:46
@ShiboSheng
ShiboSheng marked this pull request as draft September 1, 2026 20:50
Filter membership-marked native rows before pinned page limits unless a persisted Agent Org runtime run proves the row is a valid root. Preserve the standalone behavior supplied by the PR 1190 base and cover page capacity, cursors, valid roots, and indexed query plans.

Verification: agent-core sidebar tests (4 passed); org2 native-sidebar tests (5 passed); cargo check and clippy for agent_core/org2; BuildFast packaged-app pagination and restart checks.
@ShiboSheng
ShiboSheng force-pushed the fix/issue-803-orphan-coordinator-pagination branch from ba56cdb to 5ee69b4 Compare September 1, 2026 21:04
@ShiboSheng
ShiboSheng marked this pull request as ready for review September 1, 2026 23:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working cloud-collaboration Cloud sync, organizations, channels, or collaboration sessions Sessions, history, replay, sidebar, workspace, or worktrees

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(sidebar): prevent orphan coordinator sessions from consuming SDE page capacity

2 participants