@team-agent/installer 0.5.61 → 0.5.63
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/crates/team-agent/src/cli/adapters.rs +5 -2
- package/crates/team-agent/src/cli/attach_app_server_leader.rs +1 -0
- package/crates/team-agent/src/cli/diagnose.rs +1 -0
- package/crates/team-agent/src/cli/emit.rs +41 -7
- package/crates/team-agent/src/cli/helpers.rs +1 -0
- package/crates/team-agent/src/cli/leader.rs +6 -1
- package/crates/team-agent/src/cli/leaders.rs +2 -0
- package/crates/team-agent/src/cli/mod.rs +33 -3
- package/crates/team-agent/src/cli/named_address.rs +8 -1
- package/crates/team-agent/src/cli/profile.rs +2 -1
- package/crates/team-agent/src/cli/send/coordinator.rs +1 -0
- package/crates/team-agent/src/cli/send/mailbox.rs +3 -0
- package/crates/team-agent/src/cli/send/persist.rs +1 -0
- package/crates/team-agent/src/cli/send/presentation.rs +1 -0
- package/crates/team-agent/src/cli/send/resolve.rs +206 -1
- package/crates/team-agent/src/cli/send.rs +2 -1
- package/crates/team-agent/src/cli/spec.rs +1 -0
- package/crates/team-agent/src/cli/status.rs +2 -1
- package/crates/team-agent/src/cli/status_port/compact.rs +1 -0
- package/crates/team-agent/src/cli/status_port/format.rs +1 -0
- package/crates/team-agent/src/cli/status_port/inbox.rs +1 -0
- package/crates/team-agent/src/cli/tests/verb_profile.rs +38 -0
- package/crates/team-agent/src/cli/types.rs +3 -2
- package/crates/team-agent/src/communication_mode/mod.rs +1 -0
- package/crates/team-agent/src/compiler.rs +1 -0
- package/crates/team-agent/src/conpty/backend.rs +1 -0
- package/crates/team-agent/src/conpty/mod.rs +1 -0
- package/crates/team-agent/src/coordinator/backoff.rs +5 -8
- package/crates/team-agent/src/coordinator/conpty_shim.rs +3 -2
- package/crates/team-agent/src/coordinator/health.rs +1 -0
- package/crates/team-agent/src/coordinator/mod.rs +2 -2
- package/crates/team-agent/src/coordinator/orphan.rs +4 -116
- package/crates/team-agent/src/coordinator/runtime_detectors.rs +1 -0
- package/crates/team-agent/src/coordinator/runtime_observation.rs +1 -0
- package/crates/team-agent/src/coordinator/steps/abnormal.rs +15 -866
- package/crates/team-agent/src/coordinator/steps/delivery.rs +1 -0
- package/crates/team-agent/src/coordinator/steps/health_sync.rs +1 -0
- package/crates/team-agent/src/coordinator/steps/mod.rs +2 -0
- package/crates/team-agent/src/coordinator/steps/persist.rs +1 -0
- package/crates/team-agent/src/coordinator/steps/runtime_prompts.rs +1 -0
- package/crates/team-agent/src/coordinator/steps/session_gate.rs +1 -0
- package/crates/team-agent/src/coordinator/tests/abnormal.rs +0 -174
- package/crates/team-agent/src/coordinator/tests/api_error_recovery.rs +139 -375
- package/crates/team-agent/src/coordinator/tests/basics.rs +0 -184
- package/crates/team-agent/src/coordinator/tests/mod.rs +2 -17
- package/crates/team-agent/src/coordinator/tests/tick_core.rs +0 -49
- package/crates/team-agent/src/coordinator/tick.rs +23 -40
- package/crates/team-agent/src/coordinator/types.rs +3 -176
- package/crates/team-agent/src/db/agent_health_capture.rs +1 -0
- package/crates/team-agent/src/db/message_store.rs +2 -1
- package/crates/team-agent/src/db/migration.rs +5 -4
- package/crates/team-agent/src/db/mod.rs +1 -0
- package/crates/team-agent/src/db/schema.rs +1 -0
- package/crates/team-agent/src/diagnose/comms.rs +2 -1
- package/crates/team-agent/src/diagnose/mod.rs +1 -0
- package/crates/team-agent/src/diagnose/orphans.rs +1 -0
- package/crates/team-agent/src/layout/manager.rs +3 -7
- package/crates/team-agent/src/layout/mod.rs +2 -2
- package/crates/team-agent/src/layout/overlay.rs +6 -1
- package/crates/team-agent/src/layout/placement.rs +1 -0
- package/crates/team-agent/src/layout/recovery.rs +3 -0
- package/crates/team-agent/src/layout/runtime_sessions.rs +8 -3
- package/crates/team-agent/src/layout/sessions.rs +8 -1
- package/crates/team-agent/src/layout/tmux_endpoint.rs +3 -0
- package/crates/team-agent/src/layout/worker_env.rs +3 -0
- package/crates/team-agent/src/layout/worker_window_helpers.rs +2 -0
- package/crates/team-agent/src/leader/helpers.rs +1 -0
- package/crates/team-agent/src/leader/incident.rs +1 -0
- package/crates/team-agent/src/leader/lease.rs +27 -22
- package/crates/team-agent/src/leader/mod.rs +2 -3
- package/crates/team-agent/src/leader/owner_bind.rs +13 -3
- package/crates/team-agent/src/leader/provider_attribution.rs +1 -0
- package/crates/team-agent/src/leader/rediscover.rs +4 -17
- package/crates/team-agent/src/leader/registry.rs +3 -15
- package/crates/team-agent/src/leader/start.rs +373 -125
- package/crates/team-agent/src/leader/takeover.rs +10 -232
- package/crates/team-agent/src/leader/tests/claim_leader_mailbox_flush_contract.rs +544 -0
- package/crates/team-agent/src/leader/tests/historical_inventory_upgrade_gate_red.rs +624 -0
- package/crates/team-agent/src/leader/tests/identity.rs +7 -2
- package/crates/team-agent/src/leader/tests/idle.rs +0 -193
- package/crates/team-agent/src/leader/tests/lease_api.rs +0 -45
- package/crates/team-agent/src/leader/tests/mod.rs +4 -41
- package/crates/team-agent/src/leader/tests/rehomed_env.rs +83 -0
- package/crates/team-agent/src/leader/tests/team_in_team_state_scope_red.rs +1273 -0
- package/crates/team-agent/src/leader/tests/terminal_and_replay_vs_rerender_invariants_red.rs +417 -0
- package/crates/team-agent/src/leader/tests/wake_start_owner.rs +22 -103
- package/crates/team-agent/src/leader/types.rs +1 -28
- package/crates/team-agent/src/lib.rs +3 -0
- package/crates/team-agent/src/lifecycle/display.rs +7 -1
- package/crates/team-agent/src/lifecycle/helpers.rs +3 -1
- package/crates/team-agent/src/lifecycle/launch/add_agent.rs +2 -2
- package/crates/team-agent/src/lifecycle/launch/fork_agent/completion.rs +1 -0
- package/crates/team-agent/src/lifecycle/launch/fork_entry.rs +1 -0
- package/crates/team-agent/src/lifecycle/launch/fork_finalize.rs +1 -0
- package/crates/team-agent/src/lifecycle/launch/plan.rs +2 -2
- package/crates/team-agent/src/lifecycle/launch/quick_start.rs +4 -26
- package/crates/team-agent/src/lifecycle/launch/readiness.rs +0 -27
- package/crates/team-agent/src/lifecycle/launch/spawn.rs +1 -27
- package/crates/team-agent/src/lifecycle/launch/spec_state.rs +4 -32
- package/crates/team-agent/src/lifecycle/launch/state_projection.rs +1 -0
- package/crates/team-agent/src/lifecycle/launch.rs +11 -12
- package/crates/team-agent/src/lifecycle/mod.rs +2 -1
- package/crates/team-agent/src/lifecycle/restart/agent.rs +3 -66
- package/crates/team-agent/src/lifecycle/restart/orchestrator.rs +2 -2
- package/crates/team-agent/src/lifecycle/restart/rebuild.rs +13 -5
- package/crates/team-agent/src/lifecycle/restart/remove.rs +1 -1
- package/crates/team-agent/src/lifecycle/restart/selection.rs +3 -3
- package/crates/team-agent/src/lifecycle/restart.rs +13 -15
- package/crates/team-agent/src/lifecycle/tests/acceptance_b_batch_red.rs +1007 -0
- package/crates/team-agent/src/lifecycle/tests/b0_legacy_snapshot_nonauthority_contract.rs +265 -0
- package/crates/team-agent/src/lifecycle/tests/b0_reader_hideone_audit_contract.rs +459 -0
- package/crates/team-agent/src/lifecycle/tests/behavioral_diff_264_red.rs +849 -0
- package/crates/team-agent/src/lifecycle/tests/claude_compatible_config_red.rs +323 -0
- package/crates/team-agent/src/lifecycle/tests/claude_profile_launch_red.rs +423 -0
- package/crates/team-agent/src/lifecycle/tests/clone_fork_copilot_perms_red.rs +737 -0
- package/crates/team-agent/src/lifecycle/tests/codex_mcp_approval_inheritance_red.rs +1187 -0
- package/crates/team-agent/src/lifecycle/tests/codex_weak_window_attribution_red.rs +683 -0
- package/crates/team-agent/src/lifecycle/tests/communication_mode_runtime_contract_red.rs +394 -0
- package/crates/team-agent/src/lifecycle/tests/copilot_provider_red.rs +1856 -0
- package/crates/team-agent/src/lifecycle/tests/core_034_real_red.rs +917 -0
- package/crates/team-agent/src/lifecycle/tests/display_adaptive_red.rs +481 -0
- package/crates/team-agent/src/lifecycle/tests/f032_startup_prompt_best_effort_red.rs +301 -0
- package/crates/team-agent/src/lifecycle/tests/harvest2_a_batch_red.rs +516 -0
- package/crates/team-agent/src/lifecycle/tests/host_cotenant_death_p0_contract.rs +986 -0
- package/crates/team-agent/src/lifecycle/tests/lifecycle_rollback_red.rs +651 -0
- package/crates/team-agent/src/lifecycle/tests/main_preserved.rs +2 -0
- package/crates/team-agent/src/lifecycle/tests/quick_start_worker_readiness_red.rs +332 -0
- package/crates/team-agent/src/lifecycle/tests/realmachine_clusters_1_6_red.rs +846 -0
- package/crates/team-agent/src/lifecycle/tests/realmachine_residual_g1_g4_red.rs +648 -0
- package/crates/team-agent/src/lifecycle/tests/restart_build_before_destroy_0540_contract.rs +910 -0
- package/crates/team-agent/src/lifecycle/tests/restart_liveness_red.rs +630 -0
- package/crates/team-agent/src/lifecycle/tests/restart_rebind_hotfix_252_red.rs +1083 -0
- package/crates/team-agent/src/lifecycle/tests/restart_session_capture_red.rs +1677 -0
- package/crates/team-agent/src/lifecycle/tests/resume_recover_red.rs +410 -0
- package/crates/team-agent/src/lifecycle/tests/stale_team_saveconflict_contract.rs +428 -0
- package/crates/team-agent/src/lifecycle/tests/startup_latency_contract.rs +1032 -0
- package/crates/team-agent/src/lifecycle/tests/status_credential_redaction_contract.rs +869 -0
- package/crates/team-agent/src/lifecycle/tests/subprep_codex_trust_roundtrip_red.rs +1249 -0
- package/crates/team-agent/src/lifecycle/tests/swallow_batch4_semantics_red.rs +342 -0
- package/crates/team-agent/src/lifecycle/tests/team_in_team_identity_scope_red.rs +542 -0
- package/crates/team-agent/src/lifecycle/tests/team_in_team_sibling_quick_start_red.rs +1103 -0
- package/crates/team-agent/src/lifecycle/tests/team_in_team_state_scope_red.rs +1276 -0
- package/crates/team-agent/src/lifecycle/tests/team_key_retirement_roster_red.rs +145 -0
- package/crates/team-agent/src/lifecycle/tests/team_key_retirement_txn_red.rs +603 -0
- package/crates/team-agent/src/lifecycle/tests/test_isolation_escape_contract.rs +837 -0
- package/crates/team-agent/src/lifecycle/tests/upgrade_compat_0211_red.rs +928 -0
- package/crates/team-agent/src/lifecycle/tests/verify_rs031_window_consistency_red.rs +951 -0
- package/crates/team-agent/src/lifecycle/tests/worker_dangerous_bypass_argv_red.rs +327 -0
- package/crates/team-agent/src/lifecycle/tests/worker_spawn_env_red.rs +760 -0
- package/crates/team-agent/src/lifecycle/tests.rs +59 -0
- package/crates/team-agent/src/lifecycle/types.rs +0 -9
- package/crates/team-agent/src/mcp_server/helpers.rs +1 -0
- package/crates/team-agent/src/mcp_server/lifecycle_tools/mod.rs +1 -0
- package/crates/team-agent/src/mcp_server/lifecycle_tools/state_status.rs +1 -0
- package/crates/team-agent/src/mcp_server/mod.rs +1 -0
- package/crates/team-agent/src/mcp_server/normalize.rs +4 -3
- package/crates/team-agent/src/mcp_server/tools.rs +1 -0
- package/crates/team-agent/src/mcp_server/types.rs +1 -18
- package/crates/team-agent/src/mcp_server/wire.rs +5 -5
- package/crates/team-agent/src/messaging/activity.rs +1 -0
- package/crates/team-agent/src/messaging/address.rs +1 -0
- package/crates/team-agent/src/messaging/delivery.rs +4 -3
- package/crates/team-agent/src/messaging/helpers.rs +2 -1
- package/crates/team-agent/src/messaging/leader_channel.rs +1 -0
- package/crates/team-agent/src/messaging/leader_receiver.rs +2 -1
- package/crates/team-agent/src/messaging/mod.rs +10 -14
- package/crates/team-agent/src/messaging/peers.rs +2 -0
- package/crates/team-agent/src/messaging/persist.rs +3 -1
- package/crates/team-agent/src/messaging/presentation.rs +2 -1
- package/crates/team-agent/src/messaging/results.rs +1 -0
- package/crates/team-agent/src/messaging/scheduler.rs +1 -0
- package/crates/team-agent/src/messaging/selftest.rs +1 -1
- package/crates/team-agent/src/messaging/send.rs +41 -8
- package/crates/team-agent/src/messaging/tests/mod.rs +5 -0
- package/crates/team-agent/src/messaging/types.rs +2 -2
- package/crates/team-agent/src/messaging/watchers.rs +19 -13
- package/crates/team-agent/src/model/enums.rs +1 -0
- package/crates/team-agent/src/model/errors.rs +1 -0
- package/crates/team-agent/src/model/ids.rs +1 -0
- package/crates/team-agent/src/model/mod.rs +1 -0
- package/crates/team-agent/src/model/name_similarity.rs +1 -0
- package/crates/team-agent/src/model/pane_authority_refusal.rs +1 -0
- package/crates/team-agent/src/model/paths.rs +1 -0
- package/crates/team-agent/src/model/permissions.rs +3 -2
- package/crates/team-agent/src/model/routing.rs +1 -0
- package/crates/team-agent/src/model/spec.rs +1 -0
- package/crates/team-agent/src/model/task_graph.rs +1 -0
- package/crates/team-agent/src/model/yaml/tests.rs +1 -0
- package/crates/team-agent/src/model/yaml.rs +1 -0
- package/crates/team-agent/src/packaging/install.rs +9 -147
- package/crates/team-agent/src/packaging/migrate.rs +2 -0
- package/crates/team-agent/src/packaging/mod.rs +1 -0
- package/crates/team-agent/src/packaging/repair.rs +2 -0
- package/crates/team-agent/src/packaging/tests.rs +29 -218
- package/crates/team-agent/src/packaging/types.rs +8 -15
- package/crates/team-agent/src/platform/argv.rs +4 -0
- package/crates/team-agent/src/platform/errors.rs +10 -1
- package/crates/team-agent/src/platform/file_lock.rs +4 -157
- package/crates/team-agent/src/platform/mod.rs +0 -61
- package/crates/team-agent/src/platform/process.rs +1 -0
- package/crates/team-agent/src/provider/adapter.rs +1 -0
- package/crates/team-agent/src/provider/adapters/claude.rs +1 -0
- package/crates/team-agent/src/provider/adapters/claude_fork.rs +1 -0
- package/crates/team-agent/src/provider/adapters/codex.rs +1 -0
- package/crates/team-agent/src/provider/adapters/copilot.rs +1 -0
- package/crates/team-agent/src/provider/adapters/copilot_fork.rs +1 -0
- package/crates/team-agent/src/provider/adapters/fake.rs +1 -0
- package/crates/team-agent/src/provider/adapters/mod.rs +1 -0
- package/crates/team-agent/src/provider/approvals/mod.rs +1 -0
- package/crates/team-agent/src/provider/approvals/parsing.rs +2 -5
- package/crates/team-agent/src/provider/approvals/runtime_prompts.rs +6 -5
- package/crates/team-agent/src/provider/classify.rs +1 -0
- package/crates/team-agent/src/provider/faults.rs +1 -26
- package/crates/team-agent/src/provider/helpers.rs +1 -0
- package/crates/team-agent/src/provider/mod.rs +1 -1
- package/crates/team-agent/src/provider/session/capture.rs +1 -4
- package/crates/team-agent/src/provider/session/context_fork/claude.rs +1 -0
- package/crates/team-agent/src/provider/session/context_fork/codex.rs +1 -0
- package/crates/team-agent/src/provider/session/context_fork/outcome.rs +1 -0
- package/crates/team-agent/src/provider/session/context_fork.rs +1 -0
- package/crates/team-agent/src/provider/session/mod.rs +2 -4
- package/crates/team-agent/src/provider/session/resume.rs +2 -209
- package/crates/team-agent/src/provider/session_scan/claude.rs +1 -0
- package/crates/team-agent/src/provider/session_scan/codex.rs +1 -0
- package/crates/team-agent/src/provider/session_scan/common.rs +1 -0
- package/crates/team-agent/src/provider/session_scan/copilot.rs +1 -0
- package/crates/team-agent/src/provider/session_scan.rs +1 -42
- package/crates/team-agent/src/provider/startup_prompt.rs +1 -0
- package/crates/team-agent/src/provider/types.rs +1 -0
- package/crates/team-agent/src/provider/wire.rs +1 -0
- package/crates/team-agent/src/state/identity.rs +16 -5
- package/crates/team-agent/src/state/identity_keys.rs +1 -0
- package/crates/team-agent/src/state/mod.rs +2 -0
- package/crates/team-agent/src/state/owner_gate.rs +5 -0
- package/crates/team-agent/src/state/ownership.rs +10 -4
- package/crates/team-agent/src/state/paths.rs +12 -0
- package/crates/team-agent/src/state/persist.rs +9 -3
- package/crates/team-agent/src/state/projection.rs +15 -2
- package/crates/team-agent/src/state/repository/intent.rs +1 -0
- package/crates/team-agent/src/state/repository/tests.rs +1 -0
- package/crates/team-agent/src/state/repository.rs +7 -13
- package/crates/team-agent/src/state/selector.rs +1 -0
- package/crates/team-agent/src/tmux_backend/tests.rs +39 -0
- package/crates/team-agent/src/tmux_backend.rs +63 -0
- package/crates/team-agent/src/transport.rs +15 -0
- package/package.json +4 -4
- package/crates/team-agent/src/leader/inject.rs +0 -33
- package/crates/team-agent/src/provider/command.rs +0 -80
|
@@ -0,0 +1,410 @@
|
|
|
1
|
+
#![allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)]
|
|
2
|
+
|
|
3
|
+
#[path = "../../../tests/support/hermetic.rs"]
|
|
4
|
+
mod hermetic_guard;
|
|
5
|
+
#[allow(dead_code)]
|
|
6
|
+
fn _hermetic_boundary_marker(_: &hermetic_guard::HermeticTestEnv) {}
|
|
7
|
+
|
|
8
|
+
use std::collections::BTreeMap;
|
|
9
|
+
use std::path::{Path, PathBuf};
|
|
10
|
+
use std::sync::atomic::{AtomicU64, Ordering};
|
|
11
|
+
use std::sync::Mutex;
|
|
12
|
+
|
|
13
|
+
use serde_json::{json, Value};
|
|
14
|
+
use serial_test::serial;
|
|
15
|
+
use team_agent::coordinator::{
|
|
16
|
+
coordinator_pid_path, write_coordinator_metadata, MetadataSource, Pid, WorkspacePath,
|
|
17
|
+
};
|
|
18
|
+
use team_agent::event_log::EventLog;
|
|
19
|
+
use team_agent::lifecycle::{restart_with_transport, RestartReport, ResumeDecision};
|
|
20
|
+
use team_agent::message_store::MessageStore;
|
|
21
|
+
use team_agent::state::persist::{load_runtime_state, save_runtime_state};
|
|
22
|
+
use team_agent::transport::{
|
|
23
|
+
AttachOutcome, BackendKind, CaptureRange, CapturedText, InjectPayload, InjectReport,
|
|
24
|
+
InjectStage, InjectVerification, Key, PaneField, PaneId, PaneInfo, PaneLiveness, SessionName,
|
|
25
|
+
SetEnvOutcome, SpawnResult, SubmitVerification, Target, Transport, TransportError,
|
|
26
|
+
TurnVerification, WindowName,
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
#[test]
|
|
30
|
+
#[serial(env)]
|
|
31
|
+
fn restart_repairs_missing_resume_session_from_events_before_resume_decision() {
|
|
32
|
+
let fixture = ResumeFixture::new("event-repair-success");
|
|
33
|
+
fixture.seed_missing_session_state();
|
|
34
|
+
let rollout = fixture.root.join("rollouts").join("worker-a.jsonl");
|
|
35
|
+
std::fs::create_dir_all(rollout.parent().unwrap()).unwrap();
|
|
36
|
+
std::fs::write(&rollout, "{}\n").unwrap();
|
|
37
|
+
EventLog::new(&fixture.team)
|
|
38
|
+
.write(
|
|
39
|
+
"session.captured",
|
|
40
|
+
json!({
|
|
41
|
+
"agent_id": "worker_a",
|
|
42
|
+
"provider": "codex",
|
|
43
|
+
"session_id": "sess-from-events",
|
|
44
|
+
"rollout_path": rollout.to_string_lossy().to_string(),
|
|
45
|
+
"attribution_confidence": "high"
|
|
46
|
+
}),
|
|
47
|
+
)
|
|
48
|
+
.unwrap();
|
|
49
|
+
let _env = fixture.bounded_empty_provider_home_env();
|
|
50
|
+
let transport = ResumeTransport::new();
|
|
51
|
+
|
|
52
|
+
let report = restart_with_transport(&fixture.team, false, None, &transport)
|
|
53
|
+
.expect("restart should repair missing session from events and continue to resume");
|
|
54
|
+
|
|
55
|
+
let state = load_runtime_state(&fixture.team).unwrap();
|
|
56
|
+
let agent = state
|
|
57
|
+
.pointer("/agents/worker_a")
|
|
58
|
+
.unwrap_or_else(|| panic!("worker_a missing; state={state}"));
|
|
59
|
+
assert_eq!(
|
|
60
|
+
agent.get("session_id").and_then(Value::as_str),
|
|
61
|
+
Some("sess-from-events"),
|
|
62
|
+
"restart must restore session_id from the newest valid session.captured event before classification; state={state}"
|
|
63
|
+
);
|
|
64
|
+
assert_eq!(
|
|
65
|
+
agent.get("captured_via").and_then(Value::as_str),
|
|
66
|
+
Some("event_log_repair"),
|
|
67
|
+
"event-log repair must mark captured_via=event_log_repair for auditability; state={state}"
|
|
68
|
+
);
|
|
69
|
+
assert_eq!(
|
|
70
|
+
agent.get("attribution_confidence").and_then(Value::as_str),
|
|
71
|
+
Some("high"),
|
|
72
|
+
"event-log repair must preserve attribution confidence; state={state}"
|
|
73
|
+
);
|
|
74
|
+
assert!(
|
|
75
|
+
matches!(
|
|
76
|
+
report,
|
|
77
|
+
RestartReport::Restarted { ref agents, .. }
|
|
78
|
+
if agents.iter().any(|decision| {
|
|
79
|
+
decision.agent_id.as_str() == "worker_a"
|
|
80
|
+
&& decision.decision == ResumeDecision::Resume
|
|
81
|
+
&& decision.session_id.as_ref().is_some_and(|id| id.as_str() == "sess-from-events")
|
|
82
|
+
})
|
|
83
|
+
),
|
|
84
|
+
"restart must choose resume after event-log repair, not fresh/refuse; report={report:?} state={state}"
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
#[test]
|
|
89
|
+
#[serial(env)]
|
|
90
|
+
fn restart_does_not_resurrect_tombstoned_event_session_and_refuses_without_allow_fresh() {
|
|
91
|
+
let fixture = ResumeFixture::new("event-repair-tombstone");
|
|
92
|
+
fixture.seed_missing_session_state();
|
|
93
|
+
let rollout = fixture
|
|
94
|
+
.root
|
|
95
|
+
.join("rollouts")
|
|
96
|
+
.join("worker-a-tombstoned.jsonl");
|
|
97
|
+
std::fs::create_dir_all(rollout.parent().unwrap()).unwrap();
|
|
98
|
+
std::fs::write(&rollout, "{}\n").unwrap();
|
|
99
|
+
EventLog::new(&fixture.team)
|
|
100
|
+
.write(
|
|
101
|
+
"session.captured",
|
|
102
|
+
json!({
|
|
103
|
+
"agent_id": "worker_a",
|
|
104
|
+
"provider": "codex",
|
|
105
|
+
"session_id": "sess-tombstoned",
|
|
106
|
+
"rollout_path": rollout.to_string_lossy().to_string(),
|
|
107
|
+
"attribution_confidence": "high"
|
|
108
|
+
}),
|
|
109
|
+
)
|
|
110
|
+
.unwrap();
|
|
111
|
+
EventLog::new(&fixture.team)
|
|
112
|
+
.write(
|
|
113
|
+
"discard.session_tombstone",
|
|
114
|
+
json!({ "agent_id": "worker_a", "session_id": "sess-tombstoned" }),
|
|
115
|
+
)
|
|
116
|
+
.unwrap();
|
|
117
|
+
let _env = fixture.bounded_empty_provider_home_env();
|
|
118
|
+
let transport = ResumeTransport::new();
|
|
119
|
+
|
|
120
|
+
let report = restart_with_transport(&fixture.team, false, None, &transport)
|
|
121
|
+
.expect("tombstoned event recovery should produce an honest typed refusal, not an error");
|
|
122
|
+
let state = load_runtime_state(&fixture.team).unwrap();
|
|
123
|
+
|
|
124
|
+
assert!(
|
|
125
|
+
matches!(report, RestartReport::RefusedResumeNotReady { .. } | RestartReport::RefusedResumeAtomicity { .. }),
|
|
126
|
+
"a newer discard.session_tombstone must block event-log resurrection and keep allow_fresh=false hard refusal; report={report:?} state={state}"
|
|
127
|
+
);
|
|
128
|
+
assert!(
|
|
129
|
+
state
|
|
130
|
+
.pointer("/agents/worker_a/session_id")
|
|
131
|
+
.and_then(Value::as_str)
|
|
132
|
+
.is_none(),
|
|
133
|
+
"tombstoned session must not be restored into state; state={state}"
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
struct ResumeFixture {
|
|
138
|
+
root: PathBuf,
|
|
139
|
+
team: PathBuf,
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
impl ResumeFixture {
|
|
143
|
+
fn new(tag: &str) -> Self {
|
|
144
|
+
let root = tmp_dir(tag);
|
|
145
|
+
let team = root.join("team");
|
|
146
|
+
std::fs::create_dir_all(team.join("agents")).unwrap();
|
|
147
|
+
std::fs::write(
|
|
148
|
+
team.join("TEAM.md"),
|
|
149
|
+
"---\nname: resumeteam\nobjective: Resume recovery contract.\nprovider: codex\n---\n\nTeam.\n",
|
|
150
|
+
)
|
|
151
|
+
.unwrap();
|
|
152
|
+
std::fs::write(
|
|
153
|
+
team.join("agents").join("worker_a.md"),
|
|
154
|
+
"---\nname: worker_a\nrole: Worker A\nprovider: codex\nmodel: gpt-5.5\nauth_mode: subscription\ntools:\n - mcp_team\n---\n\nWorker.\n",
|
|
155
|
+
)
|
|
156
|
+
.unwrap();
|
|
157
|
+
let spec = team_agent::compiler::compile_team(&team).unwrap();
|
|
158
|
+
std::fs::write(
|
|
159
|
+
team.join("team.spec.yaml"),
|
|
160
|
+
team_agent::model::yaml::dumps(&spec),
|
|
161
|
+
)
|
|
162
|
+
.unwrap();
|
|
163
|
+
Self { root, team }
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
fn seed_missing_session_state(&self) {
|
|
167
|
+
save_runtime_state(
|
|
168
|
+
&self.team,
|
|
169
|
+
&json!({
|
|
170
|
+
"active_team_key": "resumeteam",
|
|
171
|
+
"team_dir": self.team.to_string_lossy().to_string(),
|
|
172
|
+
"spec_path": self.team.join("team.spec.yaml").to_string_lossy().to_string(),
|
|
173
|
+
"session_name": "team-resumeteam",
|
|
174
|
+
"agents": {
|
|
175
|
+
"worker_a": {
|
|
176
|
+
"status": "running",
|
|
177
|
+
"provider": "codex",
|
|
178
|
+
"auth_mode": "subscription",
|
|
179
|
+
"role": "Worker A",
|
|
180
|
+
"tools": ["mcp_team"],
|
|
181
|
+
"window": "worker_a",
|
|
182
|
+
"pane_id": "%1",
|
|
183
|
+
"pane_pid": 4242,
|
|
184
|
+
"spawn_cwd": self.team.to_string_lossy().to_string(),
|
|
185
|
+
"spawned_at": "2026-06-09T00:00:00+00:00",
|
|
186
|
+
"first_send_at": "2026-06-09T00:01:00+00:00"
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}),
|
|
190
|
+
)
|
|
191
|
+
.unwrap();
|
|
192
|
+
self.seed_healthy_coordinator();
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
fn seed_healthy_coordinator(&self) {
|
|
196
|
+
let workspace = WorkspacePath::new(self.team.clone());
|
|
197
|
+
std::fs::create_dir_all(team_agent::model::paths::runtime_dir(workspace.as_path()))
|
|
198
|
+
.unwrap();
|
|
199
|
+
let _ = MessageStore::open(workspace.as_path()).unwrap();
|
|
200
|
+
let pid = Pid::new(std::process::id());
|
|
201
|
+
write_coordinator_metadata(&workspace, pid, MetadataSource::Boot).unwrap();
|
|
202
|
+
std::fs::write(coordinator_pid_path(&workspace), pid.to_string()).unwrap();
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
fn bounded_empty_provider_home_env(&self) -> EnvGuard {
|
|
206
|
+
let home = self.root.join("empty-home");
|
|
207
|
+
std::fs::create_dir_all(&home).unwrap();
|
|
208
|
+
EnvGuard::set_many(vec![
|
|
209
|
+
("HOME", home.to_string_lossy().to_string()),
|
|
210
|
+
(
|
|
211
|
+
"TEAM_AGENT_RESTART_SESSION_CAPTURE_DEADLINE_MS",
|
|
212
|
+
"25".to_string(),
|
|
213
|
+
),
|
|
214
|
+
(
|
|
215
|
+
"TEAM_AGENT_RESTART_SESSION_CAPTURE_POLL_MS",
|
|
216
|
+
"5".to_string(),
|
|
217
|
+
),
|
|
218
|
+
])
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
impl Drop for ResumeFixture {
|
|
223
|
+
fn drop(&mut self) {
|
|
224
|
+
let _ = std::fs::remove_dir_all(&self.root);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
struct EnvGuard {
|
|
229
|
+
old: Vec<(&'static str, Option<String>)>,
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
impl EnvGuard {
|
|
233
|
+
fn set_many(pairs: Vec<(&'static str, String)>) -> Self {
|
|
234
|
+
let old = pairs
|
|
235
|
+
.iter()
|
|
236
|
+
.map(|(key, _)| (*key, std::env::var(key).ok()))
|
|
237
|
+
.collect::<Vec<_>>();
|
|
238
|
+
for (key, value) in pairs {
|
|
239
|
+
std::env::set_var(key, value);
|
|
240
|
+
}
|
|
241
|
+
Self { old }
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
impl Drop for EnvGuard {
|
|
246
|
+
fn drop(&mut self) {
|
|
247
|
+
for (key, old) in self.old.drain(..) {
|
|
248
|
+
match old {
|
|
249
|
+
Some(value) => std::env::set_var(key, value),
|
|
250
|
+
None => std::env::remove_var(key),
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
#[derive(Default)]
|
|
257
|
+
struct ResumeTransport {
|
|
258
|
+
spawned: Mutex<bool>,
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
impl ResumeTransport {
|
|
262
|
+
fn new() -> Self {
|
|
263
|
+
Self::default()
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
impl Transport for ResumeTransport {
|
|
268
|
+
fn kind(&self) -> BackendKind {
|
|
269
|
+
BackendKind::Tmux
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
fn spawn_first(
|
|
273
|
+
&self,
|
|
274
|
+
session: &SessionName,
|
|
275
|
+
window: &WindowName,
|
|
276
|
+
_argv: &[String],
|
|
277
|
+
_cwd: &Path,
|
|
278
|
+
_env: &BTreeMap<String, String>,
|
|
279
|
+
) -> Result<SpawnResult, TransportError> {
|
|
280
|
+
*self.spawned.lock().unwrap() = true;
|
|
281
|
+
Ok(SpawnResult {
|
|
282
|
+
pane_id: PaneId::new("%10"),
|
|
283
|
+
session: session.clone(),
|
|
284
|
+
window: window.clone(),
|
|
285
|
+
child_pid: Some(10_010),
|
|
286
|
+
})
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
fn spawn_into(
|
|
290
|
+
&self,
|
|
291
|
+
session: &SessionName,
|
|
292
|
+
window: &WindowName,
|
|
293
|
+
argv: &[String],
|
|
294
|
+
cwd: &Path,
|
|
295
|
+
env: &BTreeMap<String, String>,
|
|
296
|
+
) -> Result<SpawnResult, TransportError> {
|
|
297
|
+
self.spawn_first(session, window, argv, cwd, env)
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
fn inject(
|
|
301
|
+
&self,
|
|
302
|
+
_target: &Target,
|
|
303
|
+
_payload: &InjectPayload,
|
|
304
|
+
_submit: Key,
|
|
305
|
+
_bracketed: bool,
|
|
306
|
+
) -> Result<InjectReport, TransportError> {
|
|
307
|
+
Ok(InjectReport {
|
|
308
|
+
stage_reached: InjectStage::Submit,
|
|
309
|
+
inject_verification: InjectVerification::NoToken,
|
|
310
|
+
submit_verification: SubmitVerification::EnterSentWithoutPlaceholderCheck,
|
|
311
|
+
turn_verification: TurnVerification::NotRequired,
|
|
312
|
+
attempts: 1,
|
|
313
|
+
submit_diagnostics: None,
|
|
314
|
+
})
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
fn send_keys(&self, _target: &Target, _keys: &[Key]) -> Result<(), TransportError> {
|
|
318
|
+
Ok(())
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
fn capture(
|
|
322
|
+
&self,
|
|
323
|
+
_target: &Target,
|
|
324
|
+
range: CaptureRange,
|
|
325
|
+
) -> Result<CapturedText, TransportError> {
|
|
326
|
+
Ok(CapturedText {
|
|
327
|
+
text: String::new(),
|
|
328
|
+
range,
|
|
329
|
+
})
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
fn query(&self, _target: &Target, field: PaneField) -> Result<Option<String>, TransportError> {
|
|
333
|
+
Ok(match field {
|
|
334
|
+
PaneField::PaneId => Some("%10".to_string()),
|
|
335
|
+
PaneField::SessionName => Some("team-resumeteam".to_string()),
|
|
336
|
+
_ => None,
|
|
337
|
+
})
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
fn liveness(&self, _pane: &PaneId) -> Result<PaneLiveness, TransportError> {
|
|
341
|
+
Ok(PaneLiveness::Live)
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
fn list_targets(&self) -> Result<Vec<PaneInfo>, TransportError> {
|
|
345
|
+
if !*self.spawned.lock().unwrap() {
|
|
346
|
+
return Ok(Vec::new());
|
|
347
|
+
}
|
|
348
|
+
Ok(vec![PaneInfo {
|
|
349
|
+
pane_id: PaneId::new("%10"),
|
|
350
|
+
session: SessionName::new("team-resumeteam"),
|
|
351
|
+
window_index: Some(0),
|
|
352
|
+
window_name: Some(WindowName::new("worker_a")),
|
|
353
|
+
pane_index: Some(0),
|
|
354
|
+
tty: None,
|
|
355
|
+
current_command: Some("codex".to_string()),
|
|
356
|
+
current_path: None,
|
|
357
|
+
active: true,
|
|
358
|
+
pane_pid: Some(10_010),
|
|
359
|
+
leader_env: BTreeMap::new(),
|
|
360
|
+
}])
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
fn has_session(&self, _session: &SessionName) -> Result<bool, TransportError> {
|
|
364
|
+
Ok(true)
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
fn list_windows(&self, _session: &SessionName) -> Result<Vec<WindowName>, TransportError> {
|
|
368
|
+
Ok(Vec::new())
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
fn set_session_env(
|
|
372
|
+
&self,
|
|
373
|
+
_session: &SessionName,
|
|
374
|
+
_key: &str,
|
|
375
|
+
_value: &str,
|
|
376
|
+
) -> Result<SetEnvOutcome, TransportError> {
|
|
377
|
+
Ok(SetEnvOutcome::Applied)
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
fn kill_session(&self, _session: &SessionName) -> Result<(), TransportError> {
|
|
381
|
+
Ok(())
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
fn kill_window(&self, _target: &Target) -> Result<(), TransportError> {
|
|
385
|
+
Ok(())
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
fn kill_pane(&self, pane: &PaneId) -> Result<(), TransportError> {
|
|
389
|
+
if pane.as_str() == "%10" {
|
|
390
|
+
*self.spawned.lock().unwrap() = false;
|
|
391
|
+
}
|
|
392
|
+
Ok(())
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
fn attach_session(&self, _session: &SessionName) -> Result<AttachOutcome, TransportError> {
|
|
396
|
+
Ok(AttachOutcome::Attached)
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
fn tmp_dir(tag: &str) -> PathBuf {
|
|
401
|
+
static N: AtomicU64 = AtomicU64::new(0);
|
|
402
|
+
let dir = std::env::temp_dir().join(format!(
|
|
403
|
+
"ta-rs-resume-recover-{tag}-{}-{}",
|
|
404
|
+
std::process::id(),
|
|
405
|
+
N.fetch_add(1, Ordering::Relaxed)
|
|
406
|
+
));
|
|
407
|
+
let _ = std::fs::remove_dir_all(&dir);
|
|
408
|
+
std::fs::create_dir_all(&dir).unwrap();
|
|
409
|
+
std::fs::canonicalize(dir).unwrap()
|
|
410
|
+
}
|