Archive: a segment damaged before its first event reads as an empty one

オープン
#1,855 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
48/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
go

調査の方向性

Start by tracing how readRecordsWith in core/session/archive/reader.go reports truncation through Page and Earlier in core/session/archive/read.go, then check replay callers in core/session/archive/replay.go and the pre-first-record branch in core/sessionapi/export.go. The issue leaves open whether to propagate the flag or return an error for damage before the first event, so check the compatibility implications for callers outside this repo. Add the garbage-first-bytes test expecting HTTP 500, and update the export comments and docs/session-export.md once the behavior is settled.

索引モデルが issue の本文から書いたものです。

説明

Split out of the #1830 review.

What happens

readRecordsWith (core/session/archive/reader.go) reports a torn tail or an
undecodable line as truncated=true, err=nil — a property of the data, not a
failure. Page then discards that flag (_, err := readSegment(...) in
core/session/archive/read.go:57), so no caller above it can tell a damaged
segment from a complete one.

For the paging endpoints that is the intended, documented behaviour: serve the
readable prefix. But a segment damaged before its first event has no readable
prefix, so it contributes nothing and is indistinguishable from an empty archive:

segment -> 39 bytes of non-zstd garbage   GET /v1/export  200 application/x-ndjson ""
segment -> symlink loop (ELOOP)           GET /v1/export  500 {"error":"archive read failed"}

Only a segment that cannot be opened produces an error today. GET /v1/export
(#1830) documents this as the tolerated case, and docs/session-export.md says an
export is not a way to detect a corrupt archive — but "nothing happened this month"
and "this month will not decode" really are different answers, and a backup/export
consumer is exactly who wants to tell them apart.

What to do

Hand truncated up from Page/Earlier, or distinguish "torn before the first
event in a non-empty file" from "torn tail" and return that as an error. Then
handleExport's pre-first-record branch catches it and answers 500, and the
claims in core/sessionapi/export.go and docs/session-export.md can be
strengthened back.

This is an archive-package change with paging and replay as callers, which is why
it is not in #1830. core/ is consumed outside this repo, so a signature change
needs the usual care.

Scope

  • core/session/archive/{reader,read,replay}.go
  • core/sessionapi/export.go comments + docs/session-export.md once it lands
  • a test with a segment whose first bytes are garbage, asserting 500 rather than an empty 200

Refs #1810, #1830

Assisted-By: Claude (Anthropic AI) [email protected]

主要言語
Go
スター
31
フォーク
49
平均マージ
9時間 43分
マージ済み PR(30日)
367

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

rossoctl/cortex のほかの issue

rossoctl/cortex の issue をすべて見る

似ている issue

Go の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。