@sagentlab/navarch-runtime 0.1.72 → 0.1.74
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/dist/git-worktree.cjs +39 -3
- package/dist/heartbeat-loop.cjs +3 -0
- package/package.json +1 -1
package/dist/git-worktree.cjs
CHANGED
|
@@ -11,6 +11,14 @@ const worktree_janitor_cjs_1 = require("./worktree-janitor.cjs");
|
|
|
11
11
|
const node_fs_1 = require("node:fs");
|
|
12
12
|
const sandbox_cjs_1 = require("./sandbox.cjs");
|
|
13
13
|
const repositoryLocks = new Map();
|
|
14
|
+
/**
|
|
15
|
+
* A freshly minted installation token can be rejected for a second or two
|
|
16
|
+
* before GitHub propagates it, and git reports that 404 on a private repo as
|
|
17
|
+
* "Repository not found". Every lease gets a new token, so the first clone
|
|
18
|
+
* right after a claim can land in that window.
|
|
19
|
+
*/
|
|
20
|
+
const DEFAULT_AUTH_RETRY_DELAYS_MS = [1_000, 2_000, 4_000];
|
|
21
|
+
const TRANSIENT_GIT_AUTH_FAILURE = /Repository not found|Authentication failed|could not read Username|The requested URL returned error: (?:401|403|404)|\bHTTP (?:401|403|404)\b/i;
|
|
14
22
|
/**
|
|
15
23
|
* Maintains one bare repository cache per project and checks out each session
|
|
16
24
|
* into its own uniquely named worktree. Sessions that need a repo-local secret
|
|
@@ -27,6 +35,8 @@ class GitWorktree {
|
|
|
27
35
|
/** Why an existing hosted checkpoint could not be restored, for the session log. */
|
|
28
36
|
hostedCheckpointRestoreFailure = null;
|
|
29
37
|
runner;
|
|
38
|
+
authRetryDelaysMs;
|
|
39
|
+
sleep;
|
|
30
40
|
checkpointRoot;
|
|
31
41
|
cloneUrl;
|
|
32
42
|
githubToken;
|
|
@@ -64,6 +74,8 @@ class GitWorktree {
|
|
|
64
74
|
this.branch = `navarch/${branchSlug(options)}${this.taskBranchSuffix}` +
|
|
65
75
|
(options.prContinuation ? `-${sessionKey}` : "");
|
|
66
76
|
this.runner = options.runner ?? sandbox_cjs_1.nodeCommandRunner;
|
|
77
|
+
this.authRetryDelaysMs = options.authRetryDelaysMs ?? DEFAULT_AUTH_RETRY_DELAYS_MS;
|
|
78
|
+
this.sleep = options.sleep ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
|
|
67
79
|
this.cloneUrl = options.cloneUrl;
|
|
68
80
|
this.githubToken = options.githubToken;
|
|
69
81
|
this.repoLocalGithubToken = options.repoLocalGithubToken;
|
|
@@ -134,7 +146,11 @@ class GitWorktree {
|
|
|
134
146
|
/** Clones the bare cache if missing, repoints origin if needed, and fetches all branches. */
|
|
135
147
|
async ensureRepositoryCache() {
|
|
136
148
|
if (!(await pathExists(node_path_1.default.join(this.repositoryPath, "HEAD")))) {
|
|
137
|
-
await this.
|
|
149
|
+
await this.runAuthenticatedGitWithRetry(["clone", "--bare", this.cloneUrl, this.repositoryPath],
|
|
150
|
+
// A failed clone can leave a partial bare repository behind, and git
|
|
151
|
+
// refuses to clone into a non-empty directory. No HEAD means nothing
|
|
152
|
+
// usable (or shared) lives there yet.
|
|
153
|
+
() => node_fs_1.promises.rm(this.repositoryPath, { recursive: true, force: true }));
|
|
138
154
|
}
|
|
139
155
|
else {
|
|
140
156
|
const origin = await this.runGit(["--git-dir", this.repositoryPath, "remote", "get-url", "origin"], false);
|
|
@@ -142,14 +158,34 @@ class GitWorktree {
|
|
|
142
158
|
await this.runGit(["--git-dir", this.repositoryPath, "remote", "set-url", "origin", this.cloneUrl], false);
|
|
143
159
|
}
|
|
144
160
|
}
|
|
145
|
-
await this.
|
|
161
|
+
await this.runAuthenticatedGitWithRetry([
|
|
146
162
|
"--git-dir",
|
|
147
163
|
this.repositoryPath,
|
|
148
164
|
"fetch",
|
|
149
165
|
"--prune",
|
|
150
166
|
"origin",
|
|
151
167
|
"+refs/heads/*:refs/remotes/origin/*",
|
|
152
|
-
]
|
|
168
|
+
]);
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Runs a token-authenticated git command, retrying with backoff while GitHub
|
|
172
|
+
* rejects the credential in a way a not-yet-propagated token produces.
|
|
173
|
+
* Without a token such a failure is a real access problem and fails at once.
|
|
174
|
+
*/
|
|
175
|
+
async runAuthenticatedGitWithRetry(args, beforeRetry) {
|
|
176
|
+
for (let attempt = 0;; attempt += 1) {
|
|
177
|
+
try {
|
|
178
|
+
return await this.runGit(args, true);
|
|
179
|
+
}
|
|
180
|
+
catch (error) {
|
|
181
|
+
const delay = this.authRetryDelaysMs[attempt];
|
|
182
|
+
if (!this.githubToken || delay === undefined || !TRANSIENT_GIT_AUTH_FAILURE.test(errorMessage(error))) {
|
|
183
|
+
throw error;
|
|
184
|
+
}
|
|
185
|
+
await this.sleep(delay);
|
|
186
|
+
await beforeRetry?.();
|
|
187
|
+
}
|
|
188
|
+
}
|
|
153
189
|
}
|
|
154
190
|
async addSessionWorktree() {
|
|
155
191
|
// A failed session may have pushed before it could report completion. The
|
package/dist/heartbeat-loop.cjs
CHANGED
|
@@ -102,6 +102,9 @@ class MachineHeartbeatLoop {
|
|
|
102
102
|
available_capacity: this.draining ? 0 : this.capacity.available(),
|
|
103
103
|
capabilities: this.config.capabilities,
|
|
104
104
|
...(agentUsage ? { agent_usage: agentUsage } : {}),
|
|
105
|
+
// Explicit null when unpinned, so the control plane clears a model
|
|
106
|
+
// this machine reported before its pin was removed.
|
|
107
|
+
default_model: this.config.model ?? null,
|
|
105
108
|
runtime: {
|
|
106
109
|
version: version_cjs_1.RUNTIME_VERSION,
|
|
107
110
|
updater_protocol: version_cjs_1.UPDATER_PROTOCOL_VERSION,
|
package/package.json
CHANGED