Recover Codex compaction failures in paired owner flow

This commit is contained in:
ejclaw
2026-04-15 03:11:14 +09:00
parent c76902a84b
commit 2ab3bddc0e
20 changed files with 449 additions and 18 deletions

View File

@@ -118,6 +118,7 @@ export function applyBaseSchema(database: Database): void {
plan_notes TEXT,
review_requested_at TEXT,
round_trip_count INTEGER NOT NULL DEFAULT 0,
owner_failure_count INTEGER NOT NULL DEFAULT 0,
status TEXT NOT NULL DEFAULT 'active',
arbiter_verdict TEXT,
arbiter_requested_at TEXT,

View File

@@ -35,6 +35,7 @@ function getExpectedSchemaMigrations(): Array<{
{ version: 8, name: 'paired_task_schema_cleanup' },
{ version: 9, name: 'paired_workspace_project_schema_cleanup' },
{ version: 10, name: 'paired_turn_provenance_upgrade' },
{ version: 11, name: 'owner_failure_count' },
];
}

View File

@@ -0,0 +1,23 @@
import type { Database } from 'bun:sqlite';
import { tableHasColumn } from './helpers.js';
import type { SchemaMigrationDefinition } from './types.js';
export const OWNER_FAILURE_COUNT_MIGRATION: SchemaMigrationDefinition = {
version: 11,
name: 'owner_failure_count',
apply(database: Database) {
if (!tableHasColumn(database, 'paired_tasks', 'owner_failure_count')) {
database.exec(`
ALTER TABLE paired_tasks
ADD COLUMN owner_failure_count INTEGER NOT NULL DEFAULT 0
`);
}
database.exec(`
UPDATE paired_tasks
SET owner_failure_count = 0
WHERE owner_failure_count IS NULL
`);
},
};

View File

@@ -10,6 +10,7 @@ import { RUNTIME_SERVICE_METADATA_MIGRATION } from './007_runtime-service-metada
import { PAIRED_TASK_SCHEMA_CLEANUP_MIGRATION } from './008_paired-task-schema-cleanup.js';
import { PAIRED_WORKSPACE_PROJECT_SCHEMA_CLEANUP_MIGRATION } from './009_paired-workspace-project-schema-cleanup.js';
import { PAIRED_TURN_PROVENANCE_UPGRADE_MIGRATION } from './010_paired-turn-provenance-upgrade.js';
import { OWNER_FAILURE_COUNT_MIGRATION } from './011_owner-failure-count.js';
import type {
SchemaMigrationArgs,
SchemaMigrationDefinition,
@@ -28,6 +29,7 @@ const ORDERED_SCHEMA_MIGRATIONS: readonly SchemaMigrationDefinition[] = [
PAIRED_TASK_SCHEMA_CLEANUP_MIGRATION,
PAIRED_WORKSPACE_PROJECT_SCHEMA_CLEANUP_MIGRATION,
PAIRED_TURN_PROVENANCE_UPGRADE_MIGRATION,
OWNER_FAILURE_COUNT_MIGRATION,
];
function ensureSchemaMigrationsTable(database: Database): void {

View File

@@ -50,6 +50,7 @@ export type PairedTaskUpdates = Partial<
| 'plan_notes'
| 'review_requested_at'
| 'round_trip_count'
| 'owner_failure_count'
| 'status'
| 'arbiter_verdict'
| 'arbiter_requested_at'
@@ -171,6 +172,7 @@ export function createPairedTaskInDatabase(
plan_notes,
review_requested_at,
round_trip_count,
owner_failure_count,
status,
arbiter_verdict,
arbiter_requested_at,
@@ -178,7 +180,7 @@ export function createPairedTaskInDatabase(
created_at,
updated_at
)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
`,
)
.run(
@@ -195,6 +197,7 @@ export function createPairedTaskInDatabase(
task.plan_notes,
task.review_requested_at,
task.round_trip_count,
task.owner_failure_count ?? 0,
task.status,
task.arbiter_verdict,
task.arbiter_requested_at,
@@ -279,6 +282,10 @@ export function updatePairedTaskInDatabase(
fields.push('round_trip_count = ?');
values.push(updates.round_trip_count);
}
if (updates.owner_failure_count !== undefined) {
fields.push('owner_failure_count = ?');
values.push(updates.owner_failure_count);
}
if (updates.status !== undefined) {
fields.push('status = ?');
values.push(updates.status);
@@ -338,6 +345,10 @@ export function updatePairedTaskIfUnchangedInDatabase(
fields.push('round_trip_count = ?');
values.push(updates.round_trip_count);
}
if (updates.owner_failure_count !== undefined) {
fields.push('owner_failure_count = ?');
values.push(updates.owner_failure_count);
}
if (updates.status !== undefined) {
fields.push('status = ?');
values.push(updates.status);