@tokenfactory/acc-runner 0.40.22 → 0.40.24
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/companion-identity.d.ts +21 -0
- package/dist/companion-identity.d.ts.map +1 -1
- package/dist/companion-identity.js +7 -0
- package/dist/companion-identity.js.map +1 -1
- package/dist/companion-run.d.ts.map +1 -1
- package/dist/companion-run.js +41 -27
- package/dist/companion-run.js.map +1 -1
- package/dist/warm-session/index.d.ts +14 -0
- package/dist/warm-session/index.d.ts.map +1 -0
- package/dist/warm-session/index.js +14 -0
- package/dist/warm-session/index.js.map +1 -0
- package/dist/warm-session/latency.d.ts +72 -0
- package/dist/warm-session/latency.d.ts.map +1 -0
- package/dist/warm-session/latency.js +102 -0
- package/dist/warm-session/latency.js.map +1 -0
- package/dist/warm-session/pool.d.ts +153 -0
- package/dist/warm-session/pool.d.ts.map +1 -0
- package/dist/warm-session/pool.js +335 -0
- package/dist/warm-session/pool.js.map +1 -0
- package/dist/warm-session/types.d.ts +124 -0
- package/dist/warm-session/types.d.ts.map +1 -0
- package/dist/warm-session/types.js +11 -0
- package/dist/warm-session/types.js.map +1 -0
- package/dist/watch-chat/fleet-chat-lane.js +4 -4
- package/dist/watch-chat/index.d.ts +4 -0
- package/dist/watch-chat/index.d.ts.map +1 -1
- package/dist/watch-chat/index.js +4 -0
- package/dist/watch-chat/index.js.map +1 -1
- package/dist/watch-chat/wire.d.ts +50 -0
- package/dist/watch-chat/wire.d.ts.map +1 -0
- package/dist/watch-chat/wire.js +200 -0
- package/dist/watch-chat/wire.js.map +1 -0
- package/dist/watch.d.ts +7 -0
- package/dist/watch.d.ts.map +1 -1
- package/dist/watch.js +43 -0
- package/dist/watch.js.map +1 -1
- package/package.json +1 -1
|
@@ -23,10 +23,10 @@
|
|
|
23
23
|
* `activeCodeTasks`, so the max-share budget keeps chat from ever starving
|
|
24
24
|
* the code/review lanes on a shared runner.
|
|
25
25
|
*
|
|
26
|
-
* The production wiring into `watch.ts`
|
|
27
|
-
* identity topic + startup backfill, the Supabase probe,
|
|
28
|
-
* the
|
|
29
|
-
*
|
|
26
|
+
* The production wiring into `watch.ts` — feeding the owner source from the
|
|
27
|
+
* identity topic + a startup backfill, the Supabase probe (supabaseFleetProbe),
|
|
28
|
+
* and the chat pump alongside the task pump — lives in `watch-chat/wire.ts`
|
|
29
|
+
* (`startFleetChatServing`), which watch.ts calls once the runner is online.
|
|
30
30
|
*/
|
|
31
31
|
import { ChatCompanion } from "../chat-companion.js";
|
|
32
32
|
import { OwnerConversationSource } from "../companion.js";
|
|
@@ -6,6 +6,9 @@
|
|
|
6
6
|
* - grace-gate.ts — companion-preference timing decision (pure).
|
|
7
7
|
* - grace-gated-transport.ts — the claim decorator + Supabase probe builder.
|
|
8
8
|
* - fleet-chat-lane.ts — the owner-scoped, grace-gated ChatCompanion.
|
|
9
|
+
* - wire.ts — production wiring into watch.ts (identity-topic
|
|
10
|
+
* feed + startup backfill, the Supabase probe, and
|
|
11
|
+
* the chat pump alongside the task pump).
|
|
9
12
|
*
|
|
10
13
|
* Machine-ownership isolation (bound-user turns only) is enforced by the
|
|
11
14
|
* owner-affinity source (runner-side) + the acc.claim_chat_turn owner gate
|
|
@@ -14,4 +17,5 @@
|
|
|
14
17
|
export { DEFAULT_FLEET_CHAT_GRACE_MS, FLEET_CHAT_GRACE_MS_ENV, MIN_FLEET_CHAT_GRACE_MS, MAX_FLEET_CHAT_GRACE_MS, resolveFleetChatGraceMs, reduceClaimableProbe, decideFleetClaim, type ClaimableTurnProbe, type FleetTurnProbeRow, type FleetClaimReason, type FleetClaimDecision, } from "./grace-gate.js";
|
|
15
18
|
export { graceGatedTransport, supabaseFleetProbe, FLEET_PROBE_STATUSES, type GraceGateOptions, } from "./grace-gated-transport.js";
|
|
16
19
|
export { FleetChatLane, type FleetChatLaneDeps } from "./fleet-chat-lane.js";
|
|
20
|
+
export { startFleetChatServing, fleetChatEnabled, resolveFleetChatMaxShare, FLEET_CHAT_ENABLED_ENV, FLEET_CHAT_MAX_SHARE_ENV, DEFAULT_FLEET_CHAT_MAX_SHARE, type FleetChatWireDeps, type FleetChatServingHandle, } from "./wire.js";
|
|
17
21
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/watch-chat/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/watch-chat/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EACL,2BAA2B,EAC3B,uBAAuB,EACvB,uBAAuB,EACvB,uBAAuB,EACvB,uBAAuB,EACvB,oBAAoB,EACpB,gBAAgB,EAChB,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,GACxB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACL,mBAAmB,EACnB,kBAAkB,EAClB,oBAAoB,EACpB,KAAK,gBAAgB,GACtB,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAAE,aAAa,EAAE,KAAK,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAE7E,OAAO,EACL,qBAAqB,EACrB,gBAAgB,EAChB,wBAAwB,EACxB,sBAAsB,EACtB,wBAAwB,EACxB,4BAA4B,EAC5B,KAAK,iBAAiB,EACtB,KAAK,sBAAsB,GAC5B,MAAM,WAAW,CAAC"}
|
package/dist/watch-chat/index.js
CHANGED
|
@@ -6,6 +6,9 @@
|
|
|
6
6
|
* - grace-gate.ts — companion-preference timing decision (pure).
|
|
7
7
|
* - grace-gated-transport.ts — the claim decorator + Supabase probe builder.
|
|
8
8
|
* - fleet-chat-lane.ts — the owner-scoped, grace-gated ChatCompanion.
|
|
9
|
+
* - wire.ts — production wiring into watch.ts (identity-topic
|
|
10
|
+
* feed + startup backfill, the Supabase probe, and
|
|
11
|
+
* the chat pump alongside the task pump).
|
|
9
12
|
*
|
|
10
13
|
* Machine-ownership isolation (bound-user turns only) is enforced by the
|
|
11
14
|
* owner-affinity source (runner-side) + the acc.claim_chat_turn owner gate
|
|
@@ -14,4 +17,5 @@
|
|
|
14
17
|
export { DEFAULT_FLEET_CHAT_GRACE_MS, FLEET_CHAT_GRACE_MS_ENV, MIN_FLEET_CHAT_GRACE_MS, MAX_FLEET_CHAT_GRACE_MS, resolveFleetChatGraceMs, reduceClaimableProbe, decideFleetClaim, } from "./grace-gate.js";
|
|
15
18
|
export { graceGatedTransport, supabaseFleetProbe, FLEET_PROBE_STATUSES, } from "./grace-gated-transport.js";
|
|
16
19
|
export { FleetChatLane } from "./fleet-chat-lane.js";
|
|
20
|
+
export { startFleetChatServing, fleetChatEnabled, resolveFleetChatMaxShare, FLEET_CHAT_ENABLED_ENV, FLEET_CHAT_MAX_SHARE_ENV, DEFAULT_FLEET_CHAT_MAX_SHARE, } from "./wire.js";
|
|
17
21
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/watch-chat/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/watch-chat/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EACL,2BAA2B,EAC3B,uBAAuB,EACvB,uBAAuB,EACvB,uBAAuB,EACvB,uBAAuB,EACvB,oBAAoB,EACpB,gBAAgB,GAKjB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACL,mBAAmB,EACnB,kBAAkB,EAClB,oBAAoB,GAErB,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAAE,aAAa,EAA0B,MAAM,sBAAsB,CAAC;AAE7E,OAAO,EACL,qBAAqB,EACrB,gBAAgB,EAChB,wBAAwB,EACxB,sBAAsB,EACtB,wBAAwB,EACxB,4BAA4B,GAG7B,MAAM,WAAW,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { RunnerConfig } from "../config.js";
|
|
2
|
+
import type { RunnerSupabaseClient } from "../supabase.js";
|
|
3
|
+
import type { StoredSession } from "../types.js";
|
|
4
|
+
/** Opt OUT of fleet-fallback chat serving on a `watch` runner (default: on). */
|
|
5
|
+
export declare const FLEET_CHAT_ENABLED_ENV = "ACC_RUNNER_FLEET_CHAT";
|
|
6
|
+
/** Fleet chat's max share of the runner's concurrency ceiling (0..1). */
|
|
7
|
+
export declare const FLEET_CHAT_MAX_SHARE_ENV = "ACC_RUNNER_FLEET_CHAT_MAX_SHARE";
|
|
8
|
+
/** Default fleet-chat share: at most half the ceiling, and the budget always reserves ≥1 code slot. */
|
|
9
|
+
export declare const DEFAULT_FLEET_CHAT_MAX_SHARE = 0.5;
|
|
10
|
+
/** Is fleet-fallback chat serving enabled? Disabled by `ACC_RUNNER_FLEET_CHAT=0`. */
|
|
11
|
+
export declare function fleetChatEnabled(env?: NodeJS.ProcessEnv): boolean;
|
|
12
|
+
/** Resolve the fleet-chat max-share (0..1); blank/invalid ⇒ default; clamped to (0,1]. */
|
|
13
|
+
export declare function resolveFleetChatMaxShare(raw: string | undefined | null): number;
|
|
14
|
+
/** What watch.ts feeds the fleet chat wiring. All I/O deps are read at call time. */
|
|
15
|
+
export interface FleetChatWireDeps {
|
|
16
|
+
cfg: RunnerConfig;
|
|
17
|
+
session: StoredSession;
|
|
18
|
+
/** The runner's live Supabase client (rebuilt on token refresh — see refreshClient). */
|
|
19
|
+
supabase: RunnerSupabaseClient;
|
|
20
|
+
/** The runner's concurrency ceiling (shared with the task pump). */
|
|
21
|
+
concurrencyLimit: number;
|
|
22
|
+
/** LIVE count of code/review tasks in flight (state.running.size) — chat shares slots. */
|
|
23
|
+
activeCodeTasks: () => number;
|
|
24
|
+
/** Best-effort log sink. */
|
|
25
|
+
onLog?: (line: string) => void;
|
|
26
|
+
}
|
|
27
|
+
/** A running fleet chat lane; `stop()` requeues in-flight turns and tears down. */
|
|
28
|
+
export interface FleetChatServingHandle {
|
|
29
|
+
/** Stop the pump, close the discovery listener, and restore the acc-mcp config. */
|
|
30
|
+
stop(): Promise<void>;
|
|
31
|
+
/** Hot-swap the transport's client + ingest bearer after a token refresh/failover. */
|
|
32
|
+
refreshClient(nextClient: RunnerSupabaseClient, nextAccessToken: string): Promise<void>;
|
|
33
|
+
/** Chat turns currently in flight on this fleet runner (observability/tests). */
|
|
34
|
+
activeChatTurns(): number;
|
|
35
|
+
/** Conversations currently in the owner-affinity served set. */
|
|
36
|
+
servedConversations(): number;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Start fleet-fallback chat serving on a `watch` runner. Builds the chat
|
|
40
|
+
* transport, owner-affinity source, Supabase probe, and per-turn delegation, then
|
|
41
|
+
* launches a `FleetChatLane` (an owner-scoped, grace-gated ChatCompanion) whose
|
|
42
|
+
* pump runs alongside the task pump. The lane claims a turn only once the
|
|
43
|
+
* companion-preference grace window has elapsed (a live companion always wins),
|
|
44
|
+
* and never claims past the chat max-share of the shared concurrency ceiling.
|
|
45
|
+
*
|
|
46
|
+
* Best-effort throughout: any startup step that fails is logged and the runner
|
|
47
|
+
* carries on serving tasks. Returns null when serving is disabled.
|
|
48
|
+
*/
|
|
49
|
+
export declare function startFleetChatServing(deps: FleetChatWireDeps): Promise<FleetChatServingHandle | null>;
|
|
50
|
+
//# sourceMappingURL=wire.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wire.d.ts","sourceRoot":"","sources":["../../src/watch-chat/wire.ts"],"names":[],"mappings":"AAuBA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAC3D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAajD,gFAAgF;AAChF,eAAO,MAAM,sBAAsB,0BAA0B,CAAC;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
|
+
* A fleet `watch` runner is already online, bound to a user, and draining the
|
|
6
|
+
* code/review lanes. This module lets it ALSO serve that user's chat turns as the
|
|
7
|
+
* fallback behind their companion, using the SAME dependencies watch.ts already
|
|
8
|
+
* holds (session, Supabase client, chat engine) plus the injectable primitives
|
|
9
|
+
* from this folder (FleetChatLane, supabaseFleetProbe, the grace gate). It is the
|
|
10
|
+
* fleet twin of companion-run.ts's glue: it feeds the owner-affinity source from
|
|
11
|
+
* the identity topic + a startup backfill, provisions the acc-mcp tool bus, mints
|
|
12
|
+
* per-turn delegation, and starts a chat pump ALONGSIDE the task pump — passing
|
|
13
|
+
* the LIVE code-task count through `activeCodeTasks` so chat never starves code.
|
|
14
|
+
*
|
|
15
|
+
* Kept out of watch.ts so that file stays the task/heartbeat loop and this glue
|
|
16
|
+
* stays independently unit-testable with injected fakes.
|
|
17
|
+
*/
|
|
18
|
+
import { createSupabaseChatTransport } from "../chat-transport.js";
|
|
19
|
+
import { CHAT_WALL_CLOCK_MS_ENV, resolveChatWallClockMs, } from "../chat-lane.js";
|
|
20
|
+
import { getChatEngine } from "../engines/registry.js";
|
|
21
|
+
import { ChatCircuitBreaker } from "../runtime/chat-circuit-breaker.js";
|
|
22
|
+
import { OwnerConversationSource, backfillActiveConversations, createConversationListener, } from "../companion.js";
|
|
23
|
+
import { writeMcpConfig } from "../mcp-spawn.js";
|
|
24
|
+
import { FleetChatLane } from "./fleet-chat-lane.js";
|
|
25
|
+
import { supabaseFleetProbe } from "./grace-gated-transport.js";
|
|
26
|
+
import { resolveFleetChatGraceMs, FLEET_CHAT_GRACE_MS_ENV } from "./grace-gate.js";
|
|
27
|
+
/** Opt OUT of fleet-fallback chat serving on a `watch` runner (default: on). */
|
|
28
|
+
export const FLEET_CHAT_ENABLED_ENV = "ACC_RUNNER_FLEET_CHAT";
|
|
29
|
+
/** Fleet chat's max share of the runner's concurrency ceiling (0..1). */
|
|
30
|
+
export const FLEET_CHAT_MAX_SHARE_ENV = "ACC_RUNNER_FLEET_CHAT_MAX_SHARE";
|
|
31
|
+
/** Default fleet-chat share: at most half the ceiling, and the budget always reserves ≥1 code slot. */
|
|
32
|
+
export const DEFAULT_FLEET_CHAT_MAX_SHARE = 0.5;
|
|
33
|
+
/** Requested per-turn lease (ms) — mirrors the companion path. */
|
|
34
|
+
const FLEET_CHAT_LEASE_MS = 60_000;
|
|
35
|
+
/** Fleet chat pump cadence (ms). */
|
|
36
|
+
const FLEET_CHAT_PUMP_MS = 1_000;
|
|
37
|
+
/** Is fleet-fallback chat serving enabled? Disabled by `ACC_RUNNER_FLEET_CHAT=0`. */
|
|
38
|
+
export function fleetChatEnabled(env = process.env) {
|
|
39
|
+
return (env[FLEET_CHAT_ENABLED_ENV] ?? "").trim() !== "0";
|
|
40
|
+
}
|
|
41
|
+
/** Resolve the fleet-chat max-share (0..1); blank/invalid ⇒ default; clamped to (0,1]. */
|
|
42
|
+
export function resolveFleetChatMaxShare(raw) {
|
|
43
|
+
const trimmed = (raw ?? "").trim();
|
|
44
|
+
if (!trimmed)
|
|
45
|
+
return DEFAULT_FLEET_CHAT_MAX_SHARE;
|
|
46
|
+
const n = Number.parseFloat(trimmed);
|
|
47
|
+
if (!Number.isFinite(n) || n <= 0)
|
|
48
|
+
return DEFAULT_FLEET_CHAT_MAX_SHARE;
|
|
49
|
+
return Math.min(1, n);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Start fleet-fallback chat serving on a `watch` runner. Builds the chat
|
|
53
|
+
* transport, owner-affinity source, Supabase probe, and per-turn delegation, then
|
|
54
|
+
* launches a `FleetChatLane` (an owner-scoped, grace-gated ChatCompanion) whose
|
|
55
|
+
* pump runs alongside the task pump. The lane claims a turn only once the
|
|
56
|
+
* companion-preference grace window has elapsed (a live companion always wins),
|
|
57
|
+
* and never claims past the chat max-share of the shared concurrency ceiling.
|
|
58
|
+
*
|
|
59
|
+
* Best-effort throughout: any startup step that fails is logged and the runner
|
|
60
|
+
* carries on serving tasks. Returns null when serving is disabled.
|
|
61
|
+
*/
|
|
62
|
+
export async function startFleetChatServing(deps) {
|
|
63
|
+
if (!fleetChatEnabled())
|
|
64
|
+
return null;
|
|
65
|
+
const { cfg, session, activeCodeTasks } = deps;
|
|
66
|
+
const log = deps.onLog ?? (() => { });
|
|
67
|
+
let supabase = deps.supabase;
|
|
68
|
+
let accessToken = session.access_token;
|
|
69
|
+
const engine = getChatEngine();
|
|
70
|
+
const breaker = new ChatCircuitBreaker();
|
|
71
|
+
await breaker.load().catch(() => {
|
|
72
|
+
/* a missing sentinel just means the breaker starts closed */
|
|
73
|
+
});
|
|
74
|
+
// CHAT-LANE-BRIDGE: durable-ingest transport (same as the companion path). The
|
|
75
|
+
// runner POSTs stream/complete frames to the server, which persists them under
|
|
76
|
+
// the service role and re-broadcasts to the browser.
|
|
77
|
+
const transport = createSupabaseChatTransport(supabase, {
|
|
78
|
+
ingest: { url: cfg.publicUrl, token: accessToken },
|
|
79
|
+
});
|
|
80
|
+
// MACHINE-OWNERSHIP ISOLATION: only the bound user's conversations are servable.
|
|
81
|
+
// Starts empty; fed live over the identity topic + a startup backfill below.
|
|
82
|
+
const conversations = new OwnerConversationSource(session.user_id);
|
|
83
|
+
// FU-4 twin: fold the browser's `conversation_active` announces on the
|
|
84
|
+
// authenticated identity topic into the owner-affinity source (owner-affinity
|
|
85
|
+
// enforced on add), so a brand-new conversation is served with no restart.
|
|
86
|
+
const conversationListener = createConversationListener(supabase, session.user_id, conversations, { onLog: log });
|
|
87
|
+
// CHAT-MCP-PROVISION: the chat engine needs a .mcp.json (acc-mcp tool bus) or it
|
|
88
|
+
// hard-errors and streams no text. Provision it at the stable repoPath (the chat
|
|
89
|
+
// cwd) before any turn can be driven; re-bake on token refresh so the fallback
|
|
90
|
+
// JWT never goes stale. Best-effort: a turn errors visibly rather than blocking.
|
|
91
|
+
let mcpCleanup = null;
|
|
92
|
+
const provisionChatMcp = async () => {
|
|
93
|
+
try {
|
|
94
|
+
mcpCleanup = await writeMcpConfig({
|
|
95
|
+
cwd: cfg.repoPath,
|
|
96
|
+
taskId: "", // no task in the chat lane — acc-mcp-server treats it as null
|
|
97
|
+
runnerId: session.runner_id,
|
|
98
|
+
accessToken,
|
|
99
|
+
publicUrl: cfg.publicUrl,
|
|
100
|
+
supabaseUrl: cfg.supabaseUrl,
|
|
101
|
+
supabaseAnonKey: cfg.supabaseAnonKey,
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
catch (err) {
|
|
105
|
+
log(`[acc-runner] fleet chat acc-mcp provisioning failed: ${err.message}`);
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
// CHAT-DELEGATION (FU-5 twin): mint a NARROW per-turn delegation token bound to
|
|
109
|
+
// the turn's conversation. The runner is owner-bound, so the operator == this
|
|
110
|
+
// session's user; the server clamps the scope to the operator's ceiling. The
|
|
111
|
+
// `companion` role matches the shared serving path — the fleet lane's delegation
|
|
112
|
+
// scope + provenance are deliberately identical to the companion's. Reads
|
|
113
|
+
// `accessToken` at CALL time so a rotation is honoured. Best-effort → undefined
|
|
114
|
+
// falls back to the baked runner-token .mcp.json.
|
|
115
|
+
const delegationBase = cfg.publicUrl.replace(/\/+$/, "");
|
|
116
|
+
const mintDelegation = async (turn) => {
|
|
117
|
+
try {
|
|
118
|
+
const res = await fetch(`${delegationBase}/api/chat/delegation`, {
|
|
119
|
+
method: "POST",
|
|
120
|
+
headers: {
|
|
121
|
+
"Content-Type": "application/json",
|
|
122
|
+
Authorization: `Bearer ${accessToken}`,
|
|
123
|
+
},
|
|
124
|
+
body: JSON.stringify({ conversation_id: turn.conversation_id, role: "companion" }),
|
|
125
|
+
});
|
|
126
|
+
if (!res.ok) {
|
|
127
|
+
log(`[acc-runner] fleet chat delegation mint failed: HTTP ${res.status}`);
|
|
128
|
+
return undefined;
|
|
129
|
+
}
|
|
130
|
+
const json = (await res.json());
|
|
131
|
+
return typeof json.token === "string" && json.token ? json.token : undefined;
|
|
132
|
+
}
|
|
133
|
+
catch (err) {
|
|
134
|
+
log(`[acc-runner] fleet chat delegation mint error: ${err.message}`);
|
|
135
|
+
return undefined;
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
const lane = new FleetChatLane({
|
|
139
|
+
runnerId: session.runner_id,
|
|
140
|
+
boundUserId: session.user_id,
|
|
141
|
+
engine,
|
|
142
|
+
transport,
|
|
143
|
+
breaker,
|
|
144
|
+
conversations,
|
|
145
|
+
concurrencyLimit: deps.concurrencyLimit,
|
|
146
|
+
maxShare: resolveFleetChatMaxShare(process.env[FLEET_CHAT_MAX_SHARE_ENV]),
|
|
147
|
+
leaseMs: FLEET_CHAT_LEASE_MS,
|
|
148
|
+
// The crucial fleet difference: chat shares slots with the code lane, so the
|
|
149
|
+
// budget subtracts the live code load and keeps chat from starving code.
|
|
150
|
+
activeCodeTasks,
|
|
151
|
+
// Read `supabase` at CALL time so the probe follows a token rotation.
|
|
152
|
+
probe: supabaseFleetProbe({ from: (t) => supabase.from(t) }),
|
|
153
|
+
graceMs: resolveFleetChatGraceMs(process.env[FLEET_CHAT_GRACE_MS_ENV]),
|
|
154
|
+
wallClockMs: resolveChatWallClockMs(process.env[CHAT_WALL_CLOCK_MS_ENV]),
|
|
155
|
+
cwd: cfg.repoPath,
|
|
156
|
+
mintDelegation,
|
|
157
|
+
onLog: log,
|
|
158
|
+
});
|
|
159
|
+
await provisionChatMcp();
|
|
160
|
+
// Begin conversation discovery + drain any already-queued turn on (re)start.
|
|
161
|
+
await conversationListener.start().catch((err) => {
|
|
162
|
+
log(`[acc-runner] fleet chat discovery listener failed to start: ${err.message}`);
|
|
163
|
+
});
|
|
164
|
+
await backfillActiveConversations(supabase, session.user_id, conversations, {
|
|
165
|
+
label: "fleet startup backfill",
|
|
166
|
+
onLog: log,
|
|
167
|
+
});
|
|
168
|
+
// Start the chat pump ALONGSIDE the task pump (its own cadence).
|
|
169
|
+
lane.start(FLEET_CHAT_PUMP_MS);
|
|
170
|
+
log(`[acc-runner] fleet chat serving enabled for user ${session.user_id} ` +
|
|
171
|
+
`(grace ${resolveFleetChatGraceMs(process.env[FLEET_CHAT_GRACE_MS_ENV])}ms; ` +
|
|
172
|
+
`discovered live over identity:${session.user_id})`);
|
|
173
|
+
return {
|
|
174
|
+
async stop() {
|
|
175
|
+
await lane.stop().catch(() => {
|
|
176
|
+
/* stop() already requeues in-flight turns; never block shutdown */
|
|
177
|
+
});
|
|
178
|
+
await conversationListener.close().catch(() => { });
|
|
179
|
+
await mcpCleanup?.restore().catch(() => {
|
|
180
|
+
/* best-effort; never block shutdown on config cleanup */
|
|
181
|
+
});
|
|
182
|
+
},
|
|
183
|
+
async refreshClient(nextClient, nextAccessToken) {
|
|
184
|
+
supabase = nextClient;
|
|
185
|
+
accessToken = nextAccessToken;
|
|
186
|
+
await transport.refreshClient(nextClient, nextAccessToken).catch(() => {
|
|
187
|
+
/* channel teardown is best-effort; the next frame re-subscribes */
|
|
188
|
+
});
|
|
189
|
+
// Re-bake the fresh JWT into .mcp.json so the acc-mcp bus keeps authorizing.
|
|
190
|
+
await provisionChatMcp();
|
|
191
|
+
},
|
|
192
|
+
activeChatTurns() {
|
|
193
|
+
return lane.activeChatTurns();
|
|
194
|
+
},
|
|
195
|
+
servedConversations() {
|
|
196
|
+
return conversations.size();
|
|
197
|
+
},
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
//# sourceMappingURL=wire.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wire.js","sourceRoot":"","sources":["../../src/watch-chat/wire.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAAE,2BAA2B,EAAE,MAAM,sBAAsB,CAAC;AACnE,OAAO,EACL,sBAAsB,EACtB,sBAAsB,GAEvB,MAAM,iBAAiB,CAAC;AAIzB,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC;AACxE,OAAO,EACL,uB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GED
|
@@ -9,6 +9,7 @@ import { type SingletonLock } from "./runtime/singleton.js";
|
|
|
9
9
|
import { type SelfUpgradeResult, type SelfUpdate426Result } from "./runtime/self-upgrade.js";
|
|
10
10
|
import { ResumeController, type ResumeControllerDeps } from "./capacity/resume-controller.js";
|
|
11
11
|
import { AccountProbeScheduler } from "./engines/account-probe.js";
|
|
12
|
+
import { type FleetChatServingHandle } from "./watch-chat/wire.js";
|
|
12
13
|
import type { EngineAccountIdentity } from "./engines/types.js";
|
|
13
14
|
import type { StoredSession } from "./types.js";
|
|
14
15
|
import { RefreshReuseDetectedError, classifyHeartbeatError, nextHeartbeatDelayMs, type HeartbeatErrorKind } from "./runtime/auth-lifecycle.js";
|
|
@@ -471,6 +472,12 @@ interface WatchState {
|
|
|
471
472
|
* null when enforcement is off (tests). Released in stop().
|
|
472
473
|
*/
|
|
473
474
|
singletonLock: SingletonLock | null;
|
|
475
|
+
/**
|
|
476
|
+
* FLEET-SERVE (wire): the running fleet-fallback chat lane, or null when chat
|
|
477
|
+
* serving is disabled (tests, or ACC_RUNNER_FLEET_CHAT=0). Its transport is
|
|
478
|
+
* refreshed on token rotation (doRefresh/doFailover) and it is stopped in stop().
|
|
479
|
+
*/
|
|
480
|
+
fleetChat: FleetChatServingHandle | null;
|
|
474
481
|
}
|
|
475
482
|
export declare function resubscribeChannel(state: WatchState, factory: typeof runTask): Promise<void>;
|
|
476
483
|
export declare function reassertRunningClaims(state: WatchState): Promise<void>;
|
package/dist/watch.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"watch.d.ts","sourceRoot":"","sources":["../src/watch.ts"],"names":[],"mappings":"AA4BA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAML,KAAK,iBAAiB,EACtB,KAAK,YAAY,EAGlB,MAAM,aAAa,CAAC;AAIrB,OAAO,EAAE,uBAAuB,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAC;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B,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC;;;;;OAKG;IACH,aAAa,EAAE,OAAO,CAAC;IACvB,sEAAsE;IACtE,iBAAiB,EAAE,MAAM,CAAC;IAC1B,cAAc,EAAE,MAAM,CAAC;IACvB;;;OAGG;IACH,aAAa,EAAE,aAAa,GAAG,IAAI,CAAC;IACpC;;;;OAIG;IACH,SAAS,EAAE,sBAAsB,GAAG,IAAI,CAAC;CAC1C;AAuID,wBAAsB,kBAAkB,CACtC,KAAK,EAAE,UAAU,EACjB,OAAO,EAAE,OAAO,OAAO,GACtB,OAAO,CAAC,IAAI,CAAC,CAoBf;AAMD,wBAAsB,qBAAqB,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAqB5E;AAshBD,wBAAsB,YAAY,CAAC,OAAO,GAAE,YAAiB,GAAG,OAAO,CAAC,WAAW,CAAC,CA4rBnF;AA8QD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAsB,gBAAgB,CACpC,KAAK,EAAE,IAAI,CAAC,UAAU,EAAE,SAAS,GAAG,UAAU,CAAC,EAC/C,IAAI,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,EACzB,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,EAC9B,MAAM,EAAE,QAAQ,GAAG,SAAS,GAC3B,OAAO,CAAC,IAAI,CAAC,CAwBf;AA6LD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,UAAU,EACjB,OAAO,EAAE,OAAO,OAAO,GACtB,IAAI,CACL,oBAAoB,EACpB,gBAAgB,GAAG,YAAY,GAAG,kBAAkB,GAAG,eAAe,GAAG,OAAO,CACjF,CA6GA"}
|
package/dist/watch.js
CHANGED
|
@@ -50,6 +50,10 @@ import { ResumeController } from "./capacity/resume-controller.js";
|
|
|
50
50
|
import { RUNNER_CAPACITY_PAUSED_VERB, RUNNER_CAPACITY_RESUME_VERB, } from "./capacity/fleet-pause-verbs.js";
|
|
51
51
|
import { AccountProbeScheduler } from "./engines/account-probe.js";
|
|
52
52
|
import { getChatEngine } from "./engines/registry.js";
|
|
53
|
+
// FLEET-SERVE (wire): fleet-fallback chat serving runs ALONGSIDE the task pump on
|
|
54
|
+
// a `watch` runner — the runner serves its bound user's chat turns behind their
|
|
55
|
+
// companion. Glue lives in watch-chat/wire.ts to keep this file the task loop.
|
|
56
|
+
import { startFleetChatServing, } from "./watch-chat/wire.js";
|
|
53
57
|
import { unknownAccountIdentity } from "./engines/account-identity.js";
|
|
54
58
|
import { checkVersion, compareSemver } from "./version-check.js";
|
|
55
59
|
import { PACKAGE_VERSION } from "./pkg-version.js";
|
|
@@ -728,6 +732,10 @@ async function doRefresh(state, taskRunnerFactory) {
|
|
|
728
732
|
}
|
|
729
733
|
state.supabase = createRunnerClient(state.cfg, state.session.access_token, state.session.realtime_config);
|
|
730
734
|
subscribeChannel(state, taskRunnerFactory);
|
|
735
|
+
// FLEET-SERVE (wire): hot-swap the chat lane's client + ingest bearer onto
|
|
736
|
+
// the fresh JWT so turn-serving keeps working across the rotation (mirrors
|
|
737
|
+
// the companion's refreshAuth). Best-effort; a failure is swallowed inside.
|
|
738
|
+
await state.fleetChat?.refreshClient(state.supabase, state.session.access_token);
|
|
731
739
|
return true;
|
|
732
740
|
}
|
|
733
741
|
catch (err) {
|
|
@@ -781,6 +789,9 @@ async function doFailover(state, taskRunnerFactory, reason) {
|
|
|
781
789
|
}
|
|
782
790
|
state.supabase = createRunnerClient(state.cfg, state.session.access_token, state.session.realtime_config);
|
|
783
791
|
subscribeChannel(state, taskRunnerFactory);
|
|
792
|
+
// FLEET-SERVE (wire): swap the chat lane onto the spare credential too, so a
|
|
793
|
+
// failover keeps chat serving alive alongside the task lane.
|
|
794
|
+
await state.fleetChat?.refreshClient(state.supabase, state.session.access_token);
|
|
784
795
|
process.stderr.write(chalk.green(`[acc-runner] credential failover: switched to a spare token (${reason}); ` +
|
|
785
796
|
`runner ${state.session.runner_id} staying online.\n`));
|
|
786
797
|
void (async () => {
|
|
@@ -1138,6 +1149,9 @@ export async function watchCommand(options = {}) {
|
|
|
1138
1149
|
capacityBackoffMs: options.capacityBackoffMs ?? DEFAULT_CAPACITY_BACKOFF_MS,
|
|
1139
1150
|
resumeJitterMs: options.resumeJitterMs ?? DEFAULT_RESUME_JITTER_MS,
|
|
1140
1151
|
singletonLock,
|
|
1152
|
+
// FLEET-SERVE (wire): started below once the runner is online (real runs
|
|
1153
|
+
// only). Left null in tests (taskRunnerFactory injected) and when opted out.
|
|
1154
|
+
fleetChat: null,
|
|
1141
1155
|
};
|
|
1142
1156
|
// AS-3 (RESUME-WIRE): build the capacity resume governor + account-probe
|
|
1143
1157
|
// cadence NOW, before subscribeChannel / the first pump, so a capacity signal
|
|
@@ -1282,6 +1296,28 @@ export async function watchCommand(options = {}) {
|
|
|
1282
1296
|
// after the first scheduled heartbeat.
|
|
1283
1297
|
await syncConcurrency(state, taskRunnerFactory);
|
|
1284
1298
|
console.log(chalk.gray(`Runner ${state.session.runner_id} is online. Ctrl-C to stop.`));
|
|
1299
|
+
// FLEET-SERVE (wire): start fleet-fallback chat serving ALONGSIDE the task pump.
|
|
1300
|
+
// Real runs only (skipped when a taskRunnerFactory is injected, i.e. tests, so
|
|
1301
|
+
// the fleet lane never opens realtime channels / spawns engines in unit tests)
|
|
1302
|
+
// and only when not opted out via ACC_RUNNER_FLEET_CHAT=0. The chat lane shares
|
|
1303
|
+
// this runner's concurrency ceiling — `activeCodeTasks` feeds it the LIVE code
|
|
1304
|
+
// load so chat can never starve the code/review lanes. Best-effort: a startup
|
|
1305
|
+
// failure is logged and the runner carries on serving tasks.
|
|
1306
|
+
if (!options.taskRunnerFactory) {
|
|
1307
|
+
try {
|
|
1308
|
+
state.fleetChat = await startFleetChatServing({
|
|
1309
|
+
cfg: state.cfg,
|
|
1310
|
+
session: state.session,
|
|
1311
|
+
supabase: state.supabase,
|
|
1312
|
+
concurrencyLimit: state.concurrencyLimit,
|
|
1313
|
+
activeCodeTasks: () => state.running.size,
|
|
1314
|
+
onLog: (line) => console.log(chalk.gray(line)),
|
|
1315
|
+
});
|
|
1316
|
+
}
|
|
1317
|
+
catch (err) {
|
|
1318
|
+
process.stderr.write(`[acc-runner] fleet chat serving failed to start (continuing): ${err.message}\n`);
|
|
1319
|
+
}
|
|
1320
|
+
}
|
|
1285
1321
|
const stop = async () => {
|
|
1286
1322
|
if (state.stopped)
|
|
1287
1323
|
return;
|
|
@@ -1307,6 +1343,13 @@ export async function watchCommand(options = {}) {
|
|
|
1307
1343
|
for (const ctrl of state.running.values()) {
|
|
1308
1344
|
ctrl.cancel();
|
|
1309
1345
|
}
|
|
1346
|
+
// FLEET-SERVE (wire): stop the chat lane (requeues in-flight chat turns for
|
|
1347
|
+
// the companion / next fleet runner) and restore the acc-mcp config. Best-
|
|
1348
|
+
// effort so a chat-lane teardown hiccup never blocks the runner's shutdown.
|
|
1349
|
+
try {
|
|
1350
|
+
await state.fleetChat?.stop();
|
|
1351
|
+
}
|
|
1352
|
+
catch { /* best-effort */ }
|
|
1310
1353
|
try {
|
|
1311
1354
|
await state.supabase.removeChannel(state.channel);
|
|
1312
1355
|
}
|