You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by wu...@apache.org on 2026/09/06 06:25:09 UTC

(skywalking-ai-sessionizer) branch main updated: Bind every round to its landed files in asz verify, and let a scenario lose a file

This is an automated email from the ASF dual-hosted git repository.

wu-sheng pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/skywalking-ai-sessionizer.git


The following commit(s) were added to refs/heads/main by this push:
     new 66a9c54  Bind every round to its landed files in asz verify, and let a scenario lose a file
66a9c54 is described below

commit 66a9c541790d5fb71d23305add4da02ce476e12e
Author: Wu Sheng <wu...@foxmail.com>
AuthorDate: Sun Sep 6 14:25:01 2026 +0800

    Bind every round to its landed files in asz verify, and let a scenario lose a file
    
    asz verify was silent when a landed file a round had consumed was gone, if
    that file was the only one of its stream: the stream checks see only what
    exists, and the chain check followed the round-to-round links without
    asking whether the files a round names are still there. The page asked
    that question; the command did not.
    
    verify.Chain walks each round's window against the landed files on disk
    and their digests, the check the page always ran, and reports a missing
    file by round and sequence, a changed file as a digest mismatch, and a
    missing or unlinked round. The page and asz verify now share it, and the
    command exits non-zero on any problem.
    
    An expectation file can now say what a person deleted from the storage
    root. lose on a checkpoint names landed files by stream or run and kind,
    since the two formats land the same files in a different order, and the
    runner deletes them after that checkpoint's parse. Every later check runs
    over the damaged root: the structure survives in the rounds, the document
    reports incomplete and names the round and the sequence, asz verify
    reports the same, and later rounds are whole. view gained problems and a
    checkpoint gained verify: {problems: N}. The coverage property no longer
    demands a verified document; it demands the state asz verify gives. The
    push property and the Collector check compare what verify says of the
    root rebuilt from the wire with what it says of the root pushed, so a
    loss travels like anything else.
    
    tests/scenarios/lost-file.yaml deletes the helper's transcript after
    round 1 and goes on to round 2. Three properties are set off there with a
    reason: a re-cut root holds only what is on disk, a source line of the
    lost file has no landed record, and re-deriving from the landed files
    changes the fold.
---
 cmd/asz/main.go                       |  30 ++++--
 docs/en/changes/changes-0.2.0.md      |  14 +++
 docs/en/guides/scenario.md            |  19 +++-
 docs/en/setup/command-line.md         |   6 +-
 internal/scenario/expect/expect.go    | 130 ++++++++++++++++++++++--
 internal/scenario/run/push.go         |  41 ++++++--
 internal/scenario/run/run.go          |  31 ++++++
 internal/verify/chain.go              | 184 ++++++++++++++++++++++++++++++++++
 internal/view/conversationview.go     |  85 ++++------------
 tests/scenarios/lost-file.expect.yaml |  51 ++++++++++
 tests/scenarios/lost-file.yaml        |  34 +++++++
 tools/collectorcheck/main.go          |   7 +-
 12 files changed, 535 insertions(+), 97 deletions(-)

