@senpi/runtime 3.0.227 → 3.0.228

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.
@@ -15,6 +15,7 @@ from typing import TypedDict
15
15
  # ru_maxrss is in kilobytes on Linux and in bytes on macOS.
16
16
  _MAXRSS_BYTES = 1 if sys.platform == "darwin" else 1024
17
17
  _MIB = 1024 * 1024
18
+ _PROC_STATUS = "/proc/self/status"
18
19
 
19
20
 
20
21
  class TickMetrics(TypedDict):
@@ -32,6 +33,23 @@ def cpu_seconds() -> float:
32
33
  return total
33
34
 
34
35
 
36
+ def _own_peak_bytes() -> int:
37
+ """This process's peak RSS in bytes.
38
+
39
+ Linux keeps ru_maxrss across exec, so a process spawned from a large parent
40
+ reports the parent's memory as its own peak. VmHWM belongs to the address space
41
+ and starts over at exec. Where /proc is missing, fall back to ru_maxrss.
42
+ """
43
+ try:
44
+ with open(_PROC_STATUS) as fh:
45
+ for line in fh:
46
+ if line.startswith("VmHWM:"):
47
+ return int(line.split()[1]) * 1024
48
+ except (OSError, ValueError, IndexError):
49
+ pass
50
+ return resource.getrusage(resource.RUSAGE_SELF).ru_maxrss * _MAXRSS_BYTES
51
+
52
+
35
53
  def peak_rss_mb() -> float:
36
54
  """This process's peak RSS plus the largest finished child's, in MiB.
37
55
 
@@ -39,8 +57,8 @@ def peak_rss_mb() -> float:
39
57
  happened. Adding it to the parent's peak can overstate a tree whose peaks did
40
58
  not overlap. Overstating is the safe side for sizing a scanner.
41
59
  """
42
- peak = sum(resource.getrusage(who).ru_maxrss for who in (resource.RUSAGE_SELF, resource.RUSAGE_CHILDREN))
43
- return round(peak * _MAXRSS_BYTES / _MIB, 1)
60
+ children = resource.getrusage(resource.RUSAGE_CHILDREN).ru_maxrss * _MAXRSS_BYTES
61
+ return round((_own_peak_bytes() + children) / _MIB, 1)
44
62
 
45
63
 
46
64
  def measure_tick(cpu_at_start: float, mcp_calls: int) -> TickMetrics:
@@ -2,7 +2,7 @@
2
2
  "id": "runtime",
3
3
  "name": "Senpi Runtime",
4
4
  "description": "Senpi runtime plugin for OpenClaw. Orchestrates scanners, LLM-based trade decisions, and a DSL trailing stop-loss exit engine.",
5
- "version": "3.0.227",
5
+ "version": "3.0.228",
6
6
  "commandAliases": [
7
7
  {
8
8
  "name": "senpi"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@senpi/runtime",
3
- "version": "3.0.227",
3
+ "version": "3.0.228",
4
4
  "description": "Senpi runtime plugin for OpenClaw",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",