@peakflo/agent-harness 0.2.24-rc.2 → 0.2.25-rc.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.
- package/dist/contract.d.ts +8 -0
- package/dist/contract.js +13 -0
- package/dist/control-plane.d.ts +4 -0
- package/dist/control-plane.js +7 -3
- package/dist/runtime/postgres-safe-text.d.ts +42 -0
- package/dist/runtime/postgres-safe-text.js +121 -0
- package/dist/runtime/session-runner.d.ts +6 -0
- package/dist/runtime/session-runner.js +72 -3
- package/package.json +1 -1
package/dist/contract.d.ts
CHANGED
|
@@ -110,6 +110,12 @@ export declare function isProtocolSupported(peerProtocolVersion: unknown, floor?
|
|
|
110
110
|
*/
|
|
111
111
|
export declare const FINAL_HTTP_STATUSES: readonly number[];
|
|
112
112
|
export declare function isFinalStatus(status: number): boolean;
|
|
113
|
+
/**
|
|
114
|
+
* `/ingest` only: every 4xx is final except 408 (timeout) and 429 (rate
|
|
115
|
+
* limit). A 4xx there is about the batch itself, so the same bytes would get
|
|
116
|
+
* the same answer. Other routes keep `FINAL_HTTP_STATUSES`.
|
|
117
|
+
*/
|
|
118
|
+
export declare function isFinalIngestStatus(status: number): boolean;
|
|
113
119
|
/** Stable, machine-readable error codes. */
|
|
114
120
|
export declare const CONTRACT_ERROR_CODES: {
|
|
115
121
|
readonly protocolUnsupported: "protocol_version_unsupported";
|
|
@@ -124,6 +130,8 @@ export declare const CONTRACT_ERROR_CODES: {
|
|
|
124
130
|
readonly leaseExpired: "lease_expired";
|
|
125
131
|
readonly leaseNotOwned: "lease_not_owned";
|
|
126
132
|
readonly sessionUnknown: "session_unknown";
|
|
133
|
+
/** `/ingest`: the batch holds text Postgres cannot store. Not retryable. */
|
|
134
|
+
readonly invalidTranscriptEncoding: "invalid_transcript_encoding";
|
|
127
135
|
readonly rateLimited: "rate_limited";
|
|
128
136
|
};
|
|
129
137
|
/**
|
package/dist/contract.js
CHANGED
|
@@ -12,6 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.EPHEMERAL_PART_TYPES = exports.PERSISTED_PART_TYPES = exports.ROUTES = exports.MAX_INGEST_PARTS = exports.MAX_INGEST_PART_BYTES = exports.DEFAULT_BASE_DELAY_MS = exports.DEFAULT_MAX_ATTEMPTS = exports.DEFAULT_LEASE_TTL_MS = exports.MISSED_HEARTBEATS_BEFORE_OFFLINE = exports.DEFAULT_HEARTBEAT_INTERVAL_MS = exports.MAX_LEASE_WAIT_SECONDS = exports.DEFAULT_LEASE_WAIT_SECONDS = exports.CONTRACT_ERROR_CODES = exports.FINAL_HTTP_STATUSES = exports.PROTOCOL_VERSION_HEADER = exports.MIN_SUPPORTED_PROTOCOL_VERSION = exports.HARNESS_UPGRADE_EXIT_CODE = exports.MIN_PROTOCOL_VERSION_FOR_NO_CEILING = exports.PROTOCOL_VERSION = void 0;
|
|
13
13
|
exports.isProtocolSupported = isProtocolSupported;
|
|
14
14
|
exports.isFinalStatus = isFinalStatus;
|
|
15
|
+
exports.isFinalIngestStatus = isFinalIngestStatus;
|
|
15
16
|
exports.ingestPartByteLength = ingestPartByteLength;
|
|
16
17
|
exports.isEphemeralPartType = isEphemeralPartType;
|
|
17
18
|
exports.isPersistablePart = isPersistablePart;
|
|
@@ -133,6 +134,16 @@ exports.FINAL_HTTP_STATUSES = [
|
|
|
133
134
|
function isFinalStatus(status) {
|
|
134
135
|
return exports.FINAL_HTTP_STATUSES.includes(status);
|
|
135
136
|
}
|
|
137
|
+
/**
|
|
138
|
+
* `/ingest` only: every 4xx is final except 408 (timeout) and 429 (rate
|
|
139
|
+
* limit). A 4xx there is about the batch itself, so the same bytes would get
|
|
140
|
+
* the same answer. Other routes keep `FINAL_HTTP_STATUSES`.
|
|
141
|
+
*/
|
|
142
|
+
function isFinalIngestStatus(status) {
|
|
143
|
+
if (isFinalStatus(status))
|
|
144
|
+
return true;
|
|
145
|
+
return status >= 400 && status < 500 && status !== 408 && status !== 429;
|
|
146
|
+
}
|
|
136
147
|
/** Stable, machine-readable error codes. */
|
|
137
148
|
exports.CONTRACT_ERROR_CODES = {
|
|
138
149
|
protocolUnsupported: 'protocol_version_unsupported',
|
|
@@ -147,6 +158,8 @@ exports.CONTRACT_ERROR_CODES = {
|
|
|
147
158
|
leaseExpired: 'lease_expired',
|
|
148
159
|
leaseNotOwned: 'lease_not_owned',
|
|
149
160
|
sessionUnknown: 'session_unknown',
|
|
161
|
+
/** `/ingest`: the batch holds text Postgres cannot store. Not retryable. */
|
|
162
|
+
invalidTranscriptEncoding: 'invalid_transcript_encoding',
|
|
150
163
|
rateLimited: 'rate_limited'
|
|
151
164
|
};
|
|
152
165
|
/* -------------------------------------------------------------------------- */
|
package/dist/control-plane.d.ts
CHANGED
|
@@ -155,6 +155,10 @@ export declare class ControlPlaneClient {
|
|
|
155
155
|
* visible product defect — the user watches text stop arriving. Retrying is
|
|
156
156
|
* safe: the upsert is keyed on (sessionId, partId), so a replayed batch is
|
|
157
157
|
* idempotent.
|
|
158
|
+
*
|
|
159
|
+
* EVERY 4xx IS FINAL HERE except 408 and 429. A 4xx says THIS BATCH is
|
|
160
|
+
* wrong (400 invalid body or text, 413 too large, 422), and sending the
|
|
161
|
+
* same bytes five more times over ~31 s cannot change that answer.
|
|
158
162
|
*/
|
|
159
163
|
ingest(sessionId: string, request: Omit<IngestRequest, 'protocolVersion'>): Promise<IngestResponse>;
|
|
160
164
|
acknowledgeSteer(sessionId: string, leaseId: string, turnId: string, consumed: boolean): Promise<{
|
package/dist/control-plane.js
CHANGED
|
@@ -328,6 +328,10 @@ class ControlPlaneClient {
|
|
|
328
328
|
* visible product defect — the user watches text stop arriving. Retrying is
|
|
329
329
|
* safe: the upsert is keyed on (sessionId, partId), so a replayed batch is
|
|
330
330
|
* idempotent.
|
|
331
|
+
*
|
|
332
|
+
* EVERY 4xx IS FINAL HERE except 408 and 429. A 4xx says THIS BATCH is
|
|
333
|
+
* wrong (400 invalid body or text, 413 too large, 422), and sending the
|
|
334
|
+
* same bytes five more times over ~31 s cannot change that answer.
|
|
331
335
|
*/
|
|
332
336
|
async ingest(sessionId, request) {
|
|
333
337
|
return this.withRetry('ingest', () => this.send({
|
|
@@ -335,7 +339,7 @@ class ControlPlaneClient {
|
|
|
335
339
|
path: contract_1.ROUTES.ingest(sessionId),
|
|
336
340
|
token: this.requireCredential(),
|
|
337
341
|
body: { protocolVersion: contract_1.PROTOCOL_VERSION, ...request }
|
|
338
|
-
}));
|
|
342
|
+
}), contract_1.isFinalIngestStatus);
|
|
339
343
|
}
|
|
340
344
|
async acknowledgeSteer(sessionId, leaseId, turnId, consumed) {
|
|
341
345
|
return this.withRetry('steer-ack', () => this.send({
|
|
@@ -443,7 +447,7 @@ class ControlPlaneClient {
|
|
|
443
447
|
* `FINAL_HTTP_STATUSES` is shared with the control plane instead of being
|
|
444
448
|
* retyped on each side.
|
|
445
449
|
*/
|
|
446
|
-
async withRetry(label, attemptFn) {
|
|
450
|
+
async withRetry(label, attemptFn, isFinal = contract_1.isFinalStatus) {
|
|
447
451
|
let lastError;
|
|
448
452
|
for (let attempt = 1; attempt <= this.maxAttempts; attempt += 1) {
|
|
449
453
|
try {
|
|
@@ -451,7 +455,7 @@ class ControlPlaneClient {
|
|
|
451
455
|
}
|
|
452
456
|
catch (error) {
|
|
453
457
|
lastError = error;
|
|
454
|
-
if (error instanceof ControlPlaneError && error.
|
|
458
|
+
if (error instanceof ControlPlaneError && isFinal(error.status)) {
|
|
455
459
|
throw error;
|
|
456
460
|
}
|
|
457
461
|
if (attempt < this.maxAttempts) {
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MAKE A VALUE STORABLE IN A POSTGRES `text` OR `jsonb` COLUMN.
|
|
3
|
+
*
|
|
4
|
+
* JavaScript strings can hold two things that PostgreSQL refuses:
|
|
5
|
+
*
|
|
6
|
+
* - U+0000 (NUL). A `text` parameter containing it fails with 22021
|
|
7
|
+
* ("invalid byte sequence for encoding UTF8: 0x00"); the same character
|
|
8
|
+
* inside JSON (`\u0000`) cast to `jsonb` fails with 22P05 ("unsupported
|
|
9
|
+
* Unicode escape sequence").
|
|
10
|
+
* - A LONE UTF-16 surrogate (a high surrogate not followed by a low one, or
|
|
11
|
+
* a low one not preceded by a high one). `JSON.stringify` writes it as a
|
|
12
|
+
* `\udXXX` escape and `jsonb` rejects that escape with 22P02.
|
|
13
|
+
*
|
|
14
|
+
* Both turn up in ordinary agent output: terminal captures, binary file reads
|
|
15
|
+
* and tool results cut in the middle of an emoji. One such character used to
|
|
16
|
+
* fail the WHOLE `/ingest` batch with a 500, so the turn lost its transcript.
|
|
17
|
+
*
|
|
18
|
+
* This removes NUL and replaces each lone surrogate with U+FFFD. Valid
|
|
19
|
+
* surrogate pairs (emoji) and every other character are unchanged. Object KEYS
|
|
20
|
+
* are cleaned as well as values, because a key is serialised into the same
|
|
21
|
+
* JSON. Nothing is copied when nothing changes.
|
|
22
|
+
*
|
|
23
|
+
* The counts are for a log line or a metric. Never log the content itself.
|
|
24
|
+
*/
|
|
25
|
+
export interface PostgresTextSanitizeResult<T> {
|
|
26
|
+
value: T;
|
|
27
|
+
/** NUL characters removed. */
|
|
28
|
+
nulBytes: number;
|
|
29
|
+
/** Lone surrogates replaced with U+FFFD. */
|
|
30
|
+
loneSurrogates: number;
|
|
31
|
+
/** `nulBytes + loneSurrogates`. Zero means `value` is the input, unchanged. */
|
|
32
|
+
replacements: number;
|
|
33
|
+
}
|
|
34
|
+
export interface PostgresTextCounts {
|
|
35
|
+
nulBytes: number;
|
|
36
|
+
loneSurrogates: number;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Clean a string, array or plain object (recursively, keys and values) so
|
|
40
|
+
* Postgres accepts it in `text` and `jsonb`. See the file comment.
|
|
41
|
+
*/
|
|
42
|
+
export declare function sanitizeForPostgres<T>(value: T): PostgresTextSanitizeResult<T>;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* A COPY of `packages/core/src/utils/postgres-text.ts` (sanitizer half).
|
|
4
|
+
*
|
|
5
|
+
* The harness is published on its own and does not depend on
|
|
6
|
+
* `@pf-workflo/core`, so it cannot import the server's helper. Keep the two in
|
|
7
|
+
* step; `postgres-safe-text.test.ts` pins the same cases on both sides.
|
|
8
|
+
*
|
|
9
|
+
* The harness cleans every batch before `/ingest` so a NUL in a tool result
|
|
10
|
+
* cannot fail the batch even against a control plane that does not clean it.
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* MAKE A VALUE STORABLE IN A POSTGRES `text` OR `jsonb` COLUMN.
|
|
14
|
+
*
|
|
15
|
+
* JavaScript strings can hold two things that PostgreSQL refuses:
|
|
16
|
+
*
|
|
17
|
+
* - U+0000 (NUL). A `text` parameter containing it fails with 22021
|
|
18
|
+
* ("invalid byte sequence for encoding UTF8: 0x00"); the same character
|
|
19
|
+
* inside JSON (`\u0000`) cast to `jsonb` fails with 22P05 ("unsupported
|
|
20
|
+
* Unicode escape sequence").
|
|
21
|
+
* - A LONE UTF-16 surrogate (a high surrogate not followed by a low one, or
|
|
22
|
+
* a low one not preceded by a high one). `JSON.stringify` writes it as a
|
|
23
|
+
* `\udXXX` escape and `jsonb` rejects that escape with 22P02.
|
|
24
|
+
*
|
|
25
|
+
* Both turn up in ordinary agent output: terminal captures, binary file reads
|
|
26
|
+
* and tool results cut in the middle of an emoji. One such character used to
|
|
27
|
+
* fail the WHOLE `/ingest` batch with a 500, so the turn lost its transcript.
|
|
28
|
+
*
|
|
29
|
+
* This removes NUL and replaces each lone surrogate with U+FFFD. Valid
|
|
30
|
+
* surrogate pairs (emoji) and every other character are unchanged. Object KEYS
|
|
31
|
+
* are cleaned as well as values, because a key is serialised into the same
|
|
32
|
+
* JSON. Nothing is copied when nothing changes.
|
|
33
|
+
*
|
|
34
|
+
* The counts are for a log line or a metric. Never log the content itself.
|
|
35
|
+
*/
|
|
36
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
+
exports.sanitizeForPostgres = sanitizeForPostgres;
|
|
38
|
+
/** Fast check: does the string contain NUL or ANY surrogate (paired or not)? */
|
|
39
|
+
// eslint-disable-next-line no-control-regex
|
|
40
|
+
const SUSPECT = /[\u0000\uD800-\uDFFF]/;
|
|
41
|
+
/*
|
|
42
|
+
* No `u` flag on purpose: the pattern must see UTF-16 code units, so that a
|
|
43
|
+
* lone surrogate is a single match. A high surrogate is lone when no low one
|
|
44
|
+
* follows; a low surrogate is lone when no high one comes before it.
|
|
45
|
+
*/
|
|
46
|
+
const INVALID =
|
|
47
|
+
// eslint-disable-next-line no-control-regex
|
|
48
|
+
/\u0000|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/g;
|
|
49
|
+
function cleanString(input, counts) {
|
|
50
|
+
if (!SUSPECT.test(input))
|
|
51
|
+
return input;
|
|
52
|
+
let changed = false;
|
|
53
|
+
const output = input.replace(INVALID, (match) => {
|
|
54
|
+
changed = true;
|
|
55
|
+
if (match === '\u0000') {
|
|
56
|
+
counts.nulBytes += 1;
|
|
57
|
+
return '';
|
|
58
|
+
}
|
|
59
|
+
counts.loneSurrogates += 1;
|
|
60
|
+
return '�';
|
|
61
|
+
});
|
|
62
|
+
return changed ? output : input;
|
|
63
|
+
}
|
|
64
|
+
function isPlainObject(value) {
|
|
65
|
+
if (value === null || typeof value !== 'object')
|
|
66
|
+
return false;
|
|
67
|
+
const proto = Object.getPrototypeOf(value);
|
|
68
|
+
return proto === Object.prototype || proto === null;
|
|
69
|
+
}
|
|
70
|
+
function walk(value, counts) {
|
|
71
|
+
if (typeof value === 'string')
|
|
72
|
+
return cleanString(value, counts);
|
|
73
|
+
if (Array.isArray(value)) {
|
|
74
|
+
let copy = null;
|
|
75
|
+
for (let i = 0; i < value.length; i += 1) {
|
|
76
|
+
const next = walk(value[i], counts);
|
|
77
|
+
if (next !== value[i]) {
|
|
78
|
+
copy ??= value.slice();
|
|
79
|
+
copy[i] = next;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return copy ?? value;
|
|
83
|
+
}
|
|
84
|
+
if (isPlainObject(value)) {
|
|
85
|
+
let changed = false;
|
|
86
|
+
const entries = [];
|
|
87
|
+
for (const [key, item] of Object.entries(value)) {
|
|
88
|
+
const nextKey = cleanString(key, counts);
|
|
89
|
+
const nextItem = walk(item, counts);
|
|
90
|
+
if (nextKey !== key || nextItem !== item)
|
|
91
|
+
changed = true;
|
|
92
|
+
entries.push([nextKey, nextItem]);
|
|
93
|
+
}
|
|
94
|
+
if (!changed)
|
|
95
|
+
return value;
|
|
96
|
+
// `Object.fromEntries` defines own properties, so a `__proto__` key from
|
|
97
|
+
// JSON.parse stays a plain key instead of replacing the prototype. When
|
|
98
|
+
// two keys become equal after cleaning, the later one wins.
|
|
99
|
+
const rebuilt = Object.fromEntries(entries);
|
|
100
|
+
return Object.getPrototypeOf(value) === null
|
|
101
|
+
? Object.assign(Object.create(null), rebuilt)
|
|
102
|
+
: rebuilt;
|
|
103
|
+
}
|
|
104
|
+
// Numbers, booleans, null, undefined and class instances are left as they
|
|
105
|
+
// are: they are not JSON text that a client sent.
|
|
106
|
+
return value;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Clean a string, array or plain object (recursively, keys and values) so
|
|
110
|
+
* Postgres accepts it in `text` and `jsonb`. See the file comment.
|
|
111
|
+
*/
|
|
112
|
+
function sanitizeForPostgres(value) {
|
|
113
|
+
const counts = { nulBytes: 0, loneSurrogates: 0 };
|
|
114
|
+
const cleaned = walk(value, counts);
|
|
115
|
+
return {
|
|
116
|
+
value: cleaned,
|
|
117
|
+
nulBytes: counts.nulBytes,
|
|
118
|
+
loneSurrogates: counts.loneSurrogates,
|
|
119
|
+
replacements: counts.nulBytes + counts.loneSurrogates
|
|
120
|
+
};
|
|
121
|
+
}
|
|
@@ -608,6 +608,12 @@ export declare class SessionRunner {
|
|
|
608
608
|
* both sides agree on it; a limit only one side knows is not a limit.
|
|
609
609
|
*/
|
|
610
610
|
private flush;
|
|
611
|
+
/**
|
|
612
|
+
* Remove NUL and replace lone UTF-16 surrogates before a batch leaves this
|
|
613
|
+
* runner: Postgres refuses both, and one such character in a tool result
|
|
614
|
+
* used to fail the whole batch. Logs counts only, never content.
|
|
615
|
+
*/
|
|
616
|
+
private postgresSafe;
|
|
611
617
|
/**
|
|
612
618
|
* WHERE `resumeFromRev` FINALLY DOES SOMETHING.
|
|
613
619
|
*
|
|
@@ -45,6 +45,7 @@ const mcp_preflight_1 = require("./mcp-preflight");
|
|
|
45
45
|
const mcp_tool_store_1 = require("./mcp-tool-store");
|
|
46
46
|
const mcp_toolset_1 = require("./mcp-toolset");
|
|
47
47
|
const permission_mode_1 = require("./permission-mode");
|
|
48
|
+
const postgres_safe_text_1 = require("./postgres-safe-text");
|
|
48
49
|
const projection_1 = require("./projection");
|
|
49
50
|
const space_files_1 = require("./space-files");
|
|
50
51
|
const task_files_1 = require("./task-files");
|
|
@@ -455,6 +456,19 @@ function resolveApproval(command, open) {
|
|
|
455
456
|
: 'Denied (no option chosen).'
|
|
456
457
|
};
|
|
457
458
|
}
|
|
459
|
+
/** The HTTP status on a control-plane error, read without importing its class. */
|
|
460
|
+
function errorStatus(error) {
|
|
461
|
+
const status = error && typeof error === 'object'
|
|
462
|
+
? error.status
|
|
463
|
+
: undefined;
|
|
464
|
+
return typeof status === 'number' ? status : undefined;
|
|
465
|
+
}
|
|
466
|
+
function errorCode(error) {
|
|
467
|
+
const code = error && typeof error === 'object'
|
|
468
|
+
? error.code
|
|
469
|
+
: undefined;
|
|
470
|
+
return typeof code === 'string' ? code : undefined;
|
|
471
|
+
}
|
|
458
472
|
class SessionRunner {
|
|
459
473
|
deps;
|
|
460
474
|
logger;
|
|
@@ -2518,10 +2532,65 @@ class SessionRunner {
|
|
|
2518
2532
|
const token = this.credentialProxyToken;
|
|
2519
2533
|
for (let i = 0; i < chunks.length; i += 1) {
|
|
2520
2534
|
const isLast = i === chunks.length - 1;
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
2535
|
+
const chunkParts = this.postgresSafe(sessionId, 'parts', (0, credential_proxy_1.redactCredentialProxyTokenDeep)(chunks[i], token));
|
|
2536
|
+
const chunkTurn = isLast
|
|
2537
|
+
? this.postgresSafe(sessionId, 'turn', (0, credential_proxy_1.redactCredentialProxyTokenDeep)(turn, token))
|
|
2538
|
+
: undefined;
|
|
2539
|
+
const chunkFinal = isLast ? final : false;
|
|
2540
|
+
const chunkMessages = isLast
|
|
2541
|
+
? this.postgresSafe(sessionId, 'modelMessages', (0, credential_proxy_1.redactCredentialProxyTokenDeep)(modelMessages, token))
|
|
2542
|
+
: undefined;
|
|
2543
|
+
try {
|
|
2544
|
+
await this.deps.ingest(sessionId, chunkParts, chunkTurn, chunkFinal, chunkMessages);
|
|
2545
|
+
}
|
|
2546
|
+
catch (error) {
|
|
2547
|
+
const status = errorStatus(error);
|
|
2548
|
+
const partIds = chunkParts.map((part) => part.partId);
|
|
2549
|
+
/*
|
|
2550
|
+
* A 400/413/422 REFUSES THIS BATCH'S CONTENT, not the turn. The
|
|
2551
|
+
* control plane will give the same answer however often it is sent
|
|
2552
|
+
* (`isFinalIngestStatus` already stopped the retries), so the batch is
|
|
2553
|
+
* DROPPED and the turn goes on. Its parts stay in the local store
|
|
2554
|
+
* (`harness.sqlite`), so the log names them for recovery.
|
|
2555
|
+
*
|
|
2556
|
+
* Every other failure (401/403/404/409/426, or a 5xx after the retry
|
|
2557
|
+
* ladder) still ends the turn, as before: the runner no longer owns
|
|
2558
|
+
* the session, or the control plane cannot be reached.
|
|
2559
|
+
*/
|
|
2560
|
+
if (status === 400 || status === 413 || status === 422) {
|
|
2561
|
+
this.logger.error(`[SessionRunner] ingest-batch-dropped session=${sessionId} status=${status} ` +
|
|
2562
|
+
`code=${errorCode(error) ?? '(none)'} parts=${partIds.length} ` +
|
|
2563
|
+
`final=${chunkFinal} partIds=${partIds.slice(0, 20).join(',')}` +
|
|
2564
|
+
(partIds.length > 20 ? ',…' : '') +
|
|
2565
|
+
' (the parts remain in the local transcript store)');
|
|
2566
|
+
// The FINAL ingest also releases the lease and records the turn. Send
|
|
2567
|
+
// that once more without the refused parts, so the turn still ends.
|
|
2568
|
+
if (chunkFinal && chunkParts.length > 0) {
|
|
2569
|
+
await this.deps.ingest(sessionId, [], chunkTurn, chunkFinal, chunkMessages);
|
|
2570
|
+
}
|
|
2571
|
+
continue;
|
|
2572
|
+
}
|
|
2573
|
+
this.logger.error(`[SessionRunner] ingest-batch-failed session=${sessionId} status=${status ?? '(network)'} ` +
|
|
2574
|
+
`parts=${partIds.length} final=${chunkFinal} ` +
|
|
2575
|
+
`partIds=${partIds.slice(0, 20).join(',')}` +
|
|
2576
|
+
(partIds.length > 20 ? ',…' : '') +
|
|
2577
|
+
' (the parts remain in the local transcript store)');
|
|
2578
|
+
throw error;
|
|
2579
|
+
}
|
|
2580
|
+
}
|
|
2581
|
+
}
|
|
2582
|
+
/**
|
|
2583
|
+
* Remove NUL and replace lone UTF-16 surrogates before a batch leaves this
|
|
2584
|
+
* runner: Postgres refuses both, and one such character in a tool result
|
|
2585
|
+
* used to fail the whole batch. Logs counts only, never content.
|
|
2586
|
+
*/
|
|
2587
|
+
postgresSafe(sessionId, field, value) {
|
|
2588
|
+
const result = (0, postgres_safe_text_1.sanitizeForPostgres)(value);
|
|
2589
|
+
if (result.replacements > 0) {
|
|
2590
|
+
this.logger.warn(`[SessionRunner] ingest-sanitized session=${sessionId} field=${field} ` +
|
|
2591
|
+
`nulBytes=${result.nulBytes} loneSurrogates=${result.loneSurrogates}`);
|
|
2524
2592
|
}
|
|
2593
|
+
return result.value;
|
|
2525
2594
|
}
|
|
2526
2595
|
/* ---------------------------------------------------------------- */
|
|
2527
2596
|
/* Wiring */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@peakflo/agent-harness",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.25-rc.1",
|
|
4
4
|
"description": "Headless Peakflo coding-agent harness. One codebase, three hosting modes: a Daytona cloud sandbox, a customer VM, and the 20x desktop.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "commonjs",
|