diff --git a/cmd/asz/main.go b/cmd/asz/main.go
index 6772cba..256ca5c 100644
--- a/cmd/asz/main.go
+++ b/cmd/asz/main.go
@@ -35,7 +35,6 @@ import (
 	"github.com/apache/skywalking-ai-sessionizer/internal/storage"
 	"github.com/apache/skywalking-ai-sessionizer/internal/verify"
 	"github.com/apache/skywalking-ai-sessionizer/pkg/sessiondata"
-	"github.com/apache/skywalking-ai-sessionizer/pkg/sessionflow"
 )
 
 const usage = `asz - SkyWalking AI Sessionizer: conversation-level observability for long-lived AI agents
@@ -457,7 +456,7 @@ func cmdVerify(cfg *config.Config, _ config.Adapter, _ bool) error {
 	// A conversation's rounds are checked too. They are a digest chain, so a
 	// missing or edited round is detectable in a way landed files are not, and
 	// the check costs one pass over a directory that is far smaller than the data.
-	chains, rounds, err := verifyChains(zoneRoot, want)
+	chains, rounds, chainProblems, err := verifyChains(zoneRoot, want)
 	if err != nil {
 		return err
 	}
@@ -465,6 +464,7 @@ func cmdVerify(cfg *config.Config, _ config.Adapter, _ bool) error {
 		fmt.Printf("checked %d conversation chain(s), %d round(s)\n", chains, rounds)
 	}
 
+	problems += chainProblems
 	if problems > 0 {
 		return fmt.Errorf("%d contiguity or integrity problem(s)", problems)
 	}
@@ -472,28 +472,38 @@ func cmdVerify(cfg *config.Config, _ config.Adapter, _ bool) error {
 	return nil
 }
 
-// verifyChains walks every conversation chain in the zone.
-func verifyChains(root, want string) (chains, rounds int, err error) {
+// verifyChains walks every conversation chain in the zone, and binds each
+// round to the landed files it consumed: a file a round names that is gone
+// is reported here, since the stream checks see only what exists.
+func verifyChains(root, want string) (chains, rounds, problems int, err error) {
 	base := filepath.Join(root, "_conversations")
 	items, rerr := os.ReadDir(base)
 	if rerr != nil {
 		if os.IsNotExist(rerr) {
-			return 0, 0, nil
+			return 0, 0, 0, nil
 		}
-		return 0, 0, rerr
+		return 0, 0, 0, rerr
 	}
+	z := storage.NewZone(root)
 	for _, d := range items {
 		if !d.IsDir() || (want != "" && d.Name() != want) {
 			continue
 		}
-		files, verr := sessionflow.OpenChain(root, d.Name()).Verify()
+		rep, verr := verify.Chain(z, d.Name(), nil)
 		if verr != nil {
-			return chains, rounds, verr
+			return chains, rounds, problems, verr
 		}
 		chains++
-		rounds += len(files)
+		rounds += len(rep.Rounds)
+		problems += rep.Problems
+		if !rep.OK() {
+			fmt.Printf("%s: %d problem(s) in the chain\n", rep.Conversation, rep.Problems)
+			for _, line := range rep.Details() {
+				fmt.Printf("   %s\n", line)
+			}
+		}
 	}
-	return chains, rounds, nil
+	return chains, rounds, problems, nil
 }
 
 func cmdShow(cfg *config.Config, _ config.Adapter, _ bool) error {
diff --git a/docs/en/changes/changes-0.2.0.md b/docs/en/changes/changes-0.2.0.md
index b7d2a53..ed99a44 100644
--- a/docs/en/changes/changes-0.2.0.md
+++ b/docs/en/changes/changes-0.2.0.md
@@ -73,6 +73,20 @@
   the scenario that holds every kind of file, so a session with open references is rebuilt and
   verified from what the Collector wrote.
 
+- An expectation file can say what a person deleted from the storage root. `lose` on a checkpoint
+  names landed files by stream or run and kind, and the runner deletes them after that
+  checkpoint's parse, so every later check runs over a root missing a file a round bound to. The
+  structure survives in the rounds, the document reports `incomplete` and names the round and the
+  sequence, and later rounds are whole. `tests/scenarios/lost-file.yaml` is the example. `view`
+  gained `problems` and a checkpoint gained `verify: {problems: N}`, and the document's state must
+  agree with `asz verify` in every scenario.
+
+- `asz verify` binds every round to the landed files it consumed, the way the page always did: a
+  file a round names that is gone, or that no longer digests to what the round consumed, is
+  reported by round and sequence, and the command exits non-zero. It was silent before when the
+  lost file was the only one of its stream, since the stream checks see only what exists. The
+  page and the command now share the one check.
+
 ## Read
 
 - `asz.view`, version 1.0, is one conversation rebuilt from its rounds and its landed files as one
diff --git a/docs/en/guides/scenario.md b/docs/en/guides/scenario.md
index 3120d93..0cee42a 100644
--- a/docs/en/guides/scenario.md
+++ b/docs/en/guides/scenario.md
@@ -137,6 +137,18 @@ damaged, and the incompleteness is in the evidence. What a check sees is the `un
 asz scenario check FILE [--format claude-code|sd|all] [--out DIR] [--at TIME] [--scale FACTOR]
 ```
 
+A checkpoint may also say what a person deleted from the storage root. `lose` names landed files
+by what they hold, a stream or a run and a kind, since the two formats land the same files in a
+different order, and the runner deletes them after the checkpoint's parse, once a round has bound
+to them. Every check from there on runs over the damaged root: the structure survives, because it
+lives in the rounds, the text of the lost file is gone, the document says `incomplete` and names
+the round and the sequence, `asz verify` reports the same, and the session goes on into later
+rounds. Three properties cannot hold on such a root and are set off with a reason: a re-cut root
+holds only what is on disk, a source line of the lost file has no landed record, and re-deriving
+from the landed files changes the fold. `tests/scenarios/lost-file.yaml` is the example, and its
+loss travels over the wire like anything else: the root rebuilt from the push reports exactly what
+the pushed root reports.
+
 For each format, and at each checkpoint in order, `check` builds through the checkpoint, collects
 when the format needs it, parses, and compares the fold with the expectation file beside the
 scenario, `NAME.expect.yaml`. At the end it runs the properties every chain must have, and with
@@ -159,7 +171,12 @@ checkpoints:
     unresolved: {open: 0, resolved: 0}
     unresolved_kinds: {tool_result: none}
     session: {from: +0s, to: +11.1s}      # the session node's range, as deltas from --at
-    view: {state: verified, talks: 3, files: 6, first_talk: {label: run the build, runs: 2}}
+    view: {state: verified, problems: 0, talks: 3, files: 6, first_talk: {label: run the build, runs: 2}}
+    verify: {problems: 0}                 # what asz verify reports over the root
+  helped:
+    lose: [{stream: checker, kind: transcript}]   # deleted from the root after this checkpoint's parse
+    view: {state: incomplete, problems: 1}
+    verify: {problems: 1}
 properties:                               # all on unless set false
   reproducible: true
   fold_equals_parse: true
diff --git a/docs/en/setup/command-line.md b/docs/en/setup/command-line.md
index 9b7da41..465952e 100644
--- a/docs/en/setup/command-line.md
+++ b/docs/en/setup/command-line.md
@@ -171,8 +171,10 @@ words instead.
 ## verify
 
 Checks every landed file against its digest and every round against its commit digest, for one
-session or all of them. It reads the storage root only, so it works without the source files and
-without a collector.
+session or all of them, and binds every round to the landed files it consumed: a round whose file
+is gone, or whose files no longer digest to what it consumed, is reported by round and sequence.
+It reads the storage root only, so it works without the source files and without a collector, and
+it exits non-zero when anything is wrong.
 
 ```text
 checked 44 session(s), 5867 stream(s), 359292 records
