mirror of
https://github.com/stablyai/orca.git
synced 2026-11-19 04:23:57 +00:00
Persist current input facts and epoch-owned completion evidence
This commit is contained in:
+88
@@ -0,0 +1,88 @@
|
||||
export const JOURNAL_DOMAIN_SCHEMA_001_INDEXES = `
|
||||
CREATE INDEX idx_agent_session_clear_successor ON agent_session_records(
|
||||
CASE WHEN json_valid(record_json) THEN json_extract(record_json, '$.conversationCommand.replacementSessionId') END);
|
||||
CREATE INDEX agent_session_command_receipts_session ON agent_session_command_receipts(session_id);
|
||||
CREATE INDEX journal_chat_ready ON journal_chat_state(session_id) WHERE epoch IS NOT NULL;
|
||||
CREATE INDEX journal_items_ordinal ON journal_items(session_id,epoch,ordinal);
|
||||
CREATE INDEX journal_items_unsettled ON journal_items(session_id,epoch,ordinal,item_id)
|
||||
WHERE hidden=0 AND (lifecycle_state IN ('running','pending') OR live_work=1);
|
||||
CREATE INDEX journal_items_context_window ON journal_items(session_id,epoch) WHERE hidden=0 AND context_window=1;
|
||||
CREATE INDEX journal_items_unverified_end ON journal_items(session_id,epoch,ordinal,item_id) WHERE hidden=0 AND unverified_end=1;
|
||||
CREATE INDEX journal_items_unverifiable_turn ON journal_items(session_id,epoch,ordinal,item_id) WHERE hidden=0 AND kind IN ('turn','status') AND lifecycle_state='unverifiable';
|
||||
CREATE INDEX journal_items_interrupted_root ON journal_items(session_id,epoch,turn_completed_at,sequence,sequence_index,ordinal,item_id)
|
||||
WHERE hidden=0 AND root=1 AND kind IN ('turn','status') AND lifecycle_state='interrupted' AND turn_completed_at IS NOT NULL;
|
||||
CREATE INDEX journal_item_subagent_names_item ON journal_item_subagent_names(session_id, epoch, item_id);
|
||||
CREATE INDEX journal_item_subagent_names_visible ON journal_item_subagent_names(
|
||||
session_id, epoch, subagent_id, sequence, sequence_index, ordinal) WHERE hidden=0;
|
||||
CREATE INDEX journal_item_aliases_target ON journal_item_aliases(session_id, epoch, item_id);
|
||||
CREATE INDEX journal_submission_echo ON journal_submission_attempts(session_id, epoch, fingerprint, submitted_at, ordinal) WHERE current=1;
|
||||
CREATE INDEX journal_submission_person_acceptance ON journal_submission_attempts(session_id, epoch, accepted_sequence DESC) WHERE dispatch_state='accepted' AND admitted_personal=1;
|
||||
CREATE INDEX journal_submission_family ON journal_submission_attempts(session_id,epoch,admission_family_id,attempt_sequence,attempt_index,ordinal) WHERE current=1;
|
||||
CREATE INDEX journal_submission_ordinal ON journal_submission_attempts(session_id,epoch,ordinal);
|
||||
CREATE INDEX journal_submission_recovery ON journal_submission_attempts(session_id,epoch,ordinal,message_id)
|
||||
WHERE current=1 AND (dispatch_state='pending' OR (dispatch_state='unknown' AND recovered=0));
|
||||
CREATE INDEX journal_submission_acceptance ON journal_submission_attempts(session_id, epoch, accepted_sequence DESC) WHERE dispatch_state='accepted';
|
||||
CREATE INDEX journal_submission_candidates ON journal_submission_attempts(session_id,epoch,ordinal,message_id) WHERE current=1 AND candidate=1;
|
||||
CREATE INDEX journal_submission_unsettled ON journal_submission_attempts(session_id,epoch,ordinal,message_id) WHERE current=1 AND dispatch_state IN ('pending','unknown');
|
||||
CREATE INDEX journal_submission_status_accepted ON journal_submission_attempts(session_id,epoch,submitted_at,ordinal,message_id) WHERE current=1 AND dispatch_state='accepted';
|
||||
CREATE INDEX journal_submission_status_failed ON journal_submission_attempts(session_id,epoch,accepted_sequence,ordinal,message_id) WHERE current=1 AND request_failure=1;
|
||||
CREATE INDEX journal_submission_non_refused ON journal_submission_attempts(session_id,epoch,accepted_sequence,ordinal,message_id) WHERE current=1 AND dispatch_state<>'rejected' AND accepted_sequence IS NOT NULL;
|
||||
CREATE INDEX journal_submission_steer ON journal_submission_attempts(session_id,epoch,steer_turn_item_id,accepted_sequence,ordinal) WHERE current=1 AND steer_turn_item_id IS NOT NULL;
|
||||
CREATE INDEX journal_submission_submitted ON journal_submission_attempts(session_id,epoch,submitted_sequence) WHERE current=1 AND submitted_sequence IS NOT NULL;
|
||||
CREATE INDEX journal_submission_stopped ON journal_submission_attempts(session_id,epoch,ordinal,message_id) WHERE current=1 AND stopped_history=1;
|
||||
CREATE INDEX journal_submission_carriers ON journal_submission_attempts(session_id,epoch,ordinal,message_id) WHERE current=1 AND covers_stopped_history=1;
|
||||
CREATE INDEX journal_send_receipt_sequence ON journal_send_receipts(session_id,epoch,cursor_sequence,message_id);
|
||||
CREATE INDEX journal_queue_order ON journal_queue_cards(session_id, epoch, position, message_id)
|
||||
WHERE state IN ('waiting','returned');
|
||||
CREATE INDEX journal_queue_last_position ON journal_queue_cards(session_id, epoch, position);
|
||||
CREATE INDEX journal_queue_returned_commands ON journal_queue_cards(session_id, epoch, command_turn_item_id)
|
||||
WHERE state='returned';
|
||||
CREATE INDEX journal_edit_leases_message ON journal_edit_leases(session_id, epoch, message_id);
|
||||
CREATE INDEX journal_edit_leases_deadline ON journal_edit_leases(session_id, epoch, expires_at);
|
||||
CREATE INDEX journal_items_root_position ON journal_items(session_id, epoch, sequence, sequence_index, ordinal)
|
||||
WHERE hidden=0 AND root=1;
|
||||
CREATE INDEX journal_items_queue_eligible_turn ON journal_items(session_id, epoch, sequence, sequence_index, ordinal)
|
||||
WHERE hidden=0 AND turn_marker=1 AND (queue_command_turn=0 OR queue_failed_outcome=0 OR queue_failed_at>0);
|
||||
CREATE INDEX journal_items_turn_marker ON journal_items(session_id, epoch, sequence, sequence_index, ordinal)
|
||||
WHERE hidden=0 AND turn_marker=1;
|
||||
CREATE INDEX journal_items_raw_turn_marker ON journal_items(session_id,epoch,sequence,ordinal)
|
||||
WHERE turn_marker=1;
|
||||
CREATE INDEX journal_items_visible_position ON journal_items(session_id, epoch, sequence, sequence_index, ordinal)
|
||||
WHERE hidden=0;
|
||||
CREATE INDEX journal_items_queue_failure_report ON journal_items(session_id, epoch, queue_failure_report_turn_item_id)
|
||||
WHERE hidden=0 AND queue_failure_report_turn_item_id IS NOT NULL;
|
||||
CREATE INDEX journal_items_stop_turn ON journal_items(session_id, epoch, turn_item_id)
|
||||
WHERE hidden=0 AND turn_item_id IS NOT NULL;
|
||||
CREATE INDEX journal_events_saved_at ON journal_events(saved_at,session_id,epoch,sequence);
|
||||
CREATE INDEX journal_items_kind ON journal_items(session_id, epoch, kind, ordinal) WHERE hidden=0;
|
||||
CREATE INDEX journal_items_user_message ON journal_items(session_id, epoch, ordinal)
|
||||
WHERE hidden=0 AND kind='message' AND message_role='user';
|
||||
CREATE INDEX journal_items_named_turn ON journal_items(session_id, epoch, turn_id, sequence, sequence_index, ordinal)
|
||||
WHERE hidden=0 AND turn_id IS NOT NULL;
|
||||
CREATE INDEX journal_items_opener ON journal_items(session_id, epoch, opener_item_id, ordinal)
|
||||
WHERE hidden=0 AND opener_item_id IS NOT NULL;
|
||||
CREATE INDEX journal_items_context_clear ON journal_items(session_id, epoch, sequence)
|
||||
WHERE hidden=0 AND context_clear=1;
|
||||
CREATE INDEX journal_items_raw_context_clear ON journal_items(session_id,epoch,sequence)
|
||||
WHERE context_clear=1;
|
||||
CREATE INDEX journal_items_goal_transition ON journal_items(session_id, epoch, sequence, ordinal)
|
||||
WHERE hidden=0 AND goal_transition=1;
|
||||
CREATE INDEX journal_items_producer_parent ON journal_items(session_id, epoch, producer_parent_ref, ordinal, producer_agent_id)
|
||||
WHERE hidden=0 AND producer_parent_ref IS NOT NULL;
|
||||
CREATE INDEX journal_items_producer_attempt ON journal_items(session_id, epoch, producer_agent_id, producer_attempt)
|
||||
WHERE hidden=0 AND producer_agent_id IS NOT NULL;
|
||||
CREATE INDEX journal_items_status_turn ON journal_items(session_id,epoch,sequence,sequence_index,ordinal) WHERE hidden=0 AND turn_id IS NOT NULL;
|
||||
CREATE INDEX journal_items_status_prompt ON journal_items(session_id,epoch,sequence,sequence_index,ordinal) WHERE hidden=0 AND prompt=1;
|
||||
CREATE INDEX journal_items_status_prose ON journal_items(session_id,epoch,sequence,sequence_index,ordinal) WHERE hidden=0 AND root=1 AND message_role='assistant' AND command_entry=0 AND assistant_prose=1;
|
||||
CREATE INDEX journal_items_status_pending ON journal_items(session_id,epoch,sequence,sequence_index,ordinal) WHERE hidden=0 AND kind IN ('approval','question') AND lifecycle_state='pending';
|
||||
CREATE INDEX journal_items_status_tool ON journal_items(session_id,epoch,sequence,sequence_index,ordinal) WHERE hidden=0 AND root=1 AND kind IN ('tool-call','diff');
|
||||
CREATE INDEX journal_items_status_assistant ON journal_items(session_id,epoch) WHERE hidden=0 AND message_role='assistant';
|
||||
CREATE INDEX journal_items_signed_out ON journal_items(session_id, epoch, COALESCE(execution_owner,owner_fence))
|
||||
WHERE hidden=0 AND root=1 AND signed_out=1;
|
||||
CREATE INDEX journal_submission_accepted_position ON journal_submission_attempts(session_id, epoch, accepted_sequence, ordinal)
|
||||
WHERE current=1 AND accepted_sequence IS NOT NULL;
|
||||
CREATE INDEX journal_submission_signed_out ON journal_submission_attempts(session_id,epoch,dispatch_fence)
|
||||
WHERE current=1 AND signed_out=1;
|
||||
CREATE INDEX journal_submission_order ON journal_submission_attempts(session_id, epoch, submitted_at, ordinal, message_id)
|
||||
WHERE current=1;
|
||||
`
|
||||
@@ -1,3 +1,5 @@
|
||||
import { JOURNAL_DOMAIN_SCHEMA_001_INDEXES } from './journal-domain-schema-001-indexes'
|
||||
|
||||
export const JOURNAL_DOMAIN_SCHEMA_001 = `
|
||||
CREATE TABLE agent_session_records (
|
||||
session_id TEXT PRIMARY KEY,
|
||||
@@ -20,8 +22,6 @@ CREATE TABLE agent_session_store_meta (
|
||||
key TEXT PRIMARY KEY,
|
||||
value TEXT NOT NULL
|
||||
);
|
||||
CREATE INDEX idx_agent_session_clear_successor ON agent_session_records(
|
||||
CASE WHEN json_valid(record_json) THEN json_extract(record_json, '$.conversationCommand.replacementSessionId') END);
|
||||
CREATE TABLE agent_session_command_receipts (
|
||||
operation_id TEXT NOT NULL,
|
||||
session_id TEXT NOT NULL REFERENCES agent_session_records(session_id) ON DELETE CASCADE,
|
||||
@@ -34,7 +34,6 @@ CREATE TABLE agent_session_command_receipts (
|
||||
accepted_at INTEGER NOT NULL,
|
||||
PRIMARY KEY(operation_id, caller_key)
|
||||
);
|
||||
CREATE INDEX agent_session_command_receipts_session ON agent_session_command_receipts(session_id);
|
||||
CREATE TABLE agent_session_attachment_claims (
|
||||
upload_id TEXT NOT NULL,
|
||||
session_id TEXT NOT NULL,
|
||||
@@ -57,6 +56,7 @@ CREATE TABLE journal_chat_state (
|
||||
last_activity_at INTEGER NOT NULL DEFAULT 0,
|
||||
derived_turn_item_id TEXT,
|
||||
history_origin_json TEXT,
|
||||
accepted_handover_sequence INTEGER NOT NULL DEFAULT 0,
|
||||
queue_latest_stop_json TEXT,
|
||||
queue_manual_stop_json TEXT,
|
||||
queue_resumed_sequence INTEGER NOT NULL DEFAULT 0,
|
||||
@@ -66,7 +66,6 @@ CREATE TABLE journal_chat_state (
|
||||
queue_clear_lifted INTEGER NOT NULL DEFAULT 0,
|
||||
queue_failure_boundary INTEGER NOT NULL DEFAULT 0
|
||||
);
|
||||
CREATE INDEX journal_chat_ready ON journal_chat_state(session_id) WHERE epoch IS NOT NULL;
|
||||
CREATE TABLE journal_queue_clear_members (
|
||||
session_id TEXT NOT NULL,
|
||||
epoch TEXT NOT NULL,
|
||||
@@ -114,24 +113,24 @@ CREATE TABLE journal_items (
|
||||
context_window INTEGER NOT NULL DEFAULT 0,
|
||||
unverified_end INTEGER NOT NULL DEFAULT 0,
|
||||
turn_completed_at REAL,
|
||||
command_entry INTEGER NOT NULL DEFAULT 0,
|
||||
assistant_prose INTEGER NOT NULL DEFAULT 0,
|
||||
turn_scope_kind TEXT,
|
||||
PRIMARY KEY(session_id, epoch, item_id)
|
||||
);
|
||||
CREATE INDEX journal_items_ordinal ON journal_items(session_id,epoch,ordinal);
|
||||
CREATE INDEX journal_items_unsettled ON journal_items(session_id,epoch,ordinal,item_id)
|
||||
WHERE hidden=0 AND (lifecycle_state IN ('running','pending') OR live_work=1);
|
||||
CREATE INDEX journal_items_context_window ON journal_items(session_id,epoch) WHERE hidden=0 AND context_window=1;
|
||||
CREATE INDEX journal_items_unverified_end ON journal_items(session_id,epoch,ordinal,item_id) WHERE hidden=0 AND unverified_end=1;
|
||||
CREATE INDEX journal_items_unverifiable_turn ON journal_items(session_id,epoch,ordinal,item_id) WHERE hidden=0 AND kind IN ('turn','status') AND lifecycle_state='unverifiable';
|
||||
CREATE INDEX journal_items_interrupted_root ON journal_items(session_id,epoch,turn_completed_at,sequence,sequence_index,ordinal,item_id)
|
||||
WHERE hidden=0 AND root=1 AND kind IN ('turn','status') AND lifecycle_state='interrupted' AND turn_completed_at IS NOT NULL;
|
||||
CREATE TABLE journal_settlements (
|
||||
session_id TEXT NOT NULL,
|
||||
epoch TEXT NOT NULL,
|
||||
settlement_id TEXT NOT NULL,
|
||||
ordinal INTEGER NOT NULL,
|
||||
PRIMARY KEY(session_id, epoch, settlement_id)
|
||||
) WITHOUT ROWID;
|
||||
CREATE INDEX journal_settlements_ordinal ON journal_settlements(session_id,epoch,ordinal);
|
||||
CREATE TABLE journal_input_end_observations (
|
||||
session_id TEXT NOT NULL,
|
||||
epoch TEXT NOT NULL,
|
||||
source_item_key TEXT NOT NULL,
|
||||
observation_json TEXT NOT NULL,
|
||||
PRIMARY KEY(session_id,epoch,source_item_key)
|
||||
) WITHOUT ROWID;
|
||||
CREATE TABLE journal_item_subagent_names (
|
||||
session_id TEXT NOT NULL,
|
||||
epoch TEXT NOT NULL,
|
||||
@@ -143,9 +142,6 @@ CREATE TABLE journal_item_subagent_names (
|
||||
hidden INTEGER NOT NULL,
|
||||
PRIMARY KEY(session_id, epoch, subagent_id, item_id)
|
||||
) WITHOUT ROWID;
|
||||
CREATE INDEX journal_item_subagent_names_item ON journal_item_subagent_names(session_id, epoch, item_id);
|
||||
CREATE INDEX journal_item_subagent_names_visible ON journal_item_subagent_names(
|
||||
session_id, epoch, subagent_id, sequence, sequence_index, ordinal) WHERE hidden=0;
|
||||
CREATE TABLE journal_item_tombstones (
|
||||
session_id TEXT NOT NULL,
|
||||
epoch TEXT NOT NULL,
|
||||
@@ -168,7 +164,6 @@ CREATE TABLE journal_item_aliases (
|
||||
echo_json TEXT,
|
||||
PRIMARY KEY(session_id, epoch, provider_item_id)
|
||||
) WITHOUT ROWID;
|
||||
CREATE INDEX journal_item_aliases_target ON journal_item_aliases(session_id, epoch, item_id);
|
||||
CREATE TABLE journal_submission_attempts (
|
||||
session_id TEXT NOT NULL,
|
||||
epoch TEXT NOT NULL,
|
||||
@@ -180,6 +175,11 @@ CREATE TABLE journal_submission_attempts (
|
||||
ordinal INTEGER NOT NULL,
|
||||
submitted_at INTEGER NOT NULL,
|
||||
accepted_sequence INTEGER,
|
||||
submitted_sequence INTEGER,
|
||||
request_failure INTEGER NOT NULL DEFAULT 0,
|
||||
steer_turn_item_id TEXT,
|
||||
stopped_history INTEGER NOT NULL DEFAULT 0,
|
||||
covers_stopped_history INTEGER NOT NULL DEFAULT 0,
|
||||
fingerprint TEXT NOT NULL,
|
||||
dispatch_state TEXT NOT NULL,
|
||||
dispatch_fence INTEGER NOT NULL DEFAULT 0,
|
||||
@@ -197,17 +197,11 @@ CREATE TABLE journal_submission_attempts (
|
||||
);
|
||||
CREATE UNIQUE INDEX journal_submission_head ON journal_submission_attempts(session_id, epoch, message_id) WHERE current=1;
|
||||
CREATE UNIQUE INDEX journal_submission_item ON journal_submission_attempts(session_id, epoch, item_id) WHERE current=1;
|
||||
CREATE INDEX journal_submission_echo ON journal_submission_attempts(session_id, epoch, fingerprint, submitted_at, ordinal) WHERE current=1;
|
||||
CREATE INDEX journal_submission_person_acceptance ON journal_submission_attempts(session_id, epoch, accepted_sequence DESC) WHERE dispatch_state='accepted' AND admitted_personal=1;
|
||||
CREATE INDEX journal_submission_family ON journal_submission_attempts(session_id,epoch,admission_family_id,attempt_sequence,attempt_index,ordinal) WHERE current=1;
|
||||
CREATE INDEX journal_submission_ordinal ON journal_submission_attempts(session_id,epoch,ordinal);
|
||||
CREATE INDEX journal_submission_recovery ON journal_submission_attempts(session_id,epoch,ordinal,message_id)
|
||||
WHERE current=1 AND (dispatch_state='pending' OR (dispatch_state='unknown' AND recovered=0));
|
||||
CREATE INDEX journal_submission_acceptance ON journal_submission_attempts(session_id, epoch, accepted_sequence DESC) WHERE dispatch_state='accepted';
|
||||
CREATE TABLE journal_send_receipts (
|
||||
session_id TEXT NOT NULL,
|
||||
epoch TEXT NOT NULL,
|
||||
message_id TEXT NOT NULL,
|
||||
cursor_sequence INTEGER NOT NULL DEFAULT 0,
|
||||
payload_json TEXT NOT NULL,
|
||||
PRIMARY KEY(session_id, epoch, message_id)
|
||||
) WITHOUT ROWID;
|
||||
@@ -237,11 +231,6 @@ CREATE TABLE journal_queue_cards (
|
||||
payload_json TEXT NOT NULL,
|
||||
PRIMARY KEY(session_id, epoch, message_id)
|
||||
);
|
||||
CREATE INDEX journal_queue_order ON journal_queue_cards(session_id, epoch, position, message_id)
|
||||
WHERE state IN ('waiting','returned');
|
||||
CREATE INDEX journal_queue_last_position ON journal_queue_cards(session_id, epoch, position);
|
||||
CREATE INDEX journal_queue_returned_commands ON journal_queue_cards(session_id, epoch, command_turn_item_id)
|
||||
WHERE state='returned';
|
||||
|
||||
CREATE TABLE journal_edit_leases (
|
||||
session_id TEXT NOT NULL,
|
||||
@@ -254,50 +243,11 @@ CREATE TABLE journal_edit_leases (
|
||||
expires_at REAL NOT NULL,
|
||||
PRIMARY KEY(session_id, epoch, owner_id, caller_key, edit_id)
|
||||
) WITHOUT ROWID;
|
||||
CREATE INDEX journal_edit_leases_message ON journal_edit_leases(session_id, epoch, message_id);
|
||||
CREATE INDEX journal_edit_leases_deadline ON journal_edit_leases(session_id, epoch, expires_at);
|
||||
CREATE INDEX journal_items_root_position ON journal_items(session_id, epoch, sequence, sequence_index, ordinal)
|
||||
WHERE hidden=0 AND root=1;
|
||||
CREATE INDEX journal_items_queue_eligible_turn ON journal_items(session_id, epoch, sequence, sequence_index, ordinal)
|
||||
WHERE hidden=0 AND turn_marker=1 AND (queue_command_turn=0 OR queue_failed_outcome=0 OR queue_failed_at>0);
|
||||
CREATE INDEX journal_items_turn_marker ON journal_items(session_id, epoch, sequence, sequence_index, ordinal)
|
||||
WHERE hidden=0 AND turn_marker=1;
|
||||
CREATE INDEX journal_items_visible_position ON journal_items(session_id, epoch, sequence, sequence_index, ordinal)
|
||||
WHERE hidden=0;
|
||||
CREATE INDEX journal_items_queue_failure_report ON journal_items(session_id, epoch, queue_failure_report_turn_item_id)
|
||||
WHERE hidden=0 AND queue_failure_report_turn_item_id IS NOT NULL;
|
||||
CREATE INDEX journal_items_stop_turn ON journal_items(session_id, epoch, turn_item_id)
|
||||
WHERE hidden=0 AND turn_item_id IS NOT NULL;
|
||||
CREATE INDEX journal_events_saved_at ON journal_events(saved_at,session_id,epoch,sequence);
|
||||
|
||||
CREATE INDEX journal_items_kind ON journal_items(session_id, epoch, kind, ordinal) WHERE hidden=0;
|
||||
CREATE INDEX journal_items_user_message ON journal_items(session_id, epoch, ordinal)
|
||||
WHERE hidden=0 AND kind='message' AND message_role='user';
|
||||
CREATE INDEX journal_items_named_turn ON journal_items(session_id, epoch, turn_id, sequence, sequence_index, ordinal)
|
||||
WHERE hidden=0 AND turn_id IS NOT NULL;
|
||||
CREATE INDEX journal_items_opener ON journal_items(session_id, epoch, opener_item_id, ordinal)
|
||||
WHERE hidden=0 AND opener_item_id IS NOT NULL;
|
||||
CREATE INDEX journal_items_context_clear ON journal_items(session_id, epoch, sequence)
|
||||
WHERE hidden=0 AND context_clear=1;
|
||||
CREATE INDEX journal_items_goal_transition ON journal_items(session_id, epoch, sequence, ordinal)
|
||||
WHERE hidden=0 AND goal_transition=1;
|
||||
CREATE INDEX journal_items_producer_parent ON journal_items(session_id, epoch, producer_parent_ref, ordinal, producer_agent_id)
|
||||
WHERE hidden=0 AND producer_parent_ref IS NOT NULL;
|
||||
CREATE INDEX journal_items_producer_attempt ON journal_items(session_id, epoch, producer_agent_id, producer_attempt)
|
||||
WHERE hidden=0 AND producer_agent_id IS NOT NULL;
|
||||
CREATE INDEX journal_items_prompt ON journal_items(session_id, epoch, sequence, ordinal)
|
||||
WHERE hidden=0 AND prompt=1;
|
||||
CREATE INDEX journal_items_signed_out ON journal_items(session_id, epoch, COALESCE(execution_owner,owner_fence))
|
||||
WHERE hidden=0 AND root=1 AND signed_out=1;
|
||||
CREATE INDEX journal_submission_accepted_position ON journal_submission_attempts(session_id, epoch, accepted_sequence, ordinal)
|
||||
WHERE current=1 AND accepted_sequence IS NOT NULL;
|
||||
CREATE INDEX journal_submission_signed_out ON journal_submission_attempts(session_id,epoch,dispatch_fence)
|
||||
WHERE current=1 AND signed_out=1;
|
||||
CREATE INDEX journal_submission_order ON journal_submission_attempts(session_id, epoch, submitted_at, ordinal, message_id)
|
||||
WHERE current=1;
|
||||
|
||||
CREATE TABLE journal_maintenance (
|
||||
id INTEGER PRIMARY KEY CHECK(id=1),
|
||||
compacted_at INTEGER NOT NULL
|
||||
);
|
||||
${JOURNAL_DOMAIN_SCHEMA_001_INDEXES}
|
||||
`
|
||||
|
||||
@@ -178,6 +178,13 @@ export function applyJournalDomainCommandTurn(
|
||||
}
|
||||
step.items.push(
|
||||
...writeJournalDomainCurrentItem(db, target, {
|
||||
inputObservation: {
|
||||
itemId: mutation.itemId,
|
||||
seq: sequence,
|
||||
fence: dispatch.fence,
|
||||
ownerFence: stored?.ownerFence ?? dispatch.fence,
|
||||
turnScope: mutation.turnScope
|
||||
},
|
||||
item: stored ? journalItemRevisionValue(stored.item, next) : next,
|
||||
...(stored ? { previous: stored } : {}),
|
||||
stopSettle,
|
||||
|
||||
@@ -16,6 +16,11 @@ import { reportedTurnItemId } from './queued-messages/journal-queue-failure-poli
|
||||
import type { JournalStopSettleFact } from './journal-writer-host-facts'
|
||||
import { normalizeJournalDomainItemBody } from './journal-domain-item-normalization'
|
||||
import { observeJournalDomainTurnScope } from './journal-domain-turn-scope'
|
||||
import {
|
||||
observeJournalDomainInputItem,
|
||||
refreshJournalDomainAcceptedHandover,
|
||||
type JournalDomainInputItemObservation
|
||||
} from './journal-domain-input-ends'
|
||||
|
||||
export type JournalDomainCurrentItemWrite = {
|
||||
item: AgentJournalRenderItem
|
||||
@@ -26,6 +31,7 @@ export type JournalDomainCurrentItemWrite = {
|
||||
executionOwner?: number | null
|
||||
writtenSequence?: number
|
||||
stopSettle?: JournalStopSettleFact
|
||||
inputObservation?: JournalDomainInputItemObservation
|
||||
}
|
||||
|
||||
function nextJournalDomainItemOrdinal(
|
||||
@@ -127,6 +133,10 @@ export function writeJournalDomainCurrentItem(
|
||||
input.previous
|
||||
)
|
||||
observeJournalDomainTurnScope(db, target, next.itemId, input.previous?.item, next)
|
||||
if (input.inputObservation && item.itemId === input.inputObservation.itemId) {
|
||||
observeJournalDomainInputItem(db, target, item, input.inputObservation)
|
||||
}
|
||||
refreshJournalDomainAcceptedHandover(db, target, next.itemId)
|
||||
const oldReport =
|
||||
previousReport?.queue_failure_report_turn_item_id == null
|
||||
? null
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import type Database from '../../sqlite/sync-database'
|
||||
import { readWholeAgentSessionFailureFact } from '../../../shared/agent-session/failures/agent-session-failure'
|
||||
import {
|
||||
JOURNAL_DOMAIN_SUBMISSION_COLUMNS,
|
||||
journalDomainSubmissionColumns
|
||||
} from './journal-domain-submission-columns'
|
||||
import { agentJournalItemKey } from '../../../shared/agent-session/journal/agent-session-journal-item-key'
|
||||
import type { AgentJournalSubmission } from '../../../shared/agent-session/journal/agent-session-journal-types'
|
||||
import { stoppedHistoryCandidate } from '../../../shared/agent-session/lifecycle/agent-session-stopped-history'
|
||||
@@ -23,19 +26,14 @@ export function writeJournalDomainDispatchAttempt(
|
||||
attempt: JournalDomainSubmissionAttempt
|
||||
): void {
|
||||
const { submission: next, candidate, handover } = attempt
|
||||
db.prepare(`UPDATE journal_submission_attempts SET dispatch_state=?,candidate=?,payload_json=?,dispatch_fence=?,signed_out=?,recovered=?,
|
||||
db.prepare(`UPDATE journal_submission_attempts SET candidate=?,payload_json=?,
|
||||
${JOURNAL_DOMAIN_SUBMISSION_COLUMNS.map((column) => `${column}=?`).join(',')},
|
||||
handover_fence=?,facts_json=?,
|
||||
admission_body_json=CASE WHEN ? THEN admission_body_json ELSE NULL END
|
||||
WHERE session_id=? AND epoch=? AND message_id=? AND current=1`).run(
|
||||
next.dispatchState,
|
||||
Number(candidate),
|
||||
JSON.stringify(next),
|
||||
next.fence,
|
||||
Number(
|
||||
next.dispatchState === 'rejected' &&
|
||||
readWholeAgentSessionFailureFact(next.rejection)?.kind === 'notSignedIn'
|
||||
),
|
||||
Number(next.recovered === true),
|
||||
...journalDomainSubmissionColumns(next, attempt.carries),
|
||||
handover?.fence ?? null,
|
||||
journalDomainSubmissionFactsJson(attempt),
|
||||
Number(
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type Database from '../../sqlite/sync-database'
|
||||
import { refreshJournalDomainAcceptedHandover } from './journal-domain-input-ends'
|
||||
import {
|
||||
agentJournalItemKey,
|
||||
agentJournalSubmissionKey
|
||||
@@ -221,6 +222,9 @@ export function applyJournalDomainDispatch(
|
||||
result.items = result.items.filter((item) => item.itemId !== itemId)
|
||||
}
|
||||
}
|
||||
if (input.state === 'accepted') {
|
||||
refreshJournalDomainAcceptedHandover(db, target, itemId)
|
||||
}
|
||||
if (input.state === 'accepted' && next.providerItemId) {
|
||||
db.prepare(`INSERT INTO journal_item_aliases(session_id,epoch,provider_item_id,item_id) VALUES(?,?,?,?)
|
||||
ON CONFLICT(session_id,epoch,provider_item_id) DO UPDATE SET item_id=excluded.item_id`).run(
|
||||
@@ -234,10 +238,11 @@ export function applyJournalDomainDispatch(
|
||||
cursor: nextCursor,
|
||||
acceptedAt: savedAt
|
||||
}
|
||||
db.prepare(`INSERT INTO journal_send_receipts(session_id,epoch,message_id,payload_json) VALUES(?,?,?,?)
|
||||
ON CONFLICT(session_id,epoch,message_id) DO UPDATE SET payload_json=excluded.payload_json`).run(
|
||||
db.prepare(`INSERT INTO journal_send_receipts(session_id,epoch,message_id,cursor_sequence,payload_json) VALUES(?,?,?,?,?)
|
||||
ON CONFLICT(session_id,epoch,message_id) DO UPDATE SET cursor_sequence=excluded.cursor_sequence,payload_json=excluded.payload_json`).run(
|
||||
...prefix,
|
||||
input.clientMessageId,
|
||||
receipt.cursor.sequence,
|
||||
JSON.stringify(receipt)
|
||||
)
|
||||
result.receipts.push(receipt)
|
||||
|
||||
@@ -51,6 +51,8 @@ export function readJournalDomainEntity(
|
||||
WHERE session_id=? AND epoch=?`)
|
||||
.get(...prefix)!
|
||||
const sequence = Number(head.last_sequence)
|
||||
const historyOrigin: JournalHistoryOrigin | null =
|
||||
head.history_origin_json === null ? null : JSON.parse(String(head.history_origin_json))
|
||||
return {
|
||||
kind: 'metadata',
|
||||
cursor: {
|
||||
@@ -61,10 +63,7 @@ export function readJournalDomainEntity(
|
||||
oldestSequence: Number(head.retained_sequence),
|
||||
highestFence: Number(head.highest_fence),
|
||||
lastActivityAt: Number(head.last_activity_at),
|
||||
historyOrigin:
|
||||
head.history_origin_json === null
|
||||
? null
|
||||
: (JSON.parse(String(head.history_origin_json)) as JournalHistoryOrigin)
|
||||
historyOrigin
|
||||
}
|
||||
}
|
||||
case 'item': {
|
||||
@@ -72,22 +71,18 @@ export function readJournalDomainEntity(
|
||||
.prepare(`SELECT payload_json FROM journal_items
|
||||
WHERE session_id=? AND epoch=? AND item_id=? AND hidden=0`)
|
||||
.get(...prefix, operation.itemId)
|
||||
return {
|
||||
kind: 'item',
|
||||
item: row ? (JSON.parse(String(row.payload_json)) as AgentJournalRenderItem) : null
|
||||
}
|
||||
const item: AgentJournalRenderItem | null = row ? JSON.parse(String(row.payload_json)) : null
|
||||
return { kind: 'item', item }
|
||||
}
|
||||
case 'submission': {
|
||||
const row = db
|
||||
.prepare(`SELECT payload_json FROM journal_submission_attempts
|
||||
WHERE session_id=? AND epoch=? AND message_id=? AND current=1`)
|
||||
.get(...prefix, operation.clientMessageId)
|
||||
return {
|
||||
kind: 'submission',
|
||||
submission: row
|
||||
? (JSON.parse(String(row.payload_json)) as AgentJournalSubmission)
|
||||
: undefined
|
||||
}
|
||||
const submission: AgentJournalSubmission | undefined = row
|
||||
? JSON.parse(String(row.payload_json))
|
||||
: undefined
|
||||
return { kind: 'submission', submission }
|
||||
}
|
||||
case 'submission-body':
|
||||
return {
|
||||
@@ -184,13 +179,9 @@ export function readJournalDomainEntity(
|
||||
.prepare(`SELECT queue_latest_stop_json FROM journal_chat_state
|
||||
WHERE session_id=? AND epoch=?`)
|
||||
.get(...prefix)!
|
||||
return {
|
||||
kind: 'latest-stop',
|
||||
stop:
|
||||
row.queue_latest_stop_json === null
|
||||
? null
|
||||
: (JSON.parse(String(row.queue_latest_stop_json)) as JournalLatestStop)
|
||||
}
|
||||
const stop: JournalLatestStop | null =
|
||||
row.queue_latest_stop_json === null ? null : JSON.parse(String(row.queue_latest_stop_json))
|
||||
return { kind: 'latest-stop', stop }
|
||||
}
|
||||
case 'turn-removed':
|
||||
return {
|
||||
|
||||
@@ -2,13 +2,9 @@ import type Database from '../../sqlite/sync-database'
|
||||
import type { JournalWriterOperation } from './journal-writer-command'
|
||||
import type { JournalStopSettleFact } from './journal-writer-host-facts'
|
||||
import type { JournalLifecycleBatchInput } from './journal-store-contracts'
|
||||
import {
|
||||
planStaleStructuredAgentSessionState,
|
||||
type StaleStructuredAgentSessionStateJournal
|
||||
} from '../agent-session-wire/termination/structured-agent-session-stale-state-settlement'
|
||||
import { planStaleStructuredAgentSessionState } from '../agent-session-wire/termination/structured-agent-session-stale-state-settlement'
|
||||
import { planStructuredAgentSessionDeadGeneration } from '../agent-session-wire/termination/structured-agent-session-dead-generation-settlement'
|
||||
import { runningTurnLifecycleRevisions } from '../agent-session-wire/termination/structured-agent-session-stale-turn-verdict'
|
||||
import type { DeadGenerationJournal } from '../agent-session-wire/termination/structured-agent-session-unfinished-work'
|
||||
import { STALE_SESSION_ROW_PREFIX } from '../../../shared/agent-session/lifecycle/agent-session-stop-row-identity'
|
||||
import { isRootAgentJournalItem } from '../../../shared/agent-session/journal/agent-session-journal-producer'
|
||||
import { isQueuedAgentJournalSubmission } from '../../../shared/agent-session/requests/agent-session-queued-submission'
|
||||
@@ -128,9 +124,7 @@ export function applyJournalDomainGenerationSettlement(
|
||||
? { completedAt: exit.verdict.completedAt, ownerFence: exit.ownerFence }
|
||||
: undefined
|
||||
)
|
||||
// The existing pure planner signatures include unused journal mutation methods.
|
||||
const journal = reads as unknown as StaleStructuredAgentSessionStateJournal &
|
||||
DeadGenerationJournal
|
||||
const journal = reads
|
||||
if (operation.kind === 'stale-settle') {
|
||||
const plan = planStaleStructuredAgentSessionState({ ...operation.input, journal })
|
||||
value = plan.mutations.length
|
||||
|
||||
@@ -24,6 +24,7 @@ export function discardJournalDomainImportPage(
|
||||
['journal_submission_attempts', 'epoch,message_id,attempt_sequence,attempt_index'],
|
||||
['journal_send_receipts', 'epoch,message_id'],
|
||||
['journal_settlements', 'epoch,settlement_id'],
|
||||
['journal_input_end_observations', 'epoch,source_item_key'],
|
||||
['journal_queue_cards', 'epoch,message_id'],
|
||||
['journal_queue_clear_members', 'epoch,message_id'],
|
||||
['journal_edit_leases', 'epoch,owner_id,caller_key,edit_id'],
|
||||
|
||||
@@ -133,10 +133,15 @@ export function insertJournalDomainImportPage(
|
||||
break
|
||||
case 'receipts': {
|
||||
const insert =
|
||||
db.prepare(`INSERT INTO journal_send_receipts(session_id,epoch,message_id,payload_json)
|
||||
VALUES(?,?,?,?) ON CONFLICT DO NOTHING`)
|
||||
db.prepare(`INSERT INTO journal_send_receipts(session_id,epoch,message_id,cursor_sequence,payload_json)
|
||||
VALUES(?,?,?,?,?) ON CONFLICT DO NOTHING`)
|
||||
for (const receipt of page.rows) {
|
||||
insert.run(...prefix, receipt.clientMessageId, JSON.stringify(receipt))
|
||||
insert.run(
|
||||
...prefix,
|
||||
receipt.clientMessageId,
|
||||
receipt.cursor.sequence,
|
||||
JSON.stringify(receipt)
|
||||
)
|
||||
}
|
||||
break
|
||||
}
|
||||
@@ -148,11 +153,19 @@ export function insertJournalDomainImportPage(
|
||||
}
|
||||
break
|
||||
case 'settlements': {
|
||||
const insert = db.prepare(`INSERT INTO journal_settlements(session_id,epoch,settlement_id)
|
||||
VALUES(?,?,?) ON CONFLICT DO NOTHING`)
|
||||
for (const { settlementId } of page.rows) {
|
||||
insert.run(...prefix, settlementId)
|
||||
}
|
||||
break
|
||||
}
|
||||
case 'input-end-observations': {
|
||||
const insert =
|
||||
db.prepare(`INSERT INTO journal_settlements(session_id,epoch,settlement_id,ordinal)
|
||||
db.prepare(`INSERT INTO journal_input_end_observations(session_id,epoch,source_item_key,observation_json)
|
||||
VALUES(?,?,?,?) ON CONFLICT DO NOTHING`)
|
||||
for (const { settlementId, ordinal } of page.rows) {
|
||||
insert.run(...prefix, settlementId, ordinal)
|
||||
for (const { sourceItemKey, observation } of page.rows) {
|
||||
insert.run(...prefix, sourceItemKey, JSON.stringify(observation))
|
||||
}
|
||||
break
|
||||
}
|
||||
@@ -201,7 +214,7 @@ export function finishJournalDomainImport(
|
||||
db.prepare(`INSERT INTO journal_chat_state(workspace_id,session_id,epoch,last_sequence,retained_sequence,
|
||||
highest_fence,context_boundary,last_activity_at,derived_turn_item_id,history_origin_json,queue_latest_stop_json,
|
||||
queue_manual_stop_json,queue_resumed_sequence,queue_reopened_sequence,queue_clear_sequence,
|
||||
queue_clear_operation_id,queue_clear_lifted,queue_failure_boundary) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
|
||||
queue_clear_operation_id,queue_clear_lifted,queue_failure_boundary,accepted_handover_sequence) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
|
||||
ON CONFLICT(session_id) DO UPDATE SET
|
||||
epoch=excluded.epoch,last_sequence=excluded.last_sequence,retained_sequence=excluded.retained_sequence,
|
||||
highest_fence=excluded.highest_fence,context_boundary=excluded.context_boundary,
|
||||
@@ -210,7 +223,8 @@ export function finishJournalDomainImport(
|
||||
queue_latest_stop_json=excluded.queue_latest_stop_json,queue_manual_stop_json=excluded.queue_manual_stop_json,
|
||||
queue_resumed_sequence=excluded.queue_resumed_sequence,queue_reopened_sequence=excluded.queue_reopened_sequence,
|
||||
queue_clear_sequence=excluded.queue_clear_sequence,queue_clear_operation_id=excluded.queue_clear_operation_id,
|
||||
queue_clear_lifted=excluded.queue_clear_lifted,queue_failure_boundary=excluded.queue_failure_boundary
|
||||
queue_clear_lifted=excluded.queue_clear_lifted,queue_failure_boundary=excluded.queue_failure_boundary,
|
||||
accepted_handover_sequence=excluded.accepted_handover_sequence
|
||||
WHERE journal_chat_state.epoch IS NULL`).run(
|
||||
header.workspaceId,
|
||||
header.sessionId,
|
||||
@@ -231,7 +245,8 @@ export function finishJournalDomainImport(
|
||||
head.queuePauseMarks.cleared?.sequence ?? null,
|
||||
head.queuePauseMarks.cleared?.operationId ?? null,
|
||||
Number(head.queuePauseMarks.cleared?.lifted ?? false),
|
||||
head.queueFailureBoundary
|
||||
head.queueFailureBoundary,
|
||||
head.acceptedHandoverSequence ?? 0
|
||||
)
|
||||
const state = journalDomainImportState(db, header.sessionId)
|
||||
if (state.state !== 'ready') {
|
||||
|
||||
@@ -2,7 +2,10 @@ import { readAnsweredTurn } from './projection/journal-dispatch-reducer'
|
||||
import type Database from '../../sqlite/sync-database'
|
||||
import { agentJournalSubmissionKey } from '../../../shared/agent-session/journal/agent-session-journal-item-key'
|
||||
import type { AgentJournalSubmission } from '../../../shared/agent-session/journal/agent-session-journal-types'
|
||||
import { readWholeAgentSessionFailureFact } from '../../../shared/agent-session/failures/agent-session-failure'
|
||||
import {
|
||||
JOURNAL_DOMAIN_SUBMISSION_COLUMNS,
|
||||
journalDomainSubmissionColumns
|
||||
} from './journal-domain-submission-columns'
|
||||
import { stoppedHistoryCandidate } from '../../../shared/agent-session/lifecycle/agent-session-stopped-history'
|
||||
import type { JournalReducerState } from './projection/journal-reducer'
|
||||
import {
|
||||
@@ -41,6 +44,7 @@ export function restoredJournalDomainSubmission(
|
||||
candidate: state.inputs.candidates.has(id),
|
||||
admittedPersonal,
|
||||
echoObserved: state.inputs.echoes.has(agentJournalSubmissionKey(id)),
|
||||
ended: state.inputs.ended.has(id),
|
||||
admission: {
|
||||
body:
|
||||
submission.dispatchState === 'pending' ||
|
||||
@@ -99,34 +103,25 @@ export function insertJournalDomainImportedSubmission(
|
||||
): void {
|
||||
const { submission, admission, handover } = attempt
|
||||
db.prepare(`INSERT INTO journal_submission_attempts(session_id,epoch,message_id,
|
||||
attempt_sequence,attempt_index,current,item_id,ordinal,submitted_at,accepted_sequence,
|
||||
fingerprint,dispatch_state,candidate,admitted_personal,dispatch_fence,signed_out,recovered,payload_json,echo_observed,
|
||||
admission_body_json,admission_family_id,handover_fence,facts_json)
|
||||
VALUES(?,?,?,?,?,1,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) ON CONFLICT DO NOTHING`).run(
|
||||
attempt_sequence,attempt_index,current,item_id,ordinal,candidate,admitted_personal,payload_json,echo_observed,
|
||||
admission_body_json,admission_family_id,handover_fence,facts_json,${JOURNAL_DOMAIN_SUBMISSION_COLUMNS.join(',')})
|
||||
VALUES(${Array.from({ length: 16 + JOURNAL_DOMAIN_SUBMISSION_COLUMNS.length }, () => '?').join(',')}) ON CONFLICT DO NOTHING`).run(
|
||||
target.sessionId,
|
||||
target.epoch,
|
||||
submission.clientMessageId,
|
||||
attempt.sequence,
|
||||
attempt.index,
|
||||
1,
|
||||
agentJournalSubmissionKey(submission.clientMessageId),
|
||||
attempt.ordinal,
|
||||
submission.submittedAt,
|
||||
submission.acceptedSequence ?? null,
|
||||
submission.payloadFingerprint,
|
||||
submission.dispatchState,
|
||||
Number(attempt.candidate),
|
||||
Number(attempt.admittedPersonal),
|
||||
submission.fence,
|
||||
Number(
|
||||
submission.dispatchState === 'rejected' &&
|
||||
readWholeAgentSessionFailureFact(submission.rejection)?.kind === 'notSignedIn'
|
||||
),
|
||||
Number(submission.recovered === true),
|
||||
JSON.stringify(submission),
|
||||
Number(attempt.echoObserved),
|
||||
admission.body === null ? null : JSON.stringify(admission.body),
|
||||
admission.familyId,
|
||||
handover?.fence ?? null,
|
||||
journalDomainSubmissionFactsJson(attempt)
|
||||
journalDomainSubmissionFactsJson(attempt),
|
||||
...journalDomainSubmissionColumns(submission, attempt.carries)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -184,11 +184,8 @@ it('imports settlement identity order and live lifecycle facts, discarding both
|
||||
maintain(db, { kind: 'import-page', target: imported, page })
|
||||
}
|
||||
expect(
|
||||
db.prepare('SELECT settlement_id,ordinal FROM journal_settlements ORDER BY ordinal').all()
|
||||
).toEqual([
|
||||
{ settlement_id: 'older', ordinal: 1 },
|
||||
{ settlement_id: 'newer', ordinal: 2 }
|
||||
])
|
||||
db.prepare('SELECT settlement_id FROM journal_settlements ORDER BY settlement_id DESC').all()
|
||||
).toEqual([{ settlement_id: 'older' }, { settlement_id: 'newer' }])
|
||||
expect(
|
||||
db
|
||||
.prepare("SELECT item_id,lifecycle_state,live_work FROM journal_items WHERE item_id='tool'")
|
||||
@@ -218,7 +215,7 @@ it('imports settlement identity order and live lifecycle facts, discarding both
|
||||
}
|
||||
maintain(db, { kind: 'import-finish', header: resumed })
|
||||
expect(
|
||||
db.prepare('SELECT settlement_id FROM journal_settlements ORDER BY ordinal').all()
|
||||
db.prepare('SELECT settlement_id FROM journal_settlements ORDER BY settlement_id DESC').all()
|
||||
).toEqual([{ settlement_id: 'older' }, { settlement_id: 'newer' }])
|
||||
})
|
||||
|
||||
|
||||
@@ -20,7 +20,10 @@ import {
|
||||
foldQueuedHandOffInDoubt,
|
||||
placeQueuedHandOffInDoubt
|
||||
} from './submissions/journal-submission-fold'
|
||||
import { journalInputPresentationMember } from './input-order/journal-input-obligations'
|
||||
import {
|
||||
journalInputPresentationMember,
|
||||
type JournalInputEnd
|
||||
} from './input-order/journal-input-obligations'
|
||||
import { journalInputOrder } from './input-order/journal-input-order'
|
||||
import { journalOutcomeSource } from './outcomes/journal-outcome-format'
|
||||
import { memoryJournalMap, memoryJournalSet } from './journal-memory-collections'
|
||||
@@ -42,6 +45,7 @@ export type JournalDomainImportHead = {
|
||||
lastActivityAt: number
|
||||
derivedTurnItemId: string | null
|
||||
historyOrigin: JournalHistoryOrigin | null
|
||||
acceptedHandoverSequence?: number
|
||||
queuePauseMarks: Omit<JournalQueuePauseMarks, 'cleared'> & {
|
||||
cleared?: Omit<NonNullable<JournalQueuePauseMarks['cleared']>, 'messageIds'>
|
||||
}
|
||||
@@ -77,7 +81,11 @@ export type JournalDomainImportPage =
|
||||
| { kind: 'activity'; rows: { fence: number; lastActivityAt: number }[] }
|
||||
| { kind: 'queue-clear-members'; rows: { messageId: string }[] }
|
||||
| { kind: 'removed-turns'; rows: { turnId: string }[] }
|
||||
| { kind: 'settlements'; rows: { settlementId: string; ordinal: number }[] }
|
||||
| { kind: 'settlements'; rows: { settlementId: string }[] }
|
||||
| {
|
||||
kind: 'input-end-observations'
|
||||
rows: { sourceItemKey: string; observation: JournalInputEnd }[]
|
||||
}
|
||||
|
||||
export type JournalDomainImportHeader = {
|
||||
sessionId: string
|
||||
@@ -134,6 +142,7 @@ export function prepareJournalDomainImport(
|
||||
lastActivityAt: state.lastActivityAt,
|
||||
derivedTurnItemId: state.derivedTurnScope.snapshot(),
|
||||
historyOrigin: state.historyOrigin,
|
||||
acceptedHandoverSequence: journalInputOrder(state).links.acceptedHandover(),
|
||||
queuePauseMarks: {
|
||||
...pauseMarks,
|
||||
...(cleared
|
||||
@@ -238,9 +247,13 @@ function* importPages(
|
||||
yield* paged('receipts', [...memoryJournalMap(state.receipts).values()])
|
||||
yield* paged(
|
||||
'settlements',
|
||||
[...memoryJournalSet(state.appliedSettlementIds)].map((settlementId, index) => ({
|
||||
settlementId,
|
||||
ordinal: index + 1
|
||||
[...memoryJournalSet(state.appliedSettlementIds)].map((settlementId) => ({ settlementId }))
|
||||
)
|
||||
yield* paged(
|
||||
'input-end-observations',
|
||||
[...memoryJournalMap(state.inputs.ends)].map(([sourceItemKey, observation]) => ({
|
||||
sourceItemKey,
|
||||
observation
|
||||
}))
|
||||
)
|
||||
yield* paged('cards', [...cards.values()])
|
||||
|
||||
@@ -0,0 +1,176 @@
|
||||
import { afterEach, expect, it } from 'vitest'
|
||||
import {
|
||||
domainLifecycleFixture,
|
||||
lifecycleIdentity as identity,
|
||||
lifecycleOptions as options,
|
||||
lifecycleTarget as target
|
||||
} from './journal-domain-lifecycle.test-fixture'
|
||||
import { observeJournalDomainInputStop } from './journal-domain-input-ends'
|
||||
import { readJournalDomainSubmissionAttempt } from './journal-domain-submission-records'
|
||||
|
||||
const cleanups: (() => void)[] = []
|
||||
afterEach(() => {
|
||||
for (const cleanup of cleanups.splice(0)) {
|
||||
cleanup()
|
||||
}
|
||||
})
|
||||
|
||||
it('retains an admitted turn identity across removal so a later scoped Stop ends the handover', async () => {
|
||||
const f = domainLifecycleFixture(cleanups)
|
||||
await f.run({
|
||||
kind: 'item',
|
||||
identity: identity('turn'),
|
||||
body: { kind: 'turn', turnId: 'provider-turn', state: 'running' },
|
||||
options
|
||||
})
|
||||
await f.run({
|
||||
kind: 'submission',
|
||||
input: {
|
||||
clientMessageId: 'send',
|
||||
body: { kind: 'message', role: 'user', blocks: [{ type: 'text', text: 'Continue' }] },
|
||||
payloadFingerprint: 'fingerprint',
|
||||
fence: 1,
|
||||
handoverRecorded: true
|
||||
}
|
||||
})
|
||||
await f.run({
|
||||
kind: 'dispatch',
|
||||
input: {
|
||||
clientMessageId: 'send',
|
||||
fence: 1,
|
||||
state: 'pending',
|
||||
turnScope: { kind: 'turn', turnItemId: 'orca:turn' }
|
||||
}
|
||||
})
|
||||
await f.run({ kind: 'tombstone', identity: identity('turn'), fence: 1 })
|
||||
expect(f.item('orca:turn')).toBeUndefined()
|
||||
expect(readJournalDomainSubmissionAttempt(f.db, target, 'send')?.ended).toBe(false)
|
||||
f.db.exec('BEGIN IMMEDIATE')
|
||||
observeJournalDomainInputStop(f.db, target, 'stop', 5, 1, {
|
||||
reason: 'user-stop',
|
||||
turnId: 'provider-turn',
|
||||
at: 100
|
||||
})
|
||||
f.db.exec('COMMIT')
|
||||
f.reopen()
|
||||
expect(readJournalDomainSubmissionAttempt(f.db, target, 'send')?.ended).toBe(true)
|
||||
})
|
||||
|
||||
it('observes only the turn body admitted by the complete lifecycle row', async () => {
|
||||
const f = domainLifecycleFixture(cleanups)
|
||||
await f.run({
|
||||
kind: 'submission',
|
||||
input: {
|
||||
clientMessageId: 'send',
|
||||
body: { kind: 'message', role: 'user', blocks: [{ type: 'text', text: 'Continue' }] },
|
||||
payloadFingerprint: 'fingerprint',
|
||||
fence: 1,
|
||||
handoverRecorded: true
|
||||
}
|
||||
})
|
||||
await f.run({
|
||||
kind: 'dispatch',
|
||||
input: {
|
||||
clientMessageId: 'send',
|
||||
fence: 1,
|
||||
state: 'pending',
|
||||
turnScope: { kind: 'turn', turnItemId: 'orca:turn' }
|
||||
}
|
||||
})
|
||||
await f.run({
|
||||
kind: 'lifecycle',
|
||||
input: {
|
||||
settlementId: 'revised',
|
||||
fence: 1,
|
||||
mutations: [
|
||||
{
|
||||
kind: 'item',
|
||||
identity: identity('turn'),
|
||||
body: { kind: 'turn', turnId: 't', state: 'interrupted' }
|
||||
},
|
||||
{
|
||||
kind: 'item',
|
||||
identity: identity('turn'),
|
||||
body: { kind: 'turn', turnId: 't', state: 'running' }
|
||||
}
|
||||
]
|
||||
}
|
||||
})
|
||||
expect(readJournalDomainSubmissionAttempt(f.db, target, 'send')?.ended).toBe(false)
|
||||
await f.run({
|
||||
kind: 'lifecycle',
|
||||
input: {
|
||||
settlementId: 'removed',
|
||||
fence: 1,
|
||||
mutations: [
|
||||
{
|
||||
kind: 'item',
|
||||
identity: identity('turn'),
|
||||
body: { kind: 'turn', turnId: 't', state: 'interrupted' }
|
||||
},
|
||||
{ kind: 'tombstone', identity: identity('turn') }
|
||||
]
|
||||
}
|
||||
})
|
||||
expect(readJournalDomainSubmissionAttempt(f.db, target, 'send')?.ended).toBe(false)
|
||||
await f.run({
|
||||
kind: 'item',
|
||||
identity: identity('turn'),
|
||||
body: { kind: 'turn', turnId: 't', state: 'interrupted' },
|
||||
options
|
||||
})
|
||||
expect(readJournalDomainSubmissionAttempt(f.db, target, 'send')?.ended).toBe(true)
|
||||
})
|
||||
|
||||
it('keeps accepted handover and receipt positions after the optimistic item is removed', async () => {
|
||||
const f = domainLifecycleFixture(cleanups)
|
||||
await f.run({
|
||||
kind: 'submission',
|
||||
input: {
|
||||
clientMessageId: 'send',
|
||||
body: { kind: 'message', role: 'user', blocks: [{ type: 'text', text: 'Hello' }] },
|
||||
payloadFingerprint: 'fingerprint',
|
||||
fence: 1,
|
||||
handoverRecorded: true
|
||||
}
|
||||
})
|
||||
await f.run({
|
||||
kind: 'dispatch',
|
||||
input: {
|
||||
clientMessageId: 'send',
|
||||
fence: 1,
|
||||
state: 'accepted',
|
||||
providerIdentity: identity('provider')
|
||||
}
|
||||
})
|
||||
await f.run({ kind: 'tombstone', identity: identity('send'), fence: 1 })
|
||||
expect(f.item('orca:send')).toBeUndefined()
|
||||
expect(f.db.prepare(`SELECT accepted_handover_sequence FROM journal_chat_state`).get()).toEqual({
|
||||
accepted_handover_sequence: 1
|
||||
})
|
||||
expect(f.db.prepare(`SELECT cursor_sequence FROM journal_send_receipts`).get()).toEqual({
|
||||
cursor_sequence: 2
|
||||
})
|
||||
await f.run({
|
||||
kind: 'submission',
|
||||
input: {
|
||||
clientMessageId: 'without-provider',
|
||||
body: { kind: 'message', role: 'user', blocks: [{ type: 'text', text: 'Continue' }] },
|
||||
payloadFingerprint: 'next-fingerprint',
|
||||
fence: 1,
|
||||
handoverRecorded: true
|
||||
}
|
||||
})
|
||||
await f.run({
|
||||
kind: 'dispatch',
|
||||
input: {
|
||||
clientMessageId: 'without-provider',
|
||||
fence: 1,
|
||||
state: 'accepted',
|
||||
providerIdentity: null
|
||||
}
|
||||
})
|
||||
expect(f.db.prepare(`SELECT accepted_handover_sequence FROM journal_chat_state`).get()).toEqual({
|
||||
accepted_handover_sequence: 4
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,210 @@
|
||||
import type Database from '../../sqlite/sync-database'
|
||||
import type {
|
||||
AgentJournalRenderItem,
|
||||
AgentJournalSubmission,
|
||||
AgentJournalStatusItem
|
||||
} from '../../../shared/agent-session/journal/agent-session-journal-types'
|
||||
import { agentJournalSubmissionKey } from '../../../shared/agent-session/journal/agent-session-journal-item-key'
|
||||
import { readAgentJournalTurn } from '../../../shared/agent-session/lifecycle/agent-session-turn-record'
|
||||
import { readCodexErrorWillRetry } from '../../codex/app-server/codex-structured-thread-facts'
|
||||
import type { JournalInputEnd } from './input-order/journal-input-obligations'
|
||||
import type { JournalDomainSubmissionStoredFacts } from './journal-domain-submission-records'
|
||||
import type { JournalItemRow, JournalStopEvent } from './durable-rows/journal-row-schema'
|
||||
|
||||
type Target = { sessionId: string; epoch: string }
|
||||
export type JournalDomainInputItemObservation = Pick<
|
||||
JournalItemRow,
|
||||
'itemId' | 'seq' | 'fence' | 'executionOwner' | 'ownerFence' | 'agentId' | 'turnScope'
|
||||
>
|
||||
|
||||
function* candidates(db: Database.Database, target: Target) {
|
||||
let ordinal = -1
|
||||
let messageId = ''
|
||||
for (;;) {
|
||||
const page = db
|
||||
.prepare(`SELECT message_id,ordinal,attempt_sequence,payload_json,facts_json,
|
||||
admission_body_json IS NOT NULL AS has_source FROM journal_submission_attempts
|
||||
WHERE session_id=? AND epoch=? AND current=1 AND candidate=1
|
||||
AND (ordinal,message_id)>(?,?) ORDER BY ordinal,message_id LIMIT 128`)
|
||||
.all(target.sessionId, target.epoch, ordinal, messageId)
|
||||
for (const row of page) {
|
||||
const submission: AgentJournalSubmission = JSON.parse(String(row.payload_json))
|
||||
const facts: JournalDomainSubmissionStoredFacts = JSON.parse(String(row.facts_json))
|
||||
yield {
|
||||
submission,
|
||||
facts,
|
||||
sourceSequence: row.has_source ? Number(row.attempt_sequence) : undefined
|
||||
}
|
||||
}
|
||||
if (page.length < 128) {
|
||||
return
|
||||
}
|
||||
const last = page.at(-1)!
|
||||
ordinal = Number(last.ordinal)
|
||||
messageId = String(last.message_id)
|
||||
}
|
||||
}
|
||||
|
||||
function observe(
|
||||
db: Database.Database,
|
||||
target: Target,
|
||||
sourceItemKey: string,
|
||||
observation: JournalInputEnd
|
||||
) {
|
||||
db.prepare(`INSERT INTO journal_input_end_observations(session_id,epoch,source_item_key,observation_json)
|
||||
VALUES(?,?,?,?) ON CONFLICT(session_id,epoch,source_item_key) DO UPDATE SET observation_json=excluded.observation_json`).run(
|
||||
target.sessionId,
|
||||
target.epoch,
|
||||
sourceItemKey,
|
||||
JSON.stringify(observation)
|
||||
)
|
||||
}
|
||||
|
||||
function ended(db: Database.Database, target: Target, messageId: string) {
|
||||
db.prepare(`UPDATE journal_submission_attempts SET facts_json=json_set(facts_json,'$.ended',json('true'))
|
||||
WHERE session_id=? AND epoch=? AND message_id=? AND current=1`).run(
|
||||
target.sessionId,
|
||||
target.epoch,
|
||||
messageId
|
||||
)
|
||||
}
|
||||
|
||||
function providerAttemptEnded(frame: AgentJournalStatusItem['providerFrame']) {
|
||||
if (
|
||||
frame?.provider !== 'codex' ||
|
||||
frame.kind !== 'notification:error' ||
|
||||
frame.payload.truncated
|
||||
) {
|
||||
return false
|
||||
}
|
||||
try {
|
||||
return !readCodexErrorWillRetry(JSON.parse(frame.payload.head))
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
/** Observe only admitted source items, never a placement change or a derived display rewrite. */
|
||||
export function observeJournalDomainInputItem(
|
||||
db: Database.Database,
|
||||
target: Target,
|
||||
item: AgentJournalRenderItem,
|
||||
source: JournalDomainInputItemObservation
|
||||
): void {
|
||||
if (source.agentId) {
|
||||
return
|
||||
}
|
||||
const fence = source.executionOwner ?? source.ownerFence ?? source.fence
|
||||
const turn = readAgentJournalTurn(item.body)
|
||||
const terminal =
|
||||
(turn && turn.state !== 'running' && turn.state !== 'unverifiable') ||
|
||||
providerAttemptEnded(item.body.kind === 'status' ? item.body.providerFrame : undefined)
|
||||
if (!turn && !terminal) {
|
||||
return
|
||||
}
|
||||
observe(db, target, source.itemId, { kind: 'item', turnId: turn?.turnId ?? null })
|
||||
if (!terminal) {
|
||||
return
|
||||
}
|
||||
let latest = 0
|
||||
for (const { submission, facts } of candidates(db, target)) {
|
||||
if ((facts.handover?.fence ?? facts.admission.fence ?? submission.fence) === fence) {
|
||||
latest = Math.max(latest, facts.handover?.sequence ?? submission.submittedSequence ?? 0)
|
||||
}
|
||||
}
|
||||
for (const { submission, facts, sourceSequence } of candidates(db, target)) {
|
||||
if (
|
||||
facts.ended ||
|
||||
(facts.handover?.fence ?? facts.admission.fence ?? submission.fence) !== fence
|
||||
) {
|
||||
continue
|
||||
}
|
||||
const after =
|
||||
facts.handover?.sequence ??
|
||||
(submission.handoverRecorded ? Infinity : (sourceSequence ?? Infinity))
|
||||
const scope = facts.handover?.scope ?? facts.admission.scope
|
||||
const matches =
|
||||
scope?.kind === 'turn'
|
||||
? scope.turnItemId ===
|
||||
(source.turnScope?.kind === 'turn' ? source.turnScope.turnItemId : source.itemId)
|
||||
: turn?.userItemId
|
||||
? turn.userItemId === agentJournalSubmissionKey(submission.clientMessageId)
|
||||
: after === latest
|
||||
if (matches && source.seq > after) {
|
||||
ended(db, target, submission.clientMessageId)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** A removed turn's admitted identity remains evidence for a later scoped user Stop. */
|
||||
export function observeJournalDomainInputStop(
|
||||
db: Database.Database,
|
||||
target: Target,
|
||||
sourceItemKey: string,
|
||||
sequence: number,
|
||||
fence: number,
|
||||
event: JournalStopEvent
|
||||
): void {
|
||||
const prior = db
|
||||
.prepare(`SELECT observation_json FROM journal_input_end_observations
|
||||
WHERE session_id=? AND epoch=? AND source_item_key=?`)
|
||||
.get(target.sessionId, target.epoch, sourceItemKey)
|
||||
const previous: JournalInputEnd | null = prior ? JSON.parse(String(prior.observation_json)) : null
|
||||
if (previous?.kind === 'stop' && JSON.stringify(previous.event) === JSON.stringify(event)) {
|
||||
return
|
||||
}
|
||||
observe(db, target, sourceItemKey, { kind: 'stop', event })
|
||||
for (const { submission, facts } of candidates(db, target)) {
|
||||
const handover = facts.handover
|
||||
if (
|
||||
facts.ended ||
|
||||
!handover ||
|
||||
handover.fence !== fence ||
|
||||
sequence <= handover.sequence ||
|
||||
event.reason !== 'user-stop'
|
||||
) {
|
||||
continue
|
||||
}
|
||||
const scope = handover.scope
|
||||
let turnId: string | null | undefined
|
||||
if (scope?.kind === 'turn') {
|
||||
const row = db
|
||||
.prepare(`SELECT observation_json FROM journal_input_end_observations
|
||||
WHERE session_id=? AND epoch=? AND source_item_key=?`)
|
||||
.get(target.sessionId, target.epoch, scope.turnItemId)
|
||||
const end: JournalInputEnd | null = row ? JSON.parse(String(row.observation_json)) : null
|
||||
if (end?.kind === 'item') {
|
||||
turnId = end.turnId
|
||||
} else {
|
||||
const current = db
|
||||
.prepare(`SELECT payload_json FROM journal_items
|
||||
WHERE session_id=? AND epoch=? AND item_id=?`)
|
||||
.get(target.sessionId, target.epoch, scope.turnItemId)
|
||||
const item: AgentJournalRenderItem | null = current
|
||||
? JSON.parse(String(current.payload_json))
|
||||
: null
|
||||
turnId = readAgentJournalTurn(item?.body)?.turnId
|
||||
}
|
||||
}
|
||||
if (!event.turnId || turnId === event.turnId) {
|
||||
ended(db, target, submission.clientMessageId)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** The accepted native item's observed placement is historical, and removal cannot lower it. */
|
||||
export function refreshJournalDomainAcceptedHandover(
|
||||
db: Database.Database,
|
||||
target: Target,
|
||||
itemId: string
|
||||
): void {
|
||||
const item = db
|
||||
.prepare(`SELECT item.sequence FROM journal_submission_attempts attempt
|
||||
JOIN journal_items item ON item.session_id=attempt.session_id AND item.epoch=attempt.epoch AND item.item_id=attempt.item_id
|
||||
WHERE attempt.session_id=? AND attempt.epoch=? AND attempt.item_id=? AND attempt.current=1 AND attempt.dispatch_state='accepted'`)
|
||||
.get(target.sessionId, target.epoch, itemId)
|
||||
if (item) {
|
||||
db.prepare(`UPDATE journal_chat_state SET accepted_handover_sequence=MAX(accepted_handover_sequence,?)
|
||||
WHERE session_id=? AND epoch=?`).run(item.sequence, target.sessionId, target.epoch)
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,10 @@ import { currentAgentSessionThreadGoalSourceBySequence } from '../../../shared/a
|
||||
import { readAgentJournalTurn } from '../../../shared/agent-session/lifecycle/agent-session-turn-record'
|
||||
import { claudeAgentRowFacts } from '../../claude/claude-subagent-journaled-identities'
|
||||
import { journalDomainHistoryMetadata } from './journal-domain-history-metadata'
|
||||
import { journalItemLifecycleState } from './journal-item-status-metadata'
|
||||
import {
|
||||
journalItemLifecycleState,
|
||||
journalItemStatusMetadata
|
||||
} from './journal-item-status-metadata'
|
||||
import { lostLiveWorkJournalBody } from './item-lifecycle/journal-subagent-liveness'
|
||||
import { isUnverifiedEndAgentJournalToolCall } from '../../../shared/agent-journal-tool-call-lifecycle'
|
||||
|
||||
@@ -98,12 +101,16 @@ export const JOURNAL_DOMAIN_ITEM_COLUMNS = [
|
||||
'live_work',
|
||||
'context_window',
|
||||
'unverified_end',
|
||||
'turn_completed_at'
|
||||
'turn_completed_at',
|
||||
'command_entry',
|
||||
'assistant_prose',
|
||||
'turn_scope_kind'
|
||||
] as const
|
||||
|
||||
/** One payload projection supplies import, current writes and derived Stop revisions. */
|
||||
export function journalDomainItemColumns(item: AgentJournalRenderItem, payload: string) {
|
||||
const metadata = journalDomainHistoryMetadata(item, payload)
|
||||
const [, commandEntry, , assistantProse, turnScopeKind] = journalItemStatusMetadata(item)
|
||||
return {
|
||||
metadata,
|
||||
values: [
|
||||
@@ -114,7 +121,10 @@ export function journalDomainItemColumns(item: AgentJournalRenderItem, payload:
|
||||
metadata.wireBytes,
|
||||
item.turnScope?.kind === 'turn' ? item.turnScope.turnItemId : null,
|
||||
...journalDomainItemReadColumns(item),
|
||||
...journalDomainItemLifecycleColumns(item)
|
||||
...journalDomainItemLifecycleColumns(item),
|
||||
commandEntry,
|
||||
assistantProse,
|
||||
turnScopeKind
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -190,6 +190,7 @@ export function applyJournalDomainItem(
|
||||
}
|
||||
const rendered = journalRenderItem(itemId, revision, row.body, row, scope)
|
||||
const items = writeJournalDomainCurrentItem(db, target, {
|
||||
inputObservation: row,
|
||||
item: previous ? journalItemRevisionValue(previous, rendered) : rendered,
|
||||
...(previous
|
||||
? {
|
||||
|
||||
@@ -125,6 +125,7 @@ export function writeJournalDomainLifecycleItem(
|
||||
}
|
||||
return {
|
||||
items,
|
||||
inputObservation: { item: items[0]!, source: { ...row, ...mutation.linkage } },
|
||||
receipts: receipt ? [receipt] : [],
|
||||
...(receipt ? { acceptedInputs: readJournalSqlAcceptedInputs(db, prefix) } : {})
|
||||
}
|
||||
|
||||
@@ -126,27 +126,22 @@ it('rolls back the entire lifecycle mutation group and its receipt if any write
|
||||
expect(retried.publication?.items).toMatchObject([{ itemId: 'orca:prefix', revision: 1 }])
|
||||
})
|
||||
|
||||
it('keeps FIFO settlement retry authority bounded without reordering a duplicate', async () => {
|
||||
it('retains settlement retry authority after more than 4096 unrelated settlements', async () => {
|
||||
const f = domainLifecycleFixture(cleanups)
|
||||
const insert = f.db.prepare(`INSERT INTO journal_settlements VALUES('chat','epoch',?,?)`)
|
||||
const insert = f.db.prepare(`INSERT INTO journal_settlements VALUES('chat','epoch',?)`)
|
||||
for (let index = 0; index < 4096; index++) {
|
||||
insert.run(`receipt-${index}`, index + 1)
|
||||
insert.run(`receipt-${index}`)
|
||||
}
|
||||
await f.run({
|
||||
kind: 'lifecycle',
|
||||
input: { settlementId: 'receipt-0', fence: 1, mutations: [status('duplicate')] }
|
||||
})
|
||||
await f.run({
|
||||
kind: 'lifecycle',
|
||||
input: { settlementId: 'new', fence: 1, mutations: [status('new')] }
|
||||
})
|
||||
expect(f.item('orca:duplicate')).toBeUndefined()
|
||||
expect(
|
||||
f.db.prepare(`SELECT settlement_id FROM journal_settlements ORDER BY ordinal LIMIT 1`).get()
|
||||
).toEqual({ settlement_id: 'receipt-1' })
|
||||
expect(f.db.prepare(`SELECT COUNT(*) AS total FROM journal_settlements`).get()).toEqual({
|
||||
total: 4096
|
||||
await f.run({
|
||||
kind: 'lifecycle',
|
||||
input: { settlementId: 'receipt-0', fence: 1, mutations: [status('duplicate')] }
|
||||
})
|
||||
expect(f.item('orca:duplicate')).toBeUndefined()
|
||||
expect(f.item('orca:new')?.body).toEqual({ kind: 'status', text: 'new' })
|
||||
})
|
||||
|
||||
it('returns direct personal input on start failure and lets an earlier handover win', async () => {
|
||||
|
||||
@@ -19,6 +19,7 @@ import { assertJournalFence } from './writing/journal-write-guards'
|
||||
import { appendJournalSqlEvent } from './journal-sql-event-tail'
|
||||
import { spendJournalSqlCommandCards } from './journal-sql-message-effects'
|
||||
import { writeJournalDomainLifecycleItem } from './journal-domain-lifecycle-item'
|
||||
import { observeJournalDomainInputItem } from './journal-domain-input-ends'
|
||||
|
||||
export type JournalDomainLifecycleCommit = JournalWriterPublication & {
|
||||
cursor: AgentJournalCursor
|
||||
@@ -65,17 +66,8 @@ function recordSettlement(
|
||||
settlementId: string
|
||||
): void {
|
||||
const prefix = [target.sessionId, target.epoch] as const
|
||||
db.prepare(`INSERT OR IGNORE INTO journal_settlements(session_id,epoch,settlement_id,ordinal)
|
||||
SELECT ?,?,?,COALESCE(MAX(ordinal),0)+1 FROM journal_settlements WHERE session_id=? AND epoch=?`).run(
|
||||
...prefix,
|
||||
settlementId,
|
||||
...prefix
|
||||
)
|
||||
db.prepare(`DELETE FROM journal_settlements WHERE session_id=? AND epoch=? AND ordinal <=
|
||||
(SELECT ordinal FROM journal_settlements WHERE session_id=? AND epoch=? ORDER BY ordinal DESC LIMIT 1 OFFSET 4096)`).run(
|
||||
...prefix,
|
||||
...prefix
|
||||
)
|
||||
db.prepare(`INSERT OR IGNORE INTO journal_settlements(session_id,epoch,settlement_id)
|
||||
VALUES(?,?,?)`).run(...prefix, settlementId)
|
||||
}
|
||||
|
||||
/** Current dispatches precede the atomic mutation groups, exactly at this writer position. */
|
||||
@@ -124,6 +116,9 @@ export function applyJournalDomainLifecycle(
|
||||
}
|
||||
const sequence = result.cursor.sequence + 1
|
||||
const changedItems: JournalWriterPublication['items'] = []
|
||||
const inputObservations: ReturnType<
|
||||
typeof writeJournalDomainLifecycleItem
|
||||
>['inputObservation'][] = []
|
||||
const removedItemIds: string[] = []
|
||||
const head = db
|
||||
.prepare(`SELECT highest_fence FROM journal_chat_state WHERE session_id=? AND epoch=?`)
|
||||
@@ -193,6 +188,7 @@ export function applyJournalDomainLifecycle(
|
||||
)
|
||||
deleted.delete(revived)
|
||||
changedItems.push(...commit.items)
|
||||
inputObservations.push(commit.inputObservation)
|
||||
result.receipts.push(...commit.receipts)
|
||||
result.inputChanged ||= commit.receipts.length > 0
|
||||
result.acceptedInputs = commit.acceptedInputs ?? result.acceptedInputs
|
||||
@@ -201,6 +197,12 @@ export function applyJournalDomainLifecycle(
|
||||
if (oversized && changedItems.length === 0 && removedItemIds.length === 0) {
|
||||
continue
|
||||
}
|
||||
const currentItems = new Map(changedItems.map((item) => [item.itemId, item]))
|
||||
for (const { item, source } of inputObservations) {
|
||||
if (item.itemId === source.itemId && currentItems.get(source.itemId)?.body === item.body) {
|
||||
observeJournalDomainInputItem(db, target, item, source)
|
||||
}
|
||||
}
|
||||
const spent = spendJournalSqlCommandCards(db, [target.sessionId, target.epoch], savedAt)
|
||||
result.cards.push(...spent.cards)
|
||||
result.inputChanged ||= spent.cards.length > 0
|
||||
|
||||
@@ -64,10 +64,10 @@ it('prunes proven retired epochs with atomic rollback while preserving incomplet
|
||||
db.prepare(`INSERT INTO journal_submission_attempts(session_id,epoch,message_id,attempt_sequence,
|
||||
attempt_index,current,item_id,ordinal,submitted_at,fingerprint,dispatch_state,payload_json)
|
||||
VALUES(?,?,'send',1,0,1,'body',1,1,'fingerprint','accepted','accepted body')`).run(...prefix)
|
||||
db.prepare(`INSERT INTO journal_send_receipts VALUES(?,?,'send','accepted receipt')`).run(
|
||||
...prefix
|
||||
)
|
||||
db.prepare(`INSERT INTO journal_settlements VALUES(?,?,'settlement',1)`).run(...prefix)
|
||||
db.prepare(
|
||||
`INSERT INTO journal_send_receipts(session_id,epoch,message_id,payload_json) VALUES(?,?,'send','accepted receipt')`
|
||||
).run(...prefix)
|
||||
db.prepare(`INSERT INTO journal_settlements VALUES(?,?,'settlement')`).run(...prefix)
|
||||
db.prepare(
|
||||
`INSERT INTO journal_queue_cards VALUES(?,?,'queued',1,'waiting',1,NULL,'domain body')`
|
||||
).run(...prefix)
|
||||
@@ -355,7 +355,9 @@ it('packs retired payload bytes across tables and lets one oversized row progres
|
||||
insert.run('second', JSON.stringify({ text: 'α'.repeat(150 * 1024) }))
|
||||
db.prepare(`UPDATE journal_items SET original_stop_note_json=?
|
||||
WHERE item_id='second'`).run('x'.repeat(600 * 1024))
|
||||
const receipt = db.prepare(`INSERT INTO journal_send_receipts VALUES('chat','before',?,?)`)
|
||||
const receipt = db.prepare(
|
||||
`INSERT INTO journal_send_receipts(session_id,epoch,message_id,payload_json) VALUES('chat','before',?,?)`
|
||||
)
|
||||
receipt.run('first', JSON.stringify({ text: 'x'.repeat(600 * 1024) }))
|
||||
receipt.run('oversized', JSON.stringify({ text: 'x'.repeat(2 * 1024 * 1024) }))
|
||||
const prune = () =>
|
||||
|
||||
@@ -26,6 +26,7 @@ const RETIRED_TABLES: readonly { name: string; key: string; payload?: readonly s
|
||||
},
|
||||
{ name: 'journal_send_receipts', key: 'message_id', payload: ['payload_json'] },
|
||||
{ name: 'journal_settlements', key: 'settlement_id' },
|
||||
{ name: 'journal_input_end_observations', key: 'source_item_key', payload: ['observation_json'] },
|
||||
{ name: 'journal_queue_cards', key: 'message_id', payload: ['payload_json'] },
|
||||
{ name: 'journal_queue_clear_members', key: 'message_id' },
|
||||
{ name: 'journal_edit_leases', key: 'owner_id,caller_key,edit_id' },
|
||||
|
||||
@@ -29,6 +29,10 @@ import {
|
||||
import { readJournalDomainTurnScope } from './journal-domain-turn-scope'
|
||||
import { writeJournalDomainQueueReopenMark } from './journal-domain-queue-pauses'
|
||||
import { appendJournalSqlEvent } from './journal-sql-event-tail'
|
||||
import {
|
||||
JOURNAL_DOMAIN_SUBMISSION_COLUMNS,
|
||||
journalDomainSubmissionColumns
|
||||
} from './journal-domain-submission-columns'
|
||||
|
||||
/** Accepted input, queue ownership and attachment claims precede provider dispatch atomically. */
|
||||
export function applyJournalDomainSubmission(
|
||||
@@ -155,17 +159,17 @@ export function applyJournalDomainSubmission(
|
||||
)
|
||||
}
|
||||
db.prepare(`INSERT INTO journal_submission_attempts(session_id,epoch,message_id,attempt_sequence,attempt_index,current,
|
||||
item_id,ordinal,submitted_at,accepted_sequence,fingerprint,dispatch_state,candidate,admitted_personal,payload_json,
|
||||
admission_body_json,admission_family_id,facts_json,dispatch_fence)
|
||||
VALUES(?,?,?,?,0,1,?,?,?,?,?,'pending',1,?,?,?,?,?,?)`).run(
|
||||
item_id,ordinal,candidate,admitted_personal,payload_json,
|
||||
admission_body_json,admission_family_id,facts_json,${JOURNAL_DOMAIN_SUBMISSION_COLUMNS.join(',')})
|
||||
VALUES(${Array.from({ length: 14 + JOURNAL_DOMAIN_SUBMISSION_COLUMNS.length }, () => '?').join(',')})`).run(
|
||||
...prefix,
|
||||
input.clientMessageId,
|
||||
sequence,
|
||||
0,
|
||||
1,
|
||||
itemId,
|
||||
ordinal,
|
||||
savedAt,
|
||||
submission.acceptedSequence ?? null,
|
||||
input.payloadFingerprint,
|
||||
1,
|
||||
Number(
|
||||
familyId !== undefined
|
||||
? selected !== null && journalDomainAdmittedPersonal(selected.card)
|
||||
@@ -188,9 +192,10 @@ export function applyJournalDomainSubmission(
|
||||
carries: [],
|
||||
rejection: null,
|
||||
presentationMember: false,
|
||||
normalizedHandOff: false
|
||||
normalizedHandOff: false,
|
||||
ended: false
|
||||
}),
|
||||
input.fence
|
||||
...journalDomainSubmissionColumns(submission, [])
|
||||
)
|
||||
const blocked = db
|
||||
.prepare(`SELECT 1 FROM journal_items WHERE session_id=? AND epoch=? AND item_id=?
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
import type { AgentJournalSubmission } from '../../../shared/agent-session/journal/agent-session-journal-types'
|
||||
import { readWholeAgentSessionFailureFact } from '../../../shared/agent-session/failures/agent-session-failure'
|
||||
import { classifyDispatchRejection } from '../../../shared/agent-session/requests/structured-agent-session-dispatch-rejection'
|
||||
import {
|
||||
refusedBeforeWrite,
|
||||
stoppedHistoryCandidate
|
||||
} from '../../../shared/agent-session/lifecycle/agent-session-stopped-history'
|
||||
|
||||
export const JOURNAL_DOMAIN_SUBMISSION_COLUMNS = [
|
||||
'submitted_at',
|
||||
'accepted_sequence',
|
||||
'fingerprint',
|
||||
'dispatch_state',
|
||||
'dispatch_fence',
|
||||
'signed_out',
|
||||
'recovered',
|
||||
'submitted_sequence',
|
||||
'request_failure',
|
||||
'steer_turn_item_id',
|
||||
'stopped_history',
|
||||
'covers_stopped_history'
|
||||
] as const
|
||||
|
||||
/** All current-attempt selectors describe the same saved dispatch and its source coverage. */
|
||||
export function journalDomainSubmissionColumns(
|
||||
submission: AgentJournalSubmission,
|
||||
carries: readonly string[]
|
||||
) {
|
||||
return [
|
||||
submission.submittedAt,
|
||||
submission.acceptedSequence ?? null,
|
||||
submission.payloadFingerprint,
|
||||
submission.dispatchState,
|
||||
submission.fence,
|
||||
Number(
|
||||
submission.dispatchState === 'rejected' &&
|
||||
readWholeAgentSessionFailureFact(submission.rejection)?.kind === 'notSignedIn'
|
||||
),
|
||||
Number(submission.recovered === true),
|
||||
submission.submittedSequence ?? null,
|
||||
Number(
|
||||
submission.dispatchState === 'rejected' &&
|
||||
classifyDispatchRejection(submission).verdict === 'failure'
|
||||
),
|
||||
submission.answeredInTurn?.via === 'steer' ? submission.answeredInTurn.turnItemId : null,
|
||||
Number(stoppedHistoryCandidate(submission)),
|
||||
Number(carries.length > 0 && !refusedBeforeWrite(submission))
|
||||
]
|
||||
}
|
||||
@@ -79,6 +79,7 @@ export type JournalDomainSubmissionAttempt = {
|
||||
rejection: JournalDomainSubmissionRejection | null
|
||||
presentationMember: boolean
|
||||
normalizedHandOff: boolean
|
||||
ended?: boolean
|
||||
}
|
||||
|
||||
export type JournalDomainSubmissionCoordinate = {
|
||||
@@ -112,14 +113,22 @@ export type JournalDomainSubmissionStoredFacts = Pick<
|
||||
| 'rejection'
|
||||
| 'presentationMember'
|
||||
| 'normalizedHandOff'
|
||||
| 'ended'
|
||||
> & {
|
||||
admission: Omit<JournalDomainSubmissionAdmission, 'body' | 'familyId'>
|
||||
}
|
||||
|
||||
export function journalDomainSubmissionFactsJson(attempt: JournalDomainSubmissionAttempt): string {
|
||||
const { body: _body, familyId: _family, ...admission } = attempt.admission
|
||||
const { handover, handoverPlace, carries, rejection, presentationMember, normalizedHandOff } =
|
||||
attempt
|
||||
const {
|
||||
handover,
|
||||
handoverPlace,
|
||||
carries,
|
||||
rejection,
|
||||
presentationMember,
|
||||
normalizedHandOff,
|
||||
ended
|
||||
} = attempt
|
||||
const facts: JournalDomainSubmissionStoredFacts = {
|
||||
admission,
|
||||
handover,
|
||||
@@ -127,7 +136,8 @@ export function journalDomainSubmissionFactsJson(attempt: JournalDomainSubmissio
|
||||
carries,
|
||||
rejection,
|
||||
presentationMember,
|
||||
normalizedHandOff
|
||||
normalizedHandOff,
|
||||
ended: ended === true
|
||||
}
|
||||
return JSON.stringify(facts)
|
||||
}
|
||||
|
||||
@@ -82,18 +82,22 @@ function publicJournalSqlValue(
|
||||
value: unknown,
|
||||
cursor: AgentJournalCursor
|
||||
): unknown {
|
||||
switch (command.operation.kind) {
|
||||
case 'item':
|
||||
case 'item-claiming':
|
||||
case 'prompt-mutate':
|
||||
case 'steps':
|
||||
return value && typeof value === 'object' ? { ...value, cursor } : value
|
||||
case 'submission':
|
||||
case 'dispatch':
|
||||
case 'lifecycle':
|
||||
case 'tombstone':
|
||||
return value == null ? value : cursor
|
||||
default:
|
||||
return value
|
||||
const operation = command.operation.kind
|
||||
if (
|
||||
operation === 'item' ||
|
||||
operation === 'item-claiming' ||
|
||||
operation === 'prompt-mutate' ||
|
||||
operation === 'steps'
|
||||
) {
|
||||
return value && typeof value === 'object' ? { ...value, cursor } : value
|
||||
}
|
||||
if (
|
||||
operation === 'submission' ||
|
||||
operation === 'dispatch' ||
|
||||
operation === 'lifecycle' ||
|
||||
operation === 'tombstone'
|
||||
) {
|
||||
return value == null ? value : cursor
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ const fixture = () => {
|
||||
it('compacts expired replay holes atomically while retaining current bodies, receipts and younger events', async () => {
|
||||
const { db, commit, item } = fixture()
|
||||
await commit(message('the current body'))
|
||||
db.exec(`INSERT INTO journal_send_receipts VALUES('chat','epoch','accepted','{"acceptedAt":100}');
|
||||
db.exec(`INSERT INTO journal_send_receipts(session_id,epoch,message_id,payload_json) VALUES('chat','epoch','accepted','{"acceptedAt":100}');
|
||||
UPDATE journal_chat_state SET last_sequence=65;
|
||||
INSERT INTO journal_events VALUES('chat','epoch',12,86400000,'{}')`)
|
||||
const insert = db.prepare(`INSERT INTO journal_events VALUES('chat','epoch',?,100,'{}')`)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type Database from '../../sqlite/sync-database'
|
||||
import { refreshJournalDomainAcceptedHandover } from './journal-domain-input-ends'
|
||||
import type {
|
||||
AgentJournalMessageItem,
|
||||
AgentJournalSubmission,
|
||||
@@ -10,6 +11,11 @@ import type { JournalItemRow } from './durable-rows/journal-row-schema'
|
||||
import type { QueuedMessageRow } from './queued-messages/queued-message-table'
|
||||
import { journalDispatchRowApplies } from './projection/journal-dispatch-settlement'
|
||||
import { readJournalDomainQueueRow } from './journal-domain-queue-rows'
|
||||
import type { JournalDomainSubmissionStoredFacts } from './journal-domain-submission-records'
|
||||
import {
|
||||
JOURNAL_DOMAIN_SUBMISSION_COLUMNS,
|
||||
journalDomainSubmissionColumns
|
||||
} from './journal-domain-submission-columns'
|
||||
import {
|
||||
journalDomainEditLeaseDeadline,
|
||||
retireJournalDomainEditHolds
|
||||
@@ -52,26 +58,24 @@ export function acceptJournalSqlMessageEcho(
|
||||
row: JournalItemRow,
|
||||
submission?: AgentJournalSubmission
|
||||
): AgentJournalAcceptanceReceipt | undefined {
|
||||
if (!submission) {
|
||||
const stored = db
|
||||
.prepare(`SELECT payload_json FROM journal_submission_attempts
|
||||
const stored = db
|
||||
.prepare(`SELECT payload_json,facts_json FROM journal_submission_attempts
|
||||
WHERE session_id=? AND epoch=? AND item_id=? AND current=1`)
|
||||
.get(...prefix, itemId)
|
||||
submission = stored ? JSON.parse(String(stored.payload_json)) : undefined
|
||||
}
|
||||
if (!submission) {
|
||||
.get(...prefix, itemId)
|
||||
if (!stored) {
|
||||
return undefined
|
||||
}
|
||||
if (!journalDispatchRowApplies(submission)) {
|
||||
const current: AgentJournalSubmission = submission ?? JSON.parse(String(stored.payload_json))
|
||||
if (!journalDispatchRowApplies(current)) {
|
||||
db.prepare(`UPDATE journal_submission_attempts SET echo_observed=1,admission_body_json=NULL
|
||||
WHERE session_id=? AND epoch=? AND message_id=? AND current=1 AND echo_observed=0`).run(
|
||||
...prefix,
|
||||
submission.clientMessageId
|
||||
current.clientMessageId
|
||||
)
|
||||
return undefined
|
||||
}
|
||||
const accepted: AgentJournalSubmission = {
|
||||
...submission,
|
||||
...current,
|
||||
fence: row.fence,
|
||||
dispatchState: 'accepted',
|
||||
providerItemId: rawId,
|
||||
@@ -79,24 +83,28 @@ export function acceptJournalSqlMessageEcho(
|
||||
resolvedAt: row.ts
|
||||
}
|
||||
delete accepted.recovered
|
||||
db.prepare(`UPDATE journal_submission_attempts SET dispatch_state='accepted',candidate=0,payload_json=?,
|
||||
echo_observed=1,dispatch_fence=?,signed_out=0,recovered=0,admission_body_json=NULL
|
||||
const facts: JournalDomainSubmissionStoredFacts = JSON.parse(String(stored.facts_json))
|
||||
db.prepare(`UPDATE journal_submission_attempts SET candidate=0,payload_json=?,
|
||||
${JOURNAL_DOMAIN_SUBMISSION_COLUMNS.map((column) => `${column}=?`).join(',')},
|
||||
echo_observed=1,admission_body_json=NULL
|
||||
WHERE session_id=? AND epoch=? AND message_id=? AND current=1`).run(
|
||||
JSON.stringify(accepted),
|
||||
row.fence,
|
||||
...journalDomainSubmissionColumns(accepted, facts.carries),
|
||||
...prefix,
|
||||
accepted.clientMessageId
|
||||
)
|
||||
refreshJournalDomainAcceptedHandover(db, { sessionId: prefix[0], epoch: prefix[1] }, itemId)
|
||||
const receipt: AgentJournalAcceptanceReceipt = {
|
||||
clientMessageId: accepted.clientMessageId,
|
||||
providerItemId: rawId,
|
||||
cursor: { epoch: row.epoch, sequence: row.seq },
|
||||
acceptedAt: row.ts
|
||||
}
|
||||
db.prepare(`INSERT INTO journal_send_receipts(session_id,epoch,message_id,payload_json) VALUES(?,?,?,?)
|
||||
ON CONFLICT(session_id,epoch,message_id) DO UPDATE SET payload_json=excluded.payload_json`).run(
|
||||
db.prepare(`INSERT INTO journal_send_receipts(session_id,epoch,message_id,cursor_sequence,payload_json) VALUES(?,?,?,?,?)
|
||||
ON CONFLICT(session_id,epoch,message_id) DO UPDATE SET cursor_sequence=excluded.cursor_sequence,payload_json=excluded.payload_json`).run(
|
||||
...prefix,
|
||||
accepted.clientMessageId,
|
||||
receipt.cursor.sequence,
|
||||
JSON.stringify(receipt)
|
||||
)
|
||||
return receipt
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { insertJournalDomainImportedSubmission } from './journal-domain-import-submissions'
|
||||
import {
|
||||
JOURNAL_DOMAIN_ITEM_COLUMNS,
|
||||
journalDomainItemColumns
|
||||
@@ -115,16 +116,32 @@ export function messageFixture(db = new Database(':memory:')) {
|
||||
body: { ...body, blocks: [...body.blocks] },
|
||||
turnScope: { kind: 'thread' }
|
||||
})
|
||||
db.prepare(`INSERT INTO journal_submission_attempts(session_id,epoch,message_id,attempt_sequence,attempt_index,current,item_id,ordinal,submitted_at,accepted_sequence,fingerprint,dispatch_state,candidate,admitted_personal,payload_json)
|
||||
VALUES(?,?,?,1,0,1,?,1,1,1,?,'unknown',1,1,?)`).run(
|
||||
'chat',
|
||||
'epoch',
|
||||
'send',
|
||||
itemId,
|
||||
submission.payloadFingerprint,
|
||||
JSON.stringify(submission)
|
||||
)
|
||||
return submission
|
||||
insertJournalDomainImportedSubmission(db, target, {
|
||||
submission,
|
||||
sequence: 1,
|
||||
index: 0,
|
||||
ordinal: 1,
|
||||
candidate: true,
|
||||
admittedPersonal: true,
|
||||
echoObserved: false,
|
||||
admission: {
|
||||
body,
|
||||
providerHandle: null,
|
||||
fence: 1,
|
||||
scope: null,
|
||||
familyId: null,
|
||||
origin: 'client',
|
||||
sourceKind: 'user',
|
||||
options: null
|
||||
},
|
||||
handover: null,
|
||||
handoverPlace: null,
|
||||
carries: [],
|
||||
rejection: null,
|
||||
presentationMember: false,
|
||||
normalizedHandOff: false,
|
||||
ended: false
|
||||
})
|
||||
}
|
||||
return { db, batch, published, commit, item, seedItem, seedSend }
|
||||
}
|
||||
|
||||
+4
-4
@@ -40,12 +40,12 @@ export type StaleStructuredAgentSessionStateJournal = Pick<
|
||||
| 'itemBody'
|
||||
| 'submissions'
|
||||
| 'statusRead'
|
||||
| 'inputOrder'
|
||||
| 'stopMarks'
|
||||
| 'lastProviderActivityAt'
|
||||
| 'cursor'
|
||||
| 'appendPlannedLifecycleBatch'
|
||||
>
|
||||
> & {
|
||||
inputOrder: Pick<AgentSessionJournal['inputOrder'], 'recoverableSubmissions'>
|
||||
stopMarks: Pick<AgentSessionJournal['stopMarks'], 'latest' | 'personStopDecides'>
|
||||
}
|
||||
|
||||
export type StaleStructuredAgentSessionStateInput = {
|
||||
journal: StaleStructuredAgentSessionStateJournal
|
||||
|
||||
+4
-2
@@ -72,7 +72,9 @@ export function turnVerdictFromReplacedRuntime(
|
||||
}
|
||||
|
||||
export function lastProvenTurnLiveAt(
|
||||
journal: Pick<AgentSessionJournal, 'stopMarks' | 'itemFence' | 'lastProviderActivityAt'>,
|
||||
journal: Pick<AgentSessionJournal, 'itemFence' | 'lastProviderActivityAt'> & {
|
||||
stopMarks: Pick<AgentSessionJournal['stopMarks'], 'latest'>
|
||||
},
|
||||
item: AgentJournalRenderItem
|
||||
): number | undefined {
|
||||
const stop = journal.stopMarks.latest()
|
||||
@@ -85,7 +87,7 @@ export function lastProvenTurnLiveAt(
|
||||
|
||||
/** Personal Stop owns these interrupted turns, suppressing provider-failure notices. */
|
||||
export function endedByPersonsStop(
|
||||
journal: Pick<AgentSessionJournal, 'stopMarks'>,
|
||||
journal: { stopMarks: Pick<AgentSessionJournal['stopMarks'], 'personStopDecides'> },
|
||||
turnEnds: readonly JournalLifecycleMutationInput[]
|
||||
): boolean {
|
||||
const interrupted = turnEnds.flatMap((mutation) => {
|
||||
|
||||
-1
@@ -15,7 +15,6 @@ import type { UnopenedSendJournal } from '../delivery/structured-agent-session-u
|
||||
import { isQueuedAgentJournalSubmission } from '../../../../shared/agent-session/requests/agent-session-queued-submission'
|
||||
|
||||
export type DeadGenerationJournal = UnopenedSendJournal & {
|
||||
appendPlannedLifecycleBatch: AgentSessionJournal['appendPlannedLifecycleBatch']
|
||||
pendingSubmissions?: AgentSessionJournal['pendingSubmissions']
|
||||
itemFence: AgentSessionJournal['itemFence']
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user