mirror of https://github.com/buster-so/buster.git
report update fixes
This commit is contained in:
parent
e63fd79df5
commit
651af9de4e
|
@ -312,14 +312,35 @@ export function createModifyReportsDelta(context: ModifyReportsContext, state: M
|
|||
},
|
||||
};
|
||||
|
||||
// Update the database with the result of all edits
|
||||
// Update the database with the result of all edits using Promise chain
|
||||
try {
|
||||
await batchUpdateReport({
|
||||
reportId: state.reportId,
|
||||
content: currentContent,
|
||||
name: state.reportName || undefined,
|
||||
versionHistory,
|
||||
});
|
||||
// Chain this write to ensure sequential execution
|
||||
state.lastDbWritePromise = (async () => {
|
||||
// Wait for any previous write to complete
|
||||
if (state.lastDbWritePromise) {
|
||||
try {
|
||||
await state.lastDbWritePromise;
|
||||
} catch (error) {
|
||||
// Previous write failed, but we continue
|
||||
console.warn('[modify-reports-delta] Previous write failed:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// Now do our write
|
||||
// We're already inside a check for state.reportId being defined
|
||||
if (!state.reportId) {
|
||||
throw new Error('Report ID is unexpectedly undefined');
|
||||
}
|
||||
return batchUpdateReport({
|
||||
reportId: state.reportId,
|
||||
content: currentContent,
|
||||
name: state.reportName || undefined,
|
||||
versionHistory,
|
||||
});
|
||||
})();
|
||||
|
||||
// Await the promise to handle errors and ensure completion
|
||||
await state.lastDbWritePromise;
|
||||
|
||||
// No cache update during delta - execute will handle write-through
|
||||
|
||||
|
|
|
@ -79,7 +79,8 @@ async function processEditOperations(
|
|||
edits: Array<{ operation?: 'replace' | 'append'; code_to_replace: string; code: string }>,
|
||||
messageId?: string,
|
||||
snapshotContent?: string,
|
||||
versionHistory?: VersionHistory
|
||||
versionHistory?: VersionHistory,
|
||||
state?: ModifyReportsState
|
||||
): Promise<{
|
||||
success: boolean;
|
||||
finalContent?: string;
|
||||
|
@ -176,6 +177,21 @@ async function processEditOperations(
|
|||
|
||||
// Write all changes to database in one operation
|
||||
try {
|
||||
// Wait for any pending delta writes to complete before doing final update
|
||||
if (state?.lastDbWritePromise) {
|
||||
console.info('[modify-reports-execute] Waiting for pending delta writes to complete');
|
||||
try {
|
||||
await state.lastDbWritePromise;
|
||||
// Add small delay to ensure we're absolutely last
|
||||
await new Promise((resolve) => setTimeout(resolve, 50));
|
||||
} catch (error) {
|
||||
console.warn(
|
||||
'[modify-reports-execute] Delta write failed, proceeding with final update:',
|
||||
error
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
await batchUpdateReport({
|
||||
reportId,
|
||||
content: currentContent,
|
||||
|
@ -239,7 +255,8 @@ const modifyReportsFile = wrapTraced(
|
|||
params: ModifyReportsInput,
|
||||
context: ModifyReportsContext,
|
||||
snapshotContent?: string,
|
||||
versionHistory?: VersionHistory
|
||||
versionHistory?: VersionHistory,
|
||||
state?: ModifyReportsState
|
||||
): Promise<ModifyReportsOutput> => {
|
||||
// Get context values
|
||||
const userId = context.userId;
|
||||
|
@ -299,7 +316,8 @@ const modifyReportsFile = wrapTraced(
|
|||
params.edits,
|
||||
messageId,
|
||||
snapshotContent, // Pass immutable snapshot
|
||||
versionHistory // Pass snapshot version history
|
||||
versionHistory, // Pass snapshot version history
|
||||
state // Pass state to access lastDbWritePromise
|
||||
);
|
||||
|
||||
// Track file associations if this is a new version (not part of same turn)
|
||||
|
@ -390,7 +408,8 @@ export function createModifyReportsExecute(
|
|||
input,
|
||||
context,
|
||||
state.snapshotContent, // Pass immutable snapshot from state
|
||||
state.versionHistory // Pass snapshot version history from state
|
||||
state.versionHistory, // Pass snapshot version history from state
|
||||
state // Pass state to access lastDbWritePromise
|
||||
);
|
||||
|
||||
if (!result) {
|
||||
|
|
|
@ -101,9 +101,13 @@ const ModifyReportsStateSchema = z.object({
|
|||
export type ModifyReportsInput = z.infer<typeof ModifyReportsInputSchema>;
|
||||
export type ModifyReportsOutput = z.infer<typeof ModifyReportsOutputSchema>;
|
||||
export type ModifyReportsContext = z.infer<typeof ModifyReportsContextSchema>;
|
||||
export type ModifyReportsState = z.infer<typeof ModifyReportsStateSchema>;
|
||||
export type ModifyReportsEditState = z.infer<typeof ModifyReportsEditStateSchema>;
|
||||
|
||||
// Extend the inferred type to include Promise field (not supported by Zod directly)
|
||||
export type ModifyReportsState = z.infer<typeof ModifyReportsStateSchema> & {
|
||||
lastDbWritePromise?: Promise<void>;
|
||||
};
|
||||
|
||||
// Factory function that accepts agent context and maps to tool context
|
||||
export function createModifyReportsTool(context: ModifyReportsContext) {
|
||||
// Initialize state for streaming
|
||||
|
|
|
@ -11,12 +11,14 @@ if (!connectionString) {
|
|||
}
|
||||
|
||||
// Disable SSL for local development
|
||||
const isDevelopment = process.env.ENVIRONMENT === 'development' || process.env.NODE_ENV === 'development';
|
||||
const isDevelopment =
|
||||
process.env.ENVIRONMENT === 'development' || process.env.NODE_ENV === 'development';
|
||||
|
||||
// Append sslmode=disable for local development if not already present
|
||||
const dbUrl = isDevelopment && !connectionString.includes('sslmode=')
|
||||
? `${connectionString}?sslmode=disable`
|
||||
: connectionString;
|
||||
const dbUrl =
|
||||
isDevelopment && !connectionString.includes('sslmode=')
|
||||
? `${connectionString}?sslmode=disable`
|
||||
: connectionString;
|
||||
|
||||
export default defineConfig({
|
||||
schema: './src/schema.ts',
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { config } from 'dotenv';
|
||||
import * as path from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
import { config } from 'dotenv';
|
||||
|
||||
// Get the directory name for ES modules
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
|
@ -61,18 +61,28 @@ export function initializePool<T extends Record<string, postgres.PostgresType>>(
|
|||
|
||||
// Create postgres client with pool configuration
|
||||
// Disable SSL for local development
|
||||
const isDevelopment = process.env.ENVIRONMENT === 'development' || process.env.NODE_ENV === 'development';
|
||||
|
||||
console.log('Database connection - ENVIRONMENT:', process.env.ENVIRONMENT, 'NODE_ENV:', process.env.NODE_ENV, 'isDevelopment:', isDevelopment);
|
||||
|
||||
const isDevelopment =
|
||||
process.env.ENVIRONMENT === 'development' || process.env.NODE_ENV === 'development';
|
||||
|
||||
console.log(
|
||||
'Database connection - ENVIRONMENT:',
|
||||
process.env.ENVIRONMENT,
|
||||
'NODE_ENV:',
|
||||
process.env.NODE_ENV,
|
||||
'isDevelopment:',
|
||||
isDevelopment
|
||||
);
|
||||
|
||||
globalPool = postgres(connectionString, {
|
||||
max: poolSize,
|
||||
idle_timeout: 30,
|
||||
connect_timeout: 30,
|
||||
prepare: true,
|
||||
ssl: isDevelopment ? false : {
|
||||
rejectUnauthorized: false, // Allow self-signed certificates
|
||||
},
|
||||
ssl: isDevelopment
|
||||
? false
|
||||
: {
|
||||
rejectUnauthorized: false, // Allow self-signed certificates
|
||||
},
|
||||
...config,
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue