Skip to content

Commit ce0c481

Browse files
authored
Merge pull request #9975 from loopx-project/codex/restore-inbox-first-read-projection-20261203
Preserve Manager Inbox summaries in stateless first reads
2 parents 3b32ab9 + 190b660 commit ce0c481

2 files changed

Lines changed: 21 additions & 14 deletions

File tree

‎loopx/control_plane/quota/progressive_context.ts‎

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,7 +1315,10 @@ export function scopedReplanYardstickReversal(decision: JsonObject) {
13151315
return {cue, fields, path: [...REPLAN_CONTEXT_PATH, "explore_basis", "work_yardsticks", index]};
13161316
}
13171317

1318-
function requiredManagerAgenda(value: unknown, requiredReads: unknown[], deferredPointer?: string): JsonObject | undefined {
1318+
const MANAGER_AGENDA_FIELDS = ["count_unit", "incoming_count", "outgoing_count", "omitted_count",
1319+
"return_attention", "planning_request", "scan_complete", "unavailable_count", "observed_at", "read_command", "instruction"];
1320+
1321+
function requiredManagerAgenda(value: unknown, requiredReads: unknown[], deferredAgendaPointer?: string): JsonObject | undefined {
13191322
const {content, ...read} = jsonObject(value) ?? {};
13201323
const source = jsonObject(content), agenda = jsonObject(source?.unfinished_delegations);
13211324
if (read.source !== "turn_start_capability_hook" || read.kind !== "operator_inbox"
@@ -1325,14 +1328,10 @@ function requiredManagerAgenda(value: unknown, requiredReads: unknown[], deferre
13251328
|| !agenda || agenda.read_command !== read.command || agenda.count_unit !== "request"
13261329
|| agenda.scan_complete !== true || agenda.unavailable_count !== 0
13271330
|| !requiredReads.some(required => isDeepStrictEqual(required, read))) return undefined;
1328-
// A projected agenda keeps its counts and return cues at this exact source;
1329-
// only its rows move to the pinned detail capture.
1330-
const deferred = deferredPointer !== undefined && agenda.supporting_material_pointer === deferredPointer
1331-
&& !Object.hasOwn(agenda, "items");
1332-
if ((!deferred && !Array.isArray(agenda.items))
1333-
|| !known(agenda, ["count_unit", deferred ? "supporting_material_pointer" : "items", "incoming_count", "outgoing_count", "omitted_count",
1334-
"return_attention", "planning_request", "scan_complete", "unavailable_count", "observed_at", "read_command", "instruction"])) return undefined;
1335-
return agenda;
1331+
const inline = Array.isArray(agenda.items) && known(agenda, [...MANAGER_AGENDA_FIELDS, "items"]);
1332+
const deferred = deferredAgendaPointer !== undefined && agenda.supporting_material_pointer === deferredAgendaPointer
1333+
&& known(agenda, [...MANAGER_AGENDA_FIELDS, "supporting_material_pointer"]);
1334+
return inline || deferred ? agenda : undefined;
13361335
}
13371336

13381337
/** A pending Manager Inbox read already delivers these scoped request rows. */
@@ -1348,6 +1347,7 @@ function managerAgendaOpeningFields(agenda: JsonObject | undefined): string[] |
13481347
|| (Array.isArray(items) && (incoming + outgoing !== items.length + omitted
13491348
|| Buffer.byteLength(JSON.stringify(items), "utf8") < 2048))) return undefined;
13501349
const fields = ["incoming_count", "outgoing_count", "scan_complete"];
1350+
if (agenda.supporting_material_pointer !== undefined) fields.push("supporting_material_pointer");
13511351
if (omitted === 0) return fields;
13521352
// A complete scan can have a bounded display. Preserve the omission count
13531353
// and reconciliation guidance while leaving the rows to the required read.
@@ -1473,11 +1473,15 @@ function initialContextReadGroups(context: JsonObject, decisionFields: readonly
14731473
? channel.required_reads : [];
14741474
const work = ["interaction_contract", "agent_channel", "work_context"];
14751475
const sources = object(channel?.work_context)?.sources;
1476-
const sourceRows = Array.isArray(sources) ? sources.map((source, index) => ({
1477-
source, index, agenda: requiredManagerAgenda(source, requiredInboxReads,
1478-
supportingSource && details && details.path === supportingSource.path && details.sha256 === supportingSource.sha256
1479-
? pointer([...work, "sources", index, "content", "unfinished_delegations"]) : undefined),
1480-
})) : [];
1476+
const unreadPointers = at(details, ["unread_context_index", "pointers"]);
1477+
const deferred = supportingSource && details?.path === supportingSource.path
1478+
&& details.sha256 === supportingSource.sha256 && Array.isArray(unreadPointers)
1479+
? new Set(unreadPointers) : undefined;
1480+
const sourceRows = Array.isArray(sources) ? sources.map((source, index) => {
1481+
const path = pointer([...work, "sources", index, "content", "unfinished_delegations"]);
1482+
const agenda = requiredManagerAgenda(source, requiredInboxReads, deferred?.has(path + "/items") ? path : undefined);
1483+
return {source, index, agenda};
1484+
}) : [];
14811485
const attentionSources = sourceRows.filter(({agenda}) => managerReturnAttention(agenda));
14821486
const requiredReadsPath = ["interaction_contract", "agent_channel", "required_reads"];
14831487
if (!attentionSources.length) include(...requiredReadsPath);

‎tests/control_plane_ts/progressive_context.test.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -977,6 +977,9 @@ test("progressiveContextPlan handles agent_review basis_digest, defers large man
977977
{...compact, return_attention: {...attention, future_gate: true}},
978978
]) assert.ok(opening(changed).includes(agendaPath));
979979
assert.ok(opening(compact, {...details, sha256: "other-source"}).includes(agendaPath));
980+
assert.ok(opening(compact, {...details, unread_context_index: {
981+
...details.unread_context_index, pointers: ["/unrelated/items"],
982+
}}).includes(agendaPath));
980983

981984
// When selected_todo explicitly requires explore, keep Explore graph history & templates inline.
982985
const exploreTurn = structuredClone(payload);

0 commit comments

Comments
 (0)