store

package
v0.192.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 23, 2026 License: MIT Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package store persists per-job log artifacts under a single result directory (<result_dir>/<job_id>/): the live stdout/stderr logs streamed by the local runner. Job metadata, the index and interactions now live in the SQLite store (internal/jobstore); from SP5 the request is persisted to the jobs.request_json column too, so the store no longer writes request.json/result.json/jobs.jsonl/ interactions.jsonl. See design §7 / §10 / §14.

Directory layout for one job:

<result_dir>/<job_id>/
  stdout.log          // child process stdout, streamed by the local runner
  stderr.log          // child process stderr, streamed by the local runner

Index

Constants

View Source
const (
	StdoutFile = "stdout.log"
	StderrFile = "stderr.log"
	// StdoutRawFile is the DEBUGGING sidecar written only when an ndjson agent sets
	// ndjson_raw: the unfiltered line stream that stdout.log was compacted from
	// (bd h-aii-rpky). It is never read by gofer — nothing in the read paths knows
	// it — and it is as large as the raw stream, so it is off by default.
	StdoutRawFile = "stdout.raw.log"
	// PtyTranscriptFile is an interactive pty job's de-ANSI'd text transcript
	// (PTY-01): its pty output never reaches StdoutFile, so this is what
	// `job logs`/the web log page fall back to.
	PtyTranscriptFile = "pty.txt"
)

Artifact file names inside a job result directory. Only the log files remain; metadata/index/request/interactions moved to the SQLite store (jobstore).

Variables

This section is empty.

Functions

func SafeJoinUnder

func SafeJoinUnder(base, name string) (string, error)

SafeJoinUnder joins a request-supplied relative name under base and guarantees the result stays inside base (design §9 — the artifact download path check):

  • empty / absolute names are rejected outright;
  • the name is anchored to root and Cleaned ("/"+name) so any "../" is folded away before joining (a "../etc" can never climb above base);
  • a Rel check rejects any path that still escapes (defence in depth);
  • EvalSymlinks resolves the real target and re-checks containment, so a symlink inside artifacts/ pointing outside is rejected (symlink escape).

It mirrors the口径 of project.SafeJoin (internal/project/path.go). Moved here from httpapi (was safeJoinUnder) so the path-safety primitive lives with the store layer and is unit-tested independently of the HTTP handler.

Types

type FileStore

type FileStore struct {
	// contains filtered or unexported fields
}

FileStore is a filesystem-backed Store rooted at a base directory. New job artifacts live under <base>/<yyyymmdd>/<job_id>/; legacy flat dirs are still readable through Dir.

func NewFileStore

func NewFileStore(base string) *FileStore

NewFileStore returns a FileStore whose per-job directories are created under base. base is not created here; Ensure creates each job dir on demand.

func (*FileStore) AppendLogWriter

func (s *FileStore) AppendLogWriter(jobID string, stream Stream) (io.WriteCloser, int64, error)

AppendLogWriter opens the stdout/stderr log file for APPEND (creating it when absent) and reports the byte offset the stream already holds. It is the RECOV-01 R4 counterpart of LogWriter: a serve that ADOPTS a job it did not start must continue the log the previous process wrote, not truncate it — and the offset it starts from is exactly what the hub tells the worker to rewind to, so the resumed stream has no gap and no duplicate.

Rotation is the same as LogWriter's, with the counter seeded from the existing size so the cap applies to the WHOLE stream rather than to the adopted tail.

func (*FileStore) Dir

func (s *FileStore) Dir(jobID string) string

Dir returns the absolute result directory for jobID.

func (*FileStore) Ensure

func (s *FileStore) Ensure(jobID string) error

Ensure creates the result directory for jobID. It first MkdirAll's the parent date/base dir, then creates the job dir with os.Mkdir so an existing dir is reported as a collision (ErrExist) — the job service relies on this to retry the id.

func (*FileStore) LogWriter

func (s *FileStore) LogWriter(jobID string, stream Stream) (io.WriteCloser, error)

LogWriter opens the stdout/stderr log file for streaming writes, truncating any previous content. The caller closes the returned writer.

The returned writer is rotation-aware (C4): it tracks bytes written and, once the live file would exceed maxPerJobLogBytes, rotates the current file to "<name>.1" (overwriting any prior .1) and continues from a fresh file at 0. This bounds a single job's on-disk log so a runaway producer cannot grow one file without limit. Normal jobs stay well under the threshold and never rotate.

func (*FileStore) ReadLogHead

func (s *FileStore) ReadLogHead(jobID string, stream Stream, lines int) ([]byte, int, error)

ReadLogHead returns the first lines of a log and its total logical line count.

func (*FileStore) ReadLogLines

func (s *FileStore) ReadLogLines(jobID string, stream Stream, lines, offset int) ([]byte, int, error)

ReadLogLines returns a line window counted from the end of the stream's log file. offset skips that many logical lines from the tail, then lines chooses how many earlier lines to return. When lines <= 0 the whole file is returned. A missing log file yields an empty result and totalLines=0.

func (*FileStore) ReadLogTail

func (s *FileStore) ReadLogTail(jobID string, stream Stream, maxBytes int64) ([]byte, error)

ReadLogTail returns the last maxBytes of the stream's log file. When maxBytes <= 0 the whole file is returned. A missing log file yields an empty result with no error (a job may not have produced output on that stream yet).

type Store

type Store interface {
	// Dir returns the absolute result directory for jobID.
	Dir(jobID string) string
	// Ensure creates the result directory (and parents) for jobID. It returns an
	// error if the directory already exists, so the job service can detect an id
	// collision and retry with a new id.
	Ensure(jobID string) error
	// LogWriter opens (truncating) the stdout/stderr log file for streaming. The
	// caller owns closing the returned writer.
	LogWriter(jobID string, stream Stream) (io.WriteCloser, error)
	// ReadLogTail returns the last maxBytes of a log stream (whole file when
	// maxBytes <= 0). It is the read path used by the HTTP log endpoints (P5).
	ReadLogTail(jobID string, stream Stream, maxBytes int64) ([]byte, error)
	// ReadLogHead returns the first lines and total logical line count.
	ReadLogHead(jobID string, stream Stream, lines int) ([]byte, int, error)
}

Store abstracts per-job log persistence. FileStore is the only implementation; the interface lets the job service and tests depend on behaviour rather than the filesystem layout. Metadata/index/interactions live in internal/jobstore, not here.

type Stream

type Stream string

Stream identifies which log file to open/read.

const (
	StreamStdout Stream = "stdout"
	StreamStderr Stream = "stderr"
	// StreamPty reads the interactive job's de-ANSI'd pty transcript
	// (PtyTranscriptFile). It is NOT an HTTP stream: serveLog selects it when a
	// stdout request targets an interactive job, whose pty output never reaches
	// stdout.log (PTY-01 §四).
	StreamPty Stream = "pty"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL