@evident-ai/runner-cdk 3.4.1-dev.1856549 → 3.4.1-dev.2b2679a

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.
@@ -1,11 +1,9 @@
1
1
  #!/usr/bin/env bash
2
2
  #
3
3
  # Re-dial with the identity /run left behind. There is no step that could fetch
4
- # a fresh runner key, so the one from /run is what resumes. Also restarts the
5
- # session-DB replicator /suspend stopped before the snapshot (#812 WI-4):
6
- # litestream does not survive a suspend/resume freeze on this design (Q2) —
7
- # /suspend stops it and /resume starts a fresh one, the same pattern already
8
- # proven for the tunnel.
4
+ # a fresh runner key, so the one from /run is what resumes. The CLI delegated by
5
+ # start_tunnel owns the credential loop and the session-DB replicator's
6
+ # post-resume start.
9
7
  set -euo pipefail
10
8
 
11
9
  # shellcheck source=./common.sh
@@ -39,13 +37,18 @@ fi
39
37
  read -r runner_key
40
38
  } <"${CONTEXT_FILE}"
41
39
 
40
+ # Restore the id so the resumed CLI can self-report and acknowledge any
41
+ # outstanding recycle request (#1906). Older images may not have this file.
42
+ if [ -s "${MICROVM_ID_FILE}" ]; then
43
+ MICROVM_ID="$(cat "${MICROVM_ID_FILE}")"
44
+ export MICROVM_ID
45
+ fi
46
+
42
47
  # Tolerant, never fatal: a resume that fails costs the user their whole
43
48
  # session, so a broken durable-state config degrades to "no session-DB
44
- # restart" rather than a failed resume (the same Q3 reasoning /run's
45
- # session-DB step follows). start_litestream's own guards (disabled/marker/
46
- # already-running) handle the rest — this needs no logic of its own.
49
+ # replication" rather than a failed resume. The CLI's own guards handle the
50
+ # rest this needs no logic of its own.
47
51
  load_state_config || warn "could not resolve durable-state config; the session DB will not resume replicating"
48
- start_litestream
49
52
 
50
53
  # Diagnostic-only, unlike /run's gate: a failed resume costs the user their
51
54
  # whole session, so this never exits — it only converts a silent "resumed but
@@ -51,20 +51,20 @@ regenerate_machine_id
51
51
  # reads it, and left behind for the hooks that flush back to the same prefix.
52
52
  printf '%s\n' "${state_prefix}" >"${STATE_PREFIX_FILE}"
53
53
 
54
- # 3 — start reading the litestream binary NOW so that read overlaps step 4,
55
- # which needs a different binary (node), instead of landing inside step 5, which
56
- # start_opencode has to wait for. Backgrounded and never waited on.
54
+ # 3 — start reading the litestream and aws CLI binaries NOW. The reads run in
55
+ # the background and overlap the CLI's own node startup and auth round trip,
56
+ # keeping their cold first touches off the path to the first credential fetch.
57
57
  prewarm_litestream
58
+ prewarm_aws_cli
58
59
 
59
- # 4 — credential stores, restored before anything that reads them starts. Fatal
60
- # only if persistence itself is unavailable (an unset bucket/prefix, or a broken
61
- # synchroniser bundle) — a VM with no model credentials yet still boots.
62
- restore_credentials
60
+ # 4 — export the durable-state config before anything that reads it. Fatal,
61
+ # because the CLI and the teardown hooks must agree on this runner's state prefix.
62
+ load_state_config || exit 1
63
63
 
64
64
  # 5 — does the runner key in this payload actually authenticate against
65
- # Evident? Checked here, before opencode or the tunnel spend any of this boot's
66
- # SIGTERM budget on a key that cannot work, and before anything has started
67
- # that cleanup would need to tear down. Fatal ONLY on contrary evidence
65
+ # Evident? Checked here, before the tunnel spends any of this boot's time on a key
66
+ # that cannot work, and before anything has started that cleanup would need to
67
+ # tear down. Fatal ONLY on contrary evidence
68
68
  # (check_runner_key's own contract, common.sh): a key the API actively rejects
69
69
  # cannot work regardless, and failing here costs ~5s against the ~10 minutes a
70
70
  # runner that can never connect would otherwise burn before the lifecycle cron
@@ -72,35 +72,14 @@ restore_credentials
72
72
  # it warns and this VM still boots.
73
73
  check_runner_key "${runner_key}" "${api_url}" || exit 1
74
74
 
75
- # 6 — the OpenCode session DB (#812 WI-2), restored before opencode opens it
76
- # the only place this can happen. Bare, like restore_credentials above:
77
- # restore_session_db never returns non-zero (Q3 — nothing about the session
78
- # DB may ever fail /run), so there is deliberately no `||` here to catch.
79
- restore_session_db
80
- log "session DB restore done ${SECONDS}s into the hook"
81
-
82
- # 7 — apply the overlay before OpenCode resolves its project configuration.
83
- apply_runner_opencode_config
84
-
85
- # 8 — configure git after credentials are restored and before agent shells start.
86
- configure_github_access
87
-
88
- # 9 — opencode. Started here, not at build time: a warm process in the shared
89
- # snapshot would carry its installation id and database into every VM. Not
90
- # waited on: a slow opencode boot is not a reason to fail /run (the tunnel CLI
91
- # auto-starts opencode when it finds none healthy,
92
- # apps/cli/src/commands/ensure-opencode.ts, and the api-worker lifecycle cron
93
- # reclaims a runner that never comes online).
94
- start_opencode
95
-
96
- # 10 — begin replicating the session DB (#812 WI-3), now that opencode has
97
- # opened it and before any work can arrive over the tunnel. Bare, like
98
- # restore_session_db above: start_litestream never returns non-zero (every
99
- # guard inside it is its own `return 0`), so there is nothing here for
100
- # `set -e` to abort on.
101
- start_litestream
75
+ # 6 — preserve the VM id across suspend/resume. The runtime always supplies it
76
+ # for a /run hook, and the subshell keeps the persisted value protected.
77
+ (
78
+ umask 077
79
+ printf '%s\n' "${MICROVM_ID}" >"${MICROVM_ID_FILE}"
80
+ )
102
81
 
103
- # 11 — the first per-VM identity on the wire. The subshell's umask makes the file
82
+ # 7 — the first per-VM identity on the wire. The subshell's umask makes the file
104
83
  # unreadable to anyone else from the moment it exists, before the key is in it.
105
84
  (
106
85
  umask 077
@@ -112,6 +91,6 @@ start_litestream
112
91
  # attempt cap (apps/cli/src/lib/tunnel/connection.ts), and a control-plane
113
92
  # reclaim pass (the api-worker lifecycle cron) is what decides whether a
114
93
  # runner that never connects gets suspended.
115
- start_tunnel "${runner_key}" "${api_url}" "${tunnel_url}"
94
+ start_tunnel "${runner_key}" "${api_url}" "${tunnel_url}" true true
116
95
 
117
96
  run_succeeded=true
@@ -8,8 +8,10 @@ set -euo pipefail
8
8
  # shellcheck source=./common.sh
9
9
  source "$(dirname "$0")/common.sh"
10
10
 
11
- sync_credentials
12
- stop_tunnel
11
+ # load_state_config exports PERSISTENCE_BUCKET, which flush_session_db below
12
+ # requires; the CLI flush completes, or is proven absent, before teardown continues.
13
+ load_state_config || warn "could not resolve durable-state config; neither the credential flush nor the session-DB flush below can run"
14
+ stop_runner_and_flush_credentials
13
15
 
14
16
  # opencode is deliberately NOT stopped here (#812 WI-4) — it is inside the
15
17
  # snapshot and must resume with it — so a turn still in flight may not be
@@ -8,8 +8,10 @@ set -uo pipefail
8
8
  # shellcheck source=./common.sh
9
9
  source "$(dirname "$0")/common.sh"
10
10
 
11
- sync_credentials
12
- stop_tunnel
11
+ # load_state_config exports PERSISTENCE_BUCKET, which flush_session_db below
12
+ # requires; the CLI flush completes, or is proven absent, before teardown continues.
13
+ load_state_config || warn "could not resolve durable-state config; neither the credential flush nor the session-DB flush below can run"
14
+ stop_runner_and_flush_credentials
13
15
 
14
16
  # Writers stopped BEFORE litestream's final sync (#812 WI-4, the
15
17
  # ordered-shutdown invariant, plan §6): otherwise litestream could snapshot
@@ -29,6 +31,6 @@ flush_session_db
29
31
  # this hook runs under `set -u` (above), so an unbound one aborts the script
30
32
  # AT THIS LINE, leaving the runner key sitting in CONTEXT_FILE on a VM that is
31
33
  # being torn down. That is the one thing this line exists to prevent.
32
- rm -f "${CONTEXT_FILE}" "${SESSION_DB_NO_REPLICATE_MARKER}"
34
+ rm -f "${CONTEXT_FILE}" "${SESSION_DB_NO_REPLICATE_MARKER}" "${CREDENTIAL_FLUSH_MARKER_FILE}"
33
35
 
34
36
  exit 0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@evident-ai/runner-cdk",
3
- "version": "3.4.1-dev.1856549",
3
+ "version": "3.4.1-dev.2b2679a",
4
4
  "description": "Reusable CDK constructs for an Evident agent runner: a single scale-to-zero Fargate runner (task + service + per-agent self-stop role + waker Lambda), or a per-session AWS Lambda MicroVM that boots on demand and suspends between messages. Instantiate once per agent from your own stack.",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",