fix(ui): observe guarded reader retargets before hydration

An already loaded schedule can hand a pressed task reader to its asking actor in one Solid effect. The raw conversation epoch was updated by a queued computed, so hydration's deferred admission mistook that guarded reader retarget for external navigation and skipped its native read.

Keep the epoch in a memo and read it at capture, admission and guarded adoption. This observes the synchronous target before hydration without acquiring another surface intent or relaxing external navigation, passage and ownership fences.

Add a real MissionControl regression with a pressed task reader, loaded red schedule and cold asking descendant. The new case fails at ee92f7e38 and passes with this fix; both real daily/scheduled current-page navigation cases also pass.
This commit is contained in:
Pascal André 2026-11-14 23:09:26 +01:00
parent ee92f7e385
commit b099e5a6f7
No known key found for this signature in database
2 changed files with 45 additions and 9 deletions

View file

@ -177,13 +177,15 @@ const MissionControl: Component<MissionControlProps> = (props) => {
return { session: props.activeSessionId(), parent: activeParentSessionId().get(props.instanceId),
kind: surface.kind, target: "target" in surface ? surface.target : undefined }
}
let conversationEpoch = 0, previousConversation = conversation()
createComputed(() => {
let previousConversation = conversation()
// Reading the memo observes a guarded retarget even inside an effect's batch.
const conversationEpoch = createMemo((epoch: number) => {
const next = conversation()
if (next.session !== previousConversation.session || next.parent !== previousConversation.parent
|| next.kind !== previousConversation.kind || next.target !== previousConversation.target) conversationEpoch++
const changed = next.session !== previousConversation.session || next.parent !== previousConversation.parent
|| next.kind !== previousConversation.kind || next.target !== previousConversation.target
previousConversation = next
})
return changed ? epoch + 1 : epoch
}, 0)
// Session-list restoration keeps priority; activation revalidates afterwards.
const visible = () => (props.isActive?.() ?? true) && sessionListRestored(props.instanceId)
@ -267,16 +269,16 @@ const MissionControl: Component<MissionControlProps> = (props) => {
const instanceId = props.instanceId, viewScope = scope(), viewCurrent = captureView(), operation = ++intent
const schedule = passageSchedule()
let passage = discoverPassage ? undefined : currentPassage.snapshot()?.passageID
let epoch = conversationEpoch
let epoch = conversationEpoch()
let surfaceIntent = captureSessionSurfaceIntent({ instanceId, sessionId: props.activeSessionId() ?? null })
return { instanceId, scope: viewScope,
current: () => surfaceIntent.current() && viewCurrent() && operation === intent && scope() === viewScope && epoch === conversationEpoch
current: () => surfaceIntent.current() && viewCurrent() && operation === intent && scope() === viewScope && epoch === conversationEpoch()
&& passageSchedule() === schedule && (!schedule || discoverPassage && passage === undefined || currentPassage.snapshot()?.passageID === passage),
bindPassage: () => { passage = currentPassage.snapshot()?.passageID },
adoptReader: () => { epoch = conversationEpoch },
adoptReader: () => { epoch = conversationEpoch() },
// Adopt only our guarded synchronous batch, never an awaited external change.
adoptConversation: () => {
epoch = conversationEpoch
epoch = conversationEpoch()
surfaceIntent = captureSessionSurfaceIntent({ instanceId, sessionId: props.activeSessionId() ?? null })
},
release: () => surfaceIntent.release(),

View file

@ -215,6 +215,40 @@ test("an admitted red schedule click discovers and opens its asking descendant",
} finally { await page.close() }
})
test("a pressed task reader hands its loaded schedule's answer to cold hydration", async () => {
const page = await browser.newPage({ viewport: { width: 1200, height: 950 } })
try {
const f = await setupReaderFollow(page, true, true)
await page.evaluate(async () => (await import("/src/stores/forms.ts" as string)).removeFormFromQueue("fixture", "form_child"))
await selectMission(page, "Daily review")
await page.locator('.mission-tree-node[data-task-key="second"] .mission-tree-task').click()
await eye(page).click()
await page.locator(".mission-reader").getByRole("heading", { name: "Next task has no actor", exact: true }).waitFor()
await page.evaluate(async () => {
const s = await import("/src/stores/session-state.ts" as string)
s.setSessions((previous: Map<string, Map<string, any>>) => {
const values = new Map(previous.get("fixture"))
values.set("ses_child", { ...values.get("ses_child"), catalogSnapshot: true })
return new Map(previous).set("fixture", values)
})
;(await import("/src/stores/forms.ts" as string)).addFormToQueue("fixture", { id: "form_child", sessionID: "ses_child",
location: { directory: "/fixture" }, title: "Real child request", tool: { name: "question" }, fields: [], time: { created: 1 } } as never)
})
await page.route("**/instance/api/session/ses_child", route => route.fulfill({ json: { data: { id: "ses_child", parentID: "ses_task",
projectID: "project", title: "Cold asking child", location: { directory: "/fixture" }, time: { created: 1, updated: 1 } } } }))
const row = await inlineMissionEntry(page, "Daily review")
await row.locator('.mission-row-flag[data-mark="permission"]').waitFor()
const hydration = page.waitForRequest(request => new URL(request.url()).pathname.endsWith("/session/ses_child"))
await row.click(); await hydration
const active = () => page.evaluate(async () => (await import("/src/stores/sessions.ts" as string)).activeSessionId().get("fixture"))
for (let attempt = 0; await active() !== "ses_child" && attempt < 100; attempt++) await page.waitForTimeout(50)
assert.equal(await active(), "ses_child")
assert.equal(await readerTarget(page), undefined)
assert.equal(await hasForegroundIntent(page), false)
assert.deepEqual(f.errors, []); assert.deepEqual(f.writes, [])
} finally { await page.close() }
})
test("a discovered schedule answer retains its original intent through cold actor hydration", async () => {
const page = await browser.newPage({ viewport: { width: 1200, height: 950 } })
const hydration = deferred(), settled = deferred()