Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
a700dcc
test(server): reproduce peer reply summary attribution
ScriptedAlchemy Nov 16, 2026
b71f68c
fix(server): attribute peer replies in conversation summaries
ScriptedAlchemy Nov 16, 2026
fe56ee3
test(server): peer replies must be named in summary input
ScriptedAlchemy Nov 16, 2026
ae7c6e7
fix(server): name the peer who spoke in conversation summaries
ScriptedAlchemy Nov 16, 2026
77582a0
test(evals): grade an open choice apart from a peer's Postgres proposal
ScriptedAlchemy Nov 16, 2026
c67afa7
fix(evals): score Postgres proposals instead of every Postgres mention
ScriptedAlchemy Nov 16, 2026
57bafc9
test(provider-core): saved facts must not treat a peer proposal as th…
ScriptedAlchemy Nov 16, 2026
992ef44
fix(provider-core): keep peer names out of saved facts
ScriptedAlchemy Nov 16, 2026
2817d36
test(server): peer speaker reads must seek an index
ScriptedAlchemy Nov 16, 2026
f2c3db2
fix(server): stop sorting peer speaker reads off their index
ScriptedAlchemy Nov 16, 2026
55b535d
fix(server): keep a peer message a peer when it is summarized
ScriptedAlchemy Nov 16, 2026
70ae659
fix(server): a decision no one but peers voiced is never saved
ScriptedAlchemy Nov 16, 2026
ca8aa91
fix(server): a read source names the peer who spoke it
ScriptedAlchemy Nov 16, 2026
209b44e
fix: a peer named by its model is named once
ScriptedAlchemy Nov 16, 2026
8a007b4
fix(evals): grade who decided, not which words sit near Postgres
ScriptedAlchemy Nov 16, 2026
cb7e583
feat(evals): compare peer-reply arms on Morph's free route
ScriptedAlchemy Nov 16, 2026
7983b5e
test(evals): grade every attribution row through the full leaf grade
ScriptedAlchemy Nov 16, 2026
3e2208a
fix(evals): count the assistant as the agent and credit no one for a …
ScriptedAlchemy Nov 16, 2026
5578875
fix(evals): the knowledge case tempts a decision the user never made
ScriptedAlchemy Nov 16, 2026
43fb07c
fix(web,mobile): a knowledge source names the peer who spoke it
ScriptedAlchemy Nov 16, 2026
56c450e
test(server): a seat and the replies it published are one source
ScriptedAlchemy Nov 16, 2026
44796d1
fix(server): a seat and the replies it published are one source
ScriptedAlchemy Nov 16, 2026
fd1af49
test(provider-core): a prompt without a peer must not carry the peer …
ScriptedAlchemy Nov 16, 2026
22af8dd
fix(provider-core): prompts without a peer match main byte for byte
ScriptedAlchemy Nov 16, 2026
dba8c78
fix(provider-core): drop the peer prompt rules the eval did not support
ScriptedAlchemy Nov 16, 2026
bac95e8
fix(evals): cut the knowledge cases and the no-rule arm
ScriptedAlchemy Nov 16, 2026
521c296
fix(evals): bound Morph summary evaluation requests
ScriptedAlchemy Nov 16, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion apps/mobile/src/components/ProjectKnowledgeFactDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import type {
ProjectKnowledgeStatus,
ThreadId,
} from "@t3tools/contracts";
import { messageAuthorLabel } from "@t3tools/client-runtime/conversationSummaries";
import {
KNOWLEDGE_SOURCE_UNAVAILABLE_LABEL,
isSupersededFact,
Expand Down Expand Up @@ -307,7 +308,7 @@ export function ProjectKnowledgeSourceInspector(props: {
{source?.state === "available" ? (
<>
<AppText className="text-xs text-foreground-muted">
{source.title} · {source.role} · {source.createdAt}
{source.title} · {messageAuthorLabel(source.role, source.speaker)} · {source.createdAt}
{source.archived ? " · archived" : ""}
</AppText>
<AppText selectable>{source.text}</AppText>
Expand Down
26 changes: 26 additions & 0 deletions apps/server/src/orchestration-v2/ProjectionStore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2932,6 +2932,32 @@ it.effect("reads message ordinals through their index", () =>
messageOrdinalsReadThroughTheirIndex.pipe(Effect.provide(layerTest)),
);

it.effect("reads peer speakers through the message index when messages are named", () =>
Effect.gen(function* () {
const projections = yield* ProjectionStore.ProjectionStoreV2;
const threadId = ThreadId.make("thread:peer-speakers");
const named = traceSqlStatements();
yield* projections
.getPeerSpeakers(threadId, [MessageId.make("message:peer")])
.pipe(Effect.withTracer(named.tracer));
yield* assertReadsThroughMessageOrdinalIndex(
named.statements.find((statement) => statement.includes("$.speaker.label")),
["thread_id=?", "<expr>=?"],
);
const open = traceSqlStatements();
yield* projections.getPeerSpeakers(threadId).pipe(Effect.withTracer(open.tracer));
const plan = yield* queryPlan(
open.statements.find((statement) => statement.includes("$.speaker.label")),
);
const search = plan.find((detail) =>
detail.includes("orchestration_v2_projection_turn_items_thread_type_idx"),
);
assert.isDefined(search, plan.join("\n"));
assert.include(search, "thread_id=?");
assert.include(search, "type=?");
}).pipe(Effect.provide(layerTest)),
);

const assertProjectScopedShells = Effect.fn("assertProjectScopedShells")(function* (
suffix: string,
) {
Expand Down
41 changes: 41 additions & 0 deletions apps/server/src/orchestration-v2/ProjectionStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
orchestrationV2RunWorkStartedAt,
RunId,
MessageId,
type OrchestrationV2MessageSpeaker,
RuntimeRequestId,
CheckpointScopeId,
CheckpointId,
Expand Down Expand Up @@ -594,6 +595,11 @@
ReadonlyMap<MessageId, OrchestrationV2ConversationMessage>,
ProjectionStoreV2Error
>;
/** Speakers of peer replies in the thread, or of the named messages only. */
readonly getPeerSpeakers: (
threadId: ThreadId,
messageIds?: ReadonlyArray<MessageId>,
) => Effect.Effect<ReadonlyMap<MessageId, OrchestrationV2MessageSpeaker>, ProjectionStoreV2Error>;
readonly getThreadRecords: <K extends ProjectionRecordField>(
threadId: ThreadId,
fields: ReadonlyArray<K>,
Expand Down Expand Up @@ -6644,6 +6650,40 @@
(effect, threadId) => effect.pipe(Effect.mapError(controlReadError(threadId))),
);

// The type list and `json_valid` term match the message-ordinal index. Speaker fields sit
// outside it, so each hit decodes the payload.
const getPeerSpeakers = Effect.fn("ProjectionStore.getPeerSpeakers")(
function* (threadId: ThreadId, messageIds?: ReadonlyArray<MessageId>) {
const speakers = new Map<MessageId, OrchestrationV2MessageSpeaker>();
if (messageIds !== undefined && messageIds.length === 0) return speakers;
const rows = yield* sql<{
readonly message_id: string;
readonly label: string | null;
readonly model: string | null;
}>`
SELECT json_extract(payload_json, '$.messageId') AS message_id,
json_extract(payload_json, '$.speaker.label') AS label,
json_extract(payload_json, '$.speaker.model') AS model
FROM orchestration_v2_projection_turn_items
WHERE thread_id = ${threadId}
AND type IN ('user_message', 'assistant_message')
AND json_valid(payload_json)
AND json_extract(payload_json, '$.speaker.label') IS NOT NULL
AND json_extract(payload_json, '$.speaker.model') IS NOT NULL
${
messageIds === undefined
? sql``
: sql`AND json_extract(payload_json, '$.messageId') IN (SELECT value FROM json_each(${encodeIdList([...new Set(messageIds)])}))`
}
`;
for (const row of rows)
if (row.label && row.model)
speakers.set(MessageId.make(row.message_id), { label: row.label, model: row.model });
return speakers;
},
(effect, threadId) => effect.pipe(Effect.mapError(controlReadError(threadId))),
);

const getThreadRecords: ProjectionStoreV2Shape["getThreadRecords"] = (
threadId,
fields,
Expand Down Expand Up @@ -7439,7 +7479,7 @@
findCursorEndIndex(indexed, decodeThreadHistoryCursor(cursor)),
indexed.length - 1,
);
while (workMode !== undefined) {

Check warning on line 7482 in apps/server/src/orchestration-v2/ProjectionStore.ts

View workflow job for this annotation

GitHub Actions / Checks and build

eslint(no-unmodified-loop-condition)

apps/server/src/orchestration-v2/ProjectionStore.ts:7482:22: 'workMode' is not modified in this loop.
const { page } = selection;
const span = [...page.items.slice(0, 1), ...page.items.slice(-1)].map(
(row) => row.canonicalPosition,
Expand Down Expand Up @@ -9507,6 +9547,7 @@
getActiveGroupThreadIds: readOnReader(getActiveGroupThreadIds),
getTurnItem: readOnReader(getTurnItem),
getMessagesById: readOnReader(getMessagesById),
getPeerSpeakers: readOnReader(getPeerSpeakers),
getThreadRecords: (threadId, fields, filter) =>
getThreadRecords(threadId, fields, filter).pipe(NodeSqliteClient.readOnly),
getRuntimeRequest: readOnReader(getRuntimeRequest),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ it.effect(
getActiveGroupThreadIds: () => Effect.die("unused group read"),
getTurnItem: () => Effect.die("unused turn item read"),
getMessagesById: () => Effect.die("unused getMessagesById"),
getPeerSpeakers: () => Effect.die("unused getPeerSpeakers"),
getThreadRecords: () => Effect.die("unused record read"),
getRuntimeRequest: () => Effect.die("unused getRuntimeRequest"),
getRunningTurnContext: () => Effect.die("unused getRunningTurnContext"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,36 @@ it.effect(
},
);

it.effect("sends a peer reply to the summary model as that peer", () => {
const model = citing();
return Effect.gen(function* () {
yield* seed;
const projections = yield* ProjectionStore.ProjectionStoreV2;
const peer = item(1);
if (peer.type !== "assistant_message") return yield* Effect.die("Expected a peer reply");
yield* projections.apply({
id: EventId.make("peer-reply-attribution"),
type: "turn-item.updated",
threadId,
providerInstanceId: instanceId,
occurredAt: at,
payload: { ...peer, speaker: { label: "Astra", model: "gpt-6-astra" } },
});
yield* summarize;
assert.deepEqual(model.calls[0]?.messages[1], {
ref: "M2",
role: "peer",
speaker: { label: "Astra", model: "gpt-6-astra" },
text: rawText(1),
});
assert.deepEqual(model.calls[0]?.messages[3], {
ref: "M4",
role: "assistant",
text: rawText(3),
});
}).pipe(Effect.provide(makeLayer(model.generate, optedIn)));
});

it.effect("negotiates ranged summary responses while preserving legacy whole-message reads", () => {
const model = citing();
return Effect.gen(function* () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
ConversationSummary,
ConversationSummaryError,
ConversationSummaryPass,
ConversationSummarySourceRange,
CONVERSATION_SUMMARY_MAX_EXPANSION_CHARS,
CONVERSATION_SUMMARY_MAX_SOURCES,
conversationSummarySourceIdentity,
Expand All @@ -19,6 +20,7 @@ import {
type KnowledgeSourceUnavailableReason,
type MessageId,
type OrchestrationV2ConversationMessage,
type OrchestrationV2MessageSpeaker,
type OrchestrationV2RunStatus,
type OrchestrationV2UserMessageInputIntent,
type ProjectId,
Expand Down Expand Up @@ -922,6 +924,7 @@ const make = Effect.gen(function* () {
createdAt: message.createdAt,
});
}
const speakers = yield* projections.getPeerSpeakers(threadId);
for (const item of records.turnItems) {
if (item.runId !== null && excluded.has(item.runId)) continue;
const text = summaryToolText(item);
Expand Down Expand Up @@ -986,11 +989,18 @@ const make = Effect.gen(function* () {
);

const publish = Effect.fnUntraced(function* (input: {
readonly messages: ReadonlyArray<{
readonly role: "user" | "assistant" | "tool" | "summary";
readonly text: string;
readonly range?: ConversationSummaryRangeRef["range"];
}>;
readonly messages: ReadonlyArray<
{
readonly text: string;
readonly range?: (typeof ConversationSummarySourceRange)["Type"];
} & (
| { readonly role: "user" | "assistant" | "tool" | "summary" }
| {
readonly role: "peer";
readonly speaker: OrchestrationV2MessageSpeaker;
}
)
>;
readonly sources: ReadonlyArray<ConversationSummarySourceRef>;
readonly ranges: ReadonlyArray<ConversationSummaryRangeRef>;
readonly position: string;
Expand All @@ -999,12 +1009,7 @@ const make = Effect.gen(function* () {
const messages = input.messages.map((message, index) => {
const ref = `M${index + 1}`;
refs.set(ref, conversationSummarySourceKey(input.sources[index]!));
return {
ref,
role: message.role,
text: message.text,
...(message.range === undefined ? {} : { range: message.range }),
};
return { ref, ...message };
});
const reply = yield* textGeneration
.generateConversationSummary({
Expand Down Expand Up @@ -1080,11 +1085,14 @@ const make = Effect.gen(function* () {

const summarizeLeaf = (chunk: ReadonlyArray<SummarySource>) =>
publish({
messages: chunk.map((source) => ({
role: source.role,
text: source.text,
...(source.ref.range === undefined ? {} : { range: source.ref.range }),
})),
messages: chunk.map((source) => {
const speaker =
source.ref.kind === "message" ? speakers.get(source.ref.messageId) : undefined;
const range = source.ref.range === undefined ? {} : { range: source.ref.range };
return speaker === undefined
? { role: source.role, text: source.text, ...range }
: { role: "peer" as const, speaker, text: source.text, ...range };
}),
sources: chunk.map((source) => source.ref),
ranges: chunk.map((source) => source.ref),
position: leafPosition(DateTime.formatIso(chunk[0]!.createdAt), chunk[0]!.ref),
Expand Down
Loading
Loading