Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ module.exports = (env, argv) => {
process.env.ORGII_DEEP_LINK_SCHEME ?? "orgii"
),
"process.env.ORGII_AGENT_ORG_REDESIGN": JSON.stringify(
isE2E ? "1" : (process.env.ORGII_AGENT_ORG_REDESIGN ?? "0")
isE2E ? "1" : (process.env.ORGII_AGENT_ORG_REDESIGN ?? "1")
),
"process.env.E2E_BASE_URL": JSON.stringify(
process.env.E2E_BASE_URL ??
Expand Down
21 changes: 19 additions & 2 deletions scripts/dev/webpack-config-light.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ test("production keeps default HTML script injection", () => {
assert.equal(htmlPlugin?.userOptions?.retryMainScriptLoad, false);
});

test("WebDriver production bundles enable the E2E-only Agent Org gate", () => {
test("WebDriver production bundles force-enable the Agent Org gate", () => {
const config = withEnv(
{
ORGII_E2E: null,
Expand All @@ -101,7 +101,7 @@ test("WebDriver production bundles enable the E2E-only Agent Org gate", () => {
);
});

test("ordinary production bundles keep the Agent Org rollout disabled", () => {
test("ordinary production bundles enable the Agent Org rollout by default", () => {
const config = withEnv(
{
ORGII_E2E: null,
Expand All @@ -111,6 +111,23 @@ test("ordinary production bundles keep the Agent Org rollout disabled", () => {
() => createWebpackConfig({}, { mode: "production" })
);

assert.equal(getDefinedValue(config, "process.env.ORGII_E2E"), '"0"');
assert.equal(
getDefinedValue(config, "process.env.ORGII_AGENT_ORG_REDESIGN"),
'"1"'
);
});

test("ordinary production bundles preserve an explicit Agent Org opt-out", () => {
const config = withEnv(
{
ORGII_E2E: null,
ORGII_AGENT_ORG_REDESIGN: "0",
WEBDRIVER: null,
},
() => createWebpackConfig({}, { mode: "production" })
);

assert.equal(getDefinedValue(config, "process.env.ORGII_E2E"), '"0"');
assert.equal(
getDefinedValue(config, "process.env.ORGII_AGENT_ORG_REDESIGN"),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
//! Single internal rollout gate for the long-lived Agent Org redesign.
//!
//! This is deliberately not persisted in Team definitions or exposed to
//! model/tool context. Until the final stack PR changes the default, missing
//! or malformed configuration fails closed.
//! model/tool context. Missing configuration enables the completed redesign;
//! explicit values still fail closed unless they are exactly `1`.

const ENABLED_VALUE: &str = "1";
const ROLLOUT_ENV: &str = "ORGII_AGENT_ORG_REDESIGN";

fn configured_enabled(value: Option<&str>, test_build: bool) -> bool {
test_build || value.is_some_and(|value| value.trim() == ENABLED_VALUE)
test_build || value.is_none_or(|value| value.trim() == ENABLED_VALUE)
}

pub fn is_enabled() -> bool {
Expand Down Expand Up @@ -45,8 +45,8 @@ mod tests {
}

#[test]
fn production_gate_defaults_and_malformed_values_fail_closed() {
assert!(!super::configured_enabled(None, false));
fn production_gate_defaults_enabled_and_explicit_values_fail_closed() {
assert!(super::configured_enabled(None, false));
assert!(!super::configured_enabled(Some("true"), false));
assert!(!super::configured_enabled(Some("0"), false));
assert!(super::configured_enabled(Some("1"), false));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,10 @@ pub struct UnifiedSessionRecord {
pub merge_status: Option<String>,
pub project_slug: Option<String>,
pub agent_definition_id: Option<String>,
/// Agent Org roster member id for `session_type::ORG_MEMBER` rows.
/// This identifies the member instance, while `agent_definition_id`
/// identifies which AgentDefinition that member runs.
/// Agent Org roster member id. Worker rows use `session_type::ORG_MEMBER`;
/// a coordinator root keeps its primary session type and uses the
/// coordinator member id. `agent_definition_id` identifies which
/// AgentDefinition that member runs.
pub org_member_id: Option<String>,

pub parent_session_id: Option<String>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,14 @@ fn list_pinned_native_sidebar_sessions(
AND s.status != ?1
AND s.parent_session_id IS NULL
AND s.session_type IN (?2, ?3, ?4)
AND (
s.org_member_id IS NULL
OR EXISTS (
SELECT 1
FROM agent_org_runtime_runs r
WHERE r.root_session_id = s.session_id
)
)
{agent_cursor}
UNION ALL
SELECT c.session_id, c.updated_at, 'cli' AS source_kind
Expand Down Expand Up @@ -387,18 +395,37 @@ mod tests {
}

#[test]
fn pinned_native_page_merges_agent_and_cli_roots_in_stable_order() {
fn pinned_native_page_excludes_orphan_members_before_capacity() {
let _sandbox = crate::test_utils::test_env::sandbox();
let conn = get_connection().expect("sandbox database");

for (session_id, session_type, updated_at, pinned, parent, status) in [
for (session_id, session_type, updated_at, pinned, parent, status, member) in [
(
"orphan-coordinator-pinned",
session_type::CODING,
"2026-07-30T18:00:00Z",
true,
None,
"idle",
Some("coordinator"),
),
(
"agent-org-root-pinned",
session_type::CODING,
"2026-07-30T17:00:00Z",
true,
None,
"idle",
Some("coordinator"),
),
(
"sdeagent-pinned",
session_type::CODING,
"2026-07-30T14:00:00Z",
true,
None,
"idle",
None,
),
(
"osagent-pinned",
Expand All @@ -407,6 +434,7 @@ mod tests {
true,
None,
"idle",
None,
),
(
"humansession-pinned",
Expand All @@ -415,6 +443,7 @@ mod tests {
true,
None,
"completed",
None,
),
(
"sdeagent-unpinned",
Expand All @@ -423,6 +452,7 @@ mod tests {
false,
None,
"idle",
None,
),
(
"sdeagent-worker",
Expand All @@ -431,6 +461,7 @@ mod tests {
true,
Some("sdeagent-pinned"),
"running",
None,
),
(
"sdeagent-archived",
Expand All @@ -439,6 +470,7 @@ mod tests {
true,
None,
"archived",
None,
),
] {
session_persistence::upsert_session(&UnifiedSessionRecord {
Expand All @@ -447,13 +479,26 @@ mod tests {
status: status.to_string(),
session_type: session_type.to_string(),
parent_session_id: parent.map(str::to_string),
org_member_id: member.map(str::to_string),
created_at: updated_at.to_string(),
updated_at: updated_at.to_string(),
pinned,
..Default::default()
})
.expect("seed native session");
}
conn.execute(
"INSERT INTO agent_org_runtime_runs (
id, org_id, coordinator_agent_id, root_session_id,
entry_mode, status, created_at, updated_at
) VALUES (
'run-agent-org-root-pinned', 'org-pinned', 'builtin:sde',
'agent-org-root-pinned', 'standalone_session', 'running',
'2026-07-30T17:00:00Z', '2026-07-30T17:00:00Z'
)",
[],
)
.expect("seed pinned Agent Org run");

for (session_id, updated_at, pinned, parent) in [
("cliagent-pinned", "2026-07-30T13:00:00Z", true, None),
Expand All @@ -475,7 +520,7 @@ mod tests {
.expect("seed CLI session");
}

let page = list_native_sidebar_sessions(NativeSidebarSessionStream::PinnedNative, None, 10)
let page = list_native_sidebar_sessions(NativeSidebarSessionStream::PinnedNative, None, 4)
.expect("load global pinned page");

assert_eq!(
Expand All @@ -484,14 +529,89 @@ mod tests {
.map(|session| session.session_id.as_str())
.collect::<Vec<_>>(),
vec![
"agent-org-root-pinned",
"sdeagent-pinned",
"cliagent-pinned",
"osagent-pinned",
"humansession-pinned",
]
);
assert!(page.sessions.iter().all(|session| session.pinned));
assert!(!page.has_more);
assert!(page
.sessions
.iter()
.all(|session| session.session_id != "orphan-coordinator-pinned"));
assert_eq!(page.sessions[0].agent_org_id.as_deref(), Some("org-pinned"));
assert!(page.has_more);
assert_eq!(
page.next_cursor.as_ref(),
Some(&NativeSidebarSessionCursor {
updated_at: "2026-07-30T12:00:00Z".to_string(),
session_id: "osagent-pinned".to_string(),
})
);

let second = list_native_sidebar_sessions(
NativeSidebarSessionStream::PinnedNative,
page.next_cursor.as_ref(),
4,
)
.expect("load second global pinned page");
assert_eq!(
second
.sessions
.iter()
.map(|session| session.session_id.as_str())
.collect::<Vec<_>>(),
vec!["humansession-pinned"]
);
assert!(!second.has_more);
}

#[test]
fn pinned_native_query_uses_bounded_order_and_root_membership_indexes() {
let _sandbox = crate::test_utils::test_env::sandbox();
let conn = get_connection().expect("sandbox database");
let mut stmt = conn
.prepare(
"EXPLAIN QUERY PLAN
SELECT s.session_id, s.updated_at, 'agent' AS source_kind
FROM agent_sessions s
WHERE s.pinned = 1
AND s.status != 'archived'
AND s.parent_session_id IS NULL
AND s.session_type IN ('sde', 'os', 'human')
AND (
s.org_member_id IS NULL
OR EXISTS (
SELECT 1
FROM agent_org_runtime_runs r
WHERE r.root_session_id = s.session_id
)
)
UNION ALL
SELECT c.session_id, c.updated_at, 'cli' AS source_kind
FROM code_sessions c
WHERE c.pinned = 1
AND c.parent_session_id IS NULL
ORDER BY updated_at DESC, session_id DESC
LIMIT 11",
)
.expect("prepare pinned native query plan");
let details = stmt
.query_map([], |row| row.get::<_, String>(3))
.expect("read pinned native query plan")
.collect::<Result<Vec<_>, _>>()
.expect("collect pinned native query plan")
.join("\n");

assert!(
details.contains("idx_agent_sessions_sidebar"),
"pinned agent page did not use ordered sidebar index:\n{details}"
);
assert!(
details.contains("idx_agent_org_runtime_runs_root_session"),
"pinned root membership probe did not use root-session index:\n{details}"
);
}

#[test]
Expand Down
Loading