refactor(agent)!: migrate to Pi Durable and embed the agent queue (#525)

* refactor(agent)!: migrate sessions to Pi Durable

Replace patched AgentHarness storage with per-session SQLite and PostgreSQL commit mirroring. Migrate legacy history automatically and run agent queues with the main server.

BREAKING CHANGE: Remove standalone agent workers and return native Pi entry records from chat history APIs.

* fix(agent): constrain session log dialog scrolling

Keep the header visible and wrap long output while log entries and expanded records scroll within the dialog. Cover desktop and narrow viewports through the dashboard Sessions flow.

* fix(agent): hide entry IDs from session log card headers

Retain internal entry IDs in expanded raw records for debugging. Verify that card headers omit the IDs while raw JSON preserves them.

* test(e2e): handle browser wheel limits in session log checks

Verify that a normal wheel event moves the viewport before explicitly scrolling to the final record. Keep the dialog bounds, fixed header, wrapping, and expanded-record assertions.

* fix(agent): select model providers without inheriting unrelated auth

* fix(webui): prevent resize feedback when toggling agent panel

* test(agent): reproduce concurrent comment session races

* fix(agent): serialize comment sessions and deduplicate history

* docs(changelog): consolidate Pi Durable changes into one entry
This commit is contained in:
Yiling-J
2026-11-11 16:05:18 +08:00
committed by GitHub
parent 843a56304c
commit 35a0e82284
120 changed files with 7593 additions and 5972 deletions
+34 -37
View File
@@ -1,16 +1,17 @@
import { describe, it, expect, beforeAll, afterAll, vi } from 'vitest'
import { prisma } from '@shumai/db'
import { setupTestDbHooks } from '@shumai/db/test'
import { workflowService, TaskQueueAgent } from '@shumai/workflow-core'
import type { AssistantMessage } from '@earendil-works/pi-ai'
import { initAgentWorkflows } from '@shumai/agent'
import { s3Service } from '@shumai/core/src/s3/s3'
import { mcpService } from '@shumai/core/src/mcp/mcp-service'
import {
startTestMcpServer,
standardTestTools,
startTestMcpServer,
type RunningTestMcpServer,
} from '@shumai/core/src/mcp/mcp-test-server'
import { AgentHarness } from '@earendil-works/pi-agent-core'
import { s3Service } from '@shumai/core/src/s3/s3'
import { prisma } from '@shumai/db'
import { setupTestDbHooks } from '@shumai/db/test'
import { TaskQueueAgent, workflowService } from '@shumai/workflow-core'
import { afterAll, beforeAll, describe, expect, it, vi } from 'vitest'
import { mockModelPrompt, type ModelScenario } from './model-mock'
describe('Workflow E2E - MCP tools', () => {
setupTestDbHooks()
@@ -36,9 +37,7 @@ describe('Workflow E2E - MCP tools', () => {
// proxy tool on the harness and executes it against the real MCP server,
// so the full createAgentSession → buildAgentTools → proxy execute →
// callMcpTool → MCP server path is exercised.
vi.spyOn(AgentHarness.prototype, 'prompt').mockImplementation(async function (
this: AgentHarness,
) {
mockModelPrompt(async function (this: ModelScenario) {
const tools = this.getTools()
const mcpTool = tools.find((t) => t.name === 'mcp')
if (!mcpTool) {
@@ -46,7 +45,7 @@ describe('Workflow E2E - MCP tools', () => {
content: [{ type: 'text', text: 'NO_MCP_TOOL' }],
usage: { input: 10, output: 20 },
stopReason: 'stop',
} as unknown as Awaited<ReturnType<typeof AgentHarness.prototype.prompt>>
} as unknown as AssistantMessage
}
const result = await (
mcpTool.execute as unknown as (
@@ -65,7 +64,7 @@ describe('Workflow E2E - MCP tools', () => {
content: [{ type: 'text', text }],
usage: { input: 10, output: 20 },
stopReason: 'stop',
} as unknown as Awaited<ReturnType<typeof AgentHarness.prototype.prompt>>
} as unknown as AssistantMessage
})
await workflowService.startWorkers(TaskQueueAgent)
@@ -244,35 +243,33 @@ describe('Workflow E2E - MCP tools', () => {
// For direct mode the model would call `e2e_mcp_echo` directly; simulate
// that by executing the direct tool on the harness.
const directSpy = vi
.spyOn(AgentHarness.prototype, 'prompt')
.mockImplementationOnce(async function (this: AgentHarness) {
const tools = this.getTools()
const echoTool = tools.find((t) => t.name === 'e2e_mcp_echo')
if (!echoTool) {
return {
content: [{ type: 'text', text: 'NO_DIRECT_TOOL' }],
usage: { input: 1, output: 1 },
stopReason: 'stop',
} as unknown as Awaited<ReturnType<typeof AgentHarness.prototype.prompt>>
}
const result = await (
echoTool.execute as unknown as (
id: string,
params: Record<string, unknown>,
) => Promise<{ content: Array<{ type: string; text?: string }> }>
)('e2e-direct', {
text: 'direct call',
})
const text = result.content
.map((c) => ('text' in c && typeof c.text === 'string' ? c.text : ''))
.join('\n')
const directSpy = mockModelPrompt(async function (this: ModelScenario) {
const tools = this.getTools()
const echoTool = tools.find((t) => t.name === 'e2e_mcp_echo')
if (!echoTool) {
return {
content: [{ type: 'text', text }],
content: [{ type: 'text', text: 'NO_DIRECT_TOOL' }],
usage: { input: 1, output: 1 },
stopReason: 'stop',
} as unknown as Awaited<ReturnType<typeof AgentHarness.prototype.prompt>>
} as unknown as AssistantMessage
}
const result = await (
echoTool.execute as unknown as (
id: string,
params: Record<string, unknown>,
) => Promise<{ content: Array<{ type: string; text?: string }> }>
)('e2e-direct', {
text: 'direct call',
})
const text = result.content
.map((c) => ('text' in c && typeof c.text === 'string' ? c.text : ''))
.join('\n')
return {
content: [{ type: 'text', text }],
usage: { input: 1, output: 1 },
stopReason: 'stop',
} as unknown as AssistantMessage
})
const userComment = await prisma.assetComment.create({
data: {