Skip to content
This repository was archived by the owner on May 25, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion db/init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ CREATE TABLE IF NOT EXISTS workflow_checkpoints (
agent_name VARCHAR(128) NOT NULL,
document_id UUID NOT NULL,
current_activity VARCHAR(128) NOT NULL,
state_data JSONB,
state_data TEXT,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Changing the column type in init.sql will not update existing databases where the table already exists due to the IF NOT EXISTS clause. Additionally, a simple type cast from JSONB to TEXT in an ALTER TABLE statement will preserve JSON quotes (e.g., storing "SGVsbG8=" instead of SGVsbG8=). This will cause Convert.FromBase64String to fail in DocumentProcessingAgent.cs (line 82) when the agent attempts to resume from a checkpoint created before this change.

Recommendation: Ensure a migration script is provided that both alters the type and unquotes existing data:

ALTER TABLE workflow_checkpoints ALTER COLUMN state_data TYPE TEXT USING state_data#>>'{}';

is_completed BOOLEAN NOT NULL DEFAULT FALSE,
is_failed BOOLEAN NOT NULL DEFAULT FALSE,
error_message TEXT,
Expand Down
2 changes: 1 addition & 1 deletion src/Worker/Data/AppDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
entity.HasKey(e => e.Id);
entity.Property(e => e.AgentName).HasMaxLength(128).IsRequired();
entity.Property(e => e.CurrentActivity).HasMaxLength(128).IsRequired();
entity.Property(e => e.StateData).HasColumnType("jsonb");
entity.Property(e => e.StateData).HasColumnType("text");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

While changing the column type to text resolves the 22P02 (invalid JSON) error, storing large binary data as Base64 in a database column is inefficient. Base64 encoding increases the payload size by approximately 33%, leading to significant database bloat and increased memory pressure when checkpoints are retrieved.

Since the DocumentId and FilePath are already available in the AgentContext, consider refactoring the agent to re-retrieve the file from IFileStorage upon resume instead of serializing the entire PDF into the database. If storing the payload is strictly necessary, a BYTEA column or a dedicated blob storage would be more performant.

entity.Property(e => e.ErrorMessage).HasMaxLength(4096);
entity.HasIndex(e => new { e.AgentName, e.DocumentId });
entity.HasIndex(e => e.IsCompleted);
Expand Down
Loading