Skip to content

Commit 668dfc4

Browse files
committed
fix(agent-core-v2): count dropped journal lines from the damaged line
1 parent 44887fc commit 668dfc4

2 files changed

Lines changed: 24 additions & 3 deletions

File tree

packages/agent-core-v2/src/wire/repair.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export async function repairWireJournal(
3232
try {
3333
const original = await storage.read(scope, key);
3434
if (original !== undefined) {
35-
droppedCount = Math.max(0, countJournalLines(original) - records.length);
35+
droppedCount = Math.max(0, countJournalLines(original) - truncation.lineNumber + 1);
3636
const backupKey = wireJournalBackupKey(key);
3737
if ((await storage.size(scope, backupKey)) === undefined) {
3838
await storage.write(scope, backupKey, original, { atomic: true });

packages/agent-core-v2/test/wire/wireService.test.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,9 +410,9 @@ describe('WireService corruption repair', () => {
410410
};
411411
const telemetry: ITelemetryService = {
412412
...noopTelemetryService,
413-
track2: ((name: string, payload: unknown) => {
413+
track2: (name, payload) => {
414414
capture.events.push({ name, payload });
415-
}) as ITelemetryService['track2'],
415+
},
416416
};
417417
const localIx = disposables.add(new TestInstantiationService());
418418
return registerTestAgentWire(localIx, testWireScope(SCOPE, key), {
@@ -541,6 +541,27 @@ describe('WireService corruption repair', () => {
541541
]);
542542
});
543543

544+
it('counts dropped lines from the damaged line when the repair inserts metadata', async () => {
545+
const capture: RepairCapture = { warnings: [], events: [] };
546+
const svc = wireWithCapture(KEY, capture);
547+
const raw = `${JSON.stringify({ type: 'wire.test.legacy', time: 9 })}\nGARBAGE\n`;
548+
await seedCorrupt(raw);
549+
550+
await collect(svc.readJournal());
551+
552+
expect(capture.events).toEqual([
553+
{
554+
name: 'wire_repair',
555+
payload: {
556+
kind: 'corrupted',
557+
outcome: 'repaired',
558+
dropped_count: 1,
559+
backup_created: true,
560+
},
561+
},
562+
]);
563+
});
564+
544565
it('reports a torn tail as truncation through the wire_repair event', async () => {
545566
const capture: RepairCapture = { warnings: [], events: [] };
546567
const svc = wireWithCapture(KEY, capture);

0 commit comments

Comments
 (0)