diff --git a/internal/scenario/expect/expect.go b/internal/scenario/expect/expect.go
index fadd82b..996705c 100644
--- a/internal/scenario/expect/expect.go
+++ b/internal/scenario/expect/expect.go
@@ -36,6 +36,7 @@ import (
 	"github.com/apache/skywalking-ai-sessionizer/internal/index"
 	"github.com/apache/skywalking-ai-sessionizer/internal/parse"
 	"github.com/apache/skywalking-ai-sessionizer/internal/storage"
+	"github.com/apache/skywalking-ai-sessionizer/internal/verify"
 	"github.com/apache/skywalking-ai-sessionizer/internal/view"
 	"github.com/apache/skywalking-ai-sessionizer/pkg/model"
 	"github.com/apache/skywalking-ai-sessionizer/pkg/sessiondata"
@@ -113,12 +114,74 @@ type Checkpoint struct {
 	// Delta says the round this checkpoint wrote is a delta: fewer nodes
 	// than the fold, and starting past the first landed file.
 	Delta *bool `yaml:"delta"`
+	// Lose names landed files to delete after this checkpoint's parse and
+	// before its checks: what a person deletes from a storage root after a
+	// round has bound to it. The checks that follow, here and at every
+	// later checkpoint, run over the damaged root.
+	Lose []Lose `yaml:"lose"`
+	// Verify is what asz verify must report.
+	Verify *Verify `yaml:"verify"`
+}
+
+// Lose names one landed file by what it holds rather than by its sequence,
+// since the two formats land the same files in a different order: the
+// stream or run it belongs to, its kind, and which one of that kind on that
+// stream, counting from one.
+type Lose struct {
+	Stream string `yaml:"stream"`
+	Run    string `yaml:"run"`
+	Kind   string `yaml:"kind"`
+	Nth    int    `yaml:"nth"`
+}
+
+// Verify is what asz verify must report over the root: how many problems,
+// counting the streams and the chain together.
+type Verify struct {
+	Problems *int `yaml:"problems"`
+}
+
+// landedPrefix is the file name prefix a landed file of each kind carries.
+var landedPrefix = map[string]string{
+	"transcript": "transcript", "agent_meta": "meta", "journal": "journal",
+	"workflow_manifest": "manifest", "workflow_script": "script",
+}
+
+// Resolve finds the landed file a Lose names among a session's files. The
+// stream is the resolved stream id; the caller turns a scenario name into
+// one.
+func (l Lose) Resolve(files []storage.LandedFile, stream string) (*storage.LandedFile, error) {
+	nth := l.Nth
+	if nth == 0 {
+		nth = 1
+	}
+	prefix, known := landedPrefix[l.Kind]
+	if l.Kind != "" && !known {
+		return nil, fmt.Errorf("lose: unknown kind %q; the kinds are transcript, agent_meta, journal, workflow_manifest, workflow_script", l.Kind)
+	}
+	seen := 0
+	for i := range files {
+		f := &files[i]
+		if l.Run != "" && f.RunID != l.Run {
+			continue
+		}
+		if l.Run == "" && f.Stream != stream {
+			continue
+		}
+		if prefix != "" && !strings.HasPrefix(filepath.Base(f.Path), prefix+"-") {
+			continue
+		}
+		seen++
+		if seen == nth {
+			return f, nil
+		}
+	}
+	return nil, fmt.Errorf("lose: no landed file %d of kind %q on stream %q run %q; the session has %d files", nth, l.Kind, l.Stream, l.Run, len(files))
 }
 
 // Empty reports a checkpoint with nothing to check.
 func (cp *Checkpoint) Empty() bool {
 	return cp.Rounds == nil && cp.Written == nil && len(cp.Kinds) == 0 && len(cp.TalksOn) == 0 && len(cp.RunsIn) == 0 &&
-		len(cp.Relations) == 0 && cp.Unresolved == nil && len(cp.UnresolvedKinds) == 0 && len(cp.Nodes) == 0 &&
+		len(cp.Relations) == 0 && cp.Unresolved == nil && len(cp.UnresolvedKinds) == 0 && len(cp.Nodes) == 0 && cp.Verify == nil &&
 		cp.Session == nil && cp.View == nil && cp.Delta == nil
 }
 
@@ -159,12 +222,14 @@ type Session struct {
 
 // View is what the asz.view document must say.
 type View struct {
-	State     string `yaml:"state"`
-	Talks     *int   `yaml:"talks"`
-	Steps     *int   `yaml:"steps"`
-	Files     *int   `yaml:"files"`
-	Rounds    *int   `yaml:"rounds"`
-	FirstTalk *Talk  `yaml:"first_talk"`
+	State string `yaml:"state"`
+	// Problems is how many problems the summary lists.
+	Problems  *int  `yaml:"problems"`
+	Talks     *int  `yaml:"talks"`
+	Steps     *int  `yaml:"steps"`
+	Files     *int  `yaml:"files"`
+	Rounds    *int  `yaml:"rounds"`
+	FirstTalk *Talk `yaml:"first_talk"`
 }
 
 // Talk is what a talk in the document must say.
@@ -206,6 +271,10 @@ type Context struct {
 	Round   *parse.Round
 }
 
+// Stream turns a scenario's stream name into the stream's id; a name that
+// is not a scenario name is returned as it is.
+func (c *Context) Stream(name string) string { return c.resolve(name) }
+
 func (c *Context) resolve(s string) string {
 	parts := strings.Split(s, "/")
 	for i, p := range parts {
@@ -373,6 +442,21 @@ func Evaluate(root string, cp *Checkpoint, ctx *Context) ([]string, error) {
 		}
 		out = append(out, lines...)
 	}
+	if cp.Verify != nil {
+		z := storage.NewZone(root)
+		streams, err := verify.Session(z, ctx.Session)
+		if err != nil {
+			return nil, err
+		}
+		chain, err := verify.Chain(z, ctx.Session, nil)
+		if err != nil {
+			return nil, err
+		}
+		got := streams.Problems + chain.Problems
+		if cp.Verify.Problems != nil && got != *cp.Verify.Problems {
+			bad("verify: %d problem(s) (%v %v), want %d", got, streams.Details(), chain.Details(), *cp.Verify.Problems)
+		}
+	}
 	return out, nil
 }
 
@@ -391,6 +475,9 @@ func checkView(root, session string, want *View) ([]string, error) {
 	if want.State != "" && doc.Summary.State != want.State {
 		bad("view.state is %s (%v), want %s", doc.Summary.State, doc.Summary.Problems, want.State)
 	}
+	if want.Problems != nil && len(doc.Summary.Problems) != *want.Problems {
+		bad("view.problems is %d (%v), want %d", len(doc.Summary.Problems), doc.Summary.Problems, *want.Problems)
+	}
 	if want.Talks != nil && doc.Summary.Talks != *want.Talks {
 		bad("view.talks is %d, want %d", doc.Summary.Talks, *want.Talks)
 	}
@@ -848,8 +935,29 @@ func ViewCoversTheSession(root, session string) ([]string, error) {
 	bad := func(format string, a ...any) {
 		out = append(out, "view_covers_the_session: "+fmt.Sprintf(format, a...))
 	}
-	if doc.Summary.State != sessionview.StateVerified {
-		bad("state is %s: %v", doc.Summary.State, doc.Summary.Problems)
+	// The document's state is what asz verify says of the root: verified,
+	// incomplete when a round names a file that is gone, mismatch when the
+	// evidence changed. A root a scenario damaged must be reported as such.
+	chainRep, err := verify.Chain(storage.NewZone(root), session, nil)
+	if err != nil {
+		return nil, err
+	}
+	wantState := sessionview.StateVerified
+	verifiedRound := map[uint64]bool{}
+	for _, rr := range chainRep.Rounds {
+		verifiedRound[rr.Round] = rr.OK()
+		switch {
+		case rr.Damaged():
+			wantState = sessionview.StateMismatch
+		case !rr.OK() && wantState == sessionview.StateVerified:
+			wantState = sessionview.StateIncomplete
+		}
+	}
+	if doc.Summary.State != wantState {
+		bad("state is %s (%v), asz verify says %s (%v)", doc.Summary.State, doc.Summary.Problems, wantState, chainRep.Details())
+	}
+	if len(doc.Summary.Problems) != chainRep.Problems {
+		bad("the document lists %d problem(s) %v, asz verify %d %v", len(doc.Summary.Problems), doc.Summary.Problems, chainRep.Problems, chainRep.Details())
 	}
 	// Every round, verified, and the head.
 	chain := sessionflow.OpenChain(root, session)
@@ -861,8 +969,8 @@ func ViewCoversTheSession(root, session string) ([]string, error) {
 		bad("%d rounds in the document, %d on disk; head %d/%s against %d/%s", len(doc.Rounds), len(files), doc.Head.Round, firstN(doc.Head.Digest, 12), v.Round, firstN(v.Digest, 12))
 	}
 	for _, r := range doc.Rounds {
-		if !r.Verified {
-			bad("round %d is not verified", r.Round)
+		if r.Verified != verifiedRound[r.Round] {
+			bad("round %d is verified: %v, asz verify says %v", r.Round, r.Verified, verifiedRound[r.Round])
 		}
 	}
 	// Every landed file, as on disk.
diff --git a/internal/scenario/run/push.go b/internal/scenario/run/push.go
index 1b8871b..6b1a36f 100644
--- a/internal/scenario/run/push.go
+++ b/internal/scenario/run/push.go
@@ -292,14 +292,10 @@ func pushOver(protocol, out, session string, f scenario.Format, want *expect.Pus
 			return nil, err
 		}
 	}
-	rep, err := verify.Session(storage.NewZone(twin), session)
-	if err != nil {
-		bad("the root rebuilt from the wire does not verify: %v", err)
-	} else if !rep.OK() {
-		bad("the root rebuilt from the wire has %d problem(s): %v", rep.Problems, rep.Details())
-	}
-	if _, err := sessionflow.OpenChain(twin, session).Verify(); err != nil {
-		bad("the chain rebuilt from the wire does not verify: %v", err)
+	// The wire carries the root as it is, damage included: what asz verify
+	// says of the rebuilt root is what it says of the root that was pushed.
+	for _, p := range verifyDiffers(out, twin, session) {
+		bad("%s", p)
 	}
 	a, err := expect.Summarize(out, session)
 	if err != nil {
@@ -316,6 +312,35 @@ func pushOver(protocol, out, session string, f scenario.Format, want *expect.Pus
 	return out2, nil
 }
 
+// verifyDiffers compares what asz verify says of two roots holding the same
+// session: the stream problems and the chain problems must be the same.
+func verifyDiffers(a, b, session string) []string {
+	var out []string
+	sa, err := verify.Session(storage.NewZone(a), session)
+	if err != nil {
+		return []string{"the root does not verify: " + err.Error()}
+	}
+	sb, err := verify.Session(storage.NewZone(b), session)
+	if err != nil {
+		return []string{"the root rebuilt from the wire does not verify: " + err.Error()}
+	}
+	if sa.Problems != sb.Problems {
+		out = append(out, fmt.Sprintf("the root rebuilt from the wire has %d stream problem(s) %v, the root pushed has %d %v", sb.Problems, sb.Details(), sa.Problems, sa.Details()))
+	}
+	ca, err := verify.Chain(storage.NewZone(a), session, nil)
+	if err != nil {
+		return append(out, "the chain does not verify: "+err.Error())
+	}
+	cb, err := verify.Chain(storage.NewZone(b), session, nil)
+	if err != nil {
+		return append(out, "the chain rebuilt from the wire does not verify: "+err.Error())
+	}
+	if strings.Join(ca.Details(), "; ") != strings.Join(cb.Details(), "; ") {
+		out = append(out, fmt.Sprintf("the chain rebuilt from the wire reports %v, the chain pushed reports %v", cb.Details(), ca.Details()))
+	}
+	return out
+}
+
 // wireFile is one file of the session as the receiver must see it.
 type wireFile struct {
 	rel, format, schema, kind, stream, batch string
diff --git a/internal/scenario/run/run.go b/internal/scenario/run/run.go
index 668ddca..b1498aa 100644
--- a/internal/scenario/run/run.go
+++ b/internal/scenario/run/run.go
@@ -171,6 +171,15 @@ func checkFormat(sc *scenario.Scenario, ex *expect.File, f scenario.Format, out
 			want = &expect.Checkpoint{}
 		}
 		ctx := &expect.Context{Session: built.Session, Names: names(built.Plan), At: opts.At, Round: round}
+		// What a person deletes from the root after the round bound to it.
+		// Every check from here on runs over the damaged root.
+		for _, l := range want.Lose {
+			rel, err := lose(out, built.Session, l, ctx)
+			if err != nil {
+				return nil, "", err
+			}
+			rep.say("%s %s: lost %s", f, name, rel)
+		}
 		problems, err := expect.Evaluate(out, want, ctx)
 		if err != nil {
 			return nil, "", err
@@ -298,6 +307,28 @@ func checkFormat(sc *scenario.Scenario, ex *expect.File, f scenario.Format, out
 	return summary, session, nil
 }
 
+// lose deletes one landed file of the session, as a person would: the file
+// is read-only, so it is made writable first. It returns the path relative
+// to the root.
+func lose(out, session string, l expect.Lose, ctx *expect.Context) (string, error) {
+	files, err := storage.LandedFiles(storage.NewZone(out), session)
+	if err != nil {
+		return "", err
+	}
+	f, err := l.Resolve(files, ctx.Stream(l.Stream))
+	if err != nil {
+		return "", err
+	}
+	if err := os.Chmod(f.Path, 0o644); err != nil {
+		return "", err
+	}
+	if err := os.Remove(f.Path); err != nil {
+		return "", err
+	}
+	rel, _ := filepath.Rel(out, f.Path)
+	return filepath.ToSlash(rel), nil
+}
+
 // collect lands a runtime format's source through its adapter. An sd build
 // is landed already.
 func collect(f scenario.Format, out string) error {
diff --git a/internal/verify/chain.go b/internal/verify/chain.go
new file mode 100644
index 0000000..08b7516
--- /dev/null
+++ b/internal/verify/chain.go
@@ -0,0 +1,184 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package verify
+
+import (
+	"fmt"
+	"path/filepath"
+
+	"github.com/apache/skywalking-ai-sessionizer/internal/storage"
+	"github.com/apache/skywalking-ai-sessionizer/pkg/sessionflow"
+)
+
+// ChainReport is the result of checking one conversation's chain against
+// the landed files its rounds consumed.
+type ChainReport struct {
+	Conversation string
+	Session      string
+	Rounds       []*RoundReport
+	Problems     int
+}
+
+// RoundReport is one round as the check found it. A round that could not
+// be opened has OpenError and nothing else.
+type RoundReport struct {
+	Round  uint64
+	Path   string
+	Header sessionflow.Header
+	Digest string
+
+	OpenError string
+	// MissingRound is set when a round number is skipped before this one:
+	// the round that should have come first is not on disk.
+	MissingRound uint64
+	// BrokenLink says the round names a previous digest that is not the
+	// digest of the round before it.
+	BrokenLink bool
+	// SeqGap says the round starts past where the round before ended.
+	SeqGap bool
+	// Missing lists the landed sequences the round consumed that are no
+	// longer on disk.
+	Missing []uint64
+	// DigestMismatch says the landed files on disk do not digest to what
+	// the round consumed, so at least one was changed.
+	DigestMismatch bool
+
+	Problems []string
+}
+
+// OK reports a round that verified against the chain and the landed files.
+func (r *RoundReport) OK() bool { return len(r.Problems) == 0 }
+
+// Damaged reports a round whose evidence is changed rather than missing: a
+// broken link, a digest that does not match, or a file that will not open.
+func (r *RoundReport) Damaged() bool {
+	return r.OpenError != "" || r.BrokenLink || r.DigestMismatch
+}
+
+// OK reports whether every round verified.
+func (r *ChainReport) OK() bool { return r.Problems == 0 }
+
+// Details returns every problem, in round order.
+func (r *ChainReport) Details() []string {
+	var out []string
+	for _, rr := range r.Rounds {
+		out = append(out, rr.Problems...)
+	}
+	return out
+}
+
+// LandedDigests reads the digest of every landed file of a session, by
+// sequence: what a round's input digest was computed over.
+func LandedDigests(z *storage.Zone, session string) (map[uint64]string, error) {
+	files, err := storage.LandedFiles(z, session)
+	if err != nil {
+		return nil, err
+	}
+	out := map[uint64]string{}
+	for _, lf := range files {
+		d, err := storage.FileDigest(lf.Path)
+		if err != nil {
+			return nil, err
+		}
+		out[lf.Seq] = d
+	}
+	return out, nil
+}
+
+// Chain checks a conversation's rounds against each other and against the
+// landed files: numbered from one, each naming the digest of the round
+// before, each starting where the round before ended, and each bound to
+// landed files that are still on disk and still digest to what the round
+// consumed. A landed file that a round consumed and that is gone is
+// reported here and nowhere else: the stream checks see only what exists,
+// and a stream whose one file is gone has nothing left to check.
+//
+// digests may be passed by a caller that has read the landed files already;
+// nil means read them, for the session the first round names.
+func Chain(z *storage.Zone, conversation string, digests map[uint64]string) (*ChainReport, error) {
+	chain := sessionflow.OpenChain(z.Root(), conversation)
+	list, err := chain.List()
+	if err != nil {
+		return nil, err
+	}
+	rep := &ChainReport{Conversation: conversation, Session: conversation}
+	var prevDigest, prevInput string
+	var prevThrough, prevRound uint64
+	for _, rf := range list {
+		rr := &RoundReport{Round: rf.Round, Path: rf.Path}
+		rep.Rounds = append(rep.Rounds, rr)
+		r, err := chain.Open(rf.Path)
+		if err != nil {
+			rr.OpenError = err.Error()
+			rr.Problems = append(rr.Problems, fmt.Sprintf("round %d: %v", rf.Round, err))
+			rep.Problems += len(rr.Problems)
+			continue
+		}
+		h := r.Header
+		rr.Header, rr.Digest = h, r.Commit.Digest
+		if h.Session != "" {
+			rep.Session = h.Session
+		}
+		if digests == nil {
+			digests, err = LandedDigests(z, rep.Session)
+			if err != nil {
+				return nil, err
+			}
+		}
+		if h.Round != prevRound+1 {
+			// A missing round: this one cannot link to what is not there,
+			// and nothing after it folds.
+			rr.MissingRound = prevRound + 1
+			rr.Problems = append(rr.Problems, fmt.Sprintf("round %d is missing before round %d", prevRound+1, h.Round))
+		} else if h.Previous != prevDigest {
+			rr.BrokenLink = true
+			rr.Problems = append(rr.Problems, fmt.Sprintf("round %d names previous %s, the round before is %s", h.Round, firstN(h.Previous, 12), firstN(prevDigest, 12)))
+		}
+		if h.FromSeq != prevThrough+1 {
+			rr.SeqGap = true
+			rr.Problems = append(rr.Problems, fmt.Sprintf("round %d starts at seq %d, the round before ended at %d", h.Round, h.FromSeq, prevThrough))
+		}
+		var added []string
+		for seq := h.FromSeq; seq <= h.ThroughSeq; seq++ {
+			d, have := digests[seq]
+			if !have {
+				rr.Missing = append(rr.Missing, seq)
+				rr.Problems = append(rr.Problems, fmt.Sprintf("round %d: landed file seq %d is missing", h.Round, seq))
+				continue
+			}
+			added = append(added, d)
+		}
+		if len(rr.Problems) == 0 && sessionflow.ChainInputDigest(prevInput, added) != h.InputDigest {
+			rr.DigestMismatch = true
+			rr.Problems = append(rr.Problems, fmt.Sprintf("round %d: the input digest does not match the landed files", h.Round))
+		}
+		rep.Problems += len(rr.Problems)
+		prevDigest, prevInput, prevThrough, prevRound = r.Commit.Digest, h.InputDigest, h.ThroughSeq, h.Round
+	}
+	return rep, nil
+}
+
+func firstN(s string, n int) string {
+	if len(s) <= n {
+		return s
+	}
+	return s[:n]
+}
+
+// Base is the file name of a path, for a report line.
+func Base(path string) string { return filepath.Base(path) }
diff --git a/internal/view/conversationview.go b/internal/view/conversationview.go
index 26dccdc..342f614 100644
--- a/internal/view/conversationview.go
+++ b/internal/view/conversationview.go
@@ -21,7 +21,6 @@ import (
 	"crypto/sha256"
 	"encoding/hex"
 	"encoding/json"
-	"fmt"
 	"net/http"
 	"os"
 	"path/filepath"
@@ -30,6 +29,7 @@ import (
 	"time"
 
 	"github.com/apache/skywalking-ai-sessionizer/internal/storage"
+	"github.com/apache/skywalking-ai-sessionizer/internal/verify"
 	"github.com/apache/skywalking-ai-sessionizer/pkg/model"
 	"github.com/apache/skywalking-ai-sessionizer/pkg/sessiondata"
 	"github.com/apache/skywalking-ai-sessionizer/pkg/sessionflow"
@@ -194,85 +194,51 @@ func (c *Conversation) sessions() []string {
 	return out
 }
 
-// rounds lists the chain from each round's header and file, and checks it:
-// the digest of each round, its link to the round before, and its input
-// digest over the landed files it names, computed as the parser computed
-// it. What fails is reported as content, never as an error, so a reader
-// still gets whatever folds.
+// rounds lists the chain from each round's header and file, and checks it
+// the way asz verify does: the digest of each round, its link to the round
+// before, and its input digest over the landed files it names, computed as
+// the parser computed it. What fails is reported as content, never as an
+// error, so a reader still gets whatever folds.
 func (c *Conversation) rounds(digests map[uint64]string) (rounds []sessionview.Round, files []sessionview.File, problems []string, state string) {
 	problems = []string{}
 	state = sessionview.StateVerified
-	chain := sessionflow.OpenChain(c.zone.Root(), c.ID)
-	list, err := chain.List()
+	rep, err := verify.Chain(c.zone, c.ID, digests)
 	if err != nil {
 		return nil, nil, append(problems, err.Error()), sessionview.StateIncomplete
 	}
-	var prevDigest, prevInput string
-	var prevThrough, prevRound uint64
-	for _, rf := range list {
-		r, err := chain.Open(rf.Path)
-		if err != nil {
-			problems = append(problems, fmt.Sprintf("round %d: %v", rf.Round, err))
+	for _, rr := range rep.Rounds {
+		problems = append(problems, rr.Problems...)
+		if rr.OpenError != "" {
 			state = sessionview.StateMismatch
 			continue
 		}
-		h := r.Header
-		ok := true
-		if h.Round != prevRound+1 {
-			// A missing round: this one cannot link to what is not there,
-			// and nothing after it folds.
-			problems = append(problems, fmt.Sprintf("round %d is missing before round %d", prevRound+1, h.Round))
-			ok = false
-			if state == sessionview.StateVerified {
-				state = sessionview.StateIncomplete
-			}
-		} else if h.Previous != prevDigest {
-			problems = append(problems, fmt.Sprintf("round %d names previous %s, the round before is %s", h.Round, firstN(h.Previous, 12), firstN(prevDigest, 12)))
-			ok, state = false, sessionview.StateMismatch
-		}
-		if h.FromSeq != prevThrough+1 {
-			problems = append(problems, fmt.Sprintf("round %d starts at seq %d, the round before ended at %d", h.Round, h.FromSeq, prevThrough))
-			ok = false
-			if state == sessionview.StateVerified {
-				state = sessionview.StateIncomplete
-			}
-		}
-		var added []string
-		for seq := h.FromSeq; seq <= h.ThroughSeq; seq++ {
-			d, have := digests[seq]
-			if !have {
-				problems = append(problems, fmt.Sprintf("round %d: landed file seq %d is missing", h.Round, seq))
-				ok = false
-				if state == sessionview.StateVerified {
-					state = sessionview.StateIncomplete
-				}
-				continue
-			}
-			added = append(added, d)
-		}
-		if ok && sessionflow.ChainInputDigest(prevInput, added) != h.InputDigest {
-			problems = append(problems, fmt.Sprintf("round %d: the input digest does not match the landed files", h.Round))
-			ok, state = false, sessionview.StateMismatch
+		// Changed evidence is a mismatch; evidence that is gone leaves the
+		// document incomplete, and a mismatch is never downgraded.
+		switch {
+		case rr.Damaged():
+			state = sessionview.StateMismatch
+		case !rr.OK() && state == sessionview.StateVerified:
+			state = sessionview.StateIncomplete
 		}
-		data, _ := os.ReadFile(rf.Path)
+		h := rr.Header
+		data, _ := os.ReadFile(rr.Path)
 		var previous *string
 		if h.Previous != "" {
 			p := h.Previous
 			previous = &p
 		}
 		rounds = append(rounds, sessionview.Round{
-			Round: h.Round, Digest: r.Commit.Digest, Previous: previous,
+			Round: h.Round, Digest: rr.Digest, Previous: previous,
 			FromSeq: h.FromSeq, ThroughSeq: h.ThroughSeq, InputDigest: h.InputDigest,
 			FromTime: millisPtr(h.FromTime), ThroughTime: millisPtr(h.ThroughTime),
-			Verified: ok,
+			Verified: rr.OK(),
 		})
 		round := h.Round
 		files = append(files, sessionview.File{
-			File: c.relPath(rf.Path), Format: "sf", Kind: "round", Round: &round,
+			File: c.relPath(rr.Path), Format: "sf", Kind: "round", Round: &round,
 			Lines: countByte(data, '\n'), Bytes: int64(len(data)),
 			Digest: digestOf(data), FromTime: millisPtr(h.FromTime), ThroughTime: millisPtr(h.ThroughTime),
 		})
-		prevDigest, prevInput, prevThrough, prevRound = r.Commit.Digest, h.InputDigest, h.ThroughSeq, h.Round
 	}
 	return rounds, files, problems, state
 }
@@ -360,13 +326,6 @@ func countByte(b []byte, x byte) int {
 	return n
 }
 
-func firstN(s string, n int) string {
-	if len(s) <= n {
-		return s
-	}
-	return s[:n]
-}
-
 // millisOf renders a record time a round header carries as unix
 // milliseconds, or 0 when it carries none.
 func millisOf(s string) int64 {
diff --git a/tests/scenarios/lost-file.expect.yaml b/tests/scenarios/lost-file.expect.yaml
new file mode 100644
index 0000000..9630f05
--- /dev/null
+++ b/tests/scenarios/lost-file.expect.yaml
@@ -0,0 +1,51 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+# The helper's transcript is deleted after round 1 bound to it. The
+# structure is unchanged, since it lives in the round: the helper's talk,
+# its output and the relations that start and end its stream are all still
+# there. The document says incomplete and names round 1 and the sequence,
+# asz verify reports the same one problem, and the session goes on: round 2
+# is a whole delta over the files that exist, and the count of problems
+# stays one.
+checkpoints:
+  helped:
+    rounds: 1
+    kinds: {talk: 2, llm.call: 3, stream: 2, agent.output: 1}
+    talks_on: {main: 1, helper: 1}
+    relations: {starts: 1, reports: 1, ends_with: 1}
+    lose: [{stream: helper, kind: transcript}]
+    view: {state: incomplete, problems: 1, talks: 2, files: 3, rounds: 1}
+    verify: {problems: 1}
+  final:
+    rounds: 2
+    written: true
+    delta: true
+    kinds: {talk: 3, llm.call: 4, stream: 2, agent.output: 1}
+    talks_on: {main: 2, helper: 1}
+    relations: {starts: 1, reports: 1, ends_with: 1}
+    unresolved: {open: 0, resolved: 0}
+    view: {state: incomplete, problems: 1, talks: 3, files: 5, rounds: 2}
+    verify: {problems: 1}
+properties:
+  repack_keeps_structure: false   # a re-cut root holds only what is on disk
+  every_line_a_record: false      # the lost file's source lines have no landed record
+  bundle: false                   # re-deriving from the landed files changes the fold
+push:
+  kinds: [transcript, agent_meta, round]
diff --git a/tests/scenarios/lost-file.yaml b/tests/scenarios/lost-file.yaml
new file mode 100644
index 0000000..0110fe4
--- /dev/null
+++ b/tests/scenarios/lost-file.yaml
@@ -0,0 +1,34 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+# A landed file deleted from the storage root after a round bound to it.
+# The structure survives, since it lives in the rounds; the file's text is
+# gone; and everything that reads the root says so. The session goes on
+# afterwards, and the later rounds are whole. The expectation file names
+# the file to lose and what asz verify and the document must report.
+title: a landed file lost
+steps:
+  - input: read the configuration
+  - call: {text: Reading it., tool: {name: Read, input: {path: asz.yaml}, result: "storage:\n  root: ./data"}}
+  - call:
+      text: Asking the helper.
+      agent: {name: helper, prompt: read the docs, notify: true, steps: [{call: {text: The docs say 11800.}}]}
+    checkpoint: helped
+  - input: thanks
+  - call: {text: You are welcome.}
diff --git a/tools/collectorcheck/main.go b/tools/collectorcheck/main.go
index 46d6f63..515d4bb 100644
--- a/tools/collectorcheck/main.go
+++ b/tools/collectorcheck/main.go
@@ -40,7 +40,6 @@ import (
 	"github.com/apache/skywalking-ai-sessionizer/internal/storage"
 	"github.com/apache/skywalking-ai-sessionizer/internal/verify"
 	"github.com/apache/skywalking-ai-sessionizer/pkg/model"
-	"github.com/apache/skywalking-ai-sessionizer/pkg/sessionflow"
 )
 
 // The shape the Collector's file exporter writes: one JSON line per
@@ -236,9 +235,13 @@ func run(root, logs string) error {
 		if !rep.OK() {
 			return fmt.Errorf("%s rebuilt from the Collector has %d problem(s): %v", s, rep.Problems, rep.Details())
 		}
-		if _, err := sessionflow.OpenChain(twin, s).Verify(); err != nil {
+		chain, err := verify.Chain(storage.NewZone(twin), s, nil)
+		if err != nil {
 			return fmt.Errorf("%s: the chain rebuilt from the Collector: %w", s, err)
 		}
+		if !chain.OK() {
+			return fmt.Errorf("%s: the chain rebuilt from the Collector has %d problem(s): %v", s, chain.Problems, chain.Details())
+		}
 		a, err := parse.View(root, s)
 		if err != nil {
 			return err