freshness

package
v0.22.0 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2026 License: Apache-2.0 Imports: 9 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 freshness owns the one judgment "how far behind is this mirror", shared by every surface that answers from it.

It was born in package main (cmd/gadak warnIfStale, GDK-599): the CLI read verbs printed the verdict on stderr, and that was the only copy — so the MCP server, whose hosts cannot see stderr at all, had no way to know the answer it was serving was hours old. The judgment (SQL, thresholds, precedence) lives here exactly once; the sentence each surface prints from the Report is that surface's own, because stderr advice ("run `gadak sync --if-stale 1h`") and an in-result notice ("call gadak_status") correctly differ.

Index

Constants

View Source
const StaleAfter = time.Hour

StaleAfter is when a mirror stops being worth trusting silently. It is a warning, never a refusal: an old answer with a warning beats no answer.

Variables

This section is empty.

Functions

func FormatSourceID

func FormatSourceID(id string) string

FormatSourceID makes a source_id safe to interpolate into one line. Control runes become a space; a width-aware clip collapses remaining whitespace and truncates (runewidth is this repo's width authority — a rune-counted cut renders twice as wide on CJK).

Types

type Querier

type Querier interface {
	QueryRow(query string, args ...any) *sql.Row
}

Querier is the narrow read handle both callers already hold: the CLI read verbs pass whatever connection they opened (writable or read-only), and the MCP server passes its store or a read-only open. Deliberately not *sql.DB or *store.DB — every caller has some handle, and a second open here doubled any diagnostic the open path prints (GDK-314).

type Report

type Report struct {
	State State

	// SourceID: StateFirstSync (the source currently syncing),
	// StateSyncFailed (the source whose sync failed), StateStaleSource
	// (the oldest source). Raw, unsanitized — FormatSourceID makes it safe
	// to interpolate.
	SourceID string

	// LastError: StateSyncFailed — sync_state.last_error as stored.
	LastError string

	// SyncedAt: StateStaleSource — the raw stored sources.synced_at string,
	// echoed verbatim so `gadak status` can corroborate the same string
	// (GDK-810).
	SyncedAt string

	// Age: StateStaleSource — now minus the parsed SyncedAt.
	Age time.Duration

	// Fetched, Total, WikiPending: StateFirstSync — the live sync_progress
	// heartbeat. Total.Valid is false when the origin gave no count; the
	// sentence must omit the denominator rather than invent one.
	Fetched     int
	Total       sql.NullInt64
	WikiPending bool
}

Report is the mirror's freshness in one value. Only the fields the State documents are set; the others stay zero, so a Report can be compared in tests and logged without a sentence getting in the way.

func Assess

func Assess(q Querier, now time.Time, confluenceConfigured func() bool) Report

Assess reads the mirror through q and returns its freshness judgment. now is the comparison clock (callers pass time.Now(); tests pin it). confluenceConfigured is lazy on purpose: it is consulted only while a first sync is live on the issues source, so a fresh or stale mirror never pays a config read — the CLI calls this on every read verb.

Precedence (the same order warnIfStale has always printed): a live first sync stands everything else down; then a failed sync; then the oldest source's age. Read errors are StateFresh/silence for the same reason the CLI's warnings are best-effort.

func (Report) Notice

func (r Report) Notice() string

Notice is the one-line notice the MCP read tools append to a successful result: the fact first, then the next move for an agent with no shell. StateFresh is the empty string — the notice exists only when it has something true to say, because a line that is always there is a line agents stop reading.

type State

type State int

State is the kind of answer the freshness judgment returned. The names are the vocabulary every surface speaks; `gadak status` corroborates the same facts through its own reads (watermark, last_error, per-source synced_at).

const (
	// StateFresh means no notice: the mirror finished a sync, it did not
	// fail, and the oldest source is inside StaleAfter. A freshness read
	// error also lands here — silence, never a failed read (a mirror too
	// old to have the table must not break the verbs; doctor owns the
	// detailed verdict).
	StateFresh State = iota
	// StateFirstSync: a first full sync is running right now, so every
	// answer from this mirror is partial by design. It outranks everything
	// else — a live first sync explains the mirror's state better than any
	// staleness verdict can (every source row is empty or half-written).
	StateFirstSync
	// StateNeverSynced: no sync_state rows at all, or none of them ever
	// stored a parseable synced_at. The mirror may hold data (a half-done
	// first pass) or none; either way "fresh" would be a lie.
	StateNeverSynced
	// StateSyncFailed: the most recent sync of some source ended in an
	// error. Carries SourceID and LastError.
	StateSyncFailed
	// StateStaleSource: the oldest successfully-synced source is older than
	// StaleAfter. Carries SourceID, SyncedAt (the raw stored string) and
	// Age. One stale source does not indict the whole mirror — it is named
	// (GDK-810: "mirror last synced" made a stale confluence row look like
	// the whole mirror was that old).
	StateStaleSource
)

func (State) String

func (s State) String() string

String names the state for test failures and future telemetry.

Jump to

Keyboard shortcuts

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