@tangle-network/agent-app 0.60.61 → 0.60.63
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/app-auth/index.js +53 -4
- package/dist/app-auth/index.js.map +1 -1
- package/dist/assistant/index.js +7 -7
- package/dist/chat-routes/index.js +13 -13
- package/dist/chat-store/index.js +3 -3
- package/dist/chunk-5UQJ7F3P.js +41 -0
- package/dist/chunk-5UQJ7F3P.js.map +1 -0
- package/dist/{chunk-YXYQ6MJL.js → chunk-5V6VTO5Q.js} +65 -2
- package/dist/chunk-5V6VTO5Q.js.map +1 -0
- package/dist/{chunk-TZD35SBQ.js → chunk-7DG6GGRN.js} +14 -7
- package/dist/chunk-7DG6GGRN.js.map +1 -0
- package/dist/chunk-J2O76TTS.js +458 -0
- package/dist/chunk-J2O76TTS.js.map +1 -0
- package/dist/{chunk-2YLSWZ5W.js → chunk-JBEFTXDO.js} +4 -4
- package/dist/{chunk-JGZ7WEPL.js → chunk-JC7YSRBR.js} +15 -1
- package/dist/chunk-JC7YSRBR.js.map +1 -0
- package/dist/{chunk-4WJREKXX.js → chunk-O3ZM5QPC.js} +6 -6
- package/dist/{chunk-FWLCPAST.js → chunk-SH56N4PV.js} +3 -3
- package/dist/{chunk-ZGUXI5SI.js → chunk-XNKLQG26.js} +5 -5
- package/dist/chunk-Y6LE5CAW.js +503 -0
- package/dist/chunk-Y6LE5CAW.js.map +1 -0
- package/dist/design-canvas-react/index.js +4 -4
- package/dist/launch-invariants/auth-lookup-cache.d.ts +57 -0
- package/dist/launch-invariants/catalog.d.ts +51 -0
- package/dist/launch-invariants/cli.d.ts +10 -0
- package/dist/launch-invariants/cli.js +88 -0
- package/dist/launch-invariants/cli.js.map +1 -0
- package/dist/launch-invariants/conformance.d.ts +49 -0
- package/dist/launch-invariants/index.d.ts +19 -0
- package/dist/launch-invariants/index.js +253 -0
- package/dist/launch-invariants/index.js.map +1 -0
- package/dist/launch-invariants/limit-alarms.d.ts +66 -0
- package/dist/launch-invariants/schedule.d.ts +114 -0
- package/dist/launch-invariants/settlement.d.ts +90 -0
- package/dist/launch-invariants/sized-reads.d.ts +50 -0
- package/dist/launch-invariants/testing.d.ts +175 -0
- package/dist/launch-invariants/testing.js +45 -0
- package/dist/launch-invariants/testing.js.map +1 -0
- package/dist/public-consultation/index.d.ts +1 -1
- package/dist/public-consultation/index.js +7 -7
- package/dist/sandbox/index.d.ts +4 -0
- package/dist/sandbox/index.js +1 -1
- package/dist/stream/index.d.ts +1 -0
- package/dist/stream/index.js +9 -5
- package/dist/stream/orphaned-turns.d.ts +56 -0
- package/dist/stream/turn-buffer.d.ts +12 -0
- package/dist/teams/invitations-api.js +3 -3
- package/dist/turn-health/index.js +6 -17
- package/dist/turn-health/index.js.map +1 -1
- package/dist/turn-stream/index.js +1 -1
- package/dist/web-react/index.js +13 -13
- package/package.json +13 -2
- package/dist/chunk-JGZ7WEPL.js.map +0 -1
- package/dist/chunk-TZD35SBQ.js.map +0 -1
- package/dist/chunk-YXYQ6MJL.js.map +0 -1
- /package/dist/{chunk-2YLSWZ5W.js.map → chunk-JBEFTXDO.js.map} +0 -0
- /package/dist/{chunk-4WJREKXX.js.map → chunk-O3ZM5QPC.js.map} +0 -0
- /package/dist/{chunk-FWLCPAST.js.map → chunk-SH56N4PV.js.map} +0 -0
- /package/dist/{chunk-ZGUXI5SI.js.map → chunk-XNKLQG26.js.map} +0 -0
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Scheduled jobs that cannot take each other down.
|
|
3
|
+
*
|
|
4
|
+
* On 2026-10-10 at 21:00Z GTM's turn health ran out of memory while the hourly
|
|
5
|
+
* sweeps shared one scheduled run, and none of the eight queued after it ran.
|
|
6
|
+
* Here each scheduled invocation runs exactly one job. A cron can carry a
|
|
7
|
+
* minute list (`0,1,2 * * * *`) with one job per minute, so a Worker keeps a
|
|
8
|
+
* few trigger expressions while every job gets its own invocation, its own
|
|
9
|
+
* memory and its own failure.
|
|
10
|
+
*
|
|
11
|
+
* Cloudflare hands the handler the configured string verbatim as `event.cron`,
|
|
12
|
+
* so dispatch is exact-string; a tick no entry handles is reported as
|
|
13
|
+
* unhandled instead of silently running nothing. {@link checkIsolatedJobs}
|
|
14
|
+
* holds the table against the deployment's configured crons.
|
|
15
|
+
*/
|
|
16
|
+
import { type InvariantVerdict } from './catalog.js';
|
|
17
|
+
/** One cron expression and the job it runs, or one job per listed minute. */
|
|
18
|
+
export type ScheduleEntry = {
|
|
19
|
+
cron: string;
|
|
20
|
+
job: string;
|
|
21
|
+
} | {
|
|
22
|
+
cron: string;
|
|
23
|
+
minutes: Readonly<Record<number, string>>;
|
|
24
|
+
};
|
|
25
|
+
/** One scheduled invocation: the cron, the minute for a minute-list entry, and the job it runs. */
|
|
26
|
+
export interface ScheduleSlot {
|
|
27
|
+
cron: string;
|
|
28
|
+
minute?: number;
|
|
29
|
+
job: string;
|
|
30
|
+
}
|
|
31
|
+
export interface ScheduledJobInput<Ctx> {
|
|
32
|
+
cron: string;
|
|
33
|
+
scheduledTime: Date;
|
|
34
|
+
context: Ctx;
|
|
35
|
+
/** 1 for the first try. */
|
|
36
|
+
attempt: number;
|
|
37
|
+
}
|
|
38
|
+
export type ScheduledJob<Ctx> = (input: ScheduledJobInput<Ctx>) => Promise<unknown>;
|
|
39
|
+
export interface ScheduledDispatchOptions<Ctx> {
|
|
40
|
+
entries: readonly ScheduleEntry[];
|
|
41
|
+
jobs: Readonly<Record<string, ScheduledJob<Ctx>>>;
|
|
42
|
+
/** Waits before each retry of a failed job; empty (the default) runs a job once. Jobs that retry must be idempotent. */
|
|
43
|
+
retryDelaysMs?: readonly number[];
|
|
44
|
+
log?: {
|
|
45
|
+
info(message: string, detail?: Record<string, unknown>): void;
|
|
46
|
+
error(message: string, detail?: Record<string, unknown>): void;
|
|
47
|
+
};
|
|
48
|
+
/** Tests pass a no-op. */
|
|
49
|
+
sleep?: (ms: number) => Promise<void>;
|
|
50
|
+
}
|
|
51
|
+
export interface ScheduledJobOutcome {
|
|
52
|
+
job: string;
|
|
53
|
+
ok: boolean;
|
|
54
|
+
attempts: number;
|
|
55
|
+
durationMs: number;
|
|
56
|
+
error?: string;
|
|
57
|
+
}
|
|
58
|
+
export interface ScheduledDispatchResult {
|
|
59
|
+
handled: boolean;
|
|
60
|
+
job: string | null;
|
|
61
|
+
/** Settles when the job's last attempt ends; never rejects. */
|
|
62
|
+
done: Promise<ScheduledJobOutcome | null>;
|
|
63
|
+
}
|
|
64
|
+
export interface ScheduledDispatch<Ctx> {
|
|
65
|
+
readonly entries: readonly ScheduleEntry[];
|
|
66
|
+
/** Every invocation the table can make. */
|
|
67
|
+
slots(): ScheduleSlot[];
|
|
68
|
+
/** The job a tick runs, or null when no entry handles it. */
|
|
69
|
+
jobFor(cron: string, scheduledTime: number | Date): string | null;
|
|
70
|
+
/**
|
|
71
|
+
* Run the tick's one job. With `waitUntil` the job runs in the background and
|
|
72
|
+
* this returns at once; without it, this waits for the job.
|
|
73
|
+
*/
|
|
74
|
+
dispatch(event: {
|
|
75
|
+
cron: string;
|
|
76
|
+
scheduledTime: number | Date;
|
|
77
|
+
}, context: Ctx, waitUntil?: (promise: Promise<unknown>) => void): Promise<ScheduledDispatchResult>;
|
|
78
|
+
}
|
|
79
|
+
export declare function createScheduledDispatch<Ctx>(options: ScheduledDispatchOptions<Ctx>): ScheduledDispatch<Ctx>;
|
|
80
|
+
/** Every invocation a schedule table can make. */
|
|
81
|
+
export declare function slotsOf(entries: readonly ScheduleEntry[]): ScheduleSlot[];
|
|
82
|
+
/**
|
|
83
|
+
* The minutes of the day (0–1439, UTC) a cron fires, or null when it does not
|
|
84
|
+
* fire every day (a day-of-month, month or weekday restriction) or cannot be read.
|
|
85
|
+
*/
|
|
86
|
+
export declare function cronDailyFirings(cron: string): Set<number> | null;
|
|
87
|
+
/** The longest wait, in minutes, between consecutive firings over a day, or null when they do not fire daily. */
|
|
88
|
+
export declare function longestGapMinutes(firings: Iterable<number>): number | null;
|
|
89
|
+
/** The cron expressions a wrangler config declares, top level and per environment. */
|
|
90
|
+
export interface WranglerCrons {
|
|
91
|
+
top: string[];
|
|
92
|
+
envs: Record<string, string[]>;
|
|
93
|
+
}
|
|
94
|
+
/** Read `[triggers] crons` (and `[env.<name>.triggers]`) from wrangler.toml, or `triggers.crons` from wrangler.json(c). */
|
|
95
|
+
export declare function parseWranglerCrons(source: string, format: 'toml' | 'json'): WranglerCrons;
|
|
96
|
+
/** What one scheduled invocation was observed to run. */
|
|
97
|
+
export interface ObservedSlot {
|
|
98
|
+
cron: string;
|
|
99
|
+
minute?: number;
|
|
100
|
+
/** The jobs the invocation ran; exactly one passes. */
|
|
101
|
+
jobs: readonly string[];
|
|
102
|
+
}
|
|
103
|
+
export interface IsolatedJobsInput {
|
|
104
|
+
/** Every cron the deployment configures, from each wrangler environment. */
|
|
105
|
+
configuredCrons: readonly string[];
|
|
106
|
+
/** What each invocation runs: from {@link slotsOf} for a {@link createScheduledDispatch} table, or observed by driving the app's own handler. */
|
|
107
|
+
slots: readonly ObservedSlot[];
|
|
108
|
+
/** Jobs that recover and settle turns; each must run at least every 15 minutes. */
|
|
109
|
+
recoveryJobs: readonly string[];
|
|
110
|
+
/** Default {@link LAUNCH_BUDGETS.recoveryEveryMs}. */
|
|
111
|
+
everyMs?: number;
|
|
112
|
+
}
|
|
113
|
+
/** One job per invocation, the table and the deployment agree, and recovery runs at least every 15 minutes. */
|
|
114
|
+
export declare function checkIsolatedJobs(input: IsolatedJobsInput): InvariantVerdict;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Honest turn settlement, checked over a product's turn records.
|
|
3
|
+
*
|
|
4
|
+
* A turn ends in exactly one terminal state: an answer, a typed failure the
|
|
5
|
+
* person can Retry, or a Stop the person chose, counted on its own. It gets
|
|
6
|
+
* there within 15 minutes of its owner stopping. A failure belongs to the time
|
|
7
|
+
* the turn was requested, not the time it was noticed, and how late it was
|
|
8
|
+
* noticed is measured. A run that completed with a tool call the Sandbox
|
|
9
|
+
* aborted stopped mid-work, so it is a failure.
|
|
10
|
+
*
|
|
11
|
+
* On 2026-10-10 GTM held turns in five places (turn status, admissions,
|
|
12
|
+
* Workflows, Sandbox sessions and the sidecar tracker) and they disagreed:
|
|
13
|
+
* 51 stream rows stayed `running` after their producers died, failure notices
|
|
14
|
+
* arrived 8–11 hours late, and completions with aborted tools counted as
|
|
15
|
+
* answers. {@link checkTurnSettlement} reads one normalized record per turn,
|
|
16
|
+
* however the product derives it, and names every turn that breaks the rule.
|
|
17
|
+
*/
|
|
18
|
+
import { type InvariantVerdict } from './catalog.js';
|
|
19
|
+
export type TurnTerminalState = 'answered' | 'failed' | 'stopped';
|
|
20
|
+
/** One turn as its product records it, normalized. Times are Unix ms. */
|
|
21
|
+
export interface SettledTurnRecord {
|
|
22
|
+
turnId: string;
|
|
23
|
+
/** When the request was accepted (the user message was saved). */
|
|
24
|
+
requestedAt: number;
|
|
25
|
+
/** Every terminal state recorded for the turn, in order; exactly one is honest. */
|
|
26
|
+
terminals: ReadonlyArray<{
|
|
27
|
+
state: TurnTerminalState;
|
|
28
|
+
/** When the terminal state was recorded. */
|
|
29
|
+
at: number;
|
|
30
|
+
/** A typed failure code, for `failed`. */
|
|
31
|
+
code?: string;
|
|
32
|
+
/** Whether the person is offered Retry, for `failed`. */
|
|
33
|
+
retryable?: boolean;
|
|
34
|
+
/** The time the failure is reported under; it must be the request time. */
|
|
35
|
+
attributedTo?: number;
|
|
36
|
+
}>;
|
|
37
|
+
/** When the turn's owner stopped: for a leased stream, when its lease expired. Null while an owner holds it. */
|
|
38
|
+
ownerEndedAt: number | null;
|
|
39
|
+
/** A completed run in which the Sandbox aborted a tool call. */
|
|
40
|
+
abortedToolCall?: boolean;
|
|
41
|
+
}
|
|
42
|
+
export interface TurnSettlementCounts {
|
|
43
|
+
turns: number;
|
|
44
|
+
answered: number;
|
|
45
|
+
failed: number;
|
|
46
|
+
stopped: number;
|
|
47
|
+
open: number;
|
|
48
|
+
/** Most minutes between an owner stopping and its turn's terminal state. */
|
|
49
|
+
maxDetectionLagMinutes: number;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Check turn records against honest settlement at `now`.
|
|
53
|
+
* A turn still open whose owner has not stopped is fine; one whose owner stopped
|
|
54
|
+
* more than {@link LAUNCH_BUDGETS.settleWithinMs} ago is not.
|
|
55
|
+
*/
|
|
56
|
+
export declare function checkTurnSettlement(turns: readonly SettledTurnRecord[], options: {
|
|
57
|
+
now: number;
|
|
58
|
+
settleWithinMs?: number;
|
|
59
|
+
subject?: string;
|
|
60
|
+
}): InvariantVerdict;
|
|
61
|
+
/**
|
|
62
|
+
* The failure shapes GTM shipped on 2026-10-10, as scenarios a product seeds
|
|
63
|
+
* into its own storage, settles with its own scheduled jobs, and reads back as
|
|
64
|
+
* {@link SettledTurnRecord}s. `expect` is the one honest terminal state.
|
|
65
|
+
*/
|
|
66
|
+
export interface SettlementScenario {
|
|
67
|
+
id: string;
|
|
68
|
+
/** What happened to the turn, for the product's seed step. */
|
|
69
|
+
story: string;
|
|
70
|
+
/** Minutes before the check's `now` that the request was accepted. */
|
|
71
|
+
requestedMinutesAgo: number;
|
|
72
|
+
/**
|
|
73
|
+
* Minutes before `now` that the owner stopped (for a stream, its lease
|
|
74
|
+
* expired), or null for a live owner. Every scenario that stopped did so 12
|
|
75
|
+
* minutes ago, so an app that settles within 15 minutes has settled it by `now`.
|
|
76
|
+
*/
|
|
77
|
+
ownerEndedMinutesAgo: number | null;
|
|
78
|
+
expect: TurnTerminalState | 'open';
|
|
79
|
+
}
|
|
80
|
+
export declare const SETTLEMENT_SCENARIOS: readonly SettlementScenario[];
|
|
81
|
+
/**
|
|
82
|
+
* Check a product's settlement of {@link SETTLEMENT_SCENARIOS}: each scenario's
|
|
83
|
+
* record ends in its expected state, and all of them settle honestly. The
|
|
84
|
+
* product seeds each scenario at `now`, runs its own recovery and settlement
|
|
85
|
+
* jobs at `now`, and reads the records back keyed by scenario id.
|
|
86
|
+
*/
|
|
87
|
+
export declare function checkSettlementScenarios(records: Readonly<Record<string, SettledTurnRecord | undefined>>, options: {
|
|
88
|
+
now: number;
|
|
89
|
+
scenarios?: readonly SettlementScenario[];
|
|
90
|
+
}): InvariantVerdict;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reads of a large column a bounded batch at a time.
|
|
3
|
+
*
|
|
4
|
+
* On 2026-10-10 GTM's scheduled jobs exceeded the Worker's 128 MB by reading a
|
|
5
|
+
* day of stored turns at once: the outcome sweep held about 93 MB of turn
|
|
6
|
+
* events, the reliability report read 1.63 M events, and turn health read
|
|
7
|
+
* 121.8 MB of message parts in one query. D1 refuses the same read on its side
|
|
8
|
+
* with `D1_ERROR: Memory limit exceeded before EOF`.
|
|
9
|
+
*
|
|
10
|
+
* A caller lists each row's key with the stored size of its large column
|
|
11
|
+
* (SQLite `length(column)`), then reads and handles one batch before it reads
|
|
12
|
+
* the next, keeping only what it concluded (counts, verdicts) rather than the
|
|
13
|
+
* rows. Memory then holds one batch, not the day.
|
|
14
|
+
*
|
|
15
|
+
* Keep what you conclude, not what you read: a value sliced or matched out of a
|
|
16
|
+
* large string can pin the whole parent string in V8 (a regex match kept in a
|
|
17
|
+
* Map held every tool output it came from). Copy a kept substring out, e.g.
|
|
18
|
+
* `new URL(match).href` or `(' ' + text).slice(1)`, before the row goes.
|
|
19
|
+
*/
|
|
20
|
+
/** Most bytes of a large column one read returns; a single larger row is read alone. */
|
|
21
|
+
export declare const SIZED_READ_BYTES: number;
|
|
22
|
+
/** D1 binds at most 100 parameters to one query. */
|
|
23
|
+
export declare const D1_MAX_BOUND_PARAMETERS = 100;
|
|
24
|
+
/** Most single-column keys one read binds, leaving room for the query's own parameters. */
|
|
25
|
+
export declare const SIZED_READ_ROWS = 50;
|
|
26
|
+
/** Most two-column keys, such as (turnId, seq), one read binds: two parameters each. */
|
|
27
|
+
export declare const SIZED_READ_COMPOSITE_ROWS = 40;
|
|
28
|
+
/** A row's key and the stored size of its large column. */
|
|
29
|
+
export interface SizedRow<K> {
|
|
30
|
+
key: K;
|
|
31
|
+
/** `length()` of the large column; null when it is NULL. */
|
|
32
|
+
size: number | null | undefined;
|
|
33
|
+
}
|
|
34
|
+
export interface SizedBatchOptions {
|
|
35
|
+
/** Most bytes per batch. Default {@link SIZED_READ_BYTES}. */
|
|
36
|
+
bytes?: number;
|
|
37
|
+
/** Most keys per batch. Default {@link SIZED_READ_ROWS}; `Infinity` for a range read (`seq BETWEEN`). */
|
|
38
|
+
rows?: number;
|
|
39
|
+
}
|
|
40
|
+
/** Consecutive keys whose stored sizes fit one read, in their listed order. */
|
|
41
|
+
export declare function sizedBatches<K>(rows: Iterable<SizedRow<K>>, options?: SizedBatchOptions): K[][];
|
|
42
|
+
/**
|
|
43
|
+
* Read listed rows one sized batch at a time. Each batch is read only after the
|
|
44
|
+
* caller has handled the previous one, so a `for await` loop that keeps its
|
|
45
|
+
* conclusions and drops the rows holds one batch at most.
|
|
46
|
+
*/
|
|
47
|
+
export declare function readInSizedBatches<K, R>(rows: Iterable<SizedRow<K>>, read: (keys: K[]) => Promise<R>, options?: SizedBatchOptions): AsyncGenerator<{
|
|
48
|
+
keys: K[];
|
|
49
|
+
value: R;
|
|
50
|
+
}>;
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import type { AlertSink } from '../turn-health/sink.js';
|
|
2
|
+
import { type InvariantVerdict } from './catalog.js';
|
|
3
|
+
import { type LimitAlarms } from './limit-alarms.js';
|
|
4
|
+
export { describeVerdict } from './catalog.js';
|
|
5
|
+
/** Set by `agent-app-invariants` to the file it reads verdicts from. */
|
|
6
|
+
export declare const INVARIANT_RESULTS_ENV = "AGENT_APP_INVARIANTS_RESULTS";
|
|
7
|
+
/**
|
|
8
|
+
* Record a verdict for the conformance report and fail the caller when it did
|
|
9
|
+
* not pass. Returns the verdict on a pass.
|
|
10
|
+
*/
|
|
11
|
+
export declare function recordInvariant(verdict: InvariantVerdict): InvariantVerdict;
|
|
12
|
+
/** Record several verdicts; fails after recording all of them. */
|
|
13
|
+
export declare function recordInvariants(verdicts: readonly InvariantVerdict[]): InvariantVerdict[];
|
|
14
|
+
/** Run a full garbage collection, so a heap reading counts only live objects. */
|
|
15
|
+
export declare function forceGc(): void;
|
|
16
|
+
/** What a measured binding saw while one job ran. */
|
|
17
|
+
export interface D1Reads {
|
|
18
|
+
queries: number;
|
|
19
|
+
maxQueryBytes: number;
|
|
20
|
+
/** The query that returned the most bytes. */
|
|
21
|
+
largestSql: string;
|
|
22
|
+
peakHeapBytes: number;
|
|
23
|
+
/** The query running when the heap peaked: where a job holds what it read. */
|
|
24
|
+
peakSql: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* The D1 binding with every response measured (serialized bytes) and the live
|
|
28
|
+
* heap sampled after a collection before and after every query. Works over
|
|
29
|
+
* Cloudflare D1 and the sqlite-backed D1 shims apps test with. A database
|
|
30
|
+
* engine that keeps its pages off the JS heap (node:sqlite, better-sqlite3)
|
|
31
|
+
* leaves heap growth to the job's own objects.
|
|
32
|
+
*/
|
|
33
|
+
export declare function measureD1<D extends object>(d1: D, reads?: D1Reads, options?: {
|
|
34
|
+
sampleHeap?: boolean;
|
|
35
|
+
}): {
|
|
36
|
+
d1: D;
|
|
37
|
+
reads: D1Reads;
|
|
38
|
+
};
|
|
39
|
+
/** One scheduled job (or report route) as the budget check runs it. */
|
|
40
|
+
export interface BudgetedJob {
|
|
41
|
+
name: string;
|
|
42
|
+
run: () => Promise<unknown>;
|
|
43
|
+
/** False for a job that reads nothing from D1 (it then passes bounded reads vacuously). Default true. */
|
|
44
|
+
readsD1?: boolean;
|
|
45
|
+
}
|
|
46
|
+
export interface JobMeasurement {
|
|
47
|
+
name: string;
|
|
48
|
+
reads: D1Reads;
|
|
49
|
+
heapGrowthBytes: number;
|
|
50
|
+
error?: string;
|
|
51
|
+
}
|
|
52
|
+
export interface ScheduledJobBudgetOptions {
|
|
53
|
+
/** The app's D1 over its day-sized fixture. */
|
|
54
|
+
d1: object;
|
|
55
|
+
/** Point the app's database accessor at the measured binding (`setD1`, `setDatabase(drizzle(...))`). */
|
|
56
|
+
install: (measured: object) => void;
|
|
57
|
+
jobs: readonly BudgetedJob[];
|
|
58
|
+
/** Every job the app schedules, by the names {@link jobs} uses. Each must be measured. */
|
|
59
|
+
scheduled: readonly string[];
|
|
60
|
+
maxQueryBytes?: number;
|
|
61
|
+
maxHeapGrowthBytes?: number;
|
|
62
|
+
/** Silence the jobs' own logging while they run. Default true. */
|
|
63
|
+
quiet?: boolean;
|
|
64
|
+
}
|
|
65
|
+
/** Run one job against a measured binding. */
|
|
66
|
+
export declare function measureJob(job: BudgetedJob, d1: object, install: (measured: object) => void, quiet?: boolean): Promise<JobMeasurement>;
|
|
67
|
+
/**
|
|
68
|
+
* Bounded reads and the memory budget for every scheduled job, on the app's
|
|
69
|
+
* day-sized fixture. Returns a bounded-reads and a memory-budget verdict per
|
|
70
|
+
* job, and a coverage verdict naming any scheduled job that was not run.
|
|
71
|
+
*/
|
|
72
|
+
export declare function checkScheduledJobBudgets(options: ScheduledJobBudgetOptions): Promise<InvariantVerdict[]>;
|
|
73
|
+
export type StallMode = 'ok' | 'error' | 'hang';
|
|
74
|
+
/** The D1 binding with a switch that makes every query fail or never answer, as an overloaded D1 did. */
|
|
75
|
+
export declare function stallingD1<D extends object>(d1: D): {
|
|
76
|
+
d1: D;
|
|
77
|
+
stall(mode: StallMode): void;
|
|
78
|
+
readonly mode: StallMode;
|
|
79
|
+
};
|
|
80
|
+
export interface AuthStallOptions {
|
|
81
|
+
/** A label for the lookup: "session", "API key". */
|
|
82
|
+
subject: string;
|
|
83
|
+
/** Three distinct valid credentials the app's store accepts. */
|
|
84
|
+
credentials: {
|
|
85
|
+
cached: string;
|
|
86
|
+
revoked: string;
|
|
87
|
+
aged: string;
|
|
88
|
+
};
|
|
89
|
+
/** The app's real lookup: truthy when the credential is accepted. A throw or a falsy value is a refusal. */
|
|
90
|
+
verify: (credential: string) => Promise<unknown>;
|
|
91
|
+
/** The app's real revoke path (revoke the key, sign the session out). */
|
|
92
|
+
revoke: (credential: string) => Promise<void>;
|
|
93
|
+
/** Switch the D1 the lookup reads. */
|
|
94
|
+
stall: (mode: StallMode) => void;
|
|
95
|
+
/** The keys the app's auth caches hold. */
|
|
96
|
+
cacheKeys: () => string[];
|
|
97
|
+
/** Include a stall that never answers (costs one lookup deadline, 2.5 s). Default true. */
|
|
98
|
+
hang?: boolean;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* A verified credential keeps working while D1 errors or stalls; it is refused
|
|
102
|
+
* once revoked, and once its last verification is more than 60 s old; and the
|
|
103
|
+
* cache holds SHA-256 keys, not secrets. Uses the app's real lookup, revoke
|
|
104
|
+
* path and D1, with `Date.now` moved forward to age the cache.
|
|
105
|
+
*/
|
|
106
|
+
export declare function checkAuthSurvivesStall(options: AuthStallOptions): Promise<InvariantVerdict>;
|
|
107
|
+
export interface AuthorizeBeforeStreamOptions {
|
|
108
|
+
subject: string;
|
|
109
|
+
/** The app's real route handler, as its router mounts it. */
|
|
110
|
+
handle: (request: Request) => Promise<Response>;
|
|
111
|
+
/** Requests the route must refuse: no session, another workspace's thread, a revoked key. */
|
|
112
|
+
refused: ReadonlyArray<{
|
|
113
|
+
name: string;
|
|
114
|
+
request: () => Request;
|
|
115
|
+
status?: readonly number[];
|
|
116
|
+
}>;
|
|
117
|
+
/** Product state the route touched (rows written, producers started); empty after every refusal. */
|
|
118
|
+
touched?: () => readonly string[];
|
|
119
|
+
}
|
|
120
|
+
/** Each refused request gets a plain 4xx, opens no stream and touches nothing. */
|
|
121
|
+
export declare function checkAuthorizeBeforeStream(options: AuthorizeBeforeStreamOptions): Promise<InvariantVerdict>;
|
|
122
|
+
/** One event of the recorded long turn and the turn-relative time it arrived. */
|
|
123
|
+
export interface TimedTurnEvent {
|
|
124
|
+
atMs: number;
|
|
125
|
+
event: Record<string, unknown>;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* The long turn GTM recorded on 2026-10-10, reproduced in shape: a reasoning
|
|
129
|
+
* model streaming three events per token (the harness's raw part update, a
|
|
130
|
+
* model-processing heartbeat and the delta), with tool calls between runs of
|
|
131
|
+
* reasoning and text. 59,659 events over about ten minutes, as that turn wrote
|
|
132
|
+
* them before coalescing.
|
|
133
|
+
*/
|
|
134
|
+
export declare function recordedLongTurn(options?: {
|
|
135
|
+
tokens?: number;
|
|
136
|
+
toolCalls?: number;
|
|
137
|
+
tokenMs?: number;
|
|
138
|
+
}): TimedTurnEvent[];
|
|
139
|
+
export interface CoalescedTurnOptions {
|
|
140
|
+
subject: string;
|
|
141
|
+
/**
|
|
142
|
+
* Start persisting one turn through the app's real turn persistence (its turn
|
|
143
|
+
* store and buffer, as its chat route builds them). `detach` hands the turn
|
|
144
|
+
* to a durable owner the way the route's completion handoff does; omit it when
|
|
145
|
+
* the app has no detached lane.
|
|
146
|
+
*/
|
|
147
|
+
open: (turnId: string) => Promise<{
|
|
148
|
+
onEvent(event: unknown): Promise<void>;
|
|
149
|
+
detach?(): Promise<void>;
|
|
150
|
+
done(): Promise<void>;
|
|
151
|
+
}>;
|
|
152
|
+
/** Stored events for the turn. */
|
|
153
|
+
count: (turnId: string) => Promise<number>;
|
|
154
|
+
maxEvents?: number;
|
|
155
|
+
fixture?: readonly TimedTurnEvent[];
|
|
156
|
+
}
|
|
157
|
+
/** The recorded long turn stores at most 5,000 events, attached and after a handoff. */
|
|
158
|
+
export declare function checkCoalescedTurn(options: CoalescedTurnOptions): Promise<InvariantVerdict>;
|
|
159
|
+
/** Hard platform limits a declared budget may not exceed. */
|
|
160
|
+
export declare const PLATFORM_LIMITS: {
|
|
161
|
+
/** A Worker isolate's memory. */
|
|
162
|
+
readonly 'worker-memory': number;
|
|
163
|
+
/** Platform snapshots per sandbox; the cap GTM hit on 2026-10-10. */
|
|
164
|
+
readonly 'snapshot-count': 25;
|
|
165
|
+
/** Requests per minute per operator key. */
|
|
166
|
+
readonly 'key-rate': 60;
|
|
167
|
+
};
|
|
168
|
+
export interface LimitAlarmCheckOptions {
|
|
169
|
+
subject: string;
|
|
170
|
+
/** Build the app's real limit alarms (its budgets and wiring) over a capturing sink. */
|
|
171
|
+
create: (sink: AlertSink) => LimitAlarms | Promise<LimitAlarms>;
|
|
172
|
+
}
|
|
173
|
+
/** Every resource alarms at 80% and not below, escalates at the limit, and no budget exceeds the platform's. */
|
|
174
|
+
export declare function checkLimitAlarms(options: LimitAlarmCheckOptions): Promise<InvariantVerdict>;
|
|
175
|
+
export { buildConformanceReport, formatConformanceReport, readDeploymentFacts, readVerdicts, type ConformanceReport, type DeploymentFacts, type InvariantReport, type InvariantStatus, type LaunchInvariantsConfig, } from './conformance.js';
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import {
|
|
2
|
+
INVARIANT_RESULTS_ENV,
|
|
3
|
+
PLATFORM_LIMITS,
|
|
4
|
+
buildConformanceReport,
|
|
5
|
+
checkAuthSurvivesStall,
|
|
6
|
+
checkAuthorizeBeforeStream,
|
|
7
|
+
checkCoalescedTurn,
|
|
8
|
+
checkLimitAlarms,
|
|
9
|
+
checkScheduledJobBudgets,
|
|
10
|
+
forceGc,
|
|
11
|
+
formatConformanceReport,
|
|
12
|
+
measureD1,
|
|
13
|
+
measureJob,
|
|
14
|
+
readDeploymentFacts,
|
|
15
|
+
readVerdicts,
|
|
16
|
+
recordInvariant,
|
|
17
|
+
recordInvariants,
|
|
18
|
+
recordedLongTurn,
|
|
19
|
+
stallingD1
|
|
20
|
+
} from "../chunk-Y6LE5CAW.js";
|
|
21
|
+
import {
|
|
22
|
+
describeVerdict
|
|
23
|
+
} from "../chunk-J2O76TTS.js";
|
|
24
|
+
export {
|
|
25
|
+
INVARIANT_RESULTS_ENV,
|
|
26
|
+
PLATFORM_LIMITS,
|
|
27
|
+
buildConformanceReport,
|
|
28
|
+
checkAuthSurvivesStall,
|
|
29
|
+
checkAuthorizeBeforeStream,
|
|
30
|
+
checkCoalescedTurn,
|
|
31
|
+
checkLimitAlarms,
|
|
32
|
+
checkScheduledJobBudgets,
|
|
33
|
+
describeVerdict,
|
|
34
|
+
forceGc,
|
|
35
|
+
formatConformanceReport,
|
|
36
|
+
measureD1,
|
|
37
|
+
measureJob,
|
|
38
|
+
readDeploymentFacts,
|
|
39
|
+
readVerdicts,
|
|
40
|
+
recordInvariant,
|
|
41
|
+
recordInvariants,
|
|
42
|
+
recordedLongTurn,
|
|
43
|
+
stallingD1
|
|
44
|
+
};
|
|
45
|
+
//# sourceMappingURL=testing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -121,9 +121,9 @@ export declare function createPublicConsultation(options: PublicConsultationOpti
|
|
|
121
121
|
executionBudget?: ChatTurnExecutionLimits;
|
|
122
122
|
maxOutputTokens?: number;
|
|
123
123
|
}) => Promise<{
|
|
124
|
+
start?: undefined;
|
|
124
125
|
status: 'unsupported';
|
|
125
126
|
reason: string;
|
|
126
|
-
start?: undefined;
|
|
127
127
|
} | {
|
|
128
128
|
reason?: undefined;
|
|
129
129
|
status: 'prepared';
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createChatTurnRoutes,
|
|
3
3
|
streamChatRouteAsSandboxEvents
|
|
4
|
-
} from "../chunk-
|
|
5
|
-
import "../chunk-Q7WEEN7P.js";
|
|
4
|
+
} from "../chunk-SH56N4PV.js";
|
|
6
5
|
import "../chunk-UTAIRVOK.js";
|
|
7
6
|
import "../chunk-RN4WPTBH.js";
|
|
7
|
+
import "../chunk-Q7WEEN7P.js";
|
|
8
8
|
import "../chunk-3NCPXNBZ.js";
|
|
9
|
-
import "../chunk-
|
|
9
|
+
import "../chunk-JBEFTXDO.js";
|
|
10
10
|
import "../chunk-ZVEEWGDK.js";
|
|
11
11
|
import "../chunk-6E7LKHYV.js";
|
|
12
12
|
import "../chunk-TXD5HXLE.js";
|
|
13
|
-
import "../chunk-
|
|
13
|
+
import "../chunk-5V6VTO5Q.js";
|
|
14
14
|
import "../chunk-YG66IHDU.js";
|
|
15
|
-
import "../chunk-
|
|
16
|
-
import "../chunk-6VQCFJWP.js";
|
|
15
|
+
import "../chunk-XNKLQG26.js";
|
|
17
16
|
import "../chunk-LQYIBL3G.js";
|
|
18
|
-
import "../chunk-
|
|
17
|
+
import "../chunk-6VQCFJWP.js";
|
|
18
|
+
import "../chunk-JC7YSRBR.js";
|
|
19
19
|
|
|
20
20
|
// src/public-consultation/index.ts
|
|
21
21
|
import { searchKnowledge } from "@tangle-network/agent-knowledge";
|
package/dist/sandbox/index.d.ts
CHANGED
|
@@ -278,6 +278,10 @@ export interface EnsureWorkspaceSandboxOptions {
|
|
|
278
278
|
onProgress?: (event: ProvisionEvent) => void;
|
|
279
279
|
billingOwnerId?: string;
|
|
280
280
|
spend?: SandboxSpendHooks;
|
|
281
|
+
/** Optional stage timing for the steps of an ensure (`sandbox.ensure.*`), so a
|
|
282
|
+
* product can see which round trip a slow acquisition spent its time in.
|
|
283
|
+
* Omitted, nothing is measured. */
|
|
284
|
+
measure?: <T>(stage: string, operation: () => Promise<T>) => Promise<T>;
|
|
281
285
|
}
|
|
282
286
|
/** What `/sandbox` reports once a box is provisioned, reused, or resumed. */
|
|
283
287
|
export interface SandboxProvisionedObservation {
|
package/dist/sandbox/index.js
CHANGED
package/dist/stream/index.d.ts
CHANGED
package/dist/stream/index.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
|
+
ORPHANED_TURN_CODE,
|
|
2
3
|
consumeTurnStream,
|
|
3
4
|
observeTurnEvent,
|
|
4
|
-
parseTurnObservation
|
|
5
|
-
|
|
5
|
+
parseTurnObservation,
|
|
6
|
+
settleOrphanedTurns
|
|
7
|
+
} from "../chunk-5V6VTO5Q.js";
|
|
6
8
|
import {
|
|
7
9
|
buildUserTextParts,
|
|
8
10
|
messageHasTurnId,
|
|
@@ -30,9 +32,9 @@ import {
|
|
|
30
32
|
terminalizeDanglingAssistantToolUpdates,
|
|
31
33
|
terminalizeDanglingToolPart,
|
|
32
34
|
terminalizeDanglingToolParts
|
|
33
|
-
} from "../chunk-
|
|
34
|
-
import "../chunk-6VQCFJWP.js";
|
|
35
|
+
} from "../chunk-XNKLQG26.js";
|
|
35
36
|
import "../chunk-LQYIBL3G.js";
|
|
37
|
+
import "../chunk-6VQCFJWP.js";
|
|
36
38
|
import {
|
|
37
39
|
DEFAULT_RUNNING_TURN_LEASE_MS,
|
|
38
40
|
DEFAULT_RUNNING_TURN_RENEW_INTERVAL_MS,
|
|
@@ -49,12 +51,13 @@ import {
|
|
|
49
51
|
pumpBufferedTurn,
|
|
50
52
|
replayTurnEvents,
|
|
51
53
|
stampReplaySeq
|
|
52
|
-
} from "../chunk-
|
|
54
|
+
} from "../chunk-JC7YSRBR.js";
|
|
53
55
|
export {
|
|
54
56
|
DEFAULT_RUNNING_TURN_LEASE_MS,
|
|
55
57
|
DEFAULT_RUNNING_TURN_RENEW_INTERVAL_MS,
|
|
56
58
|
MISSING_TOOL_TERMINAL_ERROR,
|
|
57
59
|
MISSING_TOOL_TERMINAL_REASON,
|
|
60
|
+
ORPHANED_TURN_CODE,
|
|
58
61
|
TURN_EVENTS_MIGRATION_SQL,
|
|
59
62
|
TURN_STATUS_LEASE_MIGRATION_SQL,
|
|
60
63
|
TURN_STATUS_RETENTION_MIGRATION_SQL,
|
|
@@ -89,6 +92,7 @@ export {
|
|
|
89
92
|
resolveChatTurn,
|
|
90
93
|
resolveToolId,
|
|
91
94
|
resolveToolName,
|
|
95
|
+
settleOrphanedTurns,
|
|
92
96
|
stampReplaySeq,
|
|
93
97
|
terminalizeDanglingAssistantToolUpdates,
|
|
94
98
|
terminalizeDanglingToolPart,
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Settle turn streams whose owner is gone.
|
|
3
|
+
*
|
|
4
|
+
* A running turn row is a lease: the buffer renews it every 30 s while a
|
|
5
|
+
* producer lives, and a durable observer renews it on each pass. A row nothing
|
|
6
|
+
* renewed past its lease has no producer left; the Worker that streamed it
|
|
7
|
+
* died. Left alone it stays `running` forever: a reconnecting client waits on
|
|
8
|
+
* it, discovery offers it, and reports count it as in flight. On 2026-10-10
|
|
9
|
+
* GTM held 51 such rows, some for hours, and its failure notices arrived 8–11 h
|
|
10
|
+
* after the turns had stopped.
|
|
11
|
+
*
|
|
12
|
+
* {@link settleOrphanedTurns} ends each one the way the buffer ends a failed
|
|
13
|
+
* turn: a terminal `error` event naming the phase it stopped in, then status
|
|
14
|
+
* `error`, written only while the row is still running and still stale, and
|
|
15
|
+
* without moving its update time (reports place a stream by it). It returns
|
|
16
|
+
* each turn's detection lag, the time from its lease expiring to this
|
|
17
|
+
* settlement, so a product can report how late it noticed. Run it from its own
|
|
18
|
+
* scheduled invocation at least every 15 minutes.
|
|
19
|
+
*/
|
|
20
|
+
import { type StaleRunningTurn, type TurnEventStore } from './turn-buffer';
|
|
21
|
+
/** The failure code carried by the terminal event of a settled orphan. */
|
|
22
|
+
export declare const ORPHANED_TURN_CODE = "turn.orphaned";
|
|
23
|
+
export interface SettleOrphanedTurnsOptions {
|
|
24
|
+
store: TurnEventStore;
|
|
25
|
+
now?: number;
|
|
26
|
+
/** A row older than this since its last renewal is orphaned. Default the running lease, 5 minutes. */
|
|
27
|
+
staleAfterMs?: number;
|
|
28
|
+
/** Most rows settled per run; the next run takes the rest. Default 50. */
|
|
29
|
+
limit?: number;
|
|
30
|
+
/**
|
|
31
|
+
* Whether something still owns this turn although it stopped renewing the
|
|
32
|
+
* row, such as an open completion admission with a live lease. An owned turn
|
|
33
|
+
* is skipped. A product whose durable owner does not renew the row must
|
|
34
|
+
* answer this, or its live turns are settled as orphans.
|
|
35
|
+
*/
|
|
36
|
+
isOwned?: (turn: StaleRunningTurn) => Promise<boolean>;
|
|
37
|
+
}
|
|
38
|
+
export interface SettledOrphanedTurn {
|
|
39
|
+
turnId: string;
|
|
40
|
+
scopeId: string | null;
|
|
41
|
+
/** Unix ms the row was last renewed. */
|
|
42
|
+
lastRenewedAt: number;
|
|
43
|
+
/** From its lease expiring to this settlement. */
|
|
44
|
+
detectionLagMs: number;
|
|
45
|
+
/** The run phase the stream last reported, when it reported one. */
|
|
46
|
+
phase: string | null;
|
|
47
|
+
}
|
|
48
|
+
export interface SettleOrphanedTurnsResult {
|
|
49
|
+
settled: SettledOrphanedTurn[];
|
|
50
|
+
/** Stale rows an owner still held. */
|
|
51
|
+
owned: string[];
|
|
52
|
+
/** Most detection lag among the settled turns, in ms. */
|
|
53
|
+
maxDetectionLagMs: number;
|
|
54
|
+
}
|
|
55
|
+
/** End every running turn stream nothing has renewed past its lease. */
|
|
56
|
+
export declare function settleOrphanedTurns(options: SettleOrphanedTurnsOptions): Promise<SettleOrphanedTurnsResult>;
|
|
@@ -59,6 +59,18 @@ export interface TurnEventStore {
|
|
|
59
59
|
/** Remove terminal turns whose status was updated before `before` (Unix
|
|
60
60
|
* milliseconds or a Date). Running turns are never eligible. */
|
|
61
61
|
pruneTerminalTurns?(before: number | Date): Promise<number>;
|
|
62
|
+
/** Running turns last renewed before `before` (Unix ms), oldest first, at most
|
|
63
|
+
* `limit`: the candidates {@link settleOrphanedTurns} settles. */
|
|
64
|
+
listStaleRunning?(before: number, limit: number): Promise<StaleRunningTurn[]>;
|
|
65
|
+
/** The last `count` events of a turn, newest first; a bounded read of the tail. */
|
|
66
|
+
readTail?(turnId: string, count: number): Promise<BufferedTurnEvent[]>;
|
|
67
|
+
}
|
|
68
|
+
/** A running turn nothing has renewed since `updatedAt`. */
|
|
69
|
+
export interface StaleRunningTurn {
|
|
70
|
+
turnId: string;
|
|
71
|
+
scopeId: string | null;
|
|
72
|
+
/** Unix ms of the last status write. */
|
|
73
|
+
updatedAt: number;
|
|
62
74
|
}
|
|
63
75
|
/**
|
|
64
76
|
* Settling a stream nothing produces any more. A sweep that ends an orphaned
|