@descryy/runtime-orchestrator 0.3.0 → 0.4.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.
Files changed (48) hide show
  1. package/LICENSE +6 -0
  2. package/dist/attach-to-running-jvm-process.d.ts +45 -98
  3. package/dist/attach-to-running-jvm-process.d.ts.map +1 -1
  4. package/dist/attach-to-running-jvm-process.js +206 -136
  5. package/dist/attach-to-running-jvm-process.js.map +1 -1
  6. package/dist/attach-to-running-node-process.d.ts +45 -103
  7. package/dist/attach-to-running-node-process.d.ts.map +1 -1
  8. package/dist/attach-to-running-node-process.js +90 -115
  9. package/dist/attach-to-running-node-process.js.map +1 -1
  10. package/dist/attach-to-running-process.d.ts +51 -71
  11. package/dist/attach-to-running-process.d.ts.map +1 -1
  12. package/dist/attach-to-running-process.js +39 -55
  13. package/dist/attach-to-running-process.js.map +1 -1
  14. package/dist/cdp-client.d.ts +8 -18
  15. package/dist/cdp-client.d.ts.map +1 -1
  16. package/dist/cdp-client.js +9 -22
  17. package/dist/cdp-client.js.map +1 -1
  18. package/dist/cgroup-partial-restriction.d.ts +42 -89
  19. package/dist/cgroup-partial-restriction.d.ts.map +1 -1
  20. package/dist/cgroup-partial-restriction.js +44 -91
  21. package/dist/cgroup-partial-restriction.js.map +1 -1
  22. package/dist/collector-version.d.ts +3 -8
  23. package/dist/collector-version.d.ts.map +1 -1
  24. package/dist/collector-version.js +3 -8
  25. package/dist/collector-version.js.map +1 -1
  26. package/dist/index.d.ts +1 -1
  27. package/dist/index.d.ts.map +1 -1
  28. package/dist/instrumented-execution.d.ts +30 -73
  29. package/dist/instrumented-execution.d.ts.map +1 -1
  30. package/dist/instrumented-execution.js +103 -251
  31. package/dist/instrumented-execution.js.map +1 -1
  32. package/dist/jvm-agent/build.d.ts +29 -53
  33. package/dist/jvm-agent/build.d.ts.map +1 -1
  34. package/dist/jvm-agent/build.js +34 -61
  35. package/dist/jvm-agent/build.js.map +1 -1
  36. package/dist/polling-output-source.d.ts +27 -19
  37. package/dist/polling-output-source.d.ts.map +1 -1
  38. package/dist/polling-output-source.js +23 -33
  39. package/dist/polling-output-source.js.map +1 -1
  40. package/dist/profile-backend-observation.d.ts +26 -53
  41. package/dist/profile-backend-observation.d.ts.map +1 -1
  42. package/dist/profile-backend-observation.js +26 -55
  43. package/dist/profile-backend-observation.js.map +1 -1
  44. package/dist/respawn-and-supervise.d.ts +39 -72
  45. package/dist/respawn-and-supervise.d.ts.map +1 -1
  46. package/dist/respawn-and-supervise.js +43 -84
  47. package/dist/respawn-and-supervise.js.map +1 -1
  48. package/package.json +14 -9
package/LICENSE ADDED
@@ -0,0 +1,6 @@
1
+ Copyright (c) Descry
2
+
3
+ All rights reserved. This software is proprietary and confidential.
4
+ No license, express or implied, to reproduce, distribute, modify, or
5
+ create derivative works is granted except as explicitly agreed in
6
+ writing.
@@ -1,71 +1,38 @@
1
1
  /**
2
- * Retroactive attach to an already-running **JVM (Java/Kotlin/…)** process
3
- * the JVM item on `RT-attach-to-running-process-scope.md`'s own
4
- * "deliberately not built" list, and `RT-attach-to-running-jvm-process.md`
5
- * (decisions-inbox) is the short record of what got measured before any of
6
- * this was written and why the slice below is the honest first one, not a
7
- * full CDP-equivalent.
2
+ * Retroactive attach to an already-running **JVM (Java/Kotlin/…)** process. Not a
3
+ * full CDP-equivalent; see `RT-attach-to-running-jvm-process.md` (decisions-inbox)
4
+ * for what was measured before this was written.
8
5
  *
9
- * **The real mechanism, measured against a live JVM on this machine, not
10
- * assumed from docs.** The JVM ships no built-in signal-to-inspector path
11
- * the way Node's `SIGUSR1` does. What it does ship, since JDK 6, is the
12
- * HotSpot Dynamic Attach mechanism: a launcher process calls
13
- * `com.sun.tools.attach.VirtualMachine.attach(pid)`, which creates
14
- * `.attach_pid<pid>` and signals the target with `SIGQUIT`; the target's own
15
- * attach-listener thread (started lazily on first use, already running in
16
- * every stock HotSpot JVM — nothing needs to be enabled at the target's own
17
- * launch) opens a Unix-domain socket at `.java_pid<pid>` in its temp
18
- * directory and accepts commands over it. `jcmd`/`jstack`/`VisualVM` all use
19
- * exactly this. Measured directly here: attached to a plain `java
20
- * QuietServer` process with no `-agentlib`/`-Djdk.attach` flags of any kind
21
- * and no restart, confirming this is genuinely retroactive, the same
22
- * standing Node's `SIGUSR1` slice has.
6
+ * **Mechanism, measured against a live JVM, not assumed from docs.** The JVM has
7
+ * no `SIGUSR1`-equivalent, but ships (since JDK 6) HotSpot Dynamic Attach:
8
+ * `VirtualMachine.attach(pid)` creates `.attach_pid<pid>`, signals `SIGQUIT`, and
9
+ * the target's attach-listener thread (already running in every stock HotSpot
10
+ * JVM, nothing to enable at launch) opens a Unix socket at `.java_pid<pid>` and
11
+ * accepts commands the same thing `jcmd`/`jstack`/`VisualVM` use. Measured:
12
+ * attached to a plain `java QuietServer` with no special flags and no restart,
13
+ * confirming this is genuinely retroactive.
23
14
  *
24
- * **What this channel can actually give measured, and narrower than
25
- * CDP.** `VirtualMachine.loadAgent(jar, args)` loads a real Java agent
26
- * (`java.lang.instrument.Instrumentation`) into the target's own JVM,
27
- * running as that JVM's own code a strictly more powerful primitive than
28
- * CDP's remote-debugging protocol. This first slice used only the cheapest
29
- * real capability inside it: `Thread.setDefaultUncaughtExceptionHandler`
30
- * (`jvm-agent/Agent.java`), which needs no bytecode instrumentation at all,
31
- * and **did not see an exception a framework already caught** — a request
32
- * handler's own try/catch, a servlet container's default error page, any
33
- * `@ExceptionHandler` because by definition those exceptions never reach
34
- * "uncaught." `SelfFailingServer.java` (the existing execute-mode fixture)
35
- * catches and logs its own thrown exception for exactly this reason, so it
36
- * is not a fixture this module's own test can reuse; see
37
- * `test/fixtures/jvm-attach/BackgroundThreadThrows.java`, a real thread that
38
- * throws with nothing catching it, the one shape that first slice could see.
15
+ * **Narrower than CDP.** `VirtualMachine.loadAgent(jar, args)` loads a real Java
16
+ * agent (`Instrumentation`) more powerful than CDP's remote-debugging protocol
17
+ * in principle, but this slice only uses `Thread.setDefaultUncaughtExceptionHandler`
18
+ * (`jvm-agent/Agent.java`), so it never sees an exception a framework already
19
+ * caught (a try/catch, a servlet error page, `@ExceptionHandler`). RT-201 closed
20
+ * one specific instance of that gap: `Agent.java` also installs a ByteBuddy
21
+ * `ClassFileTransformer` tapping
22
+ * `DispatcherServlet#processHandlerException` Spring MVC's single stable
23
+ * exception choke point reported as `"framework-caught-exception"`, parsed
24
+ * below and emitted with `payload.handled === true`. This closes only that one
25
+ * choke point: a catch absorbed inside a `@Service` method, or any non-Spring
26
+ * framework, is still invisible.
39
27
  *
40
- * **RT-201 closed one specific, real instance of that gap**, using the same
41
- * `Instrumentation` this module already hands the agent: `Agent.java` now
42
- * also installs a ByteBuddy `ClassFileTransformer` (see that file's own
43
- * header comment for the full mechanism and what was measured) that taps
44
- * `org.springframework.web.servlet.DispatcherServlet#processHandlerException`
45
- * — Spring MVC's single stable choke point for every exception-handling
46
- * path — and reports what it catches as a `"framework-caught-exception"`
47
- * event, parsed below as `isFrameworkCaughtExceptionEvent` and emitted as
48
- * `EXCEPTION` evidence with `payload.handled === true`. **This closes only
49
- * that one choke point.** A catch that never reaches Spring's dispatcher —
50
- * absorbed inside a `@Service` method, logged nowhere — is still invisible,
51
- * and no non-Spring framework is instrumented at all. `Runtime.exceptionThrown`'s
52
- * CDP-side reach (any throw the debugger is configured to pause on,
53
- * regardless of framework) still has no equivalent here.
28
+ * **No console-output capture** `System.out`/`err` aren't intercepted; that's
29
+ * `attachToRunningProcess`'s job for a target already logging to a file.
30
+ * `capabilities()` reports `backendLogAccess` unavailable for that reason.
54
31
  *
55
- * **No console-output capture in this slice.** Unlike CDP's
56
- * `Runtime.consoleAPICalled`, `System.out`/`System.err` are not intercepted
57
- * a target already logging to a file is exactly `attachToRunningProcess`'s
58
- * (the file-based sibling) job, and duplicating that here would be two
59
- * mechanisms claiming the same evidence. `capabilities()` reports
60
- * `backendLogAccess` unavailable for that reason, unlike the Node slice.
61
- *
62
- * **Launcher is a real JDK tool process, not a library call.** There is no
63
- * Node/native binding for the Attach API in this repo and none is added —
64
- * `jvm-agent/build.ts` compiles `Attacher.java` once (cached by mtime, same
65
- * rule `kotlin-server/build.ts` already uses) and this module spawns it as a
66
- * short-lived `java` child process, the same "one helper invocation, not a
67
- * new protocol client" shape `discoverNodeInspectorUrl`'s `process.kill`
68
- * call has, just through a JDK tool instead of a POSIX signal.
32
+ * **Launcher is a real JDK tool process, not a library call** — no Node/native
33
+ * Attach-API binding exists or is added. `jvm-agent/build.ts` compiles
34
+ * `Attacher.java` once (mtime-cached) and this module spawns it as a short-lived
35
+ * `java` child process.
69
36
  */
70
37
  import type { Collector } from "@descryy/runtime-contracts";
71
38
  export interface AttachToRunningJvmProcessOptions {
@@ -78,43 +45,23 @@ export interface AttachToRunningJvmProcessOptions {
78
45
  /** How often to check the agent's output file for new events. */
79
46
  readonly pollIntervalMs?: number;
80
47
  /**
81
- * Repo-relative source roots plus the absolute repo root, enabling a JVM
82
- * frame's bare basename to be reconstructed into a repo-relative path that
83
- * graph correlation can actually join on (RT-202, extending RT-162's fix
84
- * from the log-tailing path to this one).
85
- *
86
- * ## Why the attach path needed this too, and why it went unnoticed
87
- *
88
- * `JvmRuntimeAdapterOptions.sourceRoots` (`@descryy/runtime-adapter-jvm`)
89
- * already fixed this for evidence produced by `createJvmStackTraceParser`
90
- * — the JVM prints a bare basename (`ProbeApplication.java`), never a
91
- * path, so `resolveSymbolNode` correctly refuses to match on it alone
92
- * (RT-031's identity-proxy rule), and reconstruction from the frame's
93
- * declaring type is what lets the two sides join. This collector builds
94
- * its `StackFrame.location` directly from the Java agent's own captured
95
- * `StackTraceElement` fields (`frameToStackFrame` below) and never went
96
- * through that parser at all, so it never got the fix — invisible until
97
- * RT-202, because this mechanism's only fixture before then
98
- * (`BackgroundThreadThrows.java`) is in the default package, where
99
- * reconstruction is a no-op regardless (no dot in the declaring type).
48
+ * Repo-relative source roots plus the absolute repo root, so a JVM frame's bare
49
+ * basename can be reconstructed into a repo-relative path graph correlation can
50
+ * join on (RT-202, extending RT-162's fix from the log-tailing path to this one).
100
51
  *
101
- * ## Reimplemented here, not imported a deliberate, disclosed duplication
52
+ * The JVM prints a bare basename (`ProbeApplication.java`), never a path, so
53
+ * `resolveSymbolNode` refuses to match on it alone (RT-031). This collector builds
54
+ * `StackFrame.location` straight from the agent's captured `StackTraceElement`
55
+ * fields, bypassing `createJvmStackTraceParser` entirely, so RT-162's earlier fix
56
+ * there never reached this path — invisible until RT-202, since this mechanism's
57
+ * only prior fixture was in the default package, where reconstruction is a no-op.
102
58
  *
103
- * `packages/orchestrator`'s own `src/` has never taken a real dependency
104
- * on any `@descryy/runtime-adapter-*` package only
105
- * `@descryy/runtime-adapter-typescript` is one, for an unrelated
106
- * default-path reason, and every other language adapter (including
107
- * `@descryy/runtime-adapter-jvm`) is a devDependency used solely by this
108
- * package's own tests. Importing the JVM-specific reconstruction function
109
- * into this language-agnostic-by-convention module would be a bigger
110
- * architectural change than this gap warrants, so
111
- * `reconstructJvmSourcePath` below is a second copy of the exact same
112
- * algorithm (declaring type + basename + candidate roots + `existsSync`
113
- * check, discarded rather than fabricated when nothing is on disk) —
114
- * unlike other duplication this project has measured drifting silently,
115
- * both copies are tiny, pure, and named after the one behaviour they
116
- * implement, so a future change to one is easy to notice is missing from
117
- * the other.
59
+ * `reconstructJvmSourcePath` below is a deliberate second copy of
60
+ * `jvm-stack-trace-parser.ts`'s algorithm, not a shared import: this package
61
+ * never takes a real dependency on any `@descryy/runtime-adapter-*` package
62
+ * (JVM's included), and importing the JVM-specific function here would be a
63
+ * bigger architectural change than this gap warrants. Both copies are tiny,
64
+ * pure, and named after the one behaviour they implement.
118
65
  */
119
66
  readonly sourceRoots?: {
120
67
  readonly repoRoot: string;
@@ -1 +1 @@
1
- {"version":3,"file":"attach-to-running-jvm-process.d.ts","sourceRoot":"","sources":["../src/attach-to-running-jvm-process.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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