@team-agent/installer 0.5.127 → 0.5.128
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Cargo.lock +1 -1
- package/Cargo.toml +1 -1
- package/README.md +11 -0
- package/crates/team-agent/src/cli/adapters.rs +3 -13
- package/crates/team-agent/src/cli/arguments.rs +4 -0
- package/crates/team-agent/src/cli/diagnose.rs +68 -22
- package/crates/team-agent/src/cli/emit.rs +58 -26
- package/crates/team-agent/src/cli/intent/runtime.rs +32 -5
- package/crates/team-agent/src/cli/intent/runtime_tests.rs +102 -11
- package/crates/team-agent/src/cli/intent/tests.rs +10 -12
- package/crates/team-agent/src/cli/intent.rs +1 -1
- package/crates/team-agent/src/cli/mod.rs +25 -8
- package/crates/team-agent/src/cli/models.rs +764 -7
- package/crates/team-agent/src/cli/schedule.rs +175 -0
- package/crates/team-agent/src/cli/send/persist.rs +0 -36
- package/crates/team-agent/src/cli/send/presentation.rs +1 -1
- package/crates/team-agent/src/cli/send.rs +108 -110
- package/crates/team-agent/src/cli/spec.rs +6 -0
- package/crates/team-agent/src/cli/status_port/brief.rs +5 -67
- package/crates/team-agent/src/cli/tests/leader_watch.rs +12 -62
- package/crates/team-agent/src/cli/tests/mod.rs +1 -1
- package/crates/team-agent/src/cli/tests/named_address.rs +11 -10
- package/crates/team-agent/src/cli/tests/run_delegation.rs +9 -6
- package/crates/team-agent/src/cli/tests/status_send.rs +68 -271
- package/crates/team-agent/src/compiler/tests.rs +3 -18
- package/crates/team-agent/src/compiler.rs +205 -6
- package/crates/team-agent/src/contract_runtime/backend.rs +145 -11
- package/crates/team-agent/src/contract_runtime/commands.rs +7 -7
- package/crates/team-agent/src/contract_runtime/config.rs +26 -16
- package/crates/team-agent/src/contract_runtime/config_tests.rs +24 -4
- package/crates/team-agent/src/contract_runtime/discovery.rs +12 -1
- package/crates/team-agent/src/contract_runtime/fork.rs +3 -10
- package/crates/team-agent/src/contract_runtime/framework.rs +28 -11
- package/crates/team-agent/src/contract_runtime/mcp.rs +19 -24
- package/crates/team-agent/src/contract_runtime/prompt.rs +2 -2
- package/crates/team-agent/src/contract_runtime/registry.rs +56 -92
- package/crates/team-agent/src/coordinator/steps/abnormal.rs +11 -11
- package/crates/team-agent/src/coordinator/tests/api_error_recovery.rs +16 -54
- package/crates/team-agent/src/coordinator/tests/health_sync.rs +42 -0
- package/crates/team-agent/src/coordinator/tick.rs +1 -89
- package/crates/team-agent/src/db/message_store.rs +7 -65
- package/crates/team-agent/src/direct_delivery.rs +368 -0
- package/crates/team-agent/src/inbox_store.rs +169 -0
- package/crates/team-agent/src/leader/registry.rs +5 -0
- package/crates/team-agent/src/leader/start.rs +2 -1
- package/crates/team-agent/src/leader/tests/lease_api.rs +2 -2
- package/crates/team-agent/src/leader/tests/prompt_contract.rs +1 -0
- package/crates/team-agent/src/lib.rs +2 -0
- package/crates/team-agent/src/lifecycle/launch/add_agent.rs +33 -0
- package/crates/team-agent/src/lifecycle/launch/add_agent_state.rs +206 -1
- package/crates/team-agent/src/lifecycle/launch/clone_agent.rs +28 -2
- package/crates/team-agent/src/lifecycle/launch/fork_agent.rs +38 -13
- package/crates/team-agent/src/lifecycle/launch/fork_entry.rs +87 -6
- package/crates/team-agent/src/lifecycle/launch/mcp_config.rs +9 -1
- package/crates/team-agent/src/lifecycle/launch/pi_mcp.rs +351 -81
- package/crates/team-agent/src/lifecycle/launch/pi_mcp_extension.js +3 -4
- package/crates/team-agent/src/lifecycle/launch/quick_start.rs +24 -0
- package/crates/team-agent/src/lifecycle/launch/spawn.rs +36 -13
- package/crates/team-agent/src/lifecycle/launch.rs +24 -1
- package/crates/team-agent/src/lifecycle/profile_launch.rs +321 -11
- package/crates/team-agent/src/lifecycle/restart/agent.rs +1 -0
- package/crates/team-agent/src/lifecycle/restart/avatar.rs +1798 -0
- package/crates/team-agent/src/lifecycle/restart/claude_fork.rs +163 -0
- package/crates/team-agent/src/lifecycle/restart/common.rs +345 -35
- package/crates/team-agent/src/lifecycle/restart/selection.rs +5 -5
- package/crates/team-agent/src/lifecycle/restart.rs +4 -0
- package/crates/team-agent/src/lifecycle/role_config.rs +39 -14
- package/crates/team-agent/src/lifecycle/tests/claude_compatible_config_red.rs +325 -0
- package/crates/team-agent/src/lifecycle/tests/claude_profile_launch_red.rs +320 -8
- package/crates/team-agent/src/lifecycle/tests/cli_argv_routing_red.rs +236 -13
- package/crates/team-agent/src/lifecycle/tests/clone_fork_copilot_perms_red.rs +378 -4
- package/crates/team-agent/src/lifecycle/tests/communication_mode_runtime_contract_red.rs +5 -4
- package/crates/team-agent/src/lifecycle/tests/copilot_provider_red.rs +7 -11
- package/crates/team-agent/src/lifecycle/tests/core.rs +47 -18
- package/crates/team-agent/src/lifecycle/tests/fixtures/pi_native_mcp_host.mjs +2 -1
- package/crates/team-agent/src/lifecycle/tests/grok_require_explicit_model_red.rs +14 -14
- package/crates/team-agent/src/lifecycle/tests/harvest2_a_batch_red.rs +60 -20
- package/crates/team-agent/src/lifecycle/tests/launch_spawn.rs +28 -26
- package/crates/team-agent/src/lifecycle/tests/mcp_tool_name_format_red.rs +6 -6
- package/crates/team-agent/src/lifecycle/tests/pi_catalog_red.rs +18 -6
- package/crates/team-agent/src/lifecycle/tests/pi_command_red.rs +70 -52
- package/crates/team-agent/src/lifecycle/tests/pi_compiler_red.rs +210 -0
- package/crates/team-agent/src/lifecycle/tests/pi_dual_entry_red.rs +157 -4
- package/crates/team-agent/src/lifecycle/tests/pi_executable_mcp_red.rs +526 -10
- package/crates/team-agent/src/lifecycle/tests/pi_fork_session_inheritance_red.rs +1419 -0
- package/crates/team-agent/src/lifecycle/tests/pi_lifecycle_doctor_red.rs +68 -1
- package/crates/team-agent/src/lifecycle/tests/pi_native_mcp_capability_red.rs +34 -12
- package/crates/team-agent/src/lifecycle/tests/pi_session_delivery_red.rs +94 -2
- package/crates/team-agent/src/lifecycle/tests/quick_start_worker_readiness_red.rs +10 -11
- package/crates/team-agent/src/lifecycle/tests/status_credential_redaction_contract.rs +2 -2
- package/crates/team-agent/src/lifecycle/tests/swallow_batch4_semantics_red.rs +254 -2
- package/crates/team-agent/src/lifecycle/tests/upgrade_compat_0211_red.rs +4 -4
- package/crates/team-agent/src/lifecycle/tests/verify_rs031_window_consistency_red.rs +5 -6
- package/crates/team-agent/src/lifecycle/tests/worker_spawn_env_red.rs +16 -7
- package/crates/team-agent/src/lifecycle/tests.rs +3 -0
- package/crates/team-agent/src/lifecycle/types.rs +18 -2
- package/crates/team-agent/src/lifecycle/worker_command_context.rs +43 -50
- package/crates/team-agent/src/mcp_server/readiness.rs +130 -149
- package/crates/team-agent/src/mcp_server/readiness_tests.rs +98 -119
- package/crates/team-agent/src/mcp_server/tests/scoped.rs +21 -31
- package/crates/team-agent/src/mcp_server/tests/send.rs +72 -107
- package/crates/team-agent/src/mcp_server/tests/tools.rs +10 -12
- package/crates/team-agent/src/mcp_server/tools.rs +70 -196
- package/crates/team-agent/src/messaging/delivery.rs +160 -218
- package/crates/team-agent/src/messaging/delivery_consumption_tests.rs +5 -5
- package/crates/team-agent/src/messaging/helpers.rs +1 -19
- package/crates/team-agent/src/messaging/mod.rs +1 -0
- package/crates/team-agent/src/messaging/reminders.rs +316 -0
- package/crates/team-agent/src/messaging/scheduler.rs +7 -1
- package/crates/team-agent/src/messaging/tests/dup_inject.rs +191 -85
- package/crates/team-agent/src/messaging/tests/runtime.rs +4 -110
- package/crates/team-agent/src/messaging/tests/spine.rs +40 -24
- package/crates/team-agent/src/messaging/types.rs +1 -0
- package/crates/team-agent/src/provider/adapter.rs +303 -51
- package/crates/team-agent/src/provider/adapters/claude.rs +78 -0
- package/crates/team-agent/src/provider/adapters/claude_fork.rs +131 -0
- package/crates/team-agent/src/provider/adapters/mod.rs +7 -5
- package/crates/team-agent/src/provider/adapters/pi.rs +106 -0
- package/crates/team-agent/src/provider/classify.rs +1 -66
- package/crates/team-agent/src/provider/model_catalog.rs +201 -13
- package/crates/team-agent/src/provider/session/capture.rs +106 -6
- package/crates/team-agent/src/provider/session/context_fork/claude.rs +123 -0
- package/crates/team-agent/src/provider/session/context_fork/outcome.rs +4 -0
- package/crates/team-agent/src/provider/session/context_fork.rs +150 -18
- package/crates/team-agent/src/provider/session_scan/claude.rs +523 -0
- package/crates/team-agent/src/provider/session_scan/common.rs +44 -8
- package/crates/team-agent/src/provider/session_scan/pi.rs +34 -1
- package/crates/team-agent/src/provider/session_scan.rs +16 -6
- package/crates/team-agent/src/provider/tests/adapter.rs +104 -17
- package/crates/team-agent/src/provider/tests/classify.rs +0 -53
- package/crates/team-agent/src/provider/tests/command_helpers.rs +12 -3
- package/crates/team-agent/src/provider/tests/idle.rs +37 -0
- package/crates/team-agent/src/provider/wire.rs +22 -34
- package/crates/team-agent/src/state/abnormal_watch/tests/mod.rs +1 -1
- package/crates/team-agent/src/state/persist.rs +6 -6
- package/crates/team-agent/src/state/projection.rs +1 -1
- package/crates/team-agent/src/state/repository/tests.rs +2 -2
- package/crates/team-agent/src/test_support/models_timeout_fixture.rs +144 -0
- package/crates/team-agent/src/tmux_backend/tests.rs +0 -151
- package/crates/team-agent/src/tmux_backend.rs +5 -40
- package/package.json +4 -4
- package/skills/team-agent/SKILL.md +5 -7
- package/skills/team-agent/command-coverage.json +1 -1
- package/skills/team-agent/docs/reference/team-agent-operator.md +3 -3
- package/skills/team-agent/references/team-agent-operator.md +3 -3
|
@@ -3,13 +3,12 @@ use super::*;
|
|
|
3
3
|
use crate::transport::test_support::OfflineTransport;
|
|
4
4
|
|
|
5
5
|
// Removal contract for the retired abnormal-exit automatic recovery path.
|
|
6
|
-
// Abnormal exits remain visible
|
|
7
|
-
//
|
|
8
|
-
// it), but coordinator ticks must never schedule or execute lifecycle work.
|
|
6
|
+
// Abnormal exits remain visible and keep a copyable manual start-agent hint,
|
|
7
|
+
// but coordinator ticks must never schedule or execute lifecycle work.
|
|
9
8
|
|
|
10
9
|
#[test]
|
|
11
10
|
fn abnormal_exit_is_reported_without_auto_recovery_intent_or_action() {
|
|
12
|
-
let case = RecoveryCase::new("reported-no-auto"
|
|
11
|
+
let case = RecoveryCase::new("reported-no-auto");
|
|
13
12
|
case.seed_agent("baseline-429");
|
|
14
13
|
let transport = OfflineTransport::new().with_session_present(true);
|
|
15
14
|
let coord = case.coord(transport.clone());
|
|
@@ -48,26 +47,21 @@ fn abnormal_exit_is_reported_without_auto_recovery_intent_or_action() {
|
|
|
48
47
|
transport.spawn_records()
|
|
49
48
|
);
|
|
50
49
|
|
|
51
|
-
// The claude_code row is a pre-upgrade legacy seat: start-agent would be
|
|
52
|
-
// refused, so the hint names the stop/remove + re-add recovery instead.
|
|
53
50
|
let content = case.latest_leader_notification();
|
|
54
51
|
assert!(
|
|
55
52
|
content.contains("No automatic restart was performed.")
|
|
56
|
-
&& content.contains(
|
|
57
|
-
|
|
58
|
-
)
|
|
59
|
-
&&
|
|
60
|
-
|
|
53
|
+
&& content.contains("To recover manually, run: team-agent start-agent fe-admin")
|
|
54
|
+
&& content.contains("--workspace")
|
|
55
|
+
&& content.contains("--team research")
|
|
56
|
+
&& content.contains("--force")
|
|
57
|
+
&& content.contains("--json"),
|
|
58
|
+
"abnormal notification must remain visible and keep the copyable manual recovery command; content={content}"
|
|
61
59
|
);
|
|
62
60
|
}
|
|
63
61
|
|
|
64
62
|
#[test]
|
|
65
63
|
fn first_turn_death_cannot_enter_auto_respawn_loop_and_manual_start_still_recovers() {
|
|
66
|
-
|
|
67
|
-
// startable runtime: a pre-upgrade codex row keeps its fault reader but
|
|
68
|
-
// has no runtime. Detection runs on that row; manual recovery re-adds the
|
|
69
|
-
// seat on a startable (fake) worker.
|
|
70
|
-
let case = RecoveryCase::new("first-turn-death-no-loop", "codex");
|
|
64
|
+
let case = RecoveryCase::new("first-turn-death-no-loop");
|
|
71
65
|
case.seed_agent("baseline-429");
|
|
72
66
|
let transport = OfflineTransport::new().with_session_present(true);
|
|
73
67
|
let coord = case.coord(transport.clone());
|
|
@@ -112,7 +106,6 @@ fn first_turn_death_cannot_enter_auto_respawn_loop_and_manual_start_still_recove
|
|
|
112
106
|
);
|
|
113
107
|
|
|
114
108
|
case.seed_healthy_coordinator();
|
|
115
|
-
case.readd_as_fake_worker();
|
|
116
109
|
let manual_transport = OfflineTransport::new().with_session_present(true);
|
|
117
110
|
let outcome = crate::lifecycle::start_agent_with_transport(
|
|
118
111
|
&case.root,
|
|
@@ -138,11 +131,10 @@ fn first_turn_death_cannot_enter_auto_respawn_loop_and_manual_start_still_recove
|
|
|
138
131
|
|
|
139
132
|
struct RecoveryCase {
|
|
140
133
|
root: std::path::PathBuf,
|
|
141
|
-
provider: &'static str,
|
|
142
134
|
}
|
|
143
135
|
|
|
144
136
|
impl RecoveryCase {
|
|
145
|
-
fn new(tag: &str
|
|
137
|
+
fn new(tag: &str) -> Self {
|
|
146
138
|
let base = std::env::var_os("TEAM_AGENT_TEST_TMP")
|
|
147
139
|
.map(std::path::PathBuf::from)
|
|
148
140
|
.unwrap_or_else(std::env::temp_dir);
|
|
@@ -156,7 +148,7 @@ impl RecoveryCase {
|
|
|
156
148
|
.as_nanos()
|
|
157
149
|
));
|
|
158
150
|
std::fs::create_dir_all(&root).unwrap();
|
|
159
|
-
Self { root
|
|
151
|
+
Self { root }
|
|
160
152
|
}
|
|
161
153
|
|
|
162
154
|
fn coord(&self, transport: OfflineTransport) -> Coordinator {
|
|
@@ -171,8 +163,7 @@ impl RecoveryCase {
|
|
|
171
163
|
|
|
172
164
|
fn seed_agent(&self, uuid: &str) {
|
|
173
165
|
let rollout = self.rollout();
|
|
174
|
-
std::fs::write(&rollout,
|
|
175
|
-
let model = if self.provider == "codex" { "gpt-5.5" } else { "sonnet" };
|
|
166
|
+
std::fs::write(&rollout, claude_api_error_line(uuid)).unwrap();
|
|
176
167
|
let state = serde_json::json!({
|
|
177
168
|
"active_team_key": "research",
|
|
178
169
|
"team_key": "research",
|
|
@@ -188,8 +179,8 @@ impl RecoveryCase {
|
|
|
188
179
|
"fe-admin": {
|
|
189
180
|
"agent_id": "fe-admin",
|
|
190
181
|
"id": "fe-admin",
|
|
191
|
-
"provider":
|
|
192
|
-
"model":
|
|
182
|
+
"provider": "claude_code",
|
|
183
|
+
"model": "sonnet",
|
|
193
184
|
"status": "running",
|
|
194
185
|
"window": "fe-admin",
|
|
195
186
|
"rollout_path": rollout,
|
|
@@ -231,18 +222,6 @@ impl RecoveryCase {
|
|
|
231
222
|
crate::state::persist::save_runtime_state(&self.root, &state).unwrap();
|
|
232
223
|
}
|
|
233
224
|
|
|
234
|
-
fn readd_as_fake_worker(&self) {
|
|
235
|
-
let mut state = self.state();
|
|
236
|
-
let agent = &mut state["agents"]["fe-admin"];
|
|
237
|
-
agent["provider"] = serde_json::json!("fake");
|
|
238
|
-
agent["model"] = serde_json::json!("fake");
|
|
239
|
-
// A fake worker has no resume; the re-added seat starts fresh.
|
|
240
|
-
if let Some(agent) = agent.as_object_mut() {
|
|
241
|
-
agent.remove("session_id");
|
|
242
|
-
}
|
|
243
|
-
crate::state::persist::save_runtime_state(&self.root, &state).unwrap();
|
|
244
|
-
}
|
|
245
|
-
|
|
246
225
|
fn seed_healthy_coordinator(&self) {
|
|
247
226
|
let workspace = WorkspacePath::new(self.root.clone());
|
|
248
227
|
let _ = crate::message_store::MessageStore::open(&self.root).unwrap();
|
|
@@ -257,17 +236,10 @@ impl RecoveryCase {
|
|
|
257
236
|
.append(true)
|
|
258
237
|
.open(self.rollout())
|
|
259
238
|
.unwrap();
|
|
260
|
-
file.write_all(
|
|
239
|
+
file.write_all(claude_api_error_line(uuid).as_bytes())
|
|
261
240
|
.unwrap();
|
|
262
241
|
}
|
|
263
242
|
|
|
264
|
-
fn error_line(&self, uuid: &str) -> String {
|
|
265
|
-
match self.provider {
|
|
266
|
-
"codex" => codex_failed_turn_line(uuid),
|
|
267
|
-
_ => claude_api_error_line(uuid),
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
|
|
271
243
|
fn rollout(&self) -> std::path::PathBuf {
|
|
272
244
|
self.root.join("rollout-fe-admin.jsonl")
|
|
273
245
|
}
|
|
@@ -320,16 +292,6 @@ fn claude_api_error_line(uuid: &str) -> String {
|
|
|
320
292
|
)
|
|
321
293
|
}
|
|
322
294
|
|
|
323
|
-
fn codex_failed_turn_line(turn_id: &str) -> String {
|
|
324
|
-
format!(
|
|
325
|
-
"{}\n",
|
|
326
|
-
serde_json::json!({
|
|
327
|
-
"method": "turn/completed",
|
|
328
|
-
"params": {"turn": {"id": turn_id, "status": "failed"}}
|
|
329
|
-
})
|
|
330
|
-
)
|
|
331
|
-
}
|
|
332
|
-
|
|
333
295
|
fn find_event<'a>(events: &'a [serde_json::Value], name: &str) -> Option<&'a serde_json::Value> {
|
|
334
296
|
events
|
|
335
297
|
.iter()
|
|
@@ -230,6 +230,48 @@ fn spine2_sync_health_records_last_output_at() {
|
|
|
230
230
|
);
|
|
231
231
|
}
|
|
232
232
|
|
|
233
|
+
// P1 — capture_missing: an agent with NO session_id but a discoverable transcript under spawn_cwd gets
|
|
234
|
+
// its session_id captured + persisted (real capture_session_id); an agent that already has one is
|
|
235
|
+
// untouched. Golden sessions/capture.py:capture_missing_sessions.
|
|
236
|
+
#[test]
|
|
237
|
+
fn spine2_capture_missing_captures_session_id_for_missing_agent() {
|
|
238
|
+
use std::sync::atomic::{AtomicU64, Ordering};
|
|
239
|
+
static N: AtomicU64 = AtomicU64::new(0);
|
|
240
|
+
let tdir = std::env::temp_dir().join(format!(
|
|
241
|
+
"ta-rs-health-tx-{}-{}",
|
|
242
|
+
std::process::id(),
|
|
243
|
+
N.fetch_add(1, Ordering::Relaxed)
|
|
244
|
+
));
|
|
245
|
+
std::fs::create_dir_all(&tdir).unwrap();
|
|
246
|
+
// lane-046-capture-gap: Claude no-expected_session_id capture now requires
|
|
247
|
+
// positive_agent_id_match (TEAM_AGENT_ID=<id>) OR agent_path_match. Without
|
|
248
|
+
// a worker-identity signal, weak candidates can be leader transcripts and
|
|
249
|
+
// must not be attributed to a worker. The seeded transcript includes the
|
|
250
|
+
// TEAM_AGENT_ID marker for w1.
|
|
251
|
+
std::fs::write(
|
|
252
|
+
tdir.join("session.jsonl"),
|
|
253
|
+
r#"{"type":"user","sessionId":"sess-found","cwd":"x","message":{"content":"TEAM_AGENT_ID=w1 hi"}}"#,
|
|
254
|
+
)
|
|
255
|
+
.unwrap();
|
|
256
|
+
let agents = serde_json::json!({
|
|
257
|
+
"w1": { "provider": "claude_code", "window": "w1", "spawn_cwd": tdir.to_string_lossy() },
|
|
258
|
+
"w2": { "provider": "claude_code", "window": "w2", "session_id": "existing-sess" },
|
|
259
|
+
});
|
|
260
|
+
let (coord, dir) = seeded_health_coord(agents, "");
|
|
261
|
+
coord.tick().expect("tick");
|
|
262
|
+
assert!(
|
|
263
|
+
agent_field(&dir, "w1", "session_id").and_then(|v| v.as_str().map(str::to_string)).is_some(),
|
|
264
|
+
"capture_missing must capture+persist a session_id for an agent with a discoverable transcript; today it's a probe"
|
|
265
|
+
);
|
|
266
|
+
assert_eq!(
|
|
267
|
+
agent_field(&dir, "w2", "session_id")
|
|
268
|
+
.and_then(|v| v.as_str().map(str::to_string))
|
|
269
|
+
.as_deref(),
|
|
270
|
+
Some("existing-sess"),
|
|
271
|
+
"an agent that already has a session_id must be untouched"
|
|
272
|
+
);
|
|
273
|
+
}
|
|
274
|
+
|
|
233
275
|
// CONTRACT — sync_health runs BEFORE deliver_pending, but turn-level WORKING state must not make an
|
|
234
276
|
// alive worker undeliverable. Busy delivery deferral is lifecycle-only (`state.agents[id].status=="busy"`);
|
|
235
277
|
// activity/agent_health WORKING remains diagnostic turn state.
|
|
@@ -830,7 +830,7 @@ impl Coordinator {
|
|
|
830
830
|
// runs so the CapturedRuntimeFact map stays populated for
|
|
831
831
|
// downstream runtime detectors; only the activity classify
|
|
832
832
|
// happens once.
|
|
833
|
-
let jsonl_first =
|
|
833
|
+
let jsonl_first = jsonl_activity_for_agent(agent);
|
|
834
834
|
if let Some(activity) = jsonl_first.as_ref() {
|
|
835
835
|
remember_idle_capture_schedule(agent, activity);
|
|
836
836
|
write_activity(agent, activity, false);
|
|
@@ -2313,47 +2313,6 @@ fn jsonl_activity_for_agent(agent: &Value) -> Option<crate::messaging::AgentActi
|
|
|
2313
2313
|
activity
|
|
2314
2314
|
}
|
|
2315
2315
|
|
|
2316
|
-
/// #379: for Claude, its live session registry outranks the transcript tail,
|
|
2317
|
-
/// which still reads idle between a submitted prompt and the first assistant
|
|
2318
|
-
/// record. Busy and waiting are decisive; idle yields only to a background
|
|
2319
|
-
/// task the transcript still holds open.
|
|
2320
|
-
fn native_activity_for_agent(agent: &Value) -> Option<crate::messaging::AgentActivity> {
|
|
2321
|
-
use crate::messaging::{ActivityStatus, AgentActivity};
|
|
2322
|
-
let jsonl = jsonl_activity_for_agent(agent);
|
|
2323
|
-
let claude = agent
|
|
2324
|
-
.get("provider")
|
|
2325
|
-
.and_then(Value::as_str)
|
|
2326
|
-
.and_then(parse_provider)
|
|
2327
|
-
.is_some_and(crate::provider::wire::is_claude_family);
|
|
2328
|
-
let registry = crate::provider::claude_registry_key(agent)
|
|
2329
|
-
.filter(|_| claude)
|
|
2330
|
-
.and_then(|(sessions, session_id)| {
|
|
2331
|
-
crate::provider::claude_registry_turn_state(
|
|
2332
|
-
&sessions,
|
|
2333
|
-
&session_id,
|
|
2334
|
-
agent.get("pane_id").and_then(Value::as_str),
|
|
2335
|
-
)
|
|
2336
|
-
});
|
|
2337
|
-
let (status, state) = match registry {
|
|
2338
|
-
Some(TurnState::Working) => (ActivityStatus::Working, "busy"),
|
|
2339
|
-
Some(TurnState::BlockedOnHuman) => (ActivityStatus::Uncertain, "waiting"),
|
|
2340
|
-
Some(TurnState::Idle)
|
|
2341
|
-
if jsonl
|
|
2342
|
-
.as_ref()
|
|
2343
|
-
.is_some_and(|activity| activity.rationale == "provider_jsonl:background_task") =>
|
|
2344
|
-
{
|
|
2345
|
-
return jsonl;
|
|
2346
|
-
}
|
|
2347
|
-
Some(TurnState::Idle) => (ActivityStatus::Idle, "idle"),
|
|
2348
|
-
_ => return jsonl,
|
|
2349
|
-
};
|
|
2350
|
-
Some(AgentActivity {
|
|
2351
|
-
status,
|
|
2352
|
-
confidence: 0.95,
|
|
2353
|
-
rationale: format!("claude_session_registry:{state}"),
|
|
2354
|
-
})
|
|
2355
|
-
}
|
|
2356
|
-
|
|
2357
2316
|
fn runtime_approval_target(
|
|
2358
2317
|
agent: &Value,
|
|
2359
2318
|
session_name: Option<&str>,
|
|
@@ -2949,53 +2908,6 @@ mod u1_tests {
|
|
|
2949
2908
|
use super::*;
|
|
2950
2909
|
use std::io::Write as _;
|
|
2951
2910
|
|
|
2952
|
-
// #379: the registry beside the transcript decides Claude's live turn.
|
|
2953
|
-
#[cfg(unix)]
|
|
2954
|
-
#[test]
|
|
2955
|
-
fn issue379_claude_registry_outranks_an_idle_transcript_tail() {
|
|
2956
|
-
use crate::messaging::ActivityStatus;
|
|
2957
|
-
let config = std::env::temp_dir().join(format!("ta-379-native-activity-{}", std::process::id()));
|
|
2958
|
-
let _ = std::fs::remove_dir_all(&config);
|
|
2959
|
-
let sid = "22222222-3333-4444-8555-666666666666";
|
|
2960
|
-
let projects = config.join("projects").join("-owned-cwd");
|
|
2961
|
-
std::fs::create_dir_all(&projects).unwrap();
|
|
2962
|
-
std::fs::create_dir_all(config.join("sessions")).unwrap();
|
|
2963
|
-
let rollout = projects.join(format!("{sid}.jsonl"));
|
|
2964
|
-
let pid = std::process::id();
|
|
2965
|
-
let registry = |status: &str| {
|
|
2966
|
-
let record = serde_json::json!({"pid": pid, "sessionId": sid, "tmux": "team-x:@1.%7", "status": status});
|
|
2967
|
-
std::fs::write(config.join("sessions").join(format!("{pid}.json")), record.to_string()).unwrap();
|
|
2968
|
-
};
|
|
2969
|
-
let end_turn = r#"{"type":"assistant","requestId":"r1","message":{"stop_reason":"end_turn"}}"#;
|
|
2970
|
-
let agent = serde_json::json!({
|
|
2971
|
-
"provider": "claude", "pane_id": "%7", "rollout_path": rollout, "process_alive": true,
|
|
2972
|
-
});
|
|
2973
|
-
let observe = || native_activity_for_agent(&agent).map(|a| (a.status, a.rationale));
|
|
2974
|
-
|
|
2975
|
-
// A submitted prompt before its first assistant record: the tail still reads idle.
|
|
2976
|
-
std::fs::write(&rollout, format!("{end_turn}\n")).unwrap();
|
|
2977
|
-
registry("busy");
|
|
2978
|
-
assert_eq!(observe(), Some((ActivityStatus::Working, "claude_session_registry:busy".into())));
|
|
2979
|
-
registry("waiting");
|
|
2980
|
-
assert_eq!(observe(), Some((ActivityStatus::Uncertain, "claude_session_registry:waiting".into())));
|
|
2981
|
-
registry("idle");
|
|
2982
|
-
assert_eq!(observe(), Some((ActivityStatus::Idle, "claude_session_registry:idle".into())));
|
|
2983
|
-
// A background shell the transcript holds open keeps the worker busy.
|
|
2984
|
-
let background = r#"{"type":"user","message":{"content":[{"type":"tool_result","content":"Command running in background with ID: bg1"}]}}"#;
|
|
2985
|
-
std::fs::write(&rollout, format!("{background}\n{end_turn}\n")).unwrap();
|
|
2986
|
-
assert_eq!(observe(), Some((ActivityStatus::Working, "provider_jsonl:background_task".into())));
|
|
2987
|
-
// Cold start: no transcript captured yet, only the launch's session id and root.
|
|
2988
|
-
let cold = serde_json::json!({
|
|
2989
|
-
"provider": "claude", "pane_id": "%7", "_pending_session_id": sid,
|
|
2990
|
-
"claude_projects_root": config.join("projects"),
|
|
2991
|
-
});
|
|
2992
|
-
assert_eq!(
|
|
2993
|
-
native_activity_for_agent(&cold).map(|a| (a.status, a.rationale)),
|
|
2994
|
-
Some((ActivityStatus::Idle, "claude_session_registry:idle".into()))
|
|
2995
|
-
);
|
|
2996
|
-
let _ = std::fs::remove_dir_all(&config);
|
|
2997
|
-
}
|
|
2998
|
-
|
|
2999
2911
|
struct CaptureFailureRegistry;
|
|
3000
2912
|
|
|
3001
2913
|
impl ProviderRegistry for CaptureFailureRegistry {
|
|
@@ -87,7 +87,7 @@ pub struct NotificationClaimParams<'a> {
|
|
|
87
87
|
pub pane_id: Option<&'a str>,
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
-
///
|
|
90
|
+
/// Legacy #373 parked-row marker, retained only for upgrade recovery.
|
|
91
91
|
pub(crate) const MCP_HANDSHAKE_TIMEOUT: &str = "mcp_handshake_timeout";
|
|
92
92
|
|
|
93
93
|
/// Canonical initial message-row statuses shared by persistence, presentation,
|
|
@@ -612,46 +612,6 @@ impl MessageStore {
|
|
|
612
612
|
Ok(rows == 1)
|
|
613
613
|
}
|
|
614
614
|
|
|
615
|
-
/// Park an owned pre-input claim whose readiness wait reached its bound.
|
|
616
|
-
/// `queued_until_start` is claimable but never polled by `deliver_pending`;
|
|
617
|
-
/// only [`Self::requeue_parked_deliveries`] or a seat restart resumes it.
|
|
618
|
-
pub(crate) fn park_delivery_before_input(
|
|
619
|
-
&self,
|
|
620
|
-
message_id: &str,
|
|
621
|
-
attempt: u32,
|
|
622
|
-
) -> Result<bool, MessageStoreError> {
|
|
623
|
-
if attempt == 0 {
|
|
624
|
-
return Ok(false);
|
|
625
|
-
}
|
|
626
|
-
let conn = crate::db::schema::open_db(&self.path)?;
|
|
627
|
-
let rows = conn.execute(
|
|
628
|
-
"update messages
|
|
629
|
-
set status = 'queued_until_start',
|
|
630
|
-
delivery_attempts = delivery_attempts - 1,
|
|
631
|
-
error = ?3, updated_at = ?4
|
|
632
|
-
where message_id = ?1 and status = 'target_resolved'
|
|
633
|
-
and error is null and delivery_attempts = ?2",
|
|
634
|
-
params![message_id, attempt, MCP_HANDSHAKE_TIMEOUT, now_ts()],
|
|
635
|
-
)?;
|
|
636
|
-
Ok(rows == 1)
|
|
637
|
-
}
|
|
638
|
-
|
|
639
|
-
/// Return one seat's parked rows to the normal delivery queue.
|
|
640
|
-
pub(crate) fn requeue_parked_deliveries(
|
|
641
|
-
&self,
|
|
642
|
-
recipient: &str,
|
|
643
|
-
owner_team_id: &str,
|
|
644
|
-
) -> Result<usize, MessageStoreError> {
|
|
645
|
-
let conn = crate::db::schema::open_db(&self.path)?;
|
|
646
|
-
Ok(conn.execute(
|
|
647
|
-
"update messages
|
|
648
|
-
set status = 'accepted', error = null, updated_at = ?4
|
|
649
|
-
where recipient = ?1 and status = 'queued_until_start' and error = ?3
|
|
650
|
-
and (owner_team_id = ?2 or owner_team_id is null)",
|
|
651
|
-
params![recipient, owner_team_id, MCP_HANDSHAKE_TIMEOUT, now_ts()],
|
|
652
|
-
)?)
|
|
653
|
-
}
|
|
654
|
-
|
|
655
615
|
/// Read inbox rows through [`Self::inbox`]; recovery transitions below are
|
|
656
616
|
/// separate repository owners and are not claim eligibility.
|
|
657
617
|
pub fn requeue_blocked_leader_messages(
|
|
@@ -1278,34 +1238,16 @@ mod tests {
|
|
|
1278
1238
|
}
|
|
1279
1239
|
|
|
1280
1240
|
#[test]
|
|
1281
|
-
fn
|
|
1241
|
+
fn issue372_legacy_timeout_recovery_is_scoped_to_seat_and_owner() {
|
|
1282
1242
|
let s = store();
|
|
1283
1243
|
let mid = s.create_message(Some("t"), "s", "r", "c", None, true, Some("team-a")).unwrap();
|
|
1284
|
-
|
|
1285
|
-
assert!(s.
|
|
1286
|
-
assert!(
|
|
1287
|
-
assert!(s.park_delivery_before_input(&mid, 1).unwrap());
|
|
1288
|
-
assert!(!s.park_delivery_before_input(&mid, 1).unwrap(), "single winner");
|
|
1289
|
-
let c = read(&s);
|
|
1290
|
-
assert_eq!(status_of(&c, &mid), "queued_until_start");
|
|
1291
|
-
assert_eq!(col_str(&c, &mid, "error").as_deref(), Some(MCP_HANDSHAKE_TIMEOUT));
|
|
1292
|
-
assert_eq!(col_i64(&c, &mid, "delivery_attempts"), 0, "waiting spends no input attempt");
|
|
1293
|
-
assert_eq!(s.requeue_parked_deliveries("other", "team-a").unwrap(), 0);
|
|
1294
|
-
assert_eq!(s.requeue_parked_deliveries("r", "team-b").unwrap(), 0);
|
|
1295
|
-
assert_eq!(s.requeue_parked_deliveries("r", "team-a").unwrap(), 1);
|
|
1296
|
-
let c = read(&s);
|
|
1297
|
-
assert_eq!(status_of(&c, &mid), "accepted");
|
|
1298
|
-
assert_eq!(col_str(&c, &mid, "error"), None);
|
|
1299
|
-
}
|
|
1300
|
-
|
|
1301
|
-
#[test]
|
|
1302
|
-
fn issue372_seat_restart_also_resumes_parked_handshake_rows() {
|
|
1303
|
-
let s = store();
|
|
1304
|
-
let mid = s.create_message(Some("t"), "s", "r", "c", None, true, Some("team-a")).unwrap();
|
|
1305
|
-
assert!(s.claim_for_delivery(&mid).unwrap());
|
|
1306
|
-
assert!(s.park_delivery_before_input(&mid, 1).unwrap());
|
|
1244
|
+
s.mark(&mid, "queued_until_start", Some(MCP_HANDSHAKE_TIMEOUT)).unwrap();
|
|
1245
|
+
assert!(s.recover_worker_pane_available("other", Some("team-a")).unwrap().is_empty());
|
|
1246
|
+
assert!(s.recover_worker_pane_available("r", Some("team-b")).unwrap().is_empty());
|
|
1307
1247
|
assert_eq!(s.recover_worker_pane_available("r", Some("team-a")).unwrap(), vec![mid.clone()]);
|
|
1308
1248
|
assert_eq!(status_of(&read(&s), &mid), "accepted");
|
|
1249
|
+
assert_eq!(col_str(&read(&s), &mid, "error"), None);
|
|
1250
|
+
assert!(s.recover_worker_pane_available("r", Some("team-a")).unwrap().is_empty());
|
|
1309
1251
|
}
|
|
1310
1252
|
|
|
1311
1253
|
#[test]
|