mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-30 12:54:55 +00:00
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:
@@ -8,17 +8,17 @@ import {
|
||||
type TeamMemberRole,
|
||||
} from '@shumai/db'
|
||||
import {
|
||||
type CreateQuotaRuleRequest,
|
||||
type ListQuotaRulesResponse,
|
||||
type QuotaRuleResponse,
|
||||
type ListQuotaRecordsResponse,
|
||||
type QuotaRecordResponse,
|
||||
type UpdateQuotaRuleRequest,
|
||||
normalizeQuotaPeriod,
|
||||
bashResourceDataSchema,
|
||||
formatQuotaPeriod,
|
||||
mcpResourceDataSchema,
|
||||
bashResourceDataSchema,
|
||||
normalizeQuotaPeriod,
|
||||
toolResourceDataSchema,
|
||||
type CreateQuotaRuleRequest,
|
||||
type ListQuotaRecordsResponse,
|
||||
type ListQuotaRulesResponse,
|
||||
type QuotaRecordResponse,
|
||||
type QuotaRuleResponse,
|
||||
type UpdateQuotaRuleRequest,
|
||||
} from '@shumai/dtos'
|
||||
import { HTTPException } from 'hono/http-exception'
|
||||
|
||||
@@ -765,7 +765,11 @@ export class QuotaService {
|
||||
* Lazy resets the period window in-place when previous window has expired.
|
||||
* Uses SELECT ... FOR UPDATE inside transactions for atomic concurrency protection.
|
||||
*/
|
||||
async consumeQuota(event: QuotaEvent, amount: number): Promise<void> {
|
||||
async consumeQuota(
|
||||
event: QuotaEvent,
|
||||
amount: number,
|
||||
transaction?: Prisma.TransactionClient,
|
||||
): Promise<void> {
|
||||
if (amount <= 0) return
|
||||
|
||||
const rules = await this.findMatchingRules(event)
|
||||
@@ -776,7 +780,7 @@ export class QuotaService {
|
||||
for (const rule of rules) {
|
||||
const targetUserId = getQuotaRuleTargetUserId(rule, event)
|
||||
|
||||
await this.prismaClient.$transaction(async (tx) => {
|
||||
const consume = async (tx: Prisma.TransactionClient) => {
|
||||
if (targetUserId === null) {
|
||||
// Serialize all_members (shared pool) creations and updates on the parent rule row
|
||||
await tx.$queryRaw`SELECT id FROM quota_rules WHERE id = ${rule.id} FOR UPDATE`
|
||||
@@ -851,7 +855,9 @@ export class QuotaService {
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
if (transaction) await consume(transaction)
|
||||
else await this.prismaClient.$transaction(consume)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user