forgexa-cli 1.96.3__tar.gz → 1.96.4__tar.gz

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.
Files changed (35) hide show
  1. {forgexa_cli-1.96.3 → forgexa_cli-1.96.4}/PKG-INFO +1 -1
  2. {forgexa_cli-1.96.3 → forgexa_cli-1.96.4}/forgexa_cli/__init__.py +1 -1
  3. {forgexa_cli-1.96.3 → forgexa_cli-1.96.4}/forgexa_cli/agent_core.py +37 -3
  4. {forgexa_cli-1.96.3 → forgexa_cli-1.96.4}/forgexa_cli/component_runtime.py +123 -4
  5. {forgexa_cli-1.96.3 → forgexa_cli-1.96.4}/forgexa_cli/daemon.py +18 -2
  6. {forgexa_cli-1.96.3 → forgexa_cli-1.96.4}/forgexa_cli/zcode_protocol.py +27 -0
  7. {forgexa_cli-1.96.3 → forgexa_cli-1.96.4}/forgexa_cli.egg-info/PKG-INFO +1 -1
  8. {forgexa_cli-1.96.3 → forgexa_cli-1.96.4}/pyproject.toml +1 -1
  9. {forgexa_cli-1.96.3 → forgexa_cli-1.96.4}/README.md +0 -0
  10. {forgexa_cli-1.96.3 → forgexa_cli-1.96.4}/forgexa_cli/_build_config.py +0 -0
  11. {forgexa_cli-1.96.3 → forgexa_cli-1.96.4}/forgexa_cli/_local_bind.py +0 -0
  12. {forgexa_cli-1.96.3 → forgexa_cli-1.96.4}/forgexa_cli/autoupgrade.py +0 -0
  13. {forgexa_cli-1.96.3 → forgexa_cli-1.96.4}/forgexa_cli/aws_evidence.py +0 -0
  14. {forgexa_cli-1.96.3 → forgexa_cli-1.96.4}/forgexa_cli/aws_logs_evidence.py +0 -0
  15. {forgexa_cli-1.96.3 → forgexa_cli-1.96.4}/forgexa_cli/main.py +0 -0
  16. {forgexa_cli-1.96.3 → forgexa_cli-1.96.4}/forgexa_cli/observability_contract.py +0 -0
  17. {forgexa_cli-1.96.3 → forgexa_cli-1.96.4}/forgexa_cli/observability_evidence.py +0 -0
  18. {forgexa_cli-1.96.3 → forgexa_cli-1.96.4}/forgexa_cli/py.typed +0 -0
  19. {forgexa_cli-1.96.3 → forgexa_cli-1.96.4}/forgexa_cli/runtime_evidence.py +0 -0
  20. {forgexa_cli-1.96.3 → forgexa_cli-1.96.4}/forgexa_cli.egg-info/SOURCES.txt +0 -0
  21. {forgexa_cli-1.96.3 → forgexa_cli-1.96.4}/forgexa_cli.egg-info/dependency_links.txt +0 -0
  22. {forgexa_cli-1.96.3 → forgexa_cli-1.96.4}/forgexa_cli.egg-info/entry_points.txt +0 -0
  23. {forgexa_cli-1.96.3 → forgexa_cli-1.96.4}/forgexa_cli.egg-info/requires.txt +0 -0
  24. {forgexa_cli-1.96.3 → forgexa_cli-1.96.4}/forgexa_cli.egg-info/top_level.txt +0 -0
  25. {forgexa_cli-1.96.3 → forgexa_cli-1.96.4}/setup.cfg +0 -0
  26. {forgexa_cli-1.96.3 → forgexa_cli-1.96.4}/tests/test_auth_and_runtime_commands.py +0 -0
  27. {forgexa_cli-1.96.3 → forgexa_cli-1.96.4}/tests/test_autoupgrade.py +0 -0
  28. {forgexa_cli-1.96.3 → forgexa_cli-1.96.4}/tests/test_check_command.py +0 -0
  29. {forgexa_cli-1.96.3 → forgexa_cli-1.96.4}/tests/test_expiry_warnings_and_revoke.py +0 -0
  30. {forgexa_cli-1.96.3 → forgexa_cli-1.96.4}/tests/test_local_bind_commands.py +0 -0
  31. {forgexa_cli-1.96.3 → forgexa_cli-1.96.4}/tests/test_publish_script.py +0 -0
  32. {forgexa_cli-1.96.3 → forgexa_cli-1.96.4}/tests/test_runtime_credentials.py +0 -0
  33. {forgexa_cli-1.96.3 → forgexa_cli-1.96.4}/tests/test_session_credentials.py +0 -0
  34. {forgexa_cli-1.96.3 → forgexa_cli-1.96.4}/tests/test_silent_install.py +0 -0
  35. {forgexa_cli-1.96.3 → forgexa_cli-1.96.4}/tests/test_upgrade_observability.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: forgexa-cli
3
- Version: 1.96.3
3
+ Version: 1.96.4
4
4
  Summary: Forgexa CLI — command-line client and AI agent runtime for the Forgexa platform
5
5
  Author-email: Jason Sun <dev.winds@gmail.com>
6
6
  License-Expression: MIT
@@ -1,2 +1,2 @@
1
1
  """forgexa-cli — Forgexa command-line client."""
2
- __version__ = "1.96.3"
2
+ __version__ = "1.96.4"
@@ -4016,9 +4016,14 @@ async def run_minimax(
4016
4016
  max_steps: int = 60, model: str | None = None, session_id: str | None = None,
4017
4017
  on_event: Any = None, on_started: Any = None, on_chunk: Any = None,
4018
4018
  cancel_requested: Any = None,
4019
+ component_lease: Any = None,
4019
4020
  ) -> dict:
4021
+ lease = (
4022
+ component_lease if component_lease is not None else component_runtime.current_execution()
4023
+ )
4020
4024
  state = MiniMaxRunState(expected_session_id=session_id)
4021
4025
  process = None
4026
+ observer = None
4022
4027
  lock = None
4023
4028
  root = None
4024
4029
  temporary = None
@@ -4072,19 +4077,28 @@ async def run_minimax(
4072
4077
  config=root / "config/runtime.json", timeout=remaining,
4073
4078
  max_steps=max_steps, model=model, session_id=session_id)
4074
4079
  command.insert(1, admission["build"]["entry"])
4080
+ command, environment = await asyncio.to_thread(
4081
+ component_runtime.harness_command, lease, "minimax", binary, command,
4082
+ minimax_base_env(root, temporary_root),
4083
+ )
4075
4084
  command = _minimax_sandbox(command, admission, cwd, temporary_root)
4076
4085
  if cancel_requested is not None and cancel_requested():
4077
4086
  return state.finish(-1, cancelled=True)
4078
4087
  _minimax_write_record(active, {"fingerprint": binding_identity, "state": "spawning"})
4088
+ if lease is not None:
4089
+ await asyncio.to_thread(lease.begin_spawn)
4079
4090
  process = await asyncio.create_subprocess_exec(
4080
- *command, cwd=str(cwd), env=minimax_base_env(root, temporary_root),
4091
+ *command, cwd=str(cwd), env=environment,
4081
4092
  stdin=asyncio.subprocess.PIPE, stdout=asyncio.subprocess.PIPE,
4082
4093
  stderr=asyncio.subprocess.PIPE, limit=MINIMAX_MAX_OUTPUT_BYTES,
4083
4094
  **_agent_process_group_kwargs(),
4084
4095
  )
4085
- _minimax_write_record(active, {"pid": process.pid, "fingerprint": binding_identity})
4086
4096
  if on_started is not None:
4087
4097
  on_started(process)
4098
+ if lease is not None:
4099
+ await asyncio.to_thread(lease.record_process, process.pid)
4100
+ observer = asyncio.create_task(component_runtime.observe_owned_process(lease, process))
4101
+ _minimax_write_record(active, {"pid": process.pid, "fingerprint": binding_identity})
4088
4102
 
4089
4103
  async def read_stderr() -> None:
4090
4104
  nonlocal stderr_bytes
@@ -4154,6 +4168,9 @@ async def run_minimax(
4154
4168
  code = "minimax_profile_busy" if "busy" in str(error) else "minimax_startup_failed"
4155
4169
  state.fail(str(error) if isinstance(error, (ValueError, RuntimeError)) else "MiniMax startup or stream I/O failed", code)
4156
4170
  finally:
4171
+ if observer is not None:
4172
+ observer.cancel()
4173
+ await asyncio.gather(observer, return_exceptions=True)
4157
4174
  cleaned = True
4158
4175
  if process is not None:
4159
4176
  _kill_proc(process)
@@ -4872,9 +4889,14 @@ async def run_deepseek_harness(
4872
4889
  on_started: Any = None,
4873
4890
  on_chunk: Any = None,
4874
4891
  cancel_requested: Any = None,
4892
+ component_lease: Any = None,
4875
4893
  ) -> dict:
4876
4894
  """Execute and validate a supervised one-shot process with bounded output."""
4877
4895
  process = None
4896
+ observer = None
4897
+ lease = (
4898
+ component_lease if component_lease is not None else component_runtime.current_execution()
4899
+ )
4878
4900
  state = DeepSeekHarnessRunState(expected_cwd=str(workspace_path))
4879
4901
  raw_lines = []
4880
4902
  raw_bytes = 0
@@ -4884,14 +4906,23 @@ async def run_deepseek_harness(
4884
4906
  try:
4885
4907
  command, env = await asyncio.to_thread(runtime.__enter__)
4886
4908
  entered = True
4909
+ command, env = await asyncio.to_thread(
4910
+ component_runtime.harness_command, lease, "deepseek", binary, command, env,
4911
+ )
4912
+ command = command if lease is not None else _prepare_agent_command(command)
4913
+ if lease is not None:
4914
+ await asyncio.to_thread(lease.begin_spawn)
4887
4915
  process = await asyncio.create_subprocess_exec(
4888
- *_prepare_agent_command(command), cwd=str(workspace_path), env=env,
4916
+ *command, cwd=str(workspace_path), env=env,
4889
4917
  stdin=asyncio.subprocess.PIPE, stdout=asyncio.subprocess.PIPE,
4890
4918
  stderr=asyncio.subprocess.PIPE, limit=DEEPSEEK_HARNESS_MAX_OUTPUT_BYTES,
4891
4919
  **_agent_process_group_kwargs(),
4892
4920
  )
4893
4921
  if on_started is not None:
4894
4922
  on_started(process)
4923
+ if lease is not None:
4924
+ await asyncio.to_thread(lease.record_process, process.pid)
4925
+ observer = asyncio.create_task(component_runtime.observe_owned_process(lease, process))
4895
4926
  if cancel_requested is not None and cancel_requested():
4896
4927
  _kill_proc(process)
4897
4928
 
@@ -4977,6 +5008,9 @@ async def run_deepseek_harness(
4977
5008
  code = "deepseek_harness_profile_busy" if "profile is busy" in message else "deepseek_harness_startup_failed"
4978
5009
  state.fail(message, code)
4979
5010
  finally:
5011
+ if observer is not None:
5012
+ observer.cancel()
5013
+ await asyncio.gather(observer, return_exceptions=True)
4980
5014
  if process is not None and process.returncode is None:
4981
5015
  _kill_proc(process)
4982
5016
  await process.wait()
@@ -1,5 +1,6 @@
1
1
  from __future__ import annotations
2
2
 
3
+ import asyncio
3
4
  import hashlib
4
5
  import json
5
6
  import math
@@ -12,6 +13,7 @@ import sys
12
13
  from contextlib import contextmanager
13
14
  from contextvars import ContextVar
14
15
  from pathlib import Path
16
+ from threading import RLock
15
17
  from typing import Any
16
18
 
17
19
  RECORD_LIMIT = 8 * 1024 * 1024
@@ -130,6 +132,9 @@ class ManagedComponentLease:
130
132
  self.record_path = root / "leases" / f"{self.lease_id}.json"
131
133
  self.process_directory = root / "leases" / f"{self.lease_id}.processes"
132
134
  self.process_sequence = 0
135
+ self.registered_roots: dict[int, str] = {}
136
+ self.observed_descendants: set[tuple[int, str]] = set()
137
+ self.process_event_lock = RLock()
133
138
  digest = _digest(receipt["installation_id"].removeprefix("install-"))
134
139
  self.directory = root / "versions" / digest
135
140
  entry = receipt["entry_point"]
@@ -146,7 +151,21 @@ class ManagedComponentLease:
146
151
  if entry["kind"] != "native":
147
152
  self.argv_prefix.append(str(self.directory / _relative(entry["script"])))
148
153
 
149
- def _write_process_event(self, stage: str, process_id: int | None = None) -> None:
154
+ def _write_process_event(
155
+ self,
156
+ stage: str,
157
+ process_id: int | None = None,
158
+ expected_identity: str | None = None,
159
+ ) -> dict[str, Any]:
160
+ with self.process_event_lock:
161
+ return self._write_process_event_locked(stage, process_id, expected_identity)
162
+
163
+ def _write_process_event_locked(
164
+ self,
165
+ stage: str,
166
+ process_id: int | None,
167
+ expected_identity: str | None,
168
+ ) -> dict[str, Any]:
150
169
  if self.descriptor < 0 or self.process_sequence >= 256:
151
170
  raise ComponentRuntimeError("component_usage_unavailable")
152
171
  _private_directory(self.root)
@@ -187,6 +206,8 @@ class ManagedComponentLease:
187
206
  process_identity = _process_start_identity(process_id)
188
207
  except ComponentRuntimeError:
189
208
  pass
209
+ if expected_identity is not None and process_identity != expected_identity:
210
+ raise ComponentRuntimeError("component_process_identity_unverified")
190
211
  sequence = self.process_sequence + 1
191
212
  event = {
192
213
  "schema_version": 1,
@@ -218,6 +239,7 @@ class ManagedComponentLease:
218
239
  finally:
219
240
  os.close(directory)
220
241
  self.process_sequence = sequence
242
+ return event
221
243
 
222
244
  def begin_spawn(self) -> None:
223
245
  self.process_started = True
@@ -229,10 +251,53 @@ class ManagedComponentLease:
229
251
  def record_process(self, process_id: int) -> None:
230
252
  self.process_started = True
231
253
  try:
232
- self._write_process_event("spawn_started", process_id)
254
+ event = self._write_process_event("spawn_started", process_id)
255
+ if event["process_start_identity"] is not None:
256
+ self.registered_roots[process_id] = event["process_start_identity"]
233
257
  except OSError as error:
234
258
  raise ComponentRuntimeError("component_usage_unavailable") from error
235
259
 
260
+ def observe_descendants(self, process_id: int) -> int:
261
+ with self.process_event_lock:
262
+ return self._observe_descendants_locked(process_id)
263
+
264
+ def _observe_descendants_locked(self, process_id: int) -> int:
265
+ identity = self.registered_roots.get(process_id)
266
+ if identity is None or _identity_alive(process_id, identity) is not True:
267
+ raise ComponentRuntimeError("component_process_tree_unverified")
268
+ try:
269
+ import psutil
270
+
271
+ process = psutil.Process(process_id)
272
+ children = process.children(recursive=True)
273
+ except (ImportError, OSError) as error:
274
+ raise ComponentRuntimeError("component_process_tree_unverified") from error
275
+ except psutil.Error as error:
276
+ raise ComponentRuntimeError("component_process_tree_unverified") from error
277
+ if len(children) > 128 or _identity_alive(process_id, identity) is not True:
278
+ raise ComponentRuntimeError("component_process_tree_unverified")
279
+ recorded = 0
280
+ for child in children:
281
+ try:
282
+ created = child.create_time()
283
+ except psutil.NoSuchProcess:
284
+ continue
285
+ except (psutil.Error, OSError) as error:
286
+ raise ComponentRuntimeError("component_process_tree_unverified") from error
287
+ if not math.isfinite(created) or created <= 0:
288
+ raise ComponentRuntimeError("component_process_tree_unverified")
289
+ start_identity = f"process-{child.pid}-{struct.pack('!d', created).hex()}"
290
+ key = (child.pid, start_identity)
291
+ if key in self.observed_descendants:
292
+ continue
293
+ try:
294
+ self._write_process_event("descendant_observed", child.pid, start_identity)
295
+ except OSError as error:
296
+ raise ComponentRuntimeError("component_usage_unavailable") from error
297
+ self.observed_descendants.add(key)
298
+ recorded += 1
299
+ return recorded
300
+
236
301
  def wrap_command(self, command: list[str]) -> list[str]:
237
302
  if not command or command[0] != self.argv_prefix[-1]:
238
303
  raise ComponentRuntimeError("component_instance_changed")
@@ -539,6 +604,7 @@ def inspect_usage(lease_id: str, root: Path | None = None) -> dict[str, Any]:
539
604
  "lease_id": lease_id,
540
605
  "installation_id": record["installation_id"],
541
606
  "state": "legacy_unknown",
607
+ "descendant_coverage": "observed_only",
542
608
  "owner_alive": None,
543
609
  "processes": [],
544
610
  }
@@ -582,7 +648,7 @@ def inspect_usage(lease_id: str, root: Path | None = None) -> dict[str, Any]:
582
648
  or event["owner_nonce"] != record["owner_nonce"]
583
649
  or type(event["owner_process_id"]) is not int
584
650
  or event["owner_process_id"] != record["process_id"]
585
- or event["stage"] not in {"spawn_pending", "spawn_started"}
651
+ or event["stage"] not in {"spawn_pending", "spawn_started", "descendant_observed"}
586
652
  )
587
653
  ):
588
654
  raise ComponentRuntimeError("component_process_journal_invalid")
@@ -595,7 +661,13 @@ def inspect_usage(lease_id: str, root: Path | None = None) -> dict[str, Any]:
595
661
  if event["process_id"] is not None or event["process_start_identity"] is not None:
596
662
  raise ComponentRuntimeError("component_process_journal_invalid")
597
663
  else:
598
- if not events or events[-1]["stage"] != "spawn_pending":
664
+ if event["stage"] == "spawn_started" and (
665
+ not events or events[-1]["stage"] != "spawn_pending"
666
+ ):
667
+ raise ComponentRuntimeError("component_process_journal_invalid")
668
+ if event["stage"] == "descendant_observed" and not any(
669
+ value["stage"] == "spawn_started" for value in events
670
+ ):
599
671
  raise ComponentRuntimeError("component_process_journal_invalid")
600
672
  if type(event["process_id"]) is not int or event["process_id"] <= 0:
601
673
  raise ComponentRuntimeError("component_process_journal_invalid")
@@ -607,6 +679,7 @@ def inspect_usage(lease_id: str, root: Path | None = None) -> dict[str, Any]:
607
679
  "process_id": event["process_id"],
608
680
  "start_identity": identity,
609
681
  "alive": _identity_alive(event["process_id"], identity),
682
+ "role": "descendant" if event["stage"] == "descendant_observed" else "root",
610
683
  }
611
684
  )
612
685
  events.append(event)
@@ -690,6 +763,18 @@ def _acquire_component(
690
763
  if not selection["enabled"]:
691
764
  raise ComponentRuntimeError("component_disabled")
692
765
  installation_id = _identifier(selection["installation_id"])
766
+ maintenance = _record(
767
+ root / "maintenance" / f"{installation_id}.json",
768
+ {"schema_version", "target_id", "installation_id", "operation_id"},
769
+ )
770
+ if maintenance is not None:
771
+ _identifier(maintenance["operation_id"])
772
+ if (
773
+ maintenance["target_id"] != target["target_id"]
774
+ or maintenance["installation_id"] != installation_id
775
+ ):
776
+ raise ComponentRuntimeError("component_record_invalid")
777
+ raise ComponentRuntimeError("component_maintenance_pending")
693
778
  receipt = _record(
694
779
  root / "receipts" / f"{installation_id}.json",
695
780
  {
@@ -841,6 +926,40 @@ def current_execution() -> ManagedComponentLease | None:
841
926
  return _EXECUTION_LEASE.get()
842
927
 
843
928
 
929
+ async def observe_owned_process(lease: ManagedComponentLease, process: Any) -> None:
930
+ stop = asyncio.Event()
931
+ while process.returncode is None:
932
+ try:
933
+ await asyncio.wait_for(
934
+ asyncio.to_thread(lease.observe_descendants, process.pid), timeout=1
935
+ )
936
+ except (asyncio.TimeoutError, OSError, ComponentRuntimeError):
937
+ pass
938
+ try:
939
+ await asyncio.wait_for(stop.wait(), timeout=5)
940
+ except asyncio.TimeoutError:
941
+ continue
942
+
943
+
944
+ def harness_command(
945
+ lease: ManagedComponentLease | None,
946
+ component_id: str,
947
+ binary: str,
948
+ command: list[str],
949
+ environment: dict[str, str],
950
+ ) -> tuple[list[str], dict[str, str]]:
951
+ if lease is None:
952
+ return command, environment
953
+ if lease.receipt["release"]["component_id"] != component_id or binary != lease.argv_prefix[-1]:
954
+ raise ComponentRuntimeError("component_instance_changed")
955
+ lease.verify()
956
+ if command and command[0] == binary:
957
+ command = lease.wrap_command(command)
958
+ elif command[: len(lease.argv_prefix)] != lease.argv_prefix:
959
+ raise ComponentRuntimeError("component_harness_entry_unverified")
960
+ return command, {**environment, "DISABLE_UPDATES": "1", "DISABLE_AUTOUPDATER": "1"}
961
+
962
+
844
963
  def execution_command(command: list[str], environment: dict[str, str] | None):
845
964
  lease = current_execution()
846
965
  if lease is None or not command or command[0] != lease.argv_prefix[-1]:
@@ -1412,7 +1412,7 @@ except (ImportError, ModuleNotFoundError):
1412
1412
  # DAEMON_VERSION is the protocol/logic version of the daemon code.
1413
1413
  # Kept in sync with pyproject.toml version via bump-version.sh.
1414
1414
  # CLIENT_TYPE identifies which packaging/distribution this daemon runs in.
1415
- DAEMON_VERSION = "1.96.3"
1415
+ DAEMON_VERSION = "1.96.4"
1416
1416
 
1417
1417
 
1418
1418
  def _detect_client_type() -> str:
@@ -7366,6 +7366,11 @@ class ProcessManager:
7366
7366
  _start_time = time.monotonic()
7367
7367
  # Mutable state shared between nested coroutines (list avoids nonlocal)
7368
7368
  _last_activity_at: list[float] = [time.monotonic()]
7369
+ _last_descendant_observation = 0.0
7370
+ component_lease = component_runtime.current_execution()
7371
+ observes_component = (
7372
+ component_lease is not None and proc.pid in component_lease.registered_roots
7373
+ )
7369
7374
 
7370
7375
  # Write prompt and close stdin so the agent knows input is done.
7371
7376
  if proc.stdin:
@@ -7410,6 +7415,7 @@ class ProcessManager:
7410
7415
  pass
7411
7416
 
7412
7417
  async def _read_stdout():
7418
+ nonlocal _last_descendant_observation
7413
7419
  if not proc.stdout:
7414
7420
  return
7415
7421
  pending_line = ""
@@ -7465,12 +7471,22 @@ class ProcessManager:
7465
7471
  _kill_proc(proc)
7466
7472
  raise _IdleTimeoutError(idle_elapsed)
7467
7473
 
7474
+ if observes_component and now - _last_descendant_observation >= 5:
7475
+ _last_descendant_observation = now
7476
+ try:
7477
+ await asyncio.wait_for(
7478
+ asyncio.to_thread(component_lease.observe_descendants, proc.pid),
7479
+ timeout=min(1.0, max(0.001, timeout - elapsed_abs)),
7480
+ )
7481
+ except (asyncio.TimeoutError, OSError, component_runtime.ComponentRuntimeError):
7482
+ logger.debug("Component descendants remain unverified for task %s", task_id)
7483
+
7468
7484
  # Check interval capped at 30s so the loop stays responsive
7469
7485
  # even when both timeouts are far away.
7470
7486
  check_interval = min(
7471
7487
  idle_timeout - idle_elapsed + 0.5, # until idle fires
7472
7488
  timeout - elapsed_abs + 0.5, # until absolute fires
7473
- 30.0,
7489
+ 5.0 if observes_component else 30.0,
7474
7490
  )
7475
7491
 
7476
7492
  # ── Read available bytes with a bounded wait ───────────────────
@@ -161,6 +161,8 @@ class ZCodeProtocolSession:
161
161
  self._process: asyncio.subprocess.Process | None = None
162
162
  self._reader_task: asyncio.Task[None] | None = None
163
163
  self._stderr_task: asyncio.Task[None] | None = None
164
+ self._observer_task: asyncio.Task[None] | None = None
165
+ self._observer_stop = asyncio.Event()
164
166
  self._pending: dict[str, asyncio.Future[Any]] = {}
165
167
  self._write_lock = asyncio.Lock()
166
168
  self._active_turn: asyncio.Future[_TurnTerminal] | None = None
@@ -210,6 +212,27 @@ class ZCodeProtocolSession:
210
212
  await asyncio.to_thread(self.component_lease.record_process, self._process.pid)
211
213
  self._reader_task = asyncio.create_task(self._read_loop())
212
214
  self._stderr_task = asyncio.create_task(self._read_stderr())
215
+ if self.component_lease is not None:
216
+ self._observer_task = asyncio.create_task(self._observe_process_tree())
217
+
218
+ async def _observe_process_tree(self) -> None:
219
+ while not self._observer_stop.is_set():
220
+ process = self._process
221
+ if process is None or process.returncode is not None or self.component_lease is None:
222
+ return
223
+ try:
224
+ await asyncio.wait_for(
225
+ asyncio.to_thread(self.component_lease.observe_descendants, process.pid),
226
+ timeout=1,
227
+ )
228
+ except (
229
+ asyncio.TimeoutError, OSError, agent_core.component_runtime.ComponentRuntimeError,
230
+ ):
231
+ logger.debug("ZCode component descendants remain unverified")
232
+ try:
233
+ await asyncio.wait_for(self._observer_stop.wait(), timeout=5)
234
+ except asyncio.TimeoutError:
235
+ continue
213
236
 
214
237
  async def create_session(
215
238
  self,
@@ -368,6 +391,10 @@ class ZCodeProtocolSession:
368
391
  if self._closed:
369
392
  return
370
393
  self._closed = True
394
+ self._observer_stop.set()
395
+ if self._observer_task is not None:
396
+ self._observer_task.cancel()
397
+ await asyncio.gather(self._observer_task, return_exceptions=True)
371
398
  if self._active_turn is not None and not self._active_turn.done():
372
399
  self._active_turn.set_exception(ZCodeProtocolError("ZCode Protocol session closed"))
373
400
  self._fail_pending(ZCodeProtocolError("ZCode Protocol session closed"))
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: forgexa-cli
3
- Version: 1.96.3
3
+ Version: 1.96.4
4
4
  Summary: Forgexa CLI — command-line client and AI agent runtime for the Forgexa platform
5
5
  Author-email: Jason Sun <dev.winds@gmail.com>
6
6
  License-Expression: MIT
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "forgexa-cli"
3
- version = "1.96.3"
3
+ version = "1.96.4"
4
4
  description = "Forgexa CLI — command-line client and AI agent runtime for the Forgexa platform"
5
5
  requires-python = ">=3.9"
6
6
  license = "MIT"
File without changes
File without changes