@team-agent/installer 0.5.128 → 0.6.1
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/README.md +4 -4
- package/README.zh.md +1 -1
- package/package.json +4 -8
- package/skills/team-agent/SKILL.md +37 -20
- package/skills/team-agent/command-coverage.json +169 -183
- package/skills/team-agent/docs/reference/team-agent-operator.md +64 -30
- package/skills/team-agent/references/recovery-runbook.md +1 -1
- package/skills/team-agent/references/team-agent-operator.md +64 -30
- package/templates/team_state.md +1 -1
- package/Cargo.lock +0 -1063
- package/Cargo.toml +0 -36
- package/crates/team-agent/Cargo.toml +0 -69
- package/crates/team-agent/src/app_server_test_support.rs +0 -258
- package/crates/team-agent/src/cli/adapters.rs +0 -1288
- package/crates/team-agent/src/cli/arguments.rs +0 -405
- package/crates/team-agent/src/cli/attach_app_server_leader.rs +0 -98
- package/crates/team-agent/src/cli/diagnose.rs +0 -1721
- package/crates/team-agent/src/cli/emit.rs +0 -2930
- package/crates/team-agent/src/cli/grok_slot.rs +0 -384
- package/crates/team-agent/src/cli/helpers.rs +0 -91
- package/crates/team-agent/src/cli/intent/runtime.rs +0 -1216
- package/crates/team-agent/src/cli/intent/runtime_tests.rs +0 -912
- package/crates/team-agent/src/cli/intent/tests.rs +0 -689
- package/crates/team-agent/src/cli/intent.rs +0 -664
- package/crates/team-agent/src/cli/leader.rs +0 -300
- package/crates/team-agent/src/cli/leader_prompt.rs +0 -261
- package/crates/team-agent/src/cli/leaders.rs +0 -418
- package/crates/team-agent/src/cli/mod.rs +0 -6545
- package/crates/team-agent/src/cli/models.rs +0 -1206
- package/crates/team-agent/src/cli/named_address.rs +0 -1651
- package/crates/team-agent/src/cli/profile.rs +0 -342
- package/crates/team-agent/src/cli/route.rs +0 -212
- package/crates/team-agent/src/cli/schedule.rs +0 -175
- package/crates/team-agent/src/cli/send/coordinator.rs +0 -164
- package/crates/team-agent/src/cli/send/mailbox.rs +0 -145
- package/crates/team-agent/src/cli/send/persist.rs +0 -156
- package/crates/team-agent/src/cli/send/presentation.rs +0 -370
- package/crates/team-agent/src/cli/send/resolve.rs +0 -573
- package/crates/team-agent/src/cli/send.rs +0 -199
- package/crates/team-agent/src/cli/shutdown_socket.rs +0 -288
- package/crates/team-agent/src/cli/spec.rs +0 -165
- package/crates/team-agent/src/cli/status.rs +0 -280
- package/crates/team-agent/src/cli/status_port/agents.rs +0 -358
- package/crates/team-agent/src/cli/status_port/approvals.rs +0 -79
- package/crates/team-agent/src/cli/status_port/brief.rs +0 -1981
- package/crates/team-agent/src/cli/status_port/compact.rs +0 -240
- package/crates/team-agent/src/cli/status_port/format.rs +0 -146
- package/crates/team-agent/src/cli/status_port/inbox.rs +0 -62
- package/crates/team-agent/src/cli/status_port/runtime.rs +0 -197
- package/crates/team-agent/src/cli/status_port/snapshot.rs +0 -208
- package/crates/team-agent/src/cli/status_port/store.rs +0 -416
- package/crates/team-agent/src/cli/status_port/tests.rs +0 -90
- package/crates/team-agent/src/cli/status_port.rs +0 -92
- package/crates/team-agent/src/cli/tests/base.rs +0 -885
- package/crates/team-agent/src/cli/tests/divergence.rs +0 -518
- package/crates/team-agent/src/cli/tests/lane_c.rs +0 -453
- package/crates/team-agent/src/cli/tests/leader_watch.rs +0 -322
- package/crates/team-agent/src/cli/tests/main_preserved.rs +0 -430
- package/crates/team-agent/src/cli/tests/missing_subcommands.rs +0 -336
- package/crates/team-agent/src/cli/tests/mod.rs +0 -137
- package/crates/team-agent/src/cli/tests/named_address.rs +0 -761
- package/crates/team-agent/src/cli/tests/parser_safety.rs +0 -383
- package/crates/team-agent/src/cli/tests/run_delegation.rs +0 -484
- package/crates/team-agent/src/cli/tests/shutdown_kill_plan.rs +0 -2179
- package/crates/team-agent/src/cli/tests/status_brief.rs +0 -1514
- package/crates/team-agent/src/cli/tests/status_send.rs +0 -888
- package/crates/team-agent/src/cli/tests/verb_install_skill.rs +0 -93
- package/crates/team-agent/src/cli/tests/verb_profile.rs +0 -392
- package/crates/team-agent/src/cli/triage.rs +0 -234
- package/crates/team-agent/src/cli/types.rs +0 -591
- package/crates/team-agent/src/codex_app_server.rs +0 -546
- package/crates/team-agent/src/communication_mode/mod.rs +0 -56
- package/crates/team-agent/src/compiler/tests.rs +0 -827
- package/crates/team-agent/src/compiler.rs +0 -890
- package/crates/team-agent/src/conpty/backend.rs +0 -829
- package/crates/team-agent/src/conpty/mod.rs +0 -33
- package/crates/team-agent/src/contract_runtime/backend.rs +0 -1744
- package/crates/team-agent/src/contract_runtime/commands.rs +0 -671
- package/crates/team-agent/src/contract_runtime/config.rs +0 -364
- package/crates/team-agent/src/contract_runtime/config_tests.rs +0 -76
- package/crates/team-agent/src/contract_runtime/discovery.rs +0 -449
- package/crates/team-agent/src/contract_runtime/fork.rs +0 -361
- package/crates/team-agent/src/contract_runtime/forward.rs +0 -288
- package/crates/team-agent/src/contract_runtime/framework.rs +0 -367
- package/crates/team-agent/src/contract_runtime/mcp.rs +0 -394
- package/crates/team-agent/src/contract_runtime/mod.rs +0 -17
- package/crates/team-agent/src/contract_runtime/prompt.rs +0 -216
- package/crates/team-agent/src/contract_runtime/pump.rs +0 -271
- package/crates/team-agent/src/contract_runtime/registry.rs +0 -553
- package/crates/team-agent/src/contract_runtime/workspace.rs +0 -228
- package/crates/team-agent/src/coordinator/backoff.rs +0 -741
- package/crates/team-agent/src/coordinator/conpty_shim.rs +0 -805
- package/crates/team-agent/src/coordinator/health.rs +0 -1185
- package/crates/team-agent/src/coordinator/mod.rs +0 -119
- package/crates/team-agent/src/coordinator/orphan.rs +0 -110
- package/crates/team-agent/src/coordinator/runtime_detectors.rs +0 -798
- package/crates/team-agent/src/coordinator/runtime_observation.rs +0 -84
- package/crates/team-agent/src/coordinator/steps/abnormal.rs +0 -2309
- package/crates/team-agent/src/coordinator/steps/delivery.rs +0 -15
- package/crates/team-agent/src/coordinator/steps/health_sync.rs +0 -15
- package/crates/team-agent/src/coordinator/steps/mod.rs +0 -126
- package/crates/team-agent/src/coordinator/steps/persist.rs +0 -15
- package/crates/team-agent/src/coordinator/steps/runtime_prompts.rs +0 -15
- package/crates/team-agent/src/coordinator/steps/session_gate.rs +0 -16
- package/crates/team-agent/src/coordinator/tests/a0_lostupdate.rs +0 -158
- package/crates/team-agent/src/coordinator/tests/abnormal.rs +0 -312
- package/crates/team-agent/src/coordinator/tests/api_error_recovery.rs +0 -300
- package/crates/team-agent/src/coordinator/tests/basics.rs +0 -211
- package/crates/team-agent/src/coordinator/tests/daemon.rs +0 -514
- package/crates/team-agent/src/coordinator/tests/energy.rs +0 -549
- package/crates/team-agent/src/coordinator/tests/health_sync.rs +0 -503
- package/crates/team-agent/src/coordinator/tests/main_preserved.rs +0 -186
- package/crates/team-agent/src/coordinator/tests/mod.rs +0 -295
- package/crates/team-agent/src/coordinator/tests/s3_bounded.rs +0 -207
- package/crates/team-agent/src/coordinator/tests/spine.rs +0 -308
- package/crates/team-agent/src/coordinator/tests/takeover.rs +0 -286
- package/crates/team-agent/src/coordinator/tests/tick_core.rs +0 -237
- package/crates/team-agent/src/coordinator/tick.rs +0 -3024
- package/crates/team-agent/src/coordinator/types.rs +0 -540
- package/crates/team-agent/src/db/agent_health_capture.rs +0 -126
- package/crates/team-agent/src/db/message_store.rs +0 -1527
- package/crates/team-agent/src/db/migration.rs +0 -984
- package/crates/team-agent/src/db/mod.rs +0 -26
- package/crates/team-agent/src/db/schema.rs +0 -663
- package/crates/team-agent/src/diagnose/comms.rs +0 -242
- package/crates/team-agent/src/diagnose/mod.rs +0 -44
- package/crates/team-agent/src/diagnose/orphans.rs +0 -889
- package/crates/team-agent/src/direct_delivery.rs +0 -368
- package/crates/team-agent/src/event_log.rs +0 -502
- package/crates/team-agent/src/fake_worker.rs +0 -303
- package/crates/team-agent/src/inbox_store.rs +0 -169
- package/crates/team-agent/src/kill_audit.rs +0 -106
- package/crates/team-agent/src/layout/manager.rs +0 -248
- package/crates/team-agent/src/layout/mod.rs +0 -36
- package/crates/team-agent/src/layout/overlay.rs +0 -134
- package/crates/team-agent/src/layout/placement.rs +0 -52
- package/crates/team-agent/src/layout/recovery.rs +0 -106
- package/crates/team-agent/src/layout/runtime_sessions.rs +0 -317
- package/crates/team-agent/src/layout/sessions.rs +0 -294
- package/crates/team-agent/src/layout/tmux_endpoint.rs +0 -165
- package/crates/team-agent/src/layout/worker_env.rs +0 -721
- package/crates/team-agent/src/layout/worker_window_helpers.rs +0 -37
- package/crates/team-agent/src/leader/helpers.rs +0 -178
- package/crates/team-agent/src/leader/incident.rs +0 -6
- package/crates/team-agent/src/leader/lease.rs +0 -3356
- package/crates/team-agent/src/leader/mod.rs +0 -104
- package/crates/team-agent/src/leader/owner_bind.rs +0 -400
- package/crates/team-agent/src/leader/prompt.rs +0 -905
- package/crates/team-agent/src/leader/provider_attribution.rs +0 -247
- package/crates/team-agent/src/leader/rediscover/tests.rs +0 -689
- package/crates/team-agent/src/leader/rediscover.rs +0 -1192
- package/crates/team-agent/src/leader/registry.rs +0 -888
- package/crates/team-agent/src/leader/start.rs +0 -4501
- package/crates/team-agent/src/leader/takeover.rs +0 -65
- package/crates/team-agent/src/leader/tests/basics.rs +0 -337
- package/crates/team-agent/src/leader/tests/byte_findings.rs +0 -355
- package/crates/team-agent/src/leader/tests/claim_leader_mailbox_flush_contract.rs +0 -544
- package/crates/team-agent/src/leader/tests/historical_inventory_upgrade_gate_red.rs +0 -624
- package/crates/team-agent/src/leader/tests/identity.rs +0 -465
- package/crates/team-agent/src/leader/tests/identity_session_names.rs +0 -42
- package/crates/team-agent/src/leader/tests/idle.rs +0 -113
- package/crates/team-agent/src/leader/tests/lease_api.rs +0 -520
- package/crates/team-agent/src/leader/tests/lease_claim.rs +0 -629
- package/crates/team-agent/src/leader/tests/mod.rs +0 -106
- package/crates/team-agent/src/leader/tests/prompt_contract.rs +0 -268
- package/crates/team-agent/src/leader/tests/rediscover.rs +0 -403
- package/crates/team-agent/src/leader/tests/rehomed_env.rs +0 -83
- package/crates/team-agent/src/leader/tests/team_in_team_state_scope_red.rs +0 -1273
- package/crates/team-agent/src/leader/tests/terminal_and_replay_vs_rerender_invariants_red.rs +0 -417
- package/crates/team-agent/src/leader/tests/wake_start_owner.rs +0 -168
- package/crates/team-agent/src/leader/types.rs +0 -534
- package/crates/team-agent/src/lib.rs +0 -147
- package/crates/team-agent/src/lifecycle/helpers.rs +0 -212
- package/crates/team-agent/src/lifecycle/launch/add_agent.rs +0 -881
- package/crates/team-agent/src/lifecycle/launch/add_agent_state.rs +0 -598
- package/crates/team-agent/src/lifecycle/launch/agent_state.rs +0 -332
- package/crates/team-agent/src/lifecycle/launch/clone_agent.rs +0 -204
- package/crates/team-agent/src/lifecycle/launch/fork_agent.rs +0 -107
- package/crates/team-agent/src/lifecycle/launch/fork_entry.rs +0 -144
- package/crates/team-agent/src/lifecycle/launch/identity.rs +0 -674
- package/crates/team-agent/src/lifecycle/launch/layout.rs +0 -350
- package/crates/team-agent/src/lifecycle/launch/leader_context.rs +0 -589
- package/crates/team-agent/src/lifecycle/launch/mcp_config.rs +0 -160
- package/crates/team-agent/src/lifecycle/launch/ownership.rs +0 -105
- package/crates/team-agent/src/lifecycle/launch/pi_mcp.rs +0 -899
- package/crates/team-agent/src/lifecycle/launch/pi_mcp_extension.js +0 -225
- package/crates/team-agent/src/lifecycle/launch/plan.rs +0 -269
- package/crates/team-agent/src/lifecycle/launch/quick_start.rs +0 -5200
- package/crates/team-agent/src/lifecycle/launch/quick_start_transport.rs +0 -368
- package/crates/team-agent/src/lifecycle/launch/readiness.rs +0 -519
- package/crates/team-agent/src/lifecycle/launch/role_source.rs +0 -287
- package/crates/team-agent/src/lifecycle/launch/spawn.rs +0 -473
- package/crates/team-agent/src/lifecycle/launch/spec_state.rs +0 -801
- package/crates/team-agent/src/lifecycle/launch/state_projection.rs +0 -624
- package/crates/team-agent/src/lifecycle/launch/worker_env.rs +0 -558
- package/crates/team-agent/src/lifecycle/launch.rs +0 -557
- package/crates/team-agent/src/lifecycle/lock.rs +0 -350
- package/crates/team-agent/src/lifecycle/mod.rs +0 -79
- package/crates/team-agent/src/lifecycle/pane_input_lock.rs +0 -239
- package/crates/team-agent/src/lifecycle/profile_launch.rs +0 -1067
- package/crates/team-agent/src/lifecycle/profile_smoke.rs +0 -557
- package/crates/team-agent/src/lifecycle/restart/agent.rs +0 -2199
- package/crates/team-agent/src/lifecycle/restart/avatar.rs +0 -1798
- package/crates/team-agent/src/lifecycle/restart/claude_fork.rs +0 -163
- package/crates/team-agent/src/lifecycle/restart/common.rs +0 -2362
- package/crates/team-agent/src/lifecycle/restart/orchestrator.rs +0 -65
- package/crates/team-agent/src/lifecycle/restart/preflight.rs +0 -113
- package/crates/team-agent/src/lifecycle/restart/rebuild.rs +0 -5135
- package/crates/team-agent/src/lifecycle/restart/remove.rs +0 -1504
- package/crates/team-agent/src/lifecycle/restart/selection.rs +0 -559
- package/crates/team-agent/src/lifecycle/restart/team_state.rs +0 -329
- package/crates/team-agent/src/lifecycle/restart.rs +0 -227
- package/crates/team-agent/src/lifecycle/role_config.rs +0 -1230
- package/crates/team-agent/src/lifecycle/tests/acceptance_b_batch_red.rs +0 -1021
- package/crates/team-agent/src/lifecycle/tests/agent_ops.rs +0 -1205
- package/crates/team-agent/src/lifecycle/tests/b0_legacy_snapshot_nonauthority_contract.rs +0 -265
- package/crates/team-agent/src/lifecycle/tests/b0_reader_hideone_audit_contract.rs +0 -490
- package/crates/team-agent/src/lifecycle/tests/behavioral_diff_264_red.rs +0 -656
- package/crates/team-agent/src/lifecycle/tests/claude_compatible_config_red.rs +0 -325
- package/crates/team-agent/src/lifecycle/tests/claude_profile_launch_red.rs +0 -447
- package/crates/team-agent/src/lifecycle/tests/cli_argv_routing_red.rs +0 -1638
- package/crates/team-agent/src/lifecycle/tests/clone_agent_preserves_source_tools.rs +0 -427
- package/crates/team-agent/src/lifecycle/tests/clone_fork_copilot_perms_red.rs +0 -770
- package/crates/team-agent/src/lifecycle/tests/communication_mode_runtime_contract_red.rs +0 -419
- package/crates/team-agent/src/lifecycle/tests/copilot_provider_red.rs +0 -2035
- package/crates/team-agent/src/lifecycle/tests/core.rs +0 -1327
- package/crates/team-agent/src/lifecycle/tests/f032_startup_prompt_best_effort_red.rs +0 -315
- package/crates/team-agent/src/lifecycle/tests/fixtures/pi_list_models_g0.stdout.txt +0 -222
- package/crates/team-agent/src/lifecycle/tests/fixtures/pi_list_models_spaced_ids.stdout.txt +0 -9
- package/crates/team-agent/src/lifecycle/tests/fixtures/pi_native_mcp_host.mjs +0 -72
- package/crates/team-agent/src/lifecycle/tests/gate_fixtures.rs +0 -562
- package/crates/team-agent/src/lifecycle/tests/grok_require_explicit_model_red.rs +0 -110
- package/crates/team-agent/src/lifecycle/tests/harvest2_a_batch_red.rs +0 -512
- package/crates/team-agent/src/lifecycle/tests/host_cotenant_death_p0_contract.rs +0 -921
- package/crates/team-agent/src/lifecycle/tests/issue238_codex_effort_contract.rs +0 -68
- package/crates/team-agent/src/lifecycle/tests/lane_ops.rs +0 -1851
- package/crates/team-agent/src/lifecycle/tests/launch_spawn.rs +0 -3983
- package/crates/team-agent/src/lifecycle/tests/lifecycle_lock.rs +0 -339
- package/crates/team-agent/src/lifecycle/tests/lifecycle_rollback_red.rs +0 -596
- package/crates/team-agent/src/lifecycle/tests/main_preserved.rs +0 -513
- package/crates/team-agent/src/lifecycle/tests/mcp_tool_name_format_red.rs +0 -69
- package/crates/team-agent/src/lifecycle/tests/phase_b_contracts.rs +0 -824
- package/crates/team-agent/src/lifecycle/tests/phase_golden.rs +0 -723
- package/crates/team-agent/src/lifecycle/tests/pi_catalog_red.rs +0 -164
- package/crates/team-agent/src/lifecycle/tests/pi_command_red.rs +0 -200
- package/crates/team-agent/src/lifecycle/tests/pi_compiler_red.rs +0 -210
- package/crates/team-agent/src/lifecycle/tests/pi_dual_entry_red.rs +0 -527
- package/crates/team-agent/src/lifecycle/tests/pi_executable_mcp_red.rs +0 -1062
- package/crates/team-agent/src/lifecycle/tests/pi_fork_session_inheritance_red.rs +0 -1419
- package/crates/team-agent/src/lifecycle/tests/pi_lifecycle_doctor_red.rs +0 -98
- package/crates/team-agent/src/lifecycle/tests/pi_native_mcp_capability_red.rs +0 -550
- package/crates/team-agent/src/lifecycle/tests/pi_session_delivery_red.rs +0 -226
- package/crates/team-agent/src/lifecycle/tests/quick_start_worker_readiness_red.rs +0 -332
- package/crates/team-agent/src/lifecycle/tests/realmachine_clusters_1_6_red.rs +0 -786
- package/crates/team-agent/src/lifecycle/tests/realmachine_residual_g1_g4_red.rs +0 -648
- package/crates/team-agent/src/lifecycle/tests/restart.rs +0 -185
- package/crates/team-agent/src/lifecycle/tests/restart_build_before_destroy_0540_contract.rs +0 -1053
- package/crates/team-agent/src/lifecycle/tests/restart_liveness_red.rs +0 -679
- package/crates/team-agent/src/lifecycle/tests/restart_rebind_hotfix_252_red.rs +0 -1126
- package/crates/team-agent/src/lifecycle/tests/restart_session_capture_red.rs +0 -153
- package/crates/team-agent/src/lifecycle/tests/resume_recover_red.rs +0 -427
- package/crates/team-agent/src/lifecycle/tests/stale_team_saveconflict_contract.rs +0 -431
- package/crates/team-agent/src/lifecycle/tests/startup_latency_contract.rs +0 -1066
- package/crates/team-agent/src/lifecycle/tests/status_credential_redaction_contract.rs +0 -876
- package/crates/team-agent/src/lifecycle/tests/subprep_codex_trust_roundtrip_red.rs +0 -1026
- package/crates/team-agent/src/lifecycle/tests/swallow_batch4_semantics_red.rs +0 -342
- package/crates/team-agent/src/lifecycle/tests/team_in_team_identity_scope_red.rs +0 -543
- package/crates/team-agent/src/lifecycle/tests/team_in_team_sibling_quick_start_red.rs +0 -1103
- package/crates/team-agent/src/lifecycle/tests/team_in_team_state_scope_red.rs +0 -1276
- package/crates/team-agent/src/lifecycle/tests/team_key_retirement_roster_red.rs +0 -145
- package/crates/team-agent/src/lifecycle/tests/team_key_retirement_txn_red.rs +0 -603
- package/crates/team-agent/src/lifecycle/tests/test_isolation_escape_contract.rs +0 -936
- package/crates/team-agent/src/lifecycle/tests/upgrade_compat_0211_red.rs +0 -970
- package/crates/team-agent/src/lifecycle/tests/verify_rs031_window_consistency_red.rs +0 -995
- package/crates/team-agent/src/lifecycle/tests/worker_spawn_env_red.rs +0 -836
- package/crates/team-agent/src/lifecycle/tests.rs +0 -105
- package/crates/team-agent/src/lifecycle/types.rs +0 -877
- package/crates/team-agent/src/lifecycle/worker_command_context.rs +0 -363
- package/crates/team-agent/src/main.rs +0 -52
- package/crates/team-agent/src/mcp_server/helpers.rs +0 -510
- package/crates/team-agent/src/mcp_server/lifecycle_tools/mod.rs +0 -6
- package/crates/team-agent/src/mcp_server/lifecycle_tools/state_status.rs +0 -43
- package/crates/team-agent/src/mcp_server/mod.rs +0 -119
- package/crates/team-agent/src/mcp_server/normalize.rs +0 -485
- package/crates/team-agent/src/mcp_server/readiness.rs +0 -527
- package/crates/team-agent/src/mcp_server/readiness_tests.rs +0 -348
- package/crates/team-agent/src/mcp_server/tests/golden.rs +0 -285
- package/crates/team-agent/src/mcp_server/tests/normalize.rs +0 -247
- package/crates/team-agent/src/mcp_server/tests/scoped.rs +0 -158
- package/crates/team-agent/src/mcp_server/tests/send.rs +0 -353
- package/crates/team-agent/src/mcp_server/tests/tools.rs +0 -341
- package/crates/team-agent/src/mcp_server/tests/wire.rs +0 -254
- package/crates/team-agent/src/mcp_server/tests.rs +0 -43
- package/crates/team-agent/src/mcp_server/tools.rs +0 -889
- package/crates/team-agent/src/mcp_server/types.rs +0 -396
- package/crates/team-agent/src/mcp_server/wire.rs +0 -867
- package/crates/team-agent/src/messaging/activity.rs +0 -461
- package/crates/team-agent/src/messaging/address.rs +0 -87
- package/crates/team-agent/src/messaging/delivery.rs +0 -3727
- package/crates/team-agent/src/messaging/delivery_consumption_tests.rs +0 -234
- package/crates/team-agent/src/messaging/enter_rescue.rs +0 -362
- package/crates/team-agent/src/messaging/enter_rescue_tests.rs +0 -633
- package/crates/team-agent/src/messaging/helpers.rs +0 -336
- package/crates/team-agent/src/messaging/leader_channel.rs +0 -287
- package/crates/team-agent/src/messaging/leader_receiver.rs +0 -786
- package/crates/team-agent/src/messaging/mod.rs +0 -167
- package/crates/team-agent/src/messaging/persist.rs +0 -377
- package/crates/team-agent/src/messaging/presentation.rs +0 -417
- package/crates/team-agent/src/messaging/reminders.rs +0 -316
- package/crates/team-agent/src/messaging/results/collection_tests.rs +0 -719
- package/crates/team-agent/src/messaging/results.rs +0 -1415
- package/crates/team-agent/src/messaging/scheduler.rs +0 -223
- package/crates/team-agent/src/messaging/selftest.rs +0 -315
- package/crates/team-agent/src/messaging/send.rs +0 -981
- package/crates/team-agent/src/messaging/tests/basic.rs +0 -346
- package/crates/team-agent/src/messaging/tests/dup_inject.rs +0 -657
- package/crates/team-agent/src/messaging/tests/e23.rs +0 -49
- package/crates/team-agent/src/messaging/tests/leader_channel.rs +0 -169
- package/crates/team-agent/src/messaging/tests/leader_inject_acceptance.rs +0 -817
- package/crates/team-agent/src/messaging/tests/main_preserved.rs +0 -85
- package/crates/team-agent/src/messaging/tests/mod.rs +0 -306
- package/crates/team-agent/src/messaging/tests/runtime.rs +0 -3549
- package/crates/team-agent/src/messaging/tests/spine.rs +0 -853
- package/crates/team-agent/src/messaging/tests/wave2.rs +0 -381
- package/crates/team-agent/src/messaging/trust.rs +0 -215
- package/crates/team-agent/src/messaging/types.rs +0 -472
- package/crates/team-agent/src/messaging/wait.rs +0 -366
- package/crates/team-agent/src/messaging/watchers.rs +0 -916
- package/crates/team-agent/src/model/enums.rs +0 -356
- package/crates/team-agent/src/model/errors.rs +0 -18
- package/crates/team-agent/src/model/ids.rs +0 -165
- package/crates/team-agent/src/model/mod.rs +0 -29
- package/crates/team-agent/src/model/name_similarity.rs +0 -252
- package/crates/team-agent/src/model/pane_authority_refusal.rs +0 -359
- package/crates/team-agent/src/model/paths.rs +0 -257
- package/crates/team-agent/src/model/routing.rs +0 -387
- package/crates/team-agent/src/model/spec.rs +0 -1184
- package/crates/team-agent/src/model/task_graph.rs +0 -321
- package/crates/team-agent/src/model/testdata/fuzz.golden.yaml +0 -43
- package/crates/team-agent/src/model/testdata/fuzz.yaml +0 -43
- package/crates/team-agent/src/model/testdata/spec_invalid_a.yaml +0 -209
- package/crates/team-agent/src/model/testdata/team.spec.golden.yaml +0 -208
- package/crates/team-agent/src/model/testdata/team.spec.yaml +0 -208
- package/crates/team-agent/src/model/yaml/tests.rs +0 -188
- package/crates/team-agent/src/model/yaml.rs +0 -802
- package/crates/team-agent/src/os_probe.rs +0 -280
- package/crates/team-agent/src/packaging/install.rs +0 -219
- package/crates/team-agent/src/packaging/migrate.rs +0 -38
- package/crates/team-agent/src/packaging/mod.rs +0 -91
- package/crates/team-agent/src/packaging/repair.rs +0 -33
- package/crates/team-agent/src/packaging/tests.rs +0 -822
- package/crates/team-agent/src/packaging/types.rs +0 -417
- package/crates/team-agent/src/platform/argv.rs +0 -331
- package/crates/team-agent/src/platform/errors.rs +0 -104
- package/crates/team-agent/src/platform/file_lock.rs +0 -279
- package/crates/team-agent/src/platform/mod.rs +0 -5
- package/crates/team-agent/src/platform/process.rs +0 -545
- package/crates/team-agent/src/provider/adapter.rs +0 -1150
- package/crates/team-agent/src/provider/adapters/claude.rs +0 -78
- package/crates/team-agent/src/provider/adapters/claude_fork.rs +0 -131
- package/crates/team-agent/src/provider/adapters/copilot.rs +0 -75
- package/crates/team-agent/src/provider/adapters/copilot_fork.rs +0 -307
- package/crates/team-agent/src/provider/adapters/fake.rs +0 -18
- package/crates/team-agent/src/provider/adapters/mod.rs +0 -30
- package/crates/team-agent/src/provider/adapters/pi.rs +0 -106
- package/crates/team-agent/src/provider/approvals/mod.rs +0 -3
- package/crates/team-agent/src/provider/approvals/parsing.rs +0 -586
- package/crates/team-agent/src/provider/approvals/runtime_prompts.rs +0 -205
- package/crates/team-agent/src/provider/argv_route.rs +0 -405
- package/crates/team-agent/src/provider/bypass_flags.rs +0 -116
- package/crates/team-agent/src/provider/classify.rs +0 -708
- package/crates/team-agent/src/provider/command_helpers.rs +0 -45
- package/crates/team-agent/src/provider/faults.rs +0 -165
- package/crates/team-agent/src/provider/helpers.rs +0 -52
- package/crates/team-agent/src/provider/mod.rs +0 -78
- package/crates/team-agent/src/provider/model_catalog.rs +0 -910
- package/crates/team-agent/src/provider/session/capture.rs +0 -2731
- package/crates/team-agent/src/provider/session/context_fork/claude.rs +0 -123
- package/crates/team-agent/src/provider/session/context_fork/outcome.rs +0 -172
- package/crates/team-agent/src/provider/session/context_fork.rs +0 -396
- package/crates/team-agent/src/provider/session/mod.rs +0 -36
- package/crates/team-agent/src/provider/session/resume.rs +0 -269
- package/crates/team-agent/src/provider/session_scan/claude.rs +0 -523
- package/crates/team-agent/src/provider/session_scan/common/tests.rs +0 -316
- package/crates/team-agent/src/provider/session_scan/common.rs +0 -654
- package/crates/team-agent/src/provider/session_scan/copilot.rs +0 -280
- package/crates/team-agent/src/provider/session_scan/pi.rs +0 -185
- package/crates/team-agent/src/provider/session_scan.rs +0 -71
- package/crates/team-agent/src/provider/startup_prompt.rs +0 -757
- package/crates/team-agent/src/provider/submit_now.rs +0 -71
- package/crates/team-agent/src/provider/testdata/copilot-ready-marker.txt +0 -5
- package/crates/team-agent/src/provider/testdata/copilot-trust-prompt.txt +0 -19
- package/crates/team-agent/src/provider/testdata/grok-models-authenticated.stdout +0 -9
- package/crates/team-agent/src/provider/testdata/grok-models-unauthenticated.stdout +0 -7
- package/crates/team-agent/src/provider/tests/adapter.rs +0 -441
- package/crates/team-agent/src/provider/tests/classify.rs +0 -148
- package/crates/team-agent/src/provider/tests/command_helpers.rs +0 -35
- package/crates/team-agent/src/provider/tests/copilot_fork.rs +0 -191
- package/crates/team-agent/src/provider/tests/faults.rs +0 -200
- package/crates/team-agent/src/provider/tests/idle.rs +0 -177
- package/crates/team-agent/src/provider/tests/wire.rs +0 -213
- package/crates/team-agent/src/provider/tests.rs +0 -32
- package/crates/team-agent/src/provider/types.rs +0 -529
- package/crates/team-agent/src/provider/wire.rs +0 -394
- package/crates/team-agent/src/redaction.rs +0 -259
- package/crates/team-agent/src/state/abnormal_watch/tests/mod.rs +0 -248
- package/crates/team-agent/src/state/abnormal_watch.rs +0 -144
- package/crates/team-agent/src/state/identity.rs +0 -914
- package/crates/team-agent/src/state/identity_keys.rs +0 -132
- package/crates/team-agent/src/state/mod.rs +0 -74
- package/crates/team-agent/src/state/owner_gate.rs +0 -482
- package/crates/team-agent/src/state/ownership.rs +0 -563
- package/crates/team-agent/src/state/paths.rs +0 -395
- package/crates/team-agent/src/state/persist.rs +0 -3811
- package/crates/team-agent/src/state/projection.rs +0 -1508
- package/crates/team-agent/src/state/repository/intent.rs +0 -14
- package/crates/team-agent/src/state/repository/tests.rs +0 -184
- package/crates/team-agent/src/state/repository.rs +0 -866
- package/crates/team-agent/src/state/selector.rs +0 -160
- package/crates/team-agent/src/state/testdata/state-rich.canonical.json +0 -133
- package/crates/team-agent/src/test_support/models_timeout_fixture.rs +0 -144
- package/crates/team-agent/src/tmux_backend/enter_rescue.rs +0 -325
- package/crates/team-agent/src/tmux_backend/enter_rescue_tests.rs +0 -432
- package/crates/team-agent/src/tmux_backend/native_input.rs +0 -513
- package/crates/team-agent/src/tmux_backend/native_input_tests.rs +0 -742
- package/crates/team-agent/src/tmux_backend/tests.rs +0 -4103
- package/crates/team-agent/src/tmux_backend.rs +0 -4492
- package/crates/team-agent/src/topology.rs +0 -537
- package/crates/team-agent/src/transport/enter_rescue.rs +0 -166
- package/crates/team-agent/src/transport/native_input.rs +0 -491
- package/crates/team-agent/src/transport/test_support.rs +0 -743
- package/crates/team-agent/src/transport/tests/behavior.rs +0 -326
- package/crates/team-agent/src/transport/tests/mod.rs +0 -194
- package/crates/team-agent/src/transport/tests/wire.rs +0 -574
- package/crates/team-agent/src/transport.rs +0 -1655
- package/crates/team-agent/src/transport_factory.rs +0 -819
|
@@ -1,1527 +0,0 @@
|
|
|
1
|
-
// unit-10 (Stage 4): moved from crate::message_store to crate::db::message_store.
|
|
2
|
-
// The historical body uses unwrap/expect/panic for SQL-row failures; the parent
|
|
3
|
-
// db/ module denies these lints, so re-allow them here so the move is a pure
|
|
4
|
-
// physical relocation (zero behavior change).
|
|
5
|
-
#![allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)]
|
|
6
|
-
|
|
7
|
-
//!
|
|
8
|
-
//! step 7 · message_store — core message lifecycle over `team.db`.
|
|
9
|
-
//!
|
|
10
|
-
//! Truth source (READ-ONLY): `team-agent-public` @ v0.2.11,
|
|
11
|
-
//! `team_agent/message_store/core.py` + `leader_notification_log.py`.
|
|
12
|
-
//! Builds on step 3 [`crate::db::schema`] (DDL/migration already create all 8
|
|
13
|
-
//! tables incl. `messages` + `leader_notification_log`).
|
|
14
|
-
//!
|
|
15
|
-
//! SCOPE (this slice) = the semantic-tricky core lifecycle:
|
|
16
|
-
//! 1. [`MessageStore::create_message`] — insert a fresh `msg_<hex12>` row,
|
|
17
|
-
//! status `accepted` (`core.py:71-114`).
|
|
18
|
-
//! 2. [`MessageStore::claim_for_delivery`] — atomic single-winner claim; flips
|
|
19
|
-
//! an eligible row to `target_resolved`, bumps `delivery_attempts`, returns
|
|
20
|
-
//! whether THIS caller won (`rowcount == 1`) (`core.py:190-205`).
|
|
21
|
-
//! 3. [`MessageStore::mark`] — status state machine; the only guard is that
|
|
22
|
-
//! `acknowledged` is STICKY against delivery statuses (injected/visible/
|
|
23
|
-
//! submitted/submitted_unverified/delivered) but NOT against others
|
|
24
|
-
//! (e.g. `failed` overwrites) (`core.py:116-138`, the SQL CASE).
|
|
25
|
-
//! 4. [`MessageStore::claim_leader_notification_delivery`] — exactly-once dedup
|
|
26
|
-
//! at the leader-injection boundary. Dedup key = `(result_id, owner_team_id,
|
|
27
|
-
//! owner_epoch)` via the PK + `INSERT OR IGNORE`; **`leader_session_uuid` is
|
|
28
|
-
//! NOT part of the key** (nullable audit metadata only). When `owner_epoch`
|
|
29
|
-
//! is `None` it is derived from the uuid via [`legacy_epoch_from_uuid`]
|
|
30
|
-
//! (`leader_notification_log.py:30-101,145-147`).
|
|
31
|
-
//!
|
|
32
|
-
//! DEFERRED (note, don't build) — follow-on RED slices: scheduled events, token
|
|
33
|
-
//! accounting (incl. the `delivery_tokens` side-effect of `mark`), agent health,
|
|
34
|
-
//! result watchers, results store, `artifact_refs` payloads, busy-retry timing.
|
|
35
|
-
//!
|
|
36
|
-
//! §10: pure-ish lib over SQLite — no panic on malformed input; every path
|
|
37
|
-
//! returns `Result<_, MessageStoreError>`.
|
|
38
|
-
|
|
39
|
-
use std::path::Path;
|
|
40
|
-
use std::sync::atomic::{AtomicU64, Ordering};
|
|
41
|
-
use std::time::{Duration, SystemTime, UNIX_EPOCH};
|
|
42
|
-
|
|
43
|
-
use rusqlite::{params, OptionalExtension};
|
|
44
|
-
use thiserror::Error;
|
|
45
|
-
|
|
46
|
-
static MESSAGE_COUNTER: AtomicU64 = AtomicU64::new(0);
|
|
47
|
-
|
|
48
|
-
#[derive(Debug, Error)]
|
|
49
|
-
pub enum MessageStoreError {
|
|
50
|
-
#[error("db: {0}")]
|
|
51
|
-
Db(#[from] crate::db::DbError),
|
|
52
|
-
#[error("sqlite: {0}")]
|
|
53
|
-
Sqlite(#[from] rusqlite::Error),
|
|
54
|
-
#[error("io: {0}")]
|
|
55
|
-
Io(#[from] std::io::Error),
|
|
56
|
-
#[error("event log: {0}")]
|
|
57
|
-
EventLog(#[from] crate::event_log::EventLogError),
|
|
58
|
-
#[error("delivery receipt missing for message: {0}")]
|
|
59
|
-
DeliveryReceiptMissing(String),
|
|
60
|
-
#[error("invalid message transition from {from} to {to}")]
|
|
61
|
-
InvalidTransition { from: String, to: String },
|
|
62
|
-
#[error("submitted recovery refused: {0}")]
|
|
63
|
-
RecoveryRefused(&'static str),
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/// Outcome of [`MessageStore::claim_leader_notification_delivery`]
|
|
67
|
-
/// (`leader_notification_log.py:73-101`). `status` is `"claimed_by_you"` for the
|
|
68
|
-
/// winner, `"already_notified_by"` for a deduped loser; `notified_message_id` is
|
|
69
|
-
/// always the WINNER's proposed id (a loser sees the first winner's id).
|
|
70
|
-
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
71
|
-
pub struct NotificationClaim {
|
|
72
|
-
pub status: String,
|
|
73
|
-
pub notified_message_id: String,
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/// Args for [`MessageStore::claim_leader_notification_delivery`]
|
|
77
|
-
/// (`leader_notification_log.py:30-40`).
|
|
78
|
-
#[derive(Debug, Clone)]
|
|
79
|
-
pub struct NotificationClaimParams<'a> {
|
|
80
|
-
pub result_id: &'a str,
|
|
81
|
-
pub owner_team_id: Option<&'a str>,
|
|
82
|
-
/// `None` → derived from `leader_session_uuid` via [`legacy_epoch_from_uuid`].
|
|
83
|
-
pub owner_epoch: Option<i64>,
|
|
84
|
-
pub leader_session_uuid: Option<&'a str>,
|
|
85
|
-
pub proposed_message_id: &'a str,
|
|
86
|
-
pub envelope_hash: &'a str,
|
|
87
|
-
pub pane_id: Option<&'a str>,
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/// Legacy #373 parked-row marker, retained only for upgrade recovery.
|
|
91
|
-
pub(crate) const MCP_HANDSHAKE_TIMEOUT: &str = "mcp_handshake_timeout";
|
|
92
|
-
|
|
93
|
-
/// Canonical initial message-row statuses shared by persistence, presentation,
|
|
94
|
-
/// claiming and recovery. New durable dispositions must be added here first.
|
|
95
|
-
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
96
|
-
pub enum MessageRowStatus {
|
|
97
|
-
Accepted,
|
|
98
|
-
StoredOnly,
|
|
99
|
-
QueuedUntilLeaderAttach,
|
|
100
|
-
QueuedCoordinatorUnavailable,
|
|
101
|
-
QueuedPaneMissing,
|
|
102
|
-
TargetResolved,
|
|
103
|
-
SubmittedAwaitingReceipt,
|
|
104
|
-
InjectedAwaitingReceipt,
|
|
105
|
-
SubmittedUnverified,
|
|
106
|
-
Delivered,
|
|
107
|
-
Acknowledged,
|
|
108
|
-
Consumed,
|
|
109
|
-
Failed,
|
|
110
|
-
BlockedLeaderUnbound,
|
|
111
|
-
BlockedWorkerPaneMissing,
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
impl MessageRowStatus {
|
|
115
|
-
pub const ALL: &[Self] = &[
|
|
116
|
-
Self::Accepted,
|
|
117
|
-
Self::StoredOnly,
|
|
118
|
-
Self::QueuedUntilLeaderAttach,
|
|
119
|
-
Self::QueuedCoordinatorUnavailable,
|
|
120
|
-
Self::QueuedPaneMissing,
|
|
121
|
-
Self::TargetResolved,
|
|
122
|
-
Self::SubmittedAwaitingReceipt,
|
|
123
|
-
Self::InjectedAwaitingReceipt,
|
|
124
|
-
Self::SubmittedUnverified,
|
|
125
|
-
Self::Delivered,
|
|
126
|
-
Self::Acknowledged,
|
|
127
|
-
Self::Consumed,
|
|
128
|
-
Self::Failed,
|
|
129
|
-
Self::BlockedLeaderUnbound,
|
|
130
|
-
Self::BlockedWorkerPaneMissing,
|
|
131
|
-
];
|
|
132
|
-
|
|
133
|
-
pub const fn as_str(self) -> &'static str {
|
|
134
|
-
match self {
|
|
135
|
-
Self::Accepted => "accepted",
|
|
136
|
-
Self::StoredOnly => "stored_only",
|
|
137
|
-
Self::QueuedUntilLeaderAttach => "queued_until_leader_attach",
|
|
138
|
-
Self::QueuedCoordinatorUnavailable => "queued_coordinator_unavailable",
|
|
139
|
-
Self::QueuedPaneMissing => "queued_pane_missing",
|
|
140
|
-
Self::TargetResolved => "target_resolved",
|
|
141
|
-
Self::SubmittedAwaitingReceipt => "submitted_pending_acceptance",
|
|
142
|
-
Self::InjectedAwaitingReceipt => "injected_awaiting_receipt",
|
|
143
|
-
Self::SubmittedUnverified => "submitted_unverified",
|
|
144
|
-
Self::Delivered => "delivered",
|
|
145
|
-
Self::Acknowledged => "acknowledged",
|
|
146
|
-
Self::Consumed => "consumed",
|
|
147
|
-
Self::Failed => "failed",
|
|
148
|
-
Self::BlockedLeaderUnbound => "blocked_leader_unbound",
|
|
149
|
-
Self::BlockedWorkerPaneMissing => "queued_pane_missing",
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
|
|
155
|
-
pub struct BlockedLeaderRequeueCounts {
|
|
156
|
-
pub blocked_leader_unbound: usize,
|
|
157
|
-
pub queued_until_leader_attach: usize,
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
161
|
-
pub struct RecoveryBudget {
|
|
162
|
-
pub attempt_budget: u32,
|
|
163
|
-
pub max_age_seconds: u64,
|
|
164
|
-
pub owner_epoch: i64,
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
168
|
-
pub struct PaneAvailable {
|
|
169
|
-
pub agent_id: String,
|
|
170
|
-
pub pane_id: String,
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
174
|
-
pub enum RedisplayKind {
|
|
175
|
-
FrameworkReplay,
|
|
176
|
-
ProviderRerender,
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
impl RedisplayKind {
|
|
180
|
-
pub const fn as_str(self) -> &'static str {
|
|
181
|
-
match self {
|
|
182
|
-
Self::FrameworkReplay => "framework_replay",
|
|
183
|
-
Self::ProviderRerender => "provider_rerender",
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
impl BlockedLeaderRequeueCounts {
|
|
189
|
-
pub const fn total(self) -> usize {
|
|
190
|
-
self.blocked_leader_unbound + self.queued_until_leader_attach
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
/// Fully resolved durable-message insert. Grammar, scope and transport data do
|
|
195
|
-
/// not belong here; callers must resolve those before crossing this boundary.
|
|
196
|
-
pub struct PersistMessageInput<'a> {
|
|
197
|
-
pub message_id: Option<&'a str>,
|
|
198
|
-
pub owner_team_id: Option<&'a str>,
|
|
199
|
-
pub task_id: Option<&'a str>,
|
|
200
|
-
pub sender: &'a str,
|
|
201
|
-
pub recipient: &'a str,
|
|
202
|
-
pub reply_to: Option<&'a str>,
|
|
203
|
-
pub requires_ack: bool,
|
|
204
|
-
pub status: MessageRowStatus,
|
|
205
|
-
pub content: &'a str,
|
|
206
|
-
pub presentation: &'a str,
|
|
207
|
-
pub error: Option<&'a str>,
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
/// `leader_notification_log._legacy_epoch_from_uuid` (line 145-147):
|
|
211
|
-
/// `int(zlib.crc32(str(uuid or "").encode("utf-8")) & 0x7FFFFFFF)`.
|
|
212
|
-
fn legacy_epoch_from_uuid(leader_session_uuid: Option<&str>) -> i64 {
|
|
213
|
-
let mut crc = 0xFFFF_FFFFu32;
|
|
214
|
-
for byte in leader_session_uuid.unwrap_or("").as_bytes() {
|
|
215
|
-
crc ^= u32::from(*byte);
|
|
216
|
-
for _ in 0..8 {
|
|
217
|
-
let mask = 0u32.wrapping_sub(crc & 1);
|
|
218
|
-
crc = (crc >> 1) ^ (0xEDB8_8320 & mask);
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
i64::from((!crc) & 0x7FFF_FFFF)
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
/// SQLite-backed message store (`core.py:MessageStore`). `open` mirrors
|
|
225
|
-
/// `__init__`: `runtime_dir(workspace)/team.db`, mkdir parents, init schema.
|
|
226
|
-
pub struct MessageStore {
|
|
227
|
-
#[allow(dead_code)]
|
|
228
|
-
path: std::path::PathBuf,
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
impl MessageStore {
|
|
232
|
-
/// `MessageStore.__init__` (`core.py:51-55`): `workspace/.team/runtime/team.db`,
|
|
233
|
-
/// create parents, `initialize_schema`.
|
|
234
|
-
pub fn open(workspace: &Path) -> Result<Self, MessageStoreError> {
|
|
235
|
-
let runtime_dir = workspace.join(".team").join("runtime");
|
|
236
|
-
std::fs::create_dir_all(&runtime_dir)?;
|
|
237
|
-
let path = runtime_dir.join("team.db");
|
|
238
|
-
let existed = path.exists();
|
|
239
|
-
let conn = crate::db::schema::open_db(&path)?;
|
|
240
|
-
if existed {
|
|
241
|
-
conn.busy_timeout(Duration::from_millis(5))?;
|
|
242
|
-
let version = conn.query_row("pragma user_version", [], |row| row.get::<_, i64>(0));
|
|
243
|
-
conn.busy_timeout(Duration::from_millis(30_000))?;
|
|
244
|
-
match version {
|
|
245
|
-
Ok(version) if version == crate::db::schema::SCHEMA_VERSION => {}
|
|
246
|
-
Ok(_) => crate::db::schema::initialize_schema(&conn, Some(&path))?,
|
|
247
|
-
Err(rusqlite::Error::SqliteFailure(err, _))
|
|
248
|
-
if matches!(
|
|
249
|
-
err.code,
|
|
250
|
-
rusqlite::ErrorCode::DatabaseBusy | rusqlite::ErrorCode::DatabaseLocked
|
|
251
|
-
) => {}
|
|
252
|
-
Err(error) => return Err(error.into()),
|
|
253
|
-
}
|
|
254
|
-
} else {
|
|
255
|
-
crate::db::schema::initialize_schema(&conn, Some(&path))?;
|
|
256
|
-
}
|
|
257
|
-
Ok(Self { path })
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
/// Absolute path to the backing `team.db` (test/diagnostic accessor).
|
|
261
|
-
pub fn db_path(&self) -> &Path {
|
|
262
|
-
&self.path
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
pub fn persist_message(
|
|
266
|
-
&self,
|
|
267
|
-
input: PersistMessageInput<'_>,
|
|
268
|
-
) -> Result<String, MessageStoreError> {
|
|
269
|
-
let conn = crate::db::schema::open_db(&self.path)?;
|
|
270
|
-
let message_id = input
|
|
271
|
-
.message_id
|
|
272
|
-
.map(ToOwned::to_owned)
|
|
273
|
-
.unwrap_or_else(next_message_id);
|
|
274
|
-
let now = now_ts();
|
|
275
|
-
conn.execute(
|
|
276
|
-
"insert into messages(
|
|
277
|
-
message_id, owner_team_id, task_id, sender, recipient, reply_to, requires_ack,
|
|
278
|
-
status, content, presentation, artifact_refs, created_at, updated_at, delivered_at,
|
|
279
|
-
acknowledged_at, error, delivery_attempts
|
|
280
|
-
) values (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, '[]', ?11, ?11, null, null, ?12, 0)",
|
|
281
|
-
params![
|
|
282
|
-
message_id,
|
|
283
|
-
input.owner_team_id,
|
|
284
|
-
input.task_id,
|
|
285
|
-
input.sender,
|
|
286
|
-
input.recipient,
|
|
287
|
-
input.reply_to,
|
|
288
|
-
if input.requires_ack { 1 } else { 0 },
|
|
289
|
-
input.status.as_str(),
|
|
290
|
-
input.content,
|
|
291
|
-
input.presentation,
|
|
292
|
-
now,
|
|
293
|
-
input.error,
|
|
294
|
-
],
|
|
295
|
-
)?;
|
|
296
|
-
Ok(message_id)
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
/// `create_message` (`core.py:71-114`). Returns `msg_<uuid4 hex[:12]>`; inserts
|
|
300
|
-
/// a row with `status='accepted'`, `requires_ack` as 0/1 int, `artifact_refs`
|
|
301
|
-
/// defaulting to `'[]'`, `delivery_attempts=0`, timestamps = now.
|
|
302
|
-
#[allow(clippy::too_many_arguments)]
|
|
303
|
-
pub fn create_message(
|
|
304
|
-
&self,
|
|
305
|
-
task_id: Option<&str>,
|
|
306
|
-
sender: &str,
|
|
307
|
-
recipient: &str,
|
|
308
|
-
content: &str,
|
|
309
|
-
reply_to: Option<&str>,
|
|
310
|
-
requires_ack: bool,
|
|
311
|
-
owner_team_id: Option<&str>,
|
|
312
|
-
) -> Result<String, MessageStoreError> {
|
|
313
|
-
self.persist_message(PersistMessageInput {
|
|
314
|
-
message_id: None,
|
|
315
|
-
owner_team_id,
|
|
316
|
-
task_id,
|
|
317
|
-
sender,
|
|
318
|
-
recipient,
|
|
319
|
-
reply_to,
|
|
320
|
-
requires_ack,
|
|
321
|
-
status: MessageRowStatus::Accepted,
|
|
322
|
-
content,
|
|
323
|
-
presentation: r#"{"sink":"leader","class":"message"}"#,
|
|
324
|
-
error: None,
|
|
325
|
-
})
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
/// Caller-supplied-id variant of [`create_message`] (CR-015/054 — `--message-id`).
|
|
329
|
-
/// Inserts exactly the given `message_id` instead of generating one. The store
|
|
330
|
-
/// PK is `message_id`, so a repeat with the same id is rejected by SQLite; the
|
|
331
|
-
/// caller is expected to gate via [`message_exists`] first to map collision to
|
|
332
|
-
/// a typed `Duplicate` refusal rather than an opaque sqlite error.
|
|
333
|
-
///
|
|
334
|
-
/// [`message_exists`]: Self::message_exists
|
|
335
|
-
#[allow(clippy::too_many_arguments)]
|
|
336
|
-
pub fn create_message_with_id(
|
|
337
|
-
&self,
|
|
338
|
-
message_id: &str,
|
|
339
|
-
task_id: Option<&str>,
|
|
340
|
-
sender: &str,
|
|
341
|
-
recipient: &str,
|
|
342
|
-
content: &str,
|
|
343
|
-
reply_to: Option<&str>,
|
|
344
|
-
requires_ack: bool,
|
|
345
|
-
owner_team_id: Option<&str>,
|
|
346
|
-
) -> Result<String, MessageStoreError> {
|
|
347
|
-
self.persist_message(PersistMessageInput {
|
|
348
|
-
message_id: Some(message_id),
|
|
349
|
-
owner_team_id,
|
|
350
|
-
task_id,
|
|
351
|
-
sender,
|
|
352
|
-
recipient,
|
|
353
|
-
reply_to,
|
|
354
|
-
requires_ack,
|
|
355
|
-
status: MessageRowStatus::Accepted,
|
|
356
|
-
content,
|
|
357
|
-
presentation: r#"{"sink":"leader","class":"message"}"#,
|
|
358
|
-
error: None,
|
|
359
|
-
})
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
/// `true` iff a `messages` row with this `message_id` already exists. Used by
|
|
363
|
-
/// the send path to map a caller-key collision (CR-015/054) to a `Duplicate`
|
|
364
|
-
/// refusal before attempting an insert that would otherwise fail on the PK.
|
|
365
|
-
pub fn message_exists(&self, message_id: &str) -> Result<bool, MessageStoreError> {
|
|
366
|
-
let conn = crate::db::schema::open_db(&self.path)?;
|
|
367
|
-
let row: Option<i64> = conn
|
|
368
|
-
.query_row(
|
|
369
|
-
"select 1 from messages where message_id = ?1",
|
|
370
|
-
params![message_id],
|
|
371
|
-
|row| row.get(0),
|
|
372
|
-
)
|
|
373
|
-
.optional()?;
|
|
374
|
-
Ok(row.is_some())
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
/// `mark` (`core.py:116-138`) — the messages.status state machine (this slice
|
|
378
|
-
/// excludes the `delivery_tokens` side-effect, which is deferred).
|
|
379
|
-
pub fn mark(
|
|
380
|
-
&self,
|
|
381
|
-
message_id: &str,
|
|
382
|
-
status: &str,
|
|
383
|
-
error: Option<&str>,
|
|
384
|
-
) -> Result<(), MessageStoreError> {
|
|
385
|
-
let mut conn = crate::db::schema::open_db(&self.path)?;
|
|
386
|
-
let tx = conn.transaction()?;
|
|
387
|
-
let now = now_ts();
|
|
388
|
-
let changed = tx.execute(
|
|
389
|
-
"update messages
|
|
390
|
-
set status = case
|
|
391
|
-
when status = 'acknowledged'
|
|
392
|
-
and ?2 in ('injected', 'visible', 'submitted', 'submitted_unverified', 'delivered')
|
|
393
|
-
then status
|
|
394
|
-
else ?2
|
|
395
|
-
end,
|
|
396
|
-
updated_at = ?3,
|
|
397
|
-
delivered_at = case
|
|
398
|
-
when ?2 in ('injected', 'visible', 'submitted', 'delivered')
|
|
399
|
-
then ?3
|
|
400
|
-
else delivered_at
|
|
401
|
-
end,
|
|
402
|
-
acknowledged_at = case when ?2 = 'acknowledged' then ?3 else acknowledged_at end,
|
|
403
|
-
error = case when ?2 = 'delivered' then null else coalesce(?4, error) end
|
|
404
|
-
where message_id = ?1
|
|
405
|
-
and status not in (
|
|
406
|
-
'acknowledged', 'consumed', 'submitted_pending_acceptance',
|
|
407
|
-
'injected_awaiting_receipt'
|
|
408
|
-
)
|
|
409
|
-
and (status != 'delivered' or ?2 in ('delivered', 'acknowledged'))
|
|
410
|
-
and (?2 != 'acknowledged' or status = 'delivered')",
|
|
411
|
-
params![message_id, status, now, error],
|
|
412
|
-
)?;
|
|
413
|
-
if changed == 0 {
|
|
414
|
-
let prior: Option<String> = tx
|
|
415
|
-
.query_row(
|
|
416
|
-
"select status from messages where message_id = ?1",
|
|
417
|
-
params![message_id],
|
|
418
|
-
|row| row.get(0),
|
|
419
|
-
)
|
|
420
|
-
.optional()?;
|
|
421
|
-
let workspace = self
|
|
422
|
-
.path
|
|
423
|
-
.parent()
|
|
424
|
-
.and_then(Path::parent)
|
|
425
|
-
.and_then(Path::parent)
|
|
426
|
-
.unwrap_or(Path::new("."));
|
|
427
|
-
if status == MessageRowStatus::Acknowledged.as_str()
|
|
428
|
-
&& prior.as_deref() != Some(MessageRowStatus::Delivered.as_str())
|
|
429
|
-
{
|
|
430
|
-
crate::event_log::EventLog::new(workspace).write(
|
|
431
|
-
"message.mark_refused",
|
|
432
|
-
serde_json::json!({
|
|
433
|
-
"message_id": message_id,
|
|
434
|
-
"prior_status": prior,
|
|
435
|
-
"requested_status": status,
|
|
436
|
-
"reason": "invalid_acknowledgement_transition",
|
|
437
|
-
}),
|
|
438
|
-
)?;
|
|
439
|
-
return Err(MessageStoreError::InvalidTransition {
|
|
440
|
-
from: prior.unwrap_or_else(|| "missing".to_string()),
|
|
441
|
-
to: status.to_string(),
|
|
442
|
-
});
|
|
443
|
-
}
|
|
444
|
-
let event_log = crate::event_log::EventLog::new(workspace);
|
|
445
|
-
event_log.write(
|
|
446
|
-
"message.mark_refused",
|
|
447
|
-
serde_json::json!({
|
|
448
|
-
"message_id": message_id,
|
|
449
|
-
"prior_status": prior,
|
|
450
|
-
"requested_status": status,
|
|
451
|
-
"reason": "protected_prior_state",
|
|
452
|
-
}),
|
|
453
|
-
)?;
|
|
454
|
-
return Ok(());
|
|
455
|
-
}
|
|
456
|
-
if status == "submitted_unverified" {
|
|
457
|
-
// Uncertainty and its independent safety net are one durable transition.
|
|
458
|
-
// Registration never depends on provider, parser, binding or paste proof.
|
|
459
|
-
crate::messaging::enter_rescue::schedule_in_tx(&tx, message_id, chrono::Utc::now())?;
|
|
460
|
-
}
|
|
461
|
-
tx.commit()?;
|
|
462
|
-
Ok(())
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
/// Record that the transport submitted a message without claiming that the
|
|
466
|
-
/// provider accepted it. The stable message id is also the receipt token.
|
|
467
|
-
pub fn record_delivery_submission(
|
|
468
|
-
&self,
|
|
469
|
-
message_id: &str,
|
|
470
|
-
visible: bool,
|
|
471
|
-
) -> Result<(), MessageStoreError> {
|
|
472
|
-
let conn = crate::db::schema::open_db(&self.path)?;
|
|
473
|
-
let now = now_ts();
|
|
474
|
-
conn.execute(
|
|
475
|
-
"insert into delivery_tokens(
|
|
476
|
-
message_id, unique_token, injected_at, visible_at,
|
|
477
|
-
consumed_at, failed_at, failure_reason
|
|
478
|
-
) values (?1, ?1, ?2, ?3, null, null, null)
|
|
479
|
-
on conflict(message_id) do update set
|
|
480
|
-
visible_at = coalesce(delivery_tokens.visible_at, excluded.visible_at),
|
|
481
|
-
failed_at = null,
|
|
482
|
-
failure_reason = null",
|
|
483
|
-
params![message_id, now, visible.then_some(now_ts())],
|
|
484
|
-
)?;
|
|
485
|
-
Ok(())
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
/// Persist a verified leader transport submission when no provider receipt
|
|
489
|
-
/// source is available. This state is claim/requeue-ineligible but does not
|
|
490
|
-
/// clear the delivery obligation; `consumed_at` remains unset until a
|
|
491
|
-
/// provider-side receipt reaches `mark_delivered_with_receipt`.
|
|
492
|
-
pub fn mark_injected_awaiting_receipt(
|
|
493
|
-
&self,
|
|
494
|
-
message_id: &str,
|
|
495
|
-
) -> Result<(), MessageStoreError> {
|
|
496
|
-
let conn = crate::db::schema::open_db(&self.path)?;
|
|
497
|
-
let changed = conn.execute(
|
|
498
|
-
"update messages
|
|
499
|
-
set status = ?2,
|
|
500
|
-
updated_at = ?3,
|
|
501
|
-
error = 'leader_receipt_source_unavailable'
|
|
502
|
-
where message_id = ?1
|
|
503
|
-
and status in (?4, ?5, ?6)
|
|
504
|
-
and exists (
|
|
505
|
-
select 1 from delivery_tokens
|
|
506
|
-
where delivery_tokens.message_id = messages.message_id
|
|
507
|
-
and delivery_tokens.injected_at is not null
|
|
508
|
-
)",
|
|
509
|
-
params![
|
|
510
|
-
message_id,
|
|
511
|
-
MessageRowStatus::InjectedAwaitingReceipt.as_str(),
|
|
512
|
-
now_ts(),
|
|
513
|
-
MessageRowStatus::TargetResolved.as_str(),
|
|
514
|
-
MessageRowStatus::SubmittedAwaitingReceipt.as_str(),
|
|
515
|
-
MessageRowStatus::InjectedAwaitingReceipt.as_str(),
|
|
516
|
-
],
|
|
517
|
-
)?;
|
|
518
|
-
if changed != 1 {
|
|
519
|
-
return Err(MessageStoreError::DeliveryReceiptMissing(
|
|
520
|
-
message_id.to_string(),
|
|
521
|
-
));
|
|
522
|
-
}
|
|
523
|
-
Ok(())
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
/// Atomically persist the provider-side receipt and advance the message to
|
|
527
|
-
/// delivered. A transport-only caller cannot use this without first
|
|
528
|
-
/// recording the submission row above.
|
|
529
|
-
pub fn mark_delivered_with_receipt(&self, message_id: &str) -> Result<(), MessageStoreError> {
|
|
530
|
-
let mut conn = crate::db::schema::open_db(&self.path)?;
|
|
531
|
-
let tx = conn.transaction()?;
|
|
532
|
-
let now = now_ts();
|
|
533
|
-
let receipts = tx.execute(
|
|
534
|
-
"update delivery_tokens
|
|
535
|
-
set consumed_at = coalesce(consumed_at, ?2),
|
|
536
|
-
failed_at = null,
|
|
537
|
-
failure_reason = null
|
|
538
|
-
where message_id = ?1",
|
|
539
|
-
params![message_id, now],
|
|
540
|
-
)?;
|
|
541
|
-
if receipts != 1 {
|
|
542
|
-
return Err(MessageStoreError::DeliveryReceiptMissing(
|
|
543
|
-
message_id.to_string(),
|
|
544
|
-
));
|
|
545
|
-
}
|
|
546
|
-
tx.execute(
|
|
547
|
-
"update messages
|
|
548
|
-
set status = case when status = 'acknowledged' then status else 'delivered' end,
|
|
549
|
-
updated_at = ?2,
|
|
550
|
-
delivered_at = ?2,
|
|
551
|
-
error = null
|
|
552
|
-
where message_id = ?1",
|
|
553
|
-
params![message_id, now_ts()],
|
|
554
|
-
)?;
|
|
555
|
-
tx.commit()?;
|
|
556
|
-
Ok(())
|
|
557
|
-
}
|
|
558
|
-
|
|
559
|
-
/// `claim_for_delivery` (`core.py:190-205`): atomic single-winner claim. Flips an
|
|
560
|
-
/// eligible row (status ∈ pending/accepted/queued_until_idle/queued_until_start/
|
|
561
|
-
/// queued_stopped/queued_pane_missing, **or** `target_resolved` with a non-null
|
|
562
|
-
/// error — the retry/error-bypass path) to `target_resolved`, clears `error`,
|
|
563
|
-
/// `delivery_attempts += 1`. Returns `true` iff THIS update matched exactly one
|
|
564
|
-
/// row. Clearing `error` is the CAS: a concurrent retry cannot also match
|
|
565
|
-
/// `error is not null`.
|
|
566
|
-
pub fn claim_for_delivery(&self, message_id: &str) -> Result<bool, MessageStoreError> {
|
|
567
|
-
let conn = crate::db::schema::open_db(&self.path)?;
|
|
568
|
-
let rows = conn.execute(
|
|
569
|
-
"update messages
|
|
570
|
-
set status = 'target_resolved',
|
|
571
|
-
delivery_attempts = delivery_attempts + 1,
|
|
572
|
-
error = null,
|
|
573
|
-
updated_at = ?2
|
|
574
|
-
where message_id = ?1
|
|
575
|
-
and (
|
|
576
|
-
status in (
|
|
577
|
-
'pending', 'accepted', 'queued_until_idle', 'queued_until_start',
|
|
578
|
-
'queued_stopped', 'queued_pane_missing', ?3
|
|
579
|
-
)
|
|
580
|
-
or (status = 'target_resolved' and error is not null)
|
|
581
|
-
)",
|
|
582
|
-
params![
|
|
583
|
-
message_id,
|
|
584
|
-
now_ts(),
|
|
585
|
-
MessageRowStatus::QueuedCoordinatorUnavailable.as_str()
|
|
586
|
-
],
|
|
587
|
-
)?;
|
|
588
|
-
Ok(rows == 1)
|
|
589
|
-
}
|
|
590
|
-
|
|
591
|
-
/// Release only an owned claim that has performed no input. Readiness
|
|
592
|
-
/// waiting must remain retryable without consuming the input-attempt budget.
|
|
593
|
-
/// A changed attempt, status, or error means this caller no longer owns it.
|
|
594
|
-
pub(crate) fn release_delivery_before_input(
|
|
595
|
-
&self,
|
|
596
|
-
message_id: &str,
|
|
597
|
-
attempt: u32,
|
|
598
|
-
reason: &str,
|
|
599
|
-
) -> Result<bool, MessageStoreError> {
|
|
600
|
-
if attempt == 0 || reason.is_empty() {
|
|
601
|
-
return Ok(false);
|
|
602
|
-
}
|
|
603
|
-
let conn = crate::db::schema::open_db(&self.path)?;
|
|
604
|
-
let rows = conn.execute(
|
|
605
|
-
"update messages
|
|
606
|
-
set delivery_attempts = delivery_attempts - 1,
|
|
607
|
-
error = ?3, updated_at = ?4
|
|
608
|
-
where message_id = ?1 and status = 'target_resolved'
|
|
609
|
-
and error is null and delivery_attempts = ?2",
|
|
610
|
-
params![message_id, attempt, reason, now_ts()],
|
|
611
|
-
)?;
|
|
612
|
-
Ok(rows == 1)
|
|
613
|
-
}
|
|
614
|
-
|
|
615
|
-
/// Read inbox rows through [`Self::inbox`]; recovery transitions below are
|
|
616
|
-
/// separate repository owners and are not claim eligibility.
|
|
617
|
-
pub fn requeue_blocked_leader_messages(
|
|
618
|
-
&self,
|
|
619
|
-
owner_team_id: &str,
|
|
620
|
-
) -> Result<BlockedLeaderRequeueCounts, MessageStoreError> {
|
|
621
|
-
let mut conn = crate::db::schema::open_db(&self.path)?;
|
|
622
|
-
let tx = conn.transaction()?;
|
|
623
|
-
let now = now_ts();
|
|
624
|
-
let blocked_leader_unbound = tx.execute(
|
|
625
|
-
"update messages
|
|
626
|
-
set status = 'accepted', error = null, updated_at = ?1
|
|
627
|
-
where recipient = 'leader'
|
|
628
|
-
and owner_team_id = ?2
|
|
629
|
-
and status = ?3
|
|
630
|
-
and error = 'leader_not_attached'",
|
|
631
|
-
params![now, owner_team_id, MessageRowStatus::Failed.as_str()],
|
|
632
|
-
)?;
|
|
633
|
-
let queued_until_leader_attach = tx.execute(
|
|
634
|
-
"update messages
|
|
635
|
-
set status = 'accepted', error = null, updated_at = ?1
|
|
636
|
-
where recipient = 'leader'
|
|
637
|
-
and owner_team_id = ?2
|
|
638
|
-
and status = ?3",
|
|
639
|
-
params![
|
|
640
|
-
now,
|
|
641
|
-
owner_team_id,
|
|
642
|
-
MessageRowStatus::QueuedUntilLeaderAttach.as_str()
|
|
643
|
-
],
|
|
644
|
-
)?;
|
|
645
|
-
tx.commit()?;
|
|
646
|
-
Ok(BlockedLeaderRequeueCounts {
|
|
647
|
-
blocked_leader_unbound,
|
|
648
|
-
queued_until_leader_attach,
|
|
649
|
-
})
|
|
650
|
-
}
|
|
651
|
-
|
|
652
|
-
pub fn recover_worker_pane_available(
|
|
653
|
-
&self,
|
|
654
|
-
agent_id: &str,
|
|
655
|
-
owner_team_id: Option<&str>,
|
|
656
|
-
) -> Result<Vec<String>, MessageStoreError> {
|
|
657
|
-
let mut conn = crate::db::schema::open_db(&self.path)?;
|
|
658
|
-
let tx = conn.transaction()?;
|
|
659
|
-
let ids = {
|
|
660
|
-
let mut stmt = tx.prepare(
|
|
661
|
-
"select message_id from messages
|
|
662
|
-
where recipient = ?1
|
|
663
|
-
and ((status = ?2 and error = 'tmux_target_missing')
|
|
664
|
-
or (status = 'queued_until_start' and error = ?4))
|
|
665
|
-
and (
|
|
666
|
-
(?3 is null and owner_team_id is null)
|
|
667
|
-
or owner_team_id = ?3
|
|
668
|
-
)
|
|
669
|
-
order by created_at, message_id",
|
|
670
|
-
)?;
|
|
671
|
-
let rows = stmt
|
|
672
|
-
.query_map(
|
|
673
|
-
params![
|
|
674
|
-
agent_id,
|
|
675
|
-
MessageRowStatus::QueuedPaneMissing.as_str(),
|
|
676
|
-
owner_team_id,
|
|
677
|
-
MCP_HANDSHAKE_TIMEOUT
|
|
678
|
-
],
|
|
679
|
-
|row| row.get::<_, String>(0),
|
|
680
|
-
)?
|
|
681
|
-
.collect::<Result<Vec<_>, _>>()?;
|
|
682
|
-
rows
|
|
683
|
-
};
|
|
684
|
-
let now = now_ts();
|
|
685
|
-
for message_id in &ids {
|
|
686
|
-
tx.execute(
|
|
687
|
-
"update messages
|
|
688
|
-
set status = ?1, error = null, updated_at = ?2
|
|
689
|
-
where message_id = ?3",
|
|
690
|
-
params![MessageRowStatus::Accepted.as_str(), now, message_id],
|
|
691
|
-
)?;
|
|
692
|
-
}
|
|
693
|
-
tx.commit()?;
|
|
694
|
-
Ok(ids)
|
|
695
|
-
}
|
|
696
|
-
|
|
697
|
-
pub fn retry_submitted_explicit(
|
|
698
|
-
&self,
|
|
699
|
-
message_id: &str,
|
|
700
|
-
incident_id: &str,
|
|
701
|
-
operator_reason: &str,
|
|
702
|
-
budget: RecoveryBudget,
|
|
703
|
-
) -> Result<bool, MessageStoreError> {
|
|
704
|
-
if incident_id.trim().is_empty() || operator_reason.trim().is_empty() {
|
|
705
|
-
return Err(MessageStoreError::RecoveryRefused(
|
|
706
|
-
"incident_id_and_operator_reason_required",
|
|
707
|
-
));
|
|
708
|
-
}
|
|
709
|
-
if budget.attempt_budget == 0 || budget.max_age_seconds == 0 || budget.owner_epoch <= 0 {
|
|
710
|
-
return Err(MessageStoreError::RecoveryRefused(
|
|
711
|
-
"invalid_recovery_budget",
|
|
712
|
-
));
|
|
713
|
-
}
|
|
714
|
-
let conn = crate::db::schema::open_db(&self.path)?;
|
|
715
|
-
let row: Option<(String, i64, String)> = conn
|
|
716
|
-
.query_row(
|
|
717
|
-
"select status, delivery_attempts, updated_at
|
|
718
|
-
from messages where message_id = ?1",
|
|
719
|
-
params![message_id],
|
|
720
|
-
|row| Ok((row.get(0)?, row.get(1)?, row.get(2)?)),
|
|
721
|
-
)
|
|
722
|
-
.optional()?;
|
|
723
|
-
let Some((status, attempts, updated_at)) = row else {
|
|
724
|
-
return Ok(false);
|
|
725
|
-
};
|
|
726
|
-
if status != MessageRowStatus::SubmittedAwaitingReceipt.as_str()
|
|
727
|
-
&& status != MessageRowStatus::SubmittedUnverified.as_str()
|
|
728
|
-
{
|
|
729
|
-
return Err(MessageStoreError::RecoveryRefused(
|
|
730
|
-
"message_not_submitted_recoverable",
|
|
731
|
-
));
|
|
732
|
-
}
|
|
733
|
-
if attempts >= i64::from(budget.attempt_budget) {
|
|
734
|
-
return Err(MessageStoreError::RecoveryRefused(
|
|
735
|
-
"attempt_budget_exhausted",
|
|
736
|
-
));
|
|
737
|
-
}
|
|
738
|
-
let updated_at = chrono::DateTime::parse_from_rfc3339(&updated_at)
|
|
739
|
-
.map_err(|_| MessageStoreError::RecoveryRefused("invalid_updated_at"))?;
|
|
740
|
-
let age = chrono::Utc::now()
|
|
741
|
-
.signed_duration_since(updated_at.with_timezone(&chrono::Utc))
|
|
742
|
-
.num_seconds();
|
|
743
|
-
if age < 0 || u64::try_from(age).unwrap_or(u64::MAX) > budget.max_age_seconds {
|
|
744
|
-
return Err(MessageStoreError::RecoveryRefused("message_too_old"));
|
|
745
|
-
}
|
|
746
|
-
let changed = conn.execute(
|
|
747
|
-
"update messages
|
|
748
|
-
set status = ?1, error = ?2, updated_at = ?3
|
|
749
|
-
where message_id = ?4
|
|
750
|
-
and status in (?5, ?6)
|
|
751
|
-
and delivery_attempts < ?7",
|
|
752
|
-
params![
|
|
753
|
-
MessageRowStatus::Accepted.as_str(),
|
|
754
|
-
format!("explicit_recovery:{incident_id}:{operator_reason}"),
|
|
755
|
-
now_ts(),
|
|
756
|
-
message_id,
|
|
757
|
-
MessageRowStatus::SubmittedAwaitingReceipt.as_str(),
|
|
758
|
-
MessageRowStatus::SubmittedUnverified.as_str(),
|
|
759
|
-
budget.attempt_budget
|
|
760
|
-
],
|
|
761
|
-
)?;
|
|
762
|
-
Ok(changed == 1)
|
|
763
|
-
}
|
|
764
|
-
|
|
765
|
-
/// Read ordinary inbox rows for an agent. Leader stage-result notifications are
|
|
766
|
-
/// delivered through the leader receiver, not exposed as mailbox fallback rows.
|
|
767
|
-
/// This projection intentionally has no owner-team filter when the caller does
|
|
768
|
-
/// not provide one: legacy/CLI inbox must surface NULL-owner messages stored for
|
|
769
|
-
/// the agent.
|
|
770
|
-
pub fn inbox(
|
|
771
|
-
&self,
|
|
772
|
-
agent_id: &str,
|
|
773
|
-
limit: usize,
|
|
774
|
-
owner_team_id: Option<&str>,
|
|
775
|
-
) -> Result<Vec<serde_json::Value>, MessageStoreError> {
|
|
776
|
-
let conn = crate::db::schema::open_db(&self.path)?;
|
|
777
|
-
let limit = i64::try_from(limit).unwrap_or(i64::MAX);
|
|
778
|
-
let sql = match owner_team_id {
|
|
779
|
-
Some(_) => {
|
|
780
|
-
"select message_id, owner_team_id, task_id, sender, recipient, reply_to, requires_ack,
|
|
781
|
-
status, content, artifact_refs, created_at, updated_at, delivered_at,
|
|
782
|
-
acknowledged_at, error, delivery_attempts
|
|
783
|
-
from messages
|
|
784
|
-
where (sender = ?1 or recipient = ?1)
|
|
785
|
-
and owner_team_id = ?3
|
|
786
|
-
and coalesce(json_extract(presentation, '$.class'), 'message') != 'stage_result'
|
|
787
|
-
order by created_at desc
|
|
788
|
-
limit ?2"
|
|
789
|
-
}
|
|
790
|
-
None => {
|
|
791
|
-
"select message_id, owner_team_id, task_id, sender, recipient, reply_to, requires_ack,
|
|
792
|
-
status, content, artifact_refs, created_at, updated_at, delivered_at,
|
|
793
|
-
acknowledged_at, error, delivery_attempts
|
|
794
|
-
from messages
|
|
795
|
-
where (sender = ?1 or recipient = ?1)
|
|
796
|
-
and coalesce(json_extract(presentation, '$.class'), 'message') != 'stage_result'
|
|
797
|
-
order by created_at desc
|
|
798
|
-
limit ?2"
|
|
799
|
-
}
|
|
800
|
-
};
|
|
801
|
-
let rows = match owner_team_id {
|
|
802
|
-
Some(team) => {
|
|
803
|
-
let mut stmt = conn.prepare(sql)?;
|
|
804
|
-
let values = stmt
|
|
805
|
-
.query_map(params![agent_id, limit, team], row_to_message_value)?
|
|
806
|
-
.collect::<Result<Vec<_>, _>>()?;
|
|
807
|
-
values
|
|
808
|
-
}
|
|
809
|
-
None => {
|
|
810
|
-
let mut stmt = conn.prepare(sql)?;
|
|
811
|
-
let values = stmt
|
|
812
|
-
.query_map(params![agent_id, limit], row_to_message_value)?
|
|
813
|
-
.collect::<Result<Vec<_>, _>>()?;
|
|
814
|
-
values
|
|
815
|
-
}
|
|
816
|
-
};
|
|
817
|
-
Ok(rows.into_iter().rev().collect())
|
|
818
|
-
}
|
|
819
|
-
|
|
820
|
-
/// `latest_results` (`core.py:458-471`): newest non-invalid result rows, oldest
|
|
821
|
-
/// first (Python fetches `created_at desc limit ?` then reverses).
|
|
822
|
-
pub fn latest_results(
|
|
823
|
-
&self,
|
|
824
|
-
limit: usize,
|
|
825
|
-
owner_team_id: Option<&str>,
|
|
826
|
-
) -> Result<Vec<serde_json::Value>, MessageStoreError> {
|
|
827
|
-
let conn = crate::db::schema::open_db(&self.path)?;
|
|
828
|
-
let limit = i64::try_from(limit).unwrap_or(i64::MAX);
|
|
829
|
-
let sql = match owner_team_id {
|
|
830
|
-
Some(_) => {
|
|
831
|
-
"select owner_team_id, result_id, task_id, agent_id, envelope, status, created_at
|
|
832
|
-
from results
|
|
833
|
-
where status != 'invalid' and owner_team_id = ?2
|
|
834
|
-
order by created_at desc
|
|
835
|
-
limit ?1"
|
|
836
|
-
}
|
|
837
|
-
None => {
|
|
838
|
-
"select owner_team_id, result_id, task_id, agent_id, envelope, status, created_at
|
|
839
|
-
from results
|
|
840
|
-
where status != 'invalid'
|
|
841
|
-
order by created_at desc
|
|
842
|
-
limit ?1"
|
|
843
|
-
}
|
|
844
|
-
};
|
|
845
|
-
let mut stmt = conn.prepare(sql)?;
|
|
846
|
-
let map_row = |row: &rusqlite::Row<'_>| {
|
|
847
|
-
Ok(serde_json::json!({
|
|
848
|
-
"owner_team_id": row.get::<_, Option<String>>(0)?,
|
|
849
|
-
"result_id": row.get::<_, String>(1)?,
|
|
850
|
-
"task_id": row.get::<_, Option<String>>(2)?,
|
|
851
|
-
"agent_id": row.get::<_, Option<String>>(3)?,
|
|
852
|
-
"envelope": row.get::<_, Option<String>>(4)?,
|
|
853
|
-
"status": row.get::<_, Option<String>>(5)?,
|
|
854
|
-
"created_at": row.get::<_, Option<String>>(6)?,
|
|
855
|
-
}))
|
|
856
|
-
};
|
|
857
|
-
let rows = match owner_team_id {
|
|
858
|
-
Some(team) => stmt
|
|
859
|
-
.query_map(params![limit, team], map_row)?
|
|
860
|
-
.collect::<Result<Vec<_>, _>>()?,
|
|
861
|
-
None => stmt
|
|
862
|
-
.query_map(params![limit], map_row)?
|
|
863
|
-
.collect::<Result<Vec<_>, _>>()?,
|
|
864
|
-
};
|
|
865
|
-
Ok(rows.into_iter().rev().collect())
|
|
866
|
-
}
|
|
867
|
-
|
|
868
|
-
/// `claim_leader_notification_delivery` (`leader_notification_log.py:30-101`):
|
|
869
|
-
/// `INSERT OR IGNORE` on PK `(result_id, owner_team_id, owner_epoch)`. rowcount==1
|
|
870
|
-
/// → `claimed_by_you`; else read the existing winner row → `already_notified_by`.
|
|
871
|
-
/// `owner_team_id` defaults to `""`; `owner_epoch=None` → [`legacy_epoch_from_uuid`].
|
|
872
|
-
pub fn claim_leader_notification_delivery(
|
|
873
|
-
&self,
|
|
874
|
-
params: NotificationClaimParams<'_>,
|
|
875
|
-
) -> Result<NotificationClaim, MessageStoreError> {
|
|
876
|
-
let conn = crate::db::schema::open_db(&self.path)?;
|
|
877
|
-
let owner_team_id = params.owner_team_id.unwrap_or("");
|
|
878
|
-
let owner_epoch = match params.owner_epoch {
|
|
879
|
-
Some(epoch) => epoch,
|
|
880
|
-
None => legacy_epoch_from_uuid(params.leader_session_uuid),
|
|
881
|
-
};
|
|
882
|
-
let rows = conn.execute(
|
|
883
|
-
"insert or ignore into leader_notification_log(
|
|
884
|
-
result_id, owner_team_id, owner_epoch, leader_session_uuid, notified_message_id,
|
|
885
|
-
notified_at, leader_pane_id_at_notify, envelope_content_hash
|
|
886
|
-
) values (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8)",
|
|
887
|
-
params![
|
|
888
|
-
params.result_id,
|
|
889
|
-
owner_team_id,
|
|
890
|
-
owner_epoch,
|
|
891
|
-
params.leader_session_uuid,
|
|
892
|
-
params.proposed_message_id,
|
|
893
|
-
now_ts(),
|
|
894
|
-
params.pane_id,
|
|
895
|
-
params.envelope_hash,
|
|
896
|
-
],
|
|
897
|
-
)?;
|
|
898
|
-
if rows == 1 {
|
|
899
|
-
return Ok(NotificationClaim {
|
|
900
|
-
status: "claimed_by_you".to_string(),
|
|
901
|
-
notified_message_id: params.proposed_message_id.to_string(),
|
|
902
|
-
});
|
|
903
|
-
}
|
|
904
|
-
|
|
905
|
-
let notified_message_id = conn
|
|
906
|
-
.query_row(
|
|
907
|
-
"select notified_message_id from leader_notification_log
|
|
908
|
-
where result_id = ?1 and owner_team_id = ?2 and owner_epoch = ?3",
|
|
909
|
-
params![params.result_id, owner_team_id, owner_epoch],
|
|
910
|
-
|row| row.get::<_, String>(0),
|
|
911
|
-
)
|
|
912
|
-
.optional()?
|
|
913
|
-
.ok_or(rusqlite::Error::QueryReturnedNoRows)?;
|
|
914
|
-
Ok(NotificationClaim {
|
|
915
|
-
status: "already_notified_by".to_string(),
|
|
916
|
-
notified_message_id,
|
|
917
|
-
})
|
|
918
|
-
}
|
|
919
|
-
}
|
|
920
|
-
|
|
921
|
-
fn row_to_message_value(row: &rusqlite::Row<'_>) -> rusqlite::Result<serde_json::Value> {
|
|
922
|
-
Ok(serde_json::json!({
|
|
923
|
-
"message_id": row.get::<_, String>(0)?,
|
|
924
|
-
"owner_team_id": row.get::<_, Option<String>>(1)?,
|
|
925
|
-
"task_id": row.get::<_, Option<String>>(2)?,
|
|
926
|
-
"sender": row.get::<_, Option<String>>(3)?,
|
|
927
|
-
"recipient": row.get::<_, Option<String>>(4)?,
|
|
928
|
-
"reply_to": row.get::<_, Option<String>>(5)?,
|
|
929
|
-
"requires_ack": row.get::<_, Option<i64>>(6)?,
|
|
930
|
-
"status": row.get::<_, Option<String>>(7)?,
|
|
931
|
-
"content": row.get::<_, Option<String>>(8)?,
|
|
932
|
-
"artifact_refs": row.get::<_, Option<String>>(9)?,
|
|
933
|
-
"created_at": row.get::<_, Option<String>>(10)?,
|
|
934
|
-
"updated_at": row.get::<_, Option<String>>(11)?,
|
|
935
|
-
"delivered_at": row.get::<_, Option<String>>(12)?,
|
|
936
|
-
"acknowledged_at": row.get::<_, Option<String>>(13)?,
|
|
937
|
-
"error": row.get::<_, Option<String>>(14)?,
|
|
938
|
-
"delivery_attempts": row.get::<_, Option<i64>>(15)?,
|
|
939
|
-
}))
|
|
940
|
-
}
|
|
941
|
-
|
|
942
|
-
/// `result_summary_from_row`(`status/queries.py:92-106`):解析 result 行的 envelope,
|
|
943
|
-
/// 产出 status/watch 共用的 result 摘要;envelope 坏/非对象 → `None`。
|
|
944
|
-
pub fn result_summary_from_row(row: &serde_json::Value) -> Option<serde_json::Value> {
|
|
945
|
-
let envelope = match row.get("envelope") {
|
|
946
|
-
Some(serde_json::Value::String(text)) => {
|
|
947
|
-
serde_json::from_str::<serde_json::Value>(text).ok()?
|
|
948
|
-
}
|
|
949
|
-
Some(value @ serde_json::Value::Object(_)) => value.clone(),
|
|
950
|
-
_ => return None,
|
|
951
|
-
};
|
|
952
|
-
if !envelope.is_object() {
|
|
953
|
-
return None;
|
|
954
|
-
}
|
|
955
|
-
// Python `envelope.get(k) or row.get(k)` — falsy (null/empty) falls through to the row.
|
|
956
|
-
let pick = |key: &str| {
|
|
957
|
-
envelope
|
|
958
|
-
.get(key)
|
|
959
|
-
.filter(|v| !v.is_null() && v.as_str() != Some(""))
|
|
960
|
-
.or_else(|| row.get(key))
|
|
961
|
-
.cloned()
|
|
962
|
-
.unwrap_or(serde_json::Value::Null)
|
|
963
|
-
};
|
|
964
|
-
Some(serde_json::json!({
|
|
965
|
-
"result_id": row.get("result_id").cloned().unwrap_or(serde_json::Value::Null),
|
|
966
|
-
"task_id": pick("task_id"),
|
|
967
|
-
"agent_id": pick("agent_id"),
|
|
968
|
-
"status": pick("status"),
|
|
969
|
-
"summary": envelope.get("summary").cloned().unwrap_or(serde_json::Value::Null),
|
|
970
|
-
"created_at": row.get("created_at").cloned().unwrap_or(serde_json::Value::Null),
|
|
971
|
-
}))
|
|
972
|
-
}
|
|
973
|
-
|
|
974
|
-
fn now_ts() -> String {
|
|
975
|
-
chrono::Utc::now().to_rfc3339()
|
|
976
|
-
}
|
|
977
|
-
|
|
978
|
-
fn next_message_id() -> String {
|
|
979
|
-
let nanos = match SystemTime::now().duration_since(UNIX_EPOCH) {
|
|
980
|
-
Ok(duration) => {
|
|
981
|
-
let low = duration.as_nanos() & u128::from(u64::MAX);
|
|
982
|
-
u64::try_from(low).unwrap_or(0)
|
|
983
|
-
}
|
|
984
|
-
Err(_) => 0,
|
|
985
|
-
};
|
|
986
|
-
let counter = MESSAGE_COUNTER.fetch_add(1, Ordering::Relaxed);
|
|
987
|
-
let pid = u64::from(std::process::id());
|
|
988
|
-
let value = nanos ^ counter.rotate_left(17) ^ pid.rotate_left(32);
|
|
989
|
-
format!("msg_{:012x}", value & 0xFFFF_FFFF_FFFF)
|
|
990
|
-
}
|
|
991
|
-
|
|
992
|
-
#[cfg(test)]
|
|
993
|
-
mod tests {
|
|
994
|
-
#![allow(clippy::unwrap_used)]
|
|
995
|
-
use super::*;
|
|
996
|
-
use crate::db;
|
|
997
|
-
use rusqlite::Connection;
|
|
998
|
-
use std::path::PathBuf;
|
|
999
|
-
use std::sync::atomic::{AtomicU32, Ordering};
|
|
1000
|
-
|
|
1001
|
-
static COUNTER: AtomicU32 = AtomicU32::new(0);
|
|
1002
|
-
|
|
1003
|
-
fn temp_workspace() -> PathBuf {
|
|
1004
|
-
let n = COUNTER.fetch_add(1, Ordering::Relaxed);
|
|
1005
|
-
let ws = std::env::temp_dir().join(format!("ta_rs_msgstore_{}_{}", std::process::id(), n));
|
|
1006
|
-
std::fs::create_dir_all(&ws).unwrap();
|
|
1007
|
-
ws
|
|
1008
|
-
}
|
|
1009
|
-
|
|
1010
|
-
fn store() -> MessageStore {
|
|
1011
|
-
MessageStore::open(&temp_workspace()).unwrap()
|
|
1012
|
-
}
|
|
1013
|
-
|
|
1014
|
-
/// Fresh read connection onto the store's team.db (asserts DB-STATE parity
|
|
1015
|
-
/// independently of the store's own connection).
|
|
1016
|
-
fn read(store: &MessageStore) -> Connection {
|
|
1017
|
-
db::schema::open_db(store.db_path()).unwrap()
|
|
1018
|
-
}
|
|
1019
|
-
|
|
1020
|
-
fn col_str(conn: &Connection, mid: &str, col: &str) -> Option<String> {
|
|
1021
|
-
// `col` is a fixed test literal, never user input.
|
|
1022
|
-
conn.query_row(
|
|
1023
|
-
&format!("select {col} from messages where message_id = ?1"),
|
|
1024
|
-
[mid],
|
|
1025
|
-
|r| r.get::<_, Option<String>>(0),
|
|
1026
|
-
)
|
|
1027
|
-
.unwrap()
|
|
1028
|
-
}
|
|
1029
|
-
|
|
1030
|
-
fn col_i64(conn: &Connection, mid: &str, col: &str) -> i64 {
|
|
1031
|
-
conn.query_row(
|
|
1032
|
-
&format!("select {col} from messages where message_id = ?1"),
|
|
1033
|
-
[mid],
|
|
1034
|
-
|r| r.get(0),
|
|
1035
|
-
)
|
|
1036
|
-
.unwrap()
|
|
1037
|
-
}
|
|
1038
|
-
|
|
1039
|
-
fn status_of(conn: &Connection, mid: &str) -> String {
|
|
1040
|
-
col_str(conn, mid, "status").unwrap()
|
|
1041
|
-
}
|
|
1042
|
-
|
|
1043
|
-
/// (result_id, owner_team_id, owner_epoch, leader_session_uuid, notified_message_id)
|
|
1044
|
-
/// ordered by notified_at — the dedup-relevant projection of leader_notification_log.
|
|
1045
|
-
fn notif_rows(conn: &Connection) -> Vec<(String, String, i64, Option<String>, String)> {
|
|
1046
|
-
let mut stmt = conn
|
|
1047
|
-
.prepare(
|
|
1048
|
-
"select result_id, owner_team_id, owner_epoch, leader_session_uuid, notified_message_id \
|
|
1049
|
-
from leader_notification_log order by notified_at",
|
|
1050
|
-
)
|
|
1051
|
-
.unwrap();
|
|
1052
|
-
stmt.query_map([], |r| {
|
|
1053
|
-
Ok((
|
|
1054
|
-
r.get::<_, String>(0)?,
|
|
1055
|
-
r.get::<_, String>(1)?,
|
|
1056
|
-
r.get::<_, i64>(2)?,
|
|
1057
|
-
r.get::<_, Option<String>>(3)?,
|
|
1058
|
-
r.get::<_, String>(4)?,
|
|
1059
|
-
))
|
|
1060
|
-
})
|
|
1061
|
-
.unwrap()
|
|
1062
|
-
.collect::<Result<_, _>>()
|
|
1063
|
-
.unwrap()
|
|
1064
|
-
}
|
|
1065
|
-
|
|
1066
|
-
// ───────────────────────────── create_message ─────────────────────────────
|
|
1067
|
-
|
|
1068
|
-
#[test]
|
|
1069
|
-
fn create_message_inserts_accepted_row() {
|
|
1070
|
-
let s = store();
|
|
1071
|
-
let mid = s
|
|
1072
|
-
.create_message(
|
|
1073
|
-
Some("task_1"),
|
|
1074
|
-
"leader",
|
|
1075
|
-
"alice",
|
|
1076
|
-
"hello",
|
|
1077
|
-
None,
|
|
1078
|
-
true,
|
|
1079
|
-
Some("team_A"),
|
|
1080
|
-
)
|
|
1081
|
-
.unwrap();
|
|
1082
|
-
assert!(mid.starts_with("msg_"), "id: {mid}");
|
|
1083
|
-
assert_eq!(mid.len(), 16, "msg_ + 12 hex");
|
|
1084
|
-
|
|
1085
|
-
let c = read(&s);
|
|
1086
|
-
assert_eq!(status_of(&c, &mid), "accepted");
|
|
1087
|
-
assert_eq!(col_str(&c, &mid, "task_id").as_deref(), Some("task_1"));
|
|
1088
|
-
assert_eq!(col_str(&c, &mid, "sender").as_deref(), Some("leader"));
|
|
1089
|
-
assert_eq!(col_str(&c, &mid, "recipient").as_deref(), Some("alice"));
|
|
1090
|
-
assert_eq!(
|
|
1091
|
-
col_str(&c, &mid, "owner_team_id").as_deref(),
|
|
1092
|
-
Some("team_A")
|
|
1093
|
-
);
|
|
1094
|
-
assert_eq!(col_str(&c, &mid, "content").as_deref(), Some("hello"));
|
|
1095
|
-
assert_eq!(col_str(&c, &mid, "artifact_refs").as_deref(), Some("[]"));
|
|
1096
|
-
assert_eq!(col_str(&c, &mid, "reply_to"), None);
|
|
1097
|
-
assert_eq!(col_i64(&c, &mid, "requires_ack"), 1);
|
|
1098
|
-
assert_eq!(col_i64(&c, &mid, "delivery_attempts"), 0);
|
|
1099
|
-
assert_eq!(col_str(&c, &mid, "delivered_at"), None);
|
|
1100
|
-
assert_eq!(col_str(&c, &mid, "acknowledged_at"), None);
|
|
1101
|
-
assert_eq!(col_str(&c, &mid, "error"), None);
|
|
1102
|
-
}
|
|
1103
|
-
|
|
1104
|
-
#[test]
|
|
1105
|
-
fn create_message_no_task_no_owner_ack_false() {
|
|
1106
|
-
let s = store();
|
|
1107
|
-
let mid = s
|
|
1108
|
-
.create_message(None, "leader", "bob", "hi", None, false, None)
|
|
1109
|
-
.unwrap();
|
|
1110
|
-
let c = read(&s);
|
|
1111
|
-
assert_eq!(col_str(&c, &mid, "task_id"), None);
|
|
1112
|
-
assert_eq!(col_str(&c, &mid, "owner_team_id"), None);
|
|
1113
|
-
assert_eq!(col_i64(&c, &mid, "requires_ack"), 0);
|
|
1114
|
-
assert_eq!(status_of(&c, &mid), "accepted");
|
|
1115
|
-
}
|
|
1116
|
-
|
|
1117
|
-
// ───────────────────────── claim_for_delivery (atomic claim) ─────────────────────────
|
|
1118
|
-
|
|
1119
|
-
#[test]
|
|
1120
|
-
fn claim_for_delivery_first_caller_wins() {
|
|
1121
|
-
let s = store();
|
|
1122
|
-
let mid = s
|
|
1123
|
-
.create_message(Some("t"), "s", "r", "c", None, true, None)
|
|
1124
|
-
.unwrap();
|
|
1125
|
-
|
|
1126
|
-
assert!(
|
|
1127
|
-
s.claim_for_delivery(&mid).unwrap(),
|
|
1128
|
-
"accepted is eligible → claim wins"
|
|
1129
|
-
);
|
|
1130
|
-
let c = read(&s);
|
|
1131
|
-
assert_eq!(status_of(&c, &mid), "target_resolved");
|
|
1132
|
-
assert_eq!(col_i64(&c, &mid, "delivery_attempts"), 1);
|
|
1133
|
-
}
|
|
1134
|
-
|
|
1135
|
-
#[test]
|
|
1136
|
-
fn claim_for_delivery_second_caller_loses_and_state_unchanged() {
|
|
1137
|
-
// Atomic single-winner: once target_resolved, a re-claim returns false and
|
|
1138
|
-
// must NOT bump delivery_attempts again.
|
|
1139
|
-
let s = store();
|
|
1140
|
-
let mid = s
|
|
1141
|
-
.create_message(Some("t"), "s", "r", "c", None, true, None)
|
|
1142
|
-
.unwrap();
|
|
1143
|
-
assert!(s.claim_for_delivery(&mid).unwrap());
|
|
1144
|
-
assert!(
|
|
1145
|
-
!s.claim_for_delivery(&mid).unwrap(),
|
|
1146
|
-
"already target_resolved → no second winner"
|
|
1147
|
-
);
|
|
1148
|
-
|
|
1149
|
-
let c = read(&s);
|
|
1150
|
-
assert_eq!(status_of(&c, &mid), "target_resolved");
|
|
1151
|
-
assert_eq!(col_i64(&c, &mid, "delivery_attempts"), 1);
|
|
1152
|
-
}
|
|
1153
|
-
|
|
1154
|
-
#[test]
|
|
1155
|
-
fn claim_for_delivery_nonexistent_is_false() {
|
|
1156
|
-
let s = store();
|
|
1157
|
-
assert!(!s.claim_for_delivery("msg_doesnotexist").unwrap());
|
|
1158
|
-
}
|
|
1159
|
-
|
|
1160
|
-
#[test]
|
|
1161
|
-
fn claim_for_delivery_ineligible_status_is_false() {
|
|
1162
|
-
// 'failed' is not in the eligible set → claim returns false, status unchanged.
|
|
1163
|
-
let s = store();
|
|
1164
|
-
let mid = s
|
|
1165
|
-
.create_message(Some("t"), "s", "r", "c", None, true, None)
|
|
1166
|
-
.unwrap();
|
|
1167
|
-
s.mark(&mid, "failed", Some("boom")).unwrap();
|
|
1168
|
-
assert!(!s.claim_for_delivery(&mid).unwrap());
|
|
1169
|
-
assert_eq!(status_of(&read(&s), &mid), "failed");
|
|
1170
|
-
}
|
|
1171
|
-
|
|
1172
|
-
#[test]
|
|
1173
|
-
fn claim_for_delivery_error_retry_is_atomic_single_winner() {
|
|
1174
|
-
let s = store();
|
|
1175
|
-
let mid = s
|
|
1176
|
-
.create_message(Some("t"), "s", "r", "c", None, true, None)
|
|
1177
|
-
.unwrap();
|
|
1178
|
-
s.mark(&mid, "target_resolved", Some("probe_failed"))
|
|
1179
|
-
.unwrap();
|
|
1180
|
-
assert_eq!(
|
|
1181
|
-
col_str(&read(&s), &mid, "error").as_deref(),
|
|
1182
|
-
Some("probe_failed")
|
|
1183
|
-
);
|
|
1184
|
-
assert!(
|
|
1185
|
-
s.claim_for_delivery(&mid).unwrap(),
|
|
1186
|
-
"target_resolved+error must enter the claim gate, not a non-CAS bypass"
|
|
1187
|
-
);
|
|
1188
|
-
let c = read(&s);
|
|
1189
|
-
assert_eq!(status_of(&c, &mid), "target_resolved");
|
|
1190
|
-
assert_eq!(col_str(&c, &mid, "error"), None);
|
|
1191
|
-
assert_eq!(col_i64(&c, &mid, "delivery_attempts"), 1);
|
|
1192
|
-
assert!(
|
|
1193
|
-
!s.claim_for_delivery(&mid).unwrap(),
|
|
1194
|
-
"cleared error must lose the second claim"
|
|
1195
|
-
);
|
|
1196
|
-
assert_eq!(col_i64(&read(&s), &mid, "delivery_attempts"), 1);
|
|
1197
|
-
}
|
|
1198
|
-
|
|
1199
|
-
#[test]
|
|
1200
|
-
fn release_delivery_before_input_preserves_budget_and_single_winner() {
|
|
1201
|
-
let s = store();
|
|
1202
|
-
let mid = s.create_message(Some("t"), "s", "r", "c", None, true, None).unwrap();
|
|
1203
|
-
assert!(s.claim_for_delivery(&mid).unwrap());
|
|
1204
|
-
assert!(!s.claim_for_delivery(&mid).unwrap());
|
|
1205
|
-
assert!(s.release_delivery_before_input(&mid, 1, "mcp_handshake_missing").unwrap());
|
|
1206
|
-
assert_eq!(col_i64(&read(&s), &mid, "delivery_attempts"), 0);
|
|
1207
|
-
assert_eq!(col_str(&read(&s), &mid, "error").as_deref(), Some("mcp_handshake_missing"));
|
|
1208
|
-
assert!(!s.release_delivery_before_input(&mid, 1, "late").unwrap());
|
|
1209
|
-
assert!(s.claim_for_delivery(&mid).unwrap());
|
|
1210
|
-
assert!(!s.claim_for_delivery(&mid).unwrap());
|
|
1211
|
-
assert_eq!(col_i64(&read(&s), &mid, "delivery_attempts"), 1);
|
|
1212
|
-
}
|
|
1213
|
-
|
|
1214
|
-
#[test]
|
|
1215
|
-
fn release_delivery_before_input_cannot_overwrite_changed_claims() {
|
|
1216
|
-
let s = store();
|
|
1217
|
-
let mid = s.create_message(Some("t"), "s", "r", "c", None, true, None).unwrap();
|
|
1218
|
-
assert!(s.claim_for_delivery(&mid).unwrap());
|
|
1219
|
-
assert!(!s.release_delivery_before_input(&mid, 0, "missing").unwrap());
|
|
1220
|
-
assert!(!s.release_delivery_before_input(&mid, 2, "stale").unwrap());
|
|
1221
|
-
s.mark(&mid, "target_resolved", Some("other_owner")).unwrap();
|
|
1222
|
-
assert!(!s.release_delivery_before_input(&mid, 1, "stale").unwrap());
|
|
1223
|
-
assert_eq!(col_str(&read(&s), &mid, "error").as_deref(), Some("other_owner"));
|
|
1224
|
-
assert!(s.claim_for_delivery(&mid).unwrap());
|
|
1225
|
-
assert!(!s.release_delivery_before_input(&mid, 1, "old_claim").unwrap());
|
|
1226
|
-
assert_eq!(col_i64(&read(&s), &mid, "delivery_attempts"), 2);
|
|
1227
|
-
assert_eq!(col_str(&read(&s), &mid, "error"), None);
|
|
1228
|
-
for status in ["cancelled", "delivered", "submitted_unverified"] {
|
|
1229
|
-
// Each terminal/effect state needs its own row: mark correctly
|
|
1230
|
-
// refuses to downgrade a previously delivered row.
|
|
1231
|
-
let changed = s.create_message(Some("t"), "s", "r", "c", None, true, None).unwrap();
|
|
1232
|
-
assert!(s.claim_for_delivery(&changed).unwrap());
|
|
1233
|
-
s.mark(&changed, status, None).unwrap();
|
|
1234
|
-
assert!(!s.release_delivery_before_input(&changed, 1, "stale").unwrap());
|
|
1235
|
-
assert_eq!(status_of(&read(&s), &changed), status);
|
|
1236
|
-
assert_eq!(col_i64(&read(&s), &changed, "delivery_attempts"), 1);
|
|
1237
|
-
}
|
|
1238
|
-
}
|
|
1239
|
-
|
|
1240
|
-
#[test]
|
|
1241
|
-
fn issue372_legacy_timeout_recovery_is_scoped_to_seat_and_owner() {
|
|
1242
|
-
let s = store();
|
|
1243
|
-
let mid = s.create_message(Some("t"), "s", "r", "c", None, true, Some("team-a")).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());
|
|
1247
|
-
assert_eq!(s.recover_worker_pane_available("r", Some("team-a")).unwrap(), vec![mid.clone()]);
|
|
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());
|
|
1251
|
-
}
|
|
1252
|
-
|
|
1253
|
-
#[test]
|
|
1254
|
-
fn claim_for_delivery_never_claims_stored_only_presentation() {
|
|
1255
|
-
let s = store();
|
|
1256
|
-
let mid = s
|
|
1257
|
-
.persist_message(PersistMessageInput {
|
|
1258
|
-
message_id: None,
|
|
1259
|
-
owner_team_id: Some("team-a"),
|
|
1260
|
-
task_id: None,
|
|
1261
|
-
sender: "worker",
|
|
1262
|
-
recipient: "leader",
|
|
1263
|
-
reply_to: None,
|
|
1264
|
-
requires_ack: false,
|
|
1265
|
-
status: MessageRowStatus::StoredOnly,
|
|
1266
|
-
content: "casefile evidence",
|
|
1267
|
-
presentation: r#"{"sink":"casefile","class":"stage_result"}"#,
|
|
1268
|
-
error: None,
|
|
1269
|
-
})
|
|
1270
|
-
.unwrap();
|
|
1271
|
-
assert!(!s.claim_for_delivery(&mid).unwrap());
|
|
1272
|
-
assert_eq!(status_of(&read(&s), &mid), "stored_only");
|
|
1273
|
-
assert_eq!(col_i64(&read(&s), &mid, "delivery_attempts"), 0);
|
|
1274
|
-
}
|
|
1275
|
-
|
|
1276
|
-
// ───────────────────────────── mark state machine ─────────────────────────────
|
|
1277
|
-
|
|
1278
|
-
#[test]
|
|
1279
|
-
fn mark_injected_sets_status_and_delivered_at() {
|
|
1280
|
-
let s = store();
|
|
1281
|
-
let mid = s
|
|
1282
|
-
.create_message(Some("t"), "s", "r", "c", None, true, None)
|
|
1283
|
-
.unwrap();
|
|
1284
|
-
s.mark(&mid, "injected", None).unwrap();
|
|
1285
|
-
let c = read(&s);
|
|
1286
|
-
assert_eq!(status_of(&c, &mid), "injected");
|
|
1287
|
-
assert!(
|
|
1288
|
-
col_str(&c, &mid, "delivered_at").is_some(),
|
|
1289
|
-
"delivered_at set for injected"
|
|
1290
|
-
);
|
|
1291
|
-
assert_eq!(col_str(&c, &mid, "acknowledged_at"), None);
|
|
1292
|
-
}
|
|
1293
|
-
|
|
1294
|
-
#[test]
|
|
1295
|
-
fn mark_acknowledged_is_sticky_against_delivery_statuses() {
|
|
1296
|
-
// CASE guard: once acknowledged, marks to injected/visible/... are ignored.
|
|
1297
|
-
let s = store();
|
|
1298
|
-
let mid = s
|
|
1299
|
-
.create_message(Some("t"), "s", "r", "c", None, true, None)
|
|
1300
|
-
.unwrap();
|
|
1301
|
-
s.mark(&mid, "delivered", None).unwrap();
|
|
1302
|
-
s.mark(&mid, "acknowledged", None).unwrap();
|
|
1303
|
-
assert_eq!(status_of(&read(&s), &mid), "acknowledged");
|
|
1304
|
-
assert!(col_str(&read(&s), &mid, "acknowledged_at").is_some());
|
|
1305
|
-
|
|
1306
|
-
s.mark(&mid, "injected", None).unwrap();
|
|
1307
|
-
assert_eq!(
|
|
1308
|
-
status_of(&read(&s), &mid),
|
|
1309
|
-
"acknowledged",
|
|
1310
|
-
"injected ignored after ack"
|
|
1311
|
-
);
|
|
1312
|
-
s.mark(&mid, "visible", None).unwrap();
|
|
1313
|
-
assert_eq!(
|
|
1314
|
-
status_of(&read(&s), &mid),
|
|
1315
|
-
"acknowledged",
|
|
1316
|
-
"visible ignored after ack"
|
|
1317
|
-
);
|
|
1318
|
-
}
|
|
1319
|
-
|
|
1320
|
-
#[test]
|
|
1321
|
-
fn mark_acknowledged_then_failed_stays_terminal() {
|
|
1322
|
-
let s = store();
|
|
1323
|
-
let mid = s
|
|
1324
|
-
.create_message(Some("t"), "s", "r", "c", None, true, None)
|
|
1325
|
-
.unwrap();
|
|
1326
|
-
s.mark(&mid, "delivered", None).unwrap();
|
|
1327
|
-
s.mark(&mid, "acknowledged", None).unwrap();
|
|
1328
|
-
s.mark(&mid, "failed", Some("x")).unwrap();
|
|
1329
|
-
assert_eq!(status_of(&read(&s), &mid), "acknowledged");
|
|
1330
|
-
}
|
|
1331
|
-
|
|
1332
|
-
#[test]
|
|
1333
|
-
fn mark_overwrites_for_non_acknowledged() {
|
|
1334
|
-
let s = store();
|
|
1335
|
-
let mid = s
|
|
1336
|
-
.create_message(Some("t"), "s", "r", "c", None, true, None)
|
|
1337
|
-
.unwrap();
|
|
1338
|
-
s.mark(&mid, "injected", None).unwrap();
|
|
1339
|
-
s.mark(&mid, "visible", None).unwrap();
|
|
1340
|
-
assert_eq!(status_of(&read(&s), &mid), "visible");
|
|
1341
|
-
}
|
|
1342
|
-
|
|
1343
|
-
// ───────────────────── leader_notification_log dedup ─────────────────────
|
|
1344
|
-
|
|
1345
|
-
fn params<'a>(
|
|
1346
|
-
result_id: &'a str,
|
|
1347
|
-
owner_team_id: Option<&'a str>,
|
|
1348
|
-
owner_epoch: Option<i64>,
|
|
1349
|
-
uuid: Option<&'a str>,
|
|
1350
|
-
proposed: &'a str,
|
|
1351
|
-
) -> NotificationClaimParams<'a> {
|
|
1352
|
-
NotificationClaimParams {
|
|
1353
|
-
result_id,
|
|
1354
|
-
owner_team_id,
|
|
1355
|
-
owner_epoch,
|
|
1356
|
-
leader_session_uuid: uuid,
|
|
1357
|
-
proposed_message_id: proposed,
|
|
1358
|
-
envelope_hash: "h1",
|
|
1359
|
-
pane_id: Some("%1"),
|
|
1360
|
-
}
|
|
1361
|
-
}
|
|
1362
|
-
|
|
1363
|
-
#[test]
|
|
1364
|
-
fn leader_notification_dedup_key_excludes_session_uuid() {
|
|
1365
|
-
// SAME (result_id, owner_team_id, owner_epoch) but DIFFERENT leader_session_uuid
|
|
1366
|
-
// and proposed id → second is deduped to the first winner.
|
|
1367
|
-
let s = store();
|
|
1368
|
-
let r1 = s
|
|
1369
|
-
.claim_leader_notification_delivery(params(
|
|
1370
|
-
"res_1",
|
|
1371
|
-
Some("team_A"),
|
|
1372
|
-
Some(7),
|
|
1373
|
-
Some("uuid-AAA"),
|
|
1374
|
-
"msg_notif_1",
|
|
1375
|
-
))
|
|
1376
|
-
.unwrap();
|
|
1377
|
-
assert_eq!(r1.status, "claimed_by_you");
|
|
1378
|
-
assert_eq!(r1.notified_message_id, "msg_notif_1");
|
|
1379
|
-
|
|
1380
|
-
let r2 = s
|
|
1381
|
-
.claim_leader_notification_delivery(params(
|
|
1382
|
-
"res_1",
|
|
1383
|
-
Some("team_A"),
|
|
1384
|
-
Some(7),
|
|
1385
|
-
Some("uuid-BBB"),
|
|
1386
|
-
"msg_notif_2",
|
|
1387
|
-
))
|
|
1388
|
-
.unwrap();
|
|
1389
|
-
assert_eq!(r2.status, "already_notified_by");
|
|
1390
|
-
assert_eq!(
|
|
1391
|
-
r2.notified_message_id, "msg_notif_1",
|
|
1392
|
-
"loser sees first winner's id, not its own"
|
|
1393
|
-
);
|
|
1394
|
-
|
|
1395
|
-
// Exactly ONE row — carrying the FIRST caller's uuid (uuid not in the key).
|
|
1396
|
-
assert_eq!(
|
|
1397
|
-
notif_rows(&read(&s)),
|
|
1398
|
-
vec![(
|
|
1399
|
-
"res_1".to_string(),
|
|
1400
|
-
"team_A".to_string(),
|
|
1401
|
-
7,
|
|
1402
|
-
Some("uuid-AAA".to_string()),
|
|
1403
|
-
"msg_notif_1".to_string()
|
|
1404
|
-
)]
|
|
1405
|
-
);
|
|
1406
|
-
}
|
|
1407
|
-
|
|
1408
|
-
#[test]
|
|
1409
|
-
fn leader_notification_different_epoch_is_a_new_claim() {
|
|
1410
|
-
let s = store();
|
|
1411
|
-
s.claim_leader_notification_delivery(params(
|
|
1412
|
-
"res_1",
|
|
1413
|
-
Some("team_A"),
|
|
1414
|
-
Some(7),
|
|
1415
|
-
Some("uuid-AAA"),
|
|
1416
|
-
"msg_notif_1",
|
|
1417
|
-
))
|
|
1418
|
-
.unwrap();
|
|
1419
|
-
let r3 = s
|
|
1420
|
-
.claim_leader_notification_delivery(params(
|
|
1421
|
-
"res_1",
|
|
1422
|
-
Some("team_A"),
|
|
1423
|
-
Some(8),
|
|
1424
|
-
Some("uuid-AAA"),
|
|
1425
|
-
"msg_notif_3",
|
|
1426
|
-
))
|
|
1427
|
-
.unwrap();
|
|
1428
|
-
assert_eq!(
|
|
1429
|
-
r3.status, "claimed_by_you",
|
|
1430
|
-
"different owner_epoch → different PK → new claim"
|
|
1431
|
-
);
|
|
1432
|
-
|
|
1433
|
-
let rows = notif_rows(&read(&s));
|
|
1434
|
-
assert_eq!(rows.len(), 2);
|
|
1435
|
-
assert_eq!(rows[0].2, 7);
|
|
1436
|
-
assert_eq!(rows[1].2, 8);
|
|
1437
|
-
assert_eq!(rows[1].4, "msg_notif_3");
|
|
1438
|
-
}
|
|
1439
|
-
|
|
1440
|
-
#[test]
|
|
1441
|
-
fn leader_notification_none_epoch_derives_from_uuid() {
|
|
1442
|
-
// owner_epoch=None → epoch derived from uuid. Same uuid dedups; different uuid
|
|
1443
|
-
// yields a different derived epoch → a new claim.
|
|
1444
|
-
let s = store();
|
|
1445
|
-
let a1 = s
|
|
1446
|
-
.claim_leader_notification_delivery(params(
|
|
1447
|
-
"res_2",
|
|
1448
|
-
Some("team_B"),
|
|
1449
|
-
None,
|
|
1450
|
-
Some("uuid-AAA"),
|
|
1451
|
-
"m1",
|
|
1452
|
-
))
|
|
1453
|
-
.unwrap();
|
|
1454
|
-
assert_eq!(a1.status, "claimed_by_you");
|
|
1455
|
-
|
|
1456
|
-
let a2 = s
|
|
1457
|
-
.claim_leader_notification_delivery(params(
|
|
1458
|
-
"res_2",
|
|
1459
|
-
Some("team_B"),
|
|
1460
|
-
None,
|
|
1461
|
-
Some("uuid-AAA"),
|
|
1462
|
-
"m2",
|
|
1463
|
-
))
|
|
1464
|
-
.unwrap();
|
|
1465
|
-
assert_eq!(a2.status, "already_notified_by");
|
|
1466
|
-
assert_eq!(a2.notified_message_id, "m1");
|
|
1467
|
-
|
|
1468
|
-
let a3 = s
|
|
1469
|
-
.claim_leader_notification_delivery(params(
|
|
1470
|
-
"res_2",
|
|
1471
|
-
Some("team_B"),
|
|
1472
|
-
None,
|
|
1473
|
-
Some("uuid-BBB"),
|
|
1474
|
-
"m3",
|
|
1475
|
-
))
|
|
1476
|
-
.unwrap();
|
|
1477
|
-
assert_eq!(
|
|
1478
|
-
a3.status, "claimed_by_you",
|
|
1479
|
-
"different uuid → different derived epoch → new claim"
|
|
1480
|
-
);
|
|
1481
|
-
|
|
1482
|
-
// Stored epochs equal the crc32 derivation of each uuid.
|
|
1483
|
-
let rows = notif_rows(&read(&s));
|
|
1484
|
-
assert_eq!(rows.len(), 2);
|
|
1485
|
-
assert_eq!(rows[0].2, 926068568); // crc32('uuid-AAA') & 0x7FFFFFFF
|
|
1486
|
-
assert_eq!(rows[1].2, 122688376); // crc32('uuid-BBB') & 0x7FFFFFFF
|
|
1487
|
-
}
|
|
1488
|
-
|
|
1489
|
-
#[test]
|
|
1490
|
-
fn legacy_epoch_from_uuid_crc32_golden() {
|
|
1491
|
-
assert_eq!(legacy_epoch_from_uuid(None), 0);
|
|
1492
|
-
assert_eq!(legacy_epoch_from_uuid(Some("")), 0);
|
|
1493
|
-
assert_eq!(legacy_epoch_from_uuid(Some("uuid-AAA")), 926068568);
|
|
1494
|
-
assert_eq!(legacy_epoch_from_uuid(Some("uuid-BBB")), 122688376);
|
|
1495
|
-
}
|
|
1496
|
-
|
|
1497
|
-
// ════════════════════════ FIX-LOOP (wave-1) RED test ════════════════════════
|
|
1498
|
-
// B1: mark() error column = coalesce(?, error) — a NEW error overwrites, but a
|
|
1499
|
-
// mark WITHOUT an error must PRESERVE the existing error (current impl clobbers
|
|
1500
|
-
// it to NULL). Golden /tmp/probe_b1.py vs team-agent-public v0.2.11.
|
|
1501
|
-
|
|
1502
|
-
#[test]
|
|
1503
|
-
fn fix_b1_mark_preserves_existing_error_when_none_given() {
|
|
1504
|
-
let s = store();
|
|
1505
|
-
let mid = s
|
|
1506
|
-
.create_message(Some("t"), "a", "b", "c", None, true, None)
|
|
1507
|
-
.unwrap();
|
|
1508
|
-
|
|
1509
|
-
s.mark(&mid, "failed", Some("boom")).unwrap();
|
|
1510
|
-
assert_eq!(col_str(&read(&s), &mid, "error").as_deref(), Some("boom"));
|
|
1511
|
-
|
|
1512
|
-
// Non-error mark to a delivery status: status/delivered_at advance, but error
|
|
1513
|
-
// must remain 'boom' (coalesce(NULL, error)), NOT be clobbered to NULL.
|
|
1514
|
-
s.mark(&mid, "injected", None).unwrap();
|
|
1515
|
-
let c = read(&s);
|
|
1516
|
-
assert_eq!(status_of(&c, &mid), "injected");
|
|
1517
|
-
assert_eq!(
|
|
1518
|
-
col_str(&c, &mid, "error").as_deref(),
|
|
1519
|
-
Some("boom"),
|
|
1520
|
-
"existing error must survive a no-error mark"
|
|
1521
|
-
);
|
|
1522
|
-
|
|
1523
|
-
// A NEW error overwrites.
|
|
1524
|
-
s.mark(&mid, "failed", Some("second")).unwrap();
|
|
1525
|
-
assert_eq!(col_str(&read(&s), &mid, "error").as_deref(), Some("second"));
|
|
1526
|
-
}
|
|
1527
|
-
}
|