fix(stage): align session export render cap with artifact bound

Six computed Flutter runs stopped at the export handoff gate because the
rendered session.html cap was 2 MiB while their complete sessions (well inside
the 8 MiB source read bound) rendered between 2.25 and 4.28 MiB once html
escaping and the readable projection duplicated native text.

Raise SessionExportFileLimit to 8 MiB, the server's existing per-artifact file
bound, so a complete export is still listed and served. Normal export
verification, versioned repair and the handoff gate keep using the single
shared constant. The source read bound is unchanged, and an over-cap render is
still visibly truncated and recorded partial.

Add focused regressions for a complete export above the old cap, an over-new-cap
file rejected as partial, repair above the old cap leaving original evidence
untouched, the gate accepting the larger repair, and the constant staying inside
the artifact file bound. Update the artifact, handoff-gate and operations docs
and record the diagnosis in docs/notes/session-export-render-cap.md.
This commit is contained in:
2026-10-21 15:26:29 +01:00
parent 0a00526692
commit 22801a9b06
9 changed files with 261 additions and 12 deletions
@@ -136,6 +136,56 @@ func TestSessionExportGateRetryOnlyAndExactlyOnce(t *testing.T) {
}
}
// TestSessionExportGateAcceptsRepairAboveOldRenderCap keeps the handoff gate's
// versioned-repair verification on the same larger bound as normal export.
func TestSessionExportGateAcceptsRepairAboveOldRenderCap(t *testing.T) {
h, s, id, first, second := gateRunner(t, func(context.Context, stage.SessionExportRequest) (stage.SessionExportResult, error) {
return stage.SessionExportResult{}, errors.New("export offline")
}, false)
h.runner.wg.Wait()
ctx := context.Background()
if err := s.ConfirmRecoveredSession(ctx, pipeline.SessionOwner{RunID: id, ID: "ses_exact"}); err != nil {
t.Fatal(err)
}
size := int64(2<<20) + 4096
h.runner.exportSession = func(_ context.Context, req stage.SessionExportRequest) (stage.SessionExportResult, error) {
if err := os.MkdirAll(req.ArtifactsDir, 0700); err != nil {
return stage.SessionExportResult{}, err
}
f, err := os.Create(filepath.Join(req.ArtifactsDir, req.FileName))
if err != nil {
return stage.SessionExportResult{}, err
}
if err := f.Truncate(size); err != nil {
f.Close()
return stage.SessionExportResult{}, err
}
if err := f.Close(); err != nil {
return stage.SessionExportResult{}, err
}
return stage.SessionExportResult{Source: "native_export", HTML: req.FileName, HTMLBytes: size, Messages: 2}, nil
}
if _, err := h.runner.repairSessionExport(ctx, id, 1); err != nil {
t.Fatal(err)
}
// The worker promotes a persisted complete repair before claiming a lease.
job, err := s.ClaimSessionExportJob(ctx, time.Now().Add(time.Second), time.Minute)
if err != nil {
t.Fatal(err)
}
if job != nil {
t.Fatalf("complete repair still claimed as a recovery job: %+v", job)
}
if err := h.runner.resumeExportGates(ctx); err != nil {
t.Fatal(err)
}
h.runner.wg.Wait()
d, _ := s.GetRun(ctx, id)
if first.Load() != 1 || second.Load() != 1 || d.Status != "succeeded" || len(d.Steps) != 2 {
t.Fatalf("large repair did not advance the gate: %+v (%d/%d)", d, first.Load(), second.Load())
}
}
func TestSessionExportGateCleanupUnconfirmedDoesNotExportOrAdvance(t *testing.T) {
var exports atomic.Int32
h, s, id, _, second := gateRunner(t, func(ctx context.Context, req stage.SessionExportRequest) (stage.SessionExportResult, error) {
@@ -111,6 +111,57 @@ func TestRuntimeSessionExportRepairPreservesOriginalAndUsesRecordedOwner(t *test
}
}
// TestRuntimeSessionExportRepairAcceptsAboveTheOldRenderCap proves a versioned
// repair uses the same larger bound as a normal export while leaving the
// original recorded evidence untouched.
func TestRuntimeSessionExportRepairAcceptsAboveTheOldRenderCap(t *testing.T) {
h, s, id := sessionExportRunner(t, "v2", func(stage.SessionExportRequest) (stage.SessionExportResult, error) {
return stage.SessionExportResult{}, errors.New("initial export unavailable")
})
if err := s.ConfirmRecoveredSession(context.Background(), pipeline.SessionOwner{RunID: id, ID: "ses_run"}); err != nil {
t.Fatal(err)
}
original, err := s.GetRun(context.Background(), id)
if err != nil {
t.Fatal(err)
}
before, _ := json.Marshal(original.Steps[0].SessionExport)
size := int64(2<<20) + 4096
h.runner.exportSession = func(_ context.Context, req stage.SessionExportRequest) (stage.SessionExportResult, error) {
if err := os.MkdirAll(req.ArtifactsDir, 0700); err != nil {
return stage.SessionExportResult{}, err
}
f, err := os.Create(filepath.Join(req.ArtifactsDir, req.FileName))
if err != nil {
return stage.SessionExportResult{}, err
}
if err := f.Truncate(size); err != nil {
f.Close()
return stage.SessionExportResult{}, err
}
if err := f.Close(); err != nil {
return stage.SessionExportResult{}, err
}
return stage.SessionExportResult{Source: "native_export", HTML: req.FileName, HTMLBytes: size, Messages: 2}, nil
}
repaired, err := h.runner.repairSessionExport(context.Background(), id, 1)
if err != nil {
t.Fatal(err)
}
latest := repaired.Steps[0].SessionExportRepairs[0]
if latest.Status != "complete" || latest.HTMLBytes != size || latest.HTML == "" {
t.Fatalf("repair above the old cap was not complete: %+v", latest)
}
after, _ := json.Marshal(repaired.Steps[0].SessionExport)
if string(before) != string(after) {
t.Fatal("repair above the old cap overwrote original evidence")
}
info, err := os.Stat(filepath.Join(h.runner.artifactsRoot, "1", "stages", "01-"+repaired.Steps[0].Stage, latest.HTML))
if err != nil || info.Size() != size {
t.Fatalf("repair file missing or resized: %v %+v", err, info)
}
}
func TestRuntimeRepairRejectsUnrecordedAndActiveVisits(t *testing.T) {
h, _, id := sessionExportRunner(t, "v2", func(stage.SessionExportRequest) (stage.SessionExportResult, error) {
return stage.SessionExportResult{}, errors.New("unavailable")
+62 -1
View File
@@ -1,10 +1,13 @@
package server
import (
"git.a-wan.net/alan/pipelines/internal/protocol"
"os"
"path/filepath"
"strings"
"testing"
"git.a-wan.net/alan/pipelines/internal/protocol"
"git.a-wan.net/alan/pipelines/internal/stage"
)
func TestSessionExportCompleteness(t *testing.T) {
@@ -56,3 +59,61 @@ func TestRuntimeSessionExportFileVerificationDoesNotClaimMissingEvidence(t *test
})
}
}
func sizedSessionFile(t *testing.T, size int64) string {
t.Helper()
dir := t.TempDir()
path := filepath.Join(dir, "session.html")
f, err := os.Create(path)
if err != nil {
t.Fatal(err)
}
if err := f.Truncate(size); err != nil {
f.Close()
t.Fatal(err)
}
if err := f.Close(); err != nil {
t.Fatal(err)
}
return dir
}
// TestRuntimeSessionExportVerificationAcceptsAboveTheOldRenderCap pins the
// ordinary-session case the previous 2 MiB rendered bound cut. The file is
// larger than that old cap and inside the artifact-aligned bound, so normal
// export verification must keep it and classify the evidence complete.
func TestRuntimeSessionExportVerificationAcceptsAboveTheOldRenderCap(t *testing.T) {
size := int64(2<<20) + 4096
dir := sizedSessionFile(t, size)
evidence := &protocol.SessionExport{Source: "native_export", Messages: 2, HTML: "session.html", HTMLBytes: size}
verifySessionExportFile(evidence, dir)
classifySessionExport(evidence)
if evidence.Status != "complete" || evidence.HTML != "session.html" || evidence.HTMLBytes != size || evidence.Diagnostic != "" {
t.Fatalf("complete export above the old cap was rejected: %+v", evidence)
}
}
// TestRuntimeSessionExportVerificationRejectsAboveTheNewCap confirms the larger
// bound is still a hard bound: an oversized file is not presented as evidence.
func TestRuntimeSessionExportVerificationRejectsAboveTheNewCap(t *testing.T) {
size := int64(stage.SessionExportFileLimit) + 1
dir := sizedSessionFile(t, size)
evidence := &protocol.SessionExport{Source: "native_export", Messages: 2, HTML: "session.html", HTMLBytes: size}
verifySessionExportFile(evidence, dir)
classifySessionExport(evidence)
if evidence.Status != "partial" || evidence.HTML != "" || evidence.HTMLBytes != 0 || !strings.Contains(evidence.Diagnostic, "bounded verification") {
t.Fatalf("oversized export was not rejected as partial: %+v", evidence)
}
}
// TestSessionExportFileLimitStaysInsideArtifactBounds keeps the render cap
// principled: larger than the cap that cut ordinary sessions, and no larger
// than the ordinary per-artifact file bound that serves the file.
func TestSessionExportFileLimitStaysInsideArtifactBounds(t *testing.T) {
if stage.SessionExportFileLimit <= 2<<20 {
t.Fatalf("render cap %d did not grow beyond the old 2 MiB cutoff", stage.SessionExportFileLimit)
}
if stage.SessionExportFileLimit > maxArtifactFileBytes {
t.Fatalf("render cap %d exceeds the artifact file bound %d", stage.SessionExportFileLimit, maxArtifactFileBytes)
}
}