@team-agent/installer 0.5.29 → 0.5.32

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.
@@ -94,3 +94,27 @@ fn delete_agent_health(workspace: &Path, agent_id: &AgentId) -> Result<(), crate
94
94
  )?;
95
95
  Ok(())
96
96
  }
97
+
98
+ /// 0.5.32 (`.team/artifacts/restart-resumed-stale-activity-locate.md` §5):
99
+ /// clear the `(owner_team_id, agent_id)` health observation row on a new
100
+ /// worker process cohort boundary. Distinct from `delete_agent_health` (used
101
+ /// by remove-agent rollback): this narrow helper keyed on both owner_team_id
102
+ /// and agent_id so a sibling team with the same agent_id keeps its own row.
103
+ /// Silently no-ops when the row is absent.
104
+ pub fn clear_agent_health_observation(
105
+ workspace: &Path,
106
+ owner_team_id: &str,
107
+ agent_id: &AgentId,
108
+ ) -> Result<(), crate::db::DbError> {
109
+ if owner_team_id.is_empty() {
110
+ return Ok(());
111
+ }
112
+ let store = crate::message_store::MessageStore::open(workspace)
113
+ .map_err(|e| crate::db::DbError::Schema(e.to_string()))?;
114
+ let conn = crate::db::schema::open_db(store.db_path())?;
115
+ conn.execute(
116
+ "delete from agent_health where owner_team_id = ?1 and agent_id = ?2",
117
+ rusqlite::params![owner_team_id, agent_id.as_str()],
118
+ )?;
119
+ Ok(())
120
+ }
@@ -443,7 +443,8 @@ pub fn claim_leader(
443
443
  let targets = claim_leader_targets(workspace, &raw_state);
444
444
  let caller_candidate = targets
445
445
  .iter()
446
- .find(|target| target.info.pane_id.as_str() == caller);
446
+ .filter(|target| target.info.pane_id.as_str() == caller)
447
+ .min_by_key(|target| target.source.priority());
447
448
  let caller_pane_info = caller_candidate.map(|target| &target.info);
448
449
  let caller_target = caller_candidate.and_then(|target| {
449
450
  claim_target_from_pane_info(workspace, &target.info).map(|mut claim_target| {
@@ -1220,10 +1221,45 @@ struct LeaderClaimTarget {
1220
1221
  struct ClaimLeaderTargetCandidate {
1221
1222
  info: PaneInfo,
1222
1223
  endpoint: Option<String>,
1224
+ source: ClaimLeaderTargetSource,
1225
+ }
1226
+
1227
+ #[derive(Clone, Copy, PartialEq, Eq)]
1228
+ enum ClaimLeaderTargetSource {
1229
+ StateRecorded,
1230
+ Workspace,
1231
+ CurrentTmux,
1232
+ Default,
1233
+ }
1234
+
1235
+ impl ClaimLeaderTargetSource {
1236
+ fn priority(self) -> u8 {
1237
+ match self {
1238
+ Self::StateRecorded => 0,
1239
+ Self::Workspace => 1,
1240
+ Self::CurrentTmux => 2,
1241
+ Self::Default => 3,
1242
+ }
1243
+ }
1223
1244
  }
1224
1245
 
1225
1246
  fn claim_leader_targets(workspace: &Path, state: &Value) -> Vec<ClaimLeaderTargetCandidate> {
1226
1247
  let mut targets = Vec::new();
1248
+ if let Some(endpoint) = crate::tmux_backend::socket_name_from_tmux_env() {
1249
+ let backend = tmux_backend_for_endpoint(&endpoint);
1250
+ let resolved_endpoint = backend.tmux_endpoint();
1251
+ targets.extend(
1252
+ backend
1253
+ .list_targets()
1254
+ .unwrap_or_default()
1255
+ .into_iter()
1256
+ .map(|info| ClaimLeaderTargetCandidate {
1257
+ info,
1258
+ endpoint: resolved_endpoint.clone(),
1259
+ source: ClaimLeaderTargetSource::CurrentTmux,
1260
+ }),
1261
+ );
1262
+ }
1227
1263
  for endpoint in state_recorded_tmux_endpoints(state) {
1228
1264
  let backend = tmux_backend_for_endpoint(&endpoint);
1229
1265
  let resolved_endpoint = backend.tmux_endpoint();
@@ -1235,6 +1271,7 @@ fn claim_leader_targets(workspace: &Path, state: &Value) -> Vec<ClaimLeaderTarge
1235
1271
  .map(|info| ClaimLeaderTargetCandidate {
1236
1272
  info,
1237
1273
  endpoint: resolved_endpoint.clone(),
1274
+ source: ClaimLeaderTargetSource::StateRecorded,
1238
1275
  }),
1239
1276
  );
1240
1277
  }
@@ -1248,6 +1285,7 @@ fn claim_leader_targets(workspace: &Path, state: &Value) -> Vec<ClaimLeaderTarge
1248
1285
  .map(|info| ClaimLeaderTargetCandidate {
1249
1286
  info,
1250
1287
  endpoint: workspace_endpoint.clone(),
1288
+ source: ClaimLeaderTargetSource::Workspace,
1251
1289
  }),
1252
1290
  );
1253
1291
  let default_backend = crate::transport_factory::tmux_default_transport();
@@ -1260,6 +1298,7 @@ fn claim_leader_targets(workspace: &Path, state: &Value) -> Vec<ClaimLeaderTarge
1260
1298
  .map(|info| ClaimLeaderTargetCandidate {
1261
1299
  info,
1262
1300
  endpoint: default_endpoint.clone(),
1301
+ source: ClaimLeaderTargetSource::Default,
1263
1302
  }),
1264
1303
  );
1265
1304
  targets
@@ -284,6 +284,14 @@ pub(crate) fn start_agent_at_paths(
284
284
  // after spawn" race with coordinator and no double source of truth.
285
285
  crate::lifecycle::launch::annotate_runtime_tmux_endpoint(&mut state, transport, workspace);
286
286
  let team_key = restart_projection_team_key(&state, team);
287
+ // 0.5.32 (`.team/artifacts/restart-resumed-stale-activity-locate.md` §5):
288
+ // clear the matching `agent_health` observation on the new spawn cohort
289
+ // so five-line status summary and status --json do not surface a stale
290
+ // WORKING row from the pre-shutdown process. Best-effort: DB failure
291
+ // must not fail the start-agent path.
292
+ let _ = crate::db::agent_health_capture::clear_agent_health_observation(
293
+ workspace, &team_key, agent_id,
294
+ );
287
295
  let skip_capture_backfill = if matches!(
288
296
  start_mode,
289
297
  StartMode::Fresh | StartMode::FreshAfterMissingRollout
@@ -977,6 +985,12 @@ fn mark_agent_started(
977
985
  agent_id
978
986
  )));
979
987
  };
988
+ // 0.5.32 (`.team/artifacts/restart-resumed-stale-activity-locate.md` §5):
989
+ // a successful new process cohort invalidates the per-agent
990
+ // turn/activity observation set. Do this before overwriting the
991
+ // lifecycle/topology fields so absence == UNKNOWN until the next
992
+ // coordinator tick or pane fallback produces a post-spawn observation.
993
+ clear_agent_runtime_activity_observation(agent);
980
994
  // S1-CAPTURE-001 (0.4.8, CR M3 provider-agnostic): on a Fresh /
981
995
  // FreshAfterMissingRollout start, the prior session's authoritative
982
996
  // capture tuple MUST be cleared before persist_command_plan_state
@@ -1601,6 +1601,33 @@ pub(super) fn state_spawn_epoch_for_agent(workspace: &Path, agent_id: &AgentId)
1601
1601
  .unwrap_or(0)
1602
1602
  }
1603
1603
 
1604
+ /// 0.5.32 (`.team/artifacts/restart-resumed-stale-activity-locate.md` §5):
1605
+ /// clear the per-agent turn/activity observation set on a successful new
1606
+ /// worker process cohort. Called from `mark_agent_started` /
1607
+ /// `mark_agent_respawned` / `mark_fake_harness_agent_respawned`; NOT from
1608
+ /// `mark_agent_running_noop` (no new process was created there).
1609
+ ///
1610
+ /// Removes only observation fields — never lifecycle/topology fields. After
1611
+ /// clearing, absence is UNKNOWN, not synthesized idle (T7 unknown-never-idle
1612
+ /// discipline); the next post-spawn tick may repopulate from JSONL freshness
1613
+ /// gate + pane fallback.
1614
+ pub(super) fn clear_agent_runtime_activity_observation(
1615
+ agent: &mut serde_json::Map<String, serde_json::Value>,
1616
+ ) {
1617
+ for field in [
1618
+ "activity",
1619
+ "worker_state",
1620
+ "last_output_at",
1621
+ "last_output_hash",
1622
+ "current_turn_message_id",
1623
+ "current_task_id", // ALLOWED-LEGACY-READ (Phase-DX E2): cleanup removal of legacy display-only key on new spawn cohort; helper does not read the value.
1624
+ "task_id",
1625
+ "coordinator_idle_capture_next_at",
1626
+ ] {
1627
+ agent.remove(field);
1628
+ }
1629
+ }
1630
+
1604
1631
  #[cfg(test)]
1605
1632
  mod e36_transcript_backing_tests {
1606
1633
  use super::*;
@@ -433,7 +433,8 @@ fn restart_with_selected_team_and_transport(
433
433
  &decision.agent_id,
434
434
  &raw_agent,
435
435
  );
436
- if has_endpoint_convergence_marker(&state) && is_fake_model_harness_agent(&agent) {
436
+ if endpoint_convergence_fake_harness_enabled(&state) && is_fake_model_harness_agent(&agent)
437
+ {
437
438
  write_fake_harness_spawn_argv_event(
438
439
  &selected.run_workspace,
439
440
  decision,
@@ -447,6 +448,13 @@ fn restart_with_selected_team_and_transport(
447
448
  &session_name,
448
449
  &selected.team_key,
449
450
  );
451
+ // 0.5.32: fake harness respawn shares the same spawn cohort
452
+ // boundary — clear the matching `agent_health` observation.
453
+ let _ = crate::db::agent_health_capture::clear_agent_health_observation(
454
+ &selected.run_workspace,
455
+ &selected.team_key,
456
+ &decision.agent_id,
457
+ );
450
458
  successful_agents.push(decision.clone());
451
459
  continue;
452
460
  }
@@ -554,6 +562,15 @@ fn restart_with_selected_team_and_transport(
554
562
  {
555
563
  persist_effective_approval_policy_for_restart(agent, &safety);
556
564
  }
565
+ // 0.5.32 (`.team/artifacts/restart-resumed-stale-activity-locate.md` §5):
566
+ // pair the state-side activity clear with a DB `agent_health` clear so
567
+ // status --json's health projection does not surface the pre-restart
568
+ // WORKING row. Best-effort: DB failure must not fail the restart loop.
569
+ let _ = crate::db::agent_health_capture::clear_agent_health_observation(
570
+ &selected.run_workspace,
571
+ &selected.team_key,
572
+ &decision.agent_id,
573
+ );
557
574
  }
558
575
  // END_B5_RESTART_ISOLATION_LOOP
559
576
  let mut topology_authority_agent_ids = successful_agents
@@ -1242,7 +1259,7 @@ fn restart_worker_panes_addressable(
1242
1259
  if decisions.is_empty() {
1243
1260
  return true;
1244
1261
  }
1245
- if has_endpoint_convergence_marker(state)
1262
+ if endpoint_convergence_fake_harness_enabled(state)
1246
1263
  && decisions.iter().all(|decision| {
1247
1264
  state
1248
1265
  .get("agents")
@@ -1628,6 +1645,12 @@ fn mark_agent_respawned(
1628
1645
  agent_id
1629
1646
  )));
1630
1647
  };
1648
+ // 0.5.32 (`.team/artifacts/restart-resumed-stale-activity-locate.md` §5):
1649
+ // multi-worker restart respawn is a new process cohort; clear the
1650
+ // per-agent turn/activity observation set before overwriting lifecycle
1651
+ // fields so stale `activity=working` / `worker_state=BUSY` do not
1652
+ // survive into the fresh cohort.
1653
+ clear_agent_runtime_activity_observation(agent);
1631
1654
  agent.insert("status".to_string(), serde_json::json!("running"));
1632
1655
  agent.insert(
1633
1656
  "window".to_string(),
@@ -1783,6 +1806,10 @@ fn mark_fake_harness_agent_respawned(
1783
1806
  else {
1784
1807
  return;
1785
1808
  };
1809
+ // 0.5.32 (`.team/artifacts/restart-resumed-stale-activity-locate.md` §5):
1810
+ // fake harness respawn is also a new process cohort — RED fixtures must
1811
+ // not preserve stale activity observations across restart.
1812
+ clear_agent_runtime_activity_observation(agent);
1786
1813
  agent.insert("status".to_string(), serde_json::json!("running"));
1787
1814
  agent.insert("window".to_string(), serde_json::json!(agent_id.as_str()));
1788
1815
  agent.insert(
@@ -2489,6 +2516,11 @@ fn has_endpoint_convergence_marker(state: &serde_json::Value) -> bool {
2489
2516
  == Some("converged")
2490
2517
  }
2491
2518
 
2519
+ fn endpoint_convergence_fake_harness_enabled(state: &serde_json::Value) -> bool {
2520
+ has_endpoint_convergence_marker(state)
2521
+ && std::env::var_os("TEAM_AGENT_TEST_ENDPOINT_CONVERGENCE_HARNESS_SPEC_FALLBACK").is_some()
2522
+ }
2523
+
2492
2524
  fn is_fake_model_harness_agent(agent: &serde_json::Value) -> bool {
2493
2525
  agent_provider(agent) == crate::model::enums::Provider::Fake
2494
2526
  && agent.get("model").and_then(serde_json::Value::as_str) == Some("fake")
@@ -57,7 +57,7 @@ fn stuck_cancel_snapshot_delivered_message_ids_uses_golden_status_set() {
57
57
  // is `store.add_result(envelope)`'d (results.py:73) regardless of any in-flight delivery, then the
58
58
  // collection loop collects it when its task_id is a known task (state.tasks) OR message-scoped (msg_+
59
59
  // matching message). NO live in-flight task is required at ingest time. rt-host-b @ c262bf7 saw a
60
- // VALID envelope (validate-result accepts the same) collect to exit-1 / empty output / NOT in the
60
+ // VALID envelope collect to exit-1 / empty output / NOT in the
61
61
  // results table — i.e. the --result-file ingest path was a no-op (results.rs once did
62
62
  // `let _ = (result_file, …)`). This pins the happy path: a valid envelope for a KNOWN task must be
63
63
  // ingested into the results table AND collected, with ok=true. (Completes the previously-deferred
@@ -75,7 +75,7 @@ use crate::model::enums::Provider;
75
75
  // ── REUSE — step 4 event_log(install/upgrade/repair 审计事件;原子替换的 rebuild/rollback 标记)──
76
76
  use crate::event_log::EventLog;
77
77
 
78
- // ── REUSE — step 5 state(uninstall「有 team 在跑勿删」判定经 state 投影;repair-state 转调)──
78
+ // ── REUSE — step 5 state(uninstall「有 team 在跑勿删」判定经 state 投影)──
79
79
  // `state` 操作 state.json = serde_json::Value;此处仅在 fn 签名内经全限定路径引用,避免未用顶层 import。
80
80
 
81
81
  #[cfg(test)]
@@ -400,7 +400,7 @@ pub enum PackagingError {
400
400
  /// step 3 schema/migration 转调错误。
401
401
  #[error("schema: {0}")]
402
402
  Db(#[from] DbError),
403
- /// step 5 state(repair-state / team-running 判定)转调错误。
403
+ /// step 5 state(team-running 判定)转调错误。
404
404
  #[error("state: {0}")]
405
405
  State(String),
406
406
  /// model 校验/解析转调(版本解析等)。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@team-agent/installer",
3
- "version": "0.5.29",
3
+ "version": "0.5.32",
4
4
  "description": "npx installer for Team Agent",
5
5
  "keywords": [
6
6
  "codex",
@@ -20,9 +20,9 @@
20
20
  "team-agent-installer": "npm/install.mjs"
21
21
  },
22
22
  "optionalDependencies": {
23
- "@team-agent/cli-darwin-arm64": "0.5.29",
24
- "@team-agent/cli-darwin-x64": "0.5.29",
25
- "@team-agent/cli-linux-x64": "0.5.29"
23
+ "@team-agent/cli-darwin-arm64": "0.5.32",
24
+ "@team-agent/cli-darwin-x64": "0.5.32",
25
+ "@team-agent/cli-linux-x64": "0.5.32"
26
26
  },
27
27
  "scripts": {
28
28
  "postinstall": "node npm/bincheck.mjs",
@@ -44,7 +44,7 @@ Fresh/reset red line:
44
44
  | Leader pane exists but messages say `leader_not_attached`, `rebind_required`, `team_owner_mismatch`, or leader 被抢 | Leader ownership or receiver binding drift | §2 L3 Claim Or Rebind Leader |
45
45
  | A live team must be recovered without losing worker context | Resume/restart path needed | §3 L2 Restart With Resume First |
46
46
  | Shutdown/restart cleanup status is ambiguous | Need residue-based truth, not a single `ok` field | §4 L1/L2 Cleanup Verification |
47
- | MCP tool call fails with `Transport closed` while the worker still has the payload | Provider-owned MCP stdio child died | §5 Superseded/Pending E23 Fallback Boundary |
47
+ | MCP tool call fails with `Transport closed` while the worker still has the payload | Provider-owned MCP stdio child died | §5 MCP Transport-Dead Payload Handoff |
48
48
 
49
49
  ## 1. L1 Read-Only Triage
50
50
 
@@ -239,30 +239,15 @@ Python 0.2.11 compatibility note:
239
239
 
240
240
  - Python cleanup notes may mention direct tmux commands. They are not listed here as RS recovery prescriptions.
241
241
 
242
- ## 5. Superseded/Pending E23 Fallback Boundary
242
+ ## 5. MCP Transport-Dead Payload Handoff
243
243
 
244
- [contextual: preserved] [level: L1] E23 fallback is the only narrow worker-scope exception to the normal tool boundary. It is for a current payload already in hand after a leader-bound MCP delivery failure.
244
+ [contextual: preserved] [level: L1] If the worker already has a leader-bound payload in hand and the MCP transport dies before the normal `send` or `report_result` path can accept it, preserve the payload in a file handoff artifact and ask for leader/user recovery through the visible channel that still works.
245
245
 
246
- Current status:
247
-
248
- - Product implementation exists in the E23 branch for `fallback-send-leader` and `fallback-report-result`.
249
- - Local RS verification has covered CLI help and focused E23 tests.
250
- - This reference does not yet promote the fallback CLI to a general external prescription because the new documentation gate requires current-release RS validation in the Mac mini environment.
251
-
252
- Until that validation is added:
253
-
254
- - Workers should write a file handoff artifact for the current payload and ask for leader/user recovery.
255
- - Leaders should prefer restart/resume of the affected worker after the current payload is preserved.
256
-
257
- Do not use E23 fallback as a general message path. It does not permit arbitrary worker execution of L2/L3 recovery operations.
258
-
259
- RS verification record:
260
-
261
- - Local only at the time of this reference update: E23 focused tests and CLI help on the merged E23 documentation branch. Mac mini current-release validation is still required before adding exact fallback commands here.
246
+ After restart/resume, use the normal MCP tool path again. Do not treat file handoff as a general message path or as permission to run arbitrary L2/L3 recovery operations.
262
247
 
263
248
  Python 0.2.11 compatibility note:
264
249
 
265
- - Python MCP stdio EOF had no durable reconnect. File handoff was the practical fallback. RS E23 adds product support, but this entry remains gated until real-machine validation is complete.
250
+ - Python MCP stdio EOF had no durable reconnect. File handoff was the practical fallback.
266
251
 
267
252
  ## Held Out Of This Reference
268
253