Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix([issue-708]): preserve transcript tail when clamping multi-turn scorer input

[._.]/ Adam Eivyc5bad719236d
diff --git a/server/services/digital-twin-multi-turn-testing.js b/server/services/digital-twin-multi-turn-testing.js
index ac755b74c6..4bf8f6fb13 100644
--- a/server/services/digital-twin-multi-turn-testing.js
+++ b/server/services/digital-twin-multi-turn-testing.js
@@ -87,6 +87,24 @@ export function formatTranscript(transcript) {
.join('\n\n');
}
+/**
+ * Clamp a rendered transcript to `max` chars for the scorer prompt while
+ * preserving BOTH ends. A naive `.substring(0, max)` keeps only the head, but a
+ * multi-turn test's most diagnostic content is at the *tail* — caving under
+ * repeated pushback, contradicting an earlier answer, forgetting a turn-1
+ * constraint all surface in the later turns. Constraints set up front (e.g. a
+ * stated budget) live at the head, so we keep a head slice AND a larger tail
+ * slice, joining them with an elision marker. Exported for unit testing.
+ */
+export function clampTranscript(text, max = 4000) {
+ if (typeof text !== 'string' || text.length <= max) return text || '';
+ const elision = '\n\n[…earlier turns omitted…]\n\n';
+ const budget = max - elision.length;
+ const headLen = Math.floor(budget / 3); // keep the opening constraints
+ const tailLen = budget - headLen; // bias toward the diagnostic tail
+ return text.slice(0, headLen) + elision + text.slice(text.length - tailLen);
+}
+
export async function runMultiTurnTests(providerId, model, testIds = null, personaId = null) {
const scenarios = await parseMultiTurnSuite();
// A persona flavors the embodied identity so the conversations measure
@@ -180,7 +198,7 @@ async function runSingleConversation(scenario, twinContext, provider, model) {
async function scoreConversation(scenario, transcript, provider, model) {
const scorerData = {
scenarioName: scenario.testName,
- transcript: formatTranscript(transcript).substring(0, 4000),
+ transcript: clampTranscript(formatTranscript(transcript), 4000),
consistentTrajectory: scenario.consistentTrajectory,
inconsistentTrajectory: scenario.inconsistentTrajectory
};
diff --git a/server/services/digital-twin.test.js b/server/services/digital-twin.test.js
index d6c9ef320f..e5e34d9e86 100644
--- a/server/services/digital-twin.test.js
+++ b/server/services/digital-twin.test.js
@@ -139,7 +139,7 @@ import {
saveImportAsDocument
} from './digital-twin.js';
import { formatValuesHierarchy } from './digital-twin-values-testing.js';
-import { formatTranscript } from './digital-twin-multi-turn-testing.js';
+import { formatTranscript, clampTranscript } from './digital-twin-multi-turn-testing.js';
import { parseScorerVerdict } from './digital-twin-helpers.js';
import { cache } from './digital-twin-meta.js';
@@ -919,6 +919,31 @@ Forgets the budget and recommends lodging that exceeds it.
});
});
+ describe('clampTranscript', () => {
+ it('returns the text unchanged when within the limit', () => {
+ expect(clampTranscript('short', 4000)).toBe('short');
+ });
+
+ it('preserves BOTH the head and the diagnostic tail when over the limit', () => {
+ // HEAD carries the turn-1 constraint; TAIL carries the caving the scorer
+ // must catch. A naive substring(0, max) would drop the TAIL entirely.
+ const head = 'HEAD_CONSTRAINT ';
+ const tail = ' TAIL_CAVES';
+ const text = head + 'x'.repeat(5000) + tail;
+ const out = clampTranscript(text, 200);
+ expect(out.length).toBeLessThanOrEqual(200);
+ expect(out).toContain('HEAD_CONSTRAINT');
+ expect(out).toContain('TAIL_CAVES');
+ expect(out).toContain('earlier turns omitted');
+ });
+
+ it('tolerates empty / non-string input', () => {
+ expect(clampTranscript('', 4000)).toBe('');
+ expect(clampTranscript(null, 4000)).toBe('');
+ expect(clampTranscript(undefined, 4000)).toBe('');
+ });
+ });
+
describe('parseScorerVerdict', () => {
it('should pick the first matching verdict token in priority order', () => {
expect(parseScorerVerdict('{"result": "aligned", "reasoning": "honors integrity"}', ['aligned', 'misaligned']))