Merge pull request #878 from samcharles93/feat/attempt-attribution
Feat/attempt attribution
This commit is contained in:
commit
2385e81066
104 files changed
+9593
-324
No files matched your search
@@ -162,6 +162,7 @@ existing structure combines different owners.
|
||||
| listen/relay addresses | email config | Email adapter instance settings. |
|
||||
| webhook target | `Notify` | Notification adapter instance settings. |
|
||||
| web listen address | `Web` | Web transport settings. |
|
||||
| `listen` under `[services.state]` and `[services.gateway]` | `ServiceConnection` | The bind address of the process that owns the service. Read only by that process, and defaulted to the address its clients dial so the pair cannot drift. |
|
||||
| index directory and database path | `Indexing` | Index infrastructure settings, derived from storage settings unless explicitly overridden. |
|
||||
| forge, dispatch, models, providers, containers, memory, tools, indexing and repositories | `IdentityConfig` | Existing composite duplicates unrelated settings. Replace it with associations from an `IdentityID` to independently owned configured instances. |
|
||||
| owner, name, base, gate, protection, ecosystem, preflight, storage, retry and concurrency | `Repo` | Split across work intake, workspace, workflow execution, policy, gate, and scheduling as described in Repository settings. |
|
||||
|
||||
@@ -529,3 +529,19 @@ config DTO translation will land, so it unblocks the dissolution above.
|
||||
per area when the decisions are already dictated by
|
||||
`dependencies-and-contracts.md`. That is the ceremony pattern this project
|
||||
deliberately avoids.
|
||||
|
||||
## OPEN — `[chat.*]` config section naming
|
||||
|
||||
`configuration.md:160` already states the position: `ChatConfig` holds "separate
|
||||
channel instance settings... there is no chat-wide settings owner". The config
|
||||
section name has not followed, so a settings block named for a product surface
|
||||
owns what the architecture calls channel state.
|
||||
|
||||
Two candidates, neither settled: `[channel.*]` and `[messaging.channel.*]`. The
|
||||
second reads as a domain path, and no config section in this repo is currently
|
||||
named after a domain package, so adopting it sets a precedent for every other
|
||||
section rather than fixing one name.
|
||||
|
||||
Blocked on a maintainer decision, not on evidence. This is a rename with an
|
||||
operator-visible TOML break, so it should land with the `internal/config`
|
||||
dissolution recorded above rather than on its own.
|
||||
@@ -1,7 +1,8 @@
|
||||
# Task Observability
|
||||
|
||||
**Status:** Implemented
|
||||
**Date:** 2026-08-09
|
||||
**Status:** Implemented. The per-run detail surface was added on 2026-09-18 and
|
||||
is described below.
|
||||
**Date:** 2026-08-09 (revised 2026-09-18)
|
||||
|
||||
## Historical problem
|
||||
|
||||
@@ -135,6 +136,183 @@ lifecycle rather than accumulating independently.
|
||||
Telegram or the webui chat — this is the surface that actually matters
|
||||
for the deployment model in `CLAUDE.md`, where an operator may not be
|
||||
looking at a dashboard at all.
|
||||
- The per-attempt read surface described in the next section, on top of the
|
||||
same task-scoped stream.
|
||||
|
||||
## Per-run task detail (attempts, stages, changes, config)
|
||||
|
||||
**Status:** landed, together with the change set that carries this revision
|
||||
(workflow run `76f8e877`). The provenance half is in the tree: `events.Event.Attempt`,
|
||||
the `changes_captured` and `config_captured` event kinds, and the two protobuf field
|
||||
additions. So is the read half: the three per-attempt endpoints
|
||||
(`/api/tasks/{id}/attempts`, `/changes`, `/debug`) and the dashboard run-detail page
|
||||
that consumes them. The decision record, the rejected alternatives and the honest
|
||||
limits are `docs/prds/task-run-detail.md`.
|
||||
|
||||
The task log surface above answers *why did this park?*. This surface answers
|
||||
*what did this run actually do?*, per attempt.
|
||||
|
||||
### Attempt attribution
|
||||
|
||||
One task can run many times, and the task's event stream is the durable record
|
||||
of all of them. `events.Event.Attempt` attributes each event to one run; `0`
|
||||
means **not attributable** — every event written before this change, plus the
|
||||
deliberately task-agnostic producers. An unattributed event is reported as a
|
||||
count and is never presented as an attempt.
|
||||
|
||||
Attribution is a column, not a fold over `task_queued`/`task_retried`: a fold
|
||||
would have to guess which side of a boundary an event belongs to across a daemon
|
||||
restart, a stale-run recovery, or two interleaved attempts, and a guess rendered
|
||||
as structure is exactly the false fidelity this surface exists to avoid.
|
||||
|
||||
The column reaches an existing database through the presence-gated arm in
|
||||
`internal/store`'s `migrateTasks` — `eventsSchema` is `CREATE TABLE IF NOT
|
||||
EXISTS`, so on an existing database the migrator is the *only* thing that adds
|
||||
it. `PRAGMA user_version` is unchanged because the loop is presence-gated
|
||||
rather than version-gated, and nothing is backfilled.
|
||||
|
||||
### Read surface
|
||||
|
||||
The routes are registered beside the existing task routes in
|
||||
`internal/webui`'s `registerTaskRoutes` and all resolve the task through the
|
||||
store's `TaskByID`; a task that does not exist is a `404`, never a `200` with an
|
||||
empty body.
|
||||
|
||||
- `GET /api/tasks/{id}/attempts` — every attempt with its stages inline, so the
|
||||
rail and the attempt selector can never disagree. Stages are ordered by
|
||||
occurrence within their attempt. An attempt with no stages is legitimate and
|
||||
renders as "no stages recorded", never as an unexplained empty rail.
|
||||
- `GET /api/tasks/{id}/changes?attempt=N` — the change captures for one
|
||||
attempt, ordered by capture time; more than one per attempt is normal (a
|
||||
mid-workflow commit such as TDD's `commit-repro`, then `commit-push`, then a
|
||||
final `open-pr` capture that carries the pull-request number).
|
||||
`found: false` means no capture was recorded for that attempt, which is
|
||||
**not** "no files changed"; a capture that was recorded but could not be read
|
||||
is reported as exactly that, and never as a diffstat of zeroes.
|
||||
- `GET /api/tasks/{id}` — unchanged: the raw event array, each event now
|
||||
carrying `attempt`. The per-attempt configuration is read from this response,
|
||||
selected by kind **and** attempt.
|
||||
- `GET /api/tasks/{id}/logs` — gains `stage` beside its existing filters. The
|
||||
match is exact and case-insensitive, and an entry that records no stage never
|
||||
matches (see `logging.Query.Stage`).
|
||||
- `GET /api/tasks/{id}/debug?attempt=N` — the stored task record and the task's
|
||||
events, deliberately unfiltered, so an operator can attribute everything the
|
||||
task did even when a panel has nothing to show.
|
||||
|
||||
The `attempt` parameter follows one rule on every route: absent or `0` selects
|
||||
the task's current attempt, and the resolved attempt is echoed in the response.
|
||||
|
||||
### Stage status
|
||||
|
||||
`stage_start` and `stage_finish` are the only inputs, so the derivation is
|
||||
explicit and each case is pinned by a test:
|
||||
|
||||
| Events seen for the stage | Reported |
|
||||
| --- | --- |
|
||||
| `stage_finish` with `data.error` | `failed`, with the error text |
|
||||
| `stage_finish` with `data.interrupted` | `interrupted` |
|
||||
| `stage_finish`, neither | `ok` — "returned without error" |
|
||||
| `stage_start` unmatched, and this is the task's current in-flight attempt | `running` |
|
||||
| `stage_start` unmatched on any dead attempt | `interrupted` — the run ended without finishing it |
|
||||
| `stage_finish` with no matching start | the stage, with no start time invented |
|
||||
| no stage information at all for that attempt | `unknown` |
|
||||
|
||||
**There is no exit code.** `stage_finish` carries a duration and an optional
|
||||
error string and nothing else, so no stage can be shown as pass/fail and the
|
||||
page must not imply verification. A stage that finished cleanly and then parked
|
||||
stays `ok` on a failed task, which is why the attempt status is read together
|
||||
with the task status rather than on its own.
|
||||
|
||||
### Changed files
|
||||
|
||||
The change an attempt produced is read from the worktree at the moment it is
|
||||
committed or pushed, and persisted as a `changes_captured` durable event — plus
|
||||
one final capture when `OpenPR` records the pull-request number, which is the
|
||||
only point at which a capture can carry one. It has to be captured there: the
|
||||
worktree is deleted on merge, close and no-PR terminal states, a retry resets
|
||||
the branch onto its base, and no forge contract exposes a changed-file read.
|
||||
`internal/domain/workflow/task/changes.go` owns the value types and the status
|
||||
strings they persist.
|
||||
|
||||
- One capture carries per-file `added`/`modified`/`deleted`/`renamed`/
|
||||
`typechange` status with added and deleted line counts, and totals.
|
||||
- Each capture names its schema (`archie/task-changes@1`, in `internal/events`)
|
||||
and a reader refuses a payload whose schema or key set it does not know,
|
||||
rather than rendering the zero value of every field it could not find. That
|
||||
refusal surfaces as "a capture was recorded but could not be read", which is
|
||||
a different statement from "no capture was recorded".
|
||||
- `base_sha` is the merge base the file list was diffed against, not the base
|
||||
branch's tip, so the pair describes one change set even when the base branch
|
||||
moved during the run.
|
||||
- `files` is capped; `totals` always covers the **full** set, and a truncated
|
||||
capture says so rather than silently dropping entries.
|
||||
- `binary` means "no textual hunks" — never a claim about the file's type on
|
||||
disk — and a path the repository recorded as a rename pair is reported as the
|
||||
repository recorded it.
|
||||
- Capture **degrades and never parks**: an implementation without the capture
|
||||
seam captures nothing, logs, and lets the run continue.
|
||||
|
||||
### Per-attempt configuration
|
||||
|
||||
The effective configuration an attempt ran under is persisted as a once-per-
|
||||
attempt `config_captured` durable event carrying the schema constant
|
||||
`archie/task-config@1` and the non-secret task-runtime subset from
|
||||
`config.Config.ForTask()`. It is not stored in a table and has no endpoint of
|
||||
its own: the dashboard reads it out of the events response it already fetches.
|
||||
The single-row `config_snapshot` table is left alone — it answers what the
|
||||
running configuration is now and is replaced on every publish.
|
||||
|
||||
Redaction is proven positively by a test that builds a full configuration
|
||||
containing canary values and asserts none of them survive serialising, rather
|
||||
than being inferred from the producer's contract. The timeline carries one
|
||||
human line for this kind; the document itself is rendered by the panel.
|
||||
|
||||
**Trust boundary, stated honestly.** A task-scoped grant may insert events on
|
||||
its own task ID — that is how `tool_call` and `agent_finish` already work — so a
|
||||
task could in principle write its own `config_captured` event. This widens no
|
||||
capability, because the grant could already insert arbitrary events on itself,
|
||||
but it does mean this provenance is exactly as trustworthy as the rest of that
|
||||
task's event stream, and no more. It is not tamper-proofing and must never be
|
||||
described as such.
|
||||
|
||||
### The wire
|
||||
|
||||
The whole wire change is two fields on existing messages: `Event.attempt`
|
||||
(field 11) and `ReadTaskLogRequest.stage` (field 9) in
|
||||
`proto/state/v1/state.proto`. No RPC, no table and no configuration field was
|
||||
added, so the ratified state-store contract in
|
||||
`docs/prds/state-store-contract.md` rev 2c is unchanged.
|
||||
|
||||
Version skew degrades instead of failing, and each degrade is a statement the
|
||||
page has to make rather than hide: an old server makes `attempt` read as `0` and
|
||||
`stage` match nothing, so the page says it cannot attribute events to attempts
|
||||
instead of labelling the whole stream "attempt 1"; an old client sees
|
||||
`config_captured` as an unfamiliar kind, and the panel must then say it cannot
|
||||
read per-run configuration — a different claim from "not captured for this
|
||||
attempt".
|
||||
|
||||
### Rules the surface keeps
|
||||
|
||||
- "No record" and "this deployment cannot read this" stay different answers,
|
||||
for logs and for configuration alike.
|
||||
- No run-duration figure is shown. A run can spend days in `waiting_human`, so
|
||||
one number would understate wall time; per-stage durations only.
|
||||
- No duration is invented for a stage with no start; it reads "not recorded".
|
||||
- The stage filter is a narrowing, not a coverage claim: agent and tool output
|
||||
carries no stage and is never matched, and the pane says so beside the
|
||||
control.
|
||||
- An attempt predating the change shows "not captured for this run" for its
|
||||
configuration and its change capture, never an empty view that implies
|
||||
defaults applied or nothing changed.
|
||||
|
||||
### Failure and rollback
|
||||
|
||||
Every part is additive. A capture or a configuration emit that cannot happen
|
||||
leaves the run alone — reporting must never park a task. Reverting the change
|
||||
set removes the endpoints and the page; the extra column and the extra event
|
||||
kinds are inert to the previous revision (SQLite ignores a column no statement
|
||||
names, and an unfamiliar event kind already renders as unfamiliar), and there is
|
||||
no data transformation to undo.
|
||||
|
||||
## Dependency direction
|
||||
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
# Service registry — one declaration per service
|
||||
|
||||
**Status:** Design, pre-implementation. Supersedes `state-store-contract.md` §10's
|
||||
`State ServiceConnection` struct-field instruction (revised to rev. 2d in the same change).
|
||||
|
||||
**Base:** the `listen` field, `internal/app/archied/listen.go`, and the listen defaults cited
|
||||
below exist on `feat/attempt-attribution`, not on `main`. This design therefore lands on top of
|
||||
that branch: `RegisterService`'s `listen` argument has nothing to carry without it.
|
||||
|
||||
## Problem
|
||||
|
||||
A service is already one Go type, `config.ServiceConnection`. What is duplicated is its
|
||||
**name**, in three layers:
|
||||
|
||||
| Layer | Location | What is hard-coded |
|
||||
|---|---|---|
|
||||
| Declaration | `internal/config/services.go:4-14` | `Gateway` and `State` as struct fields |
|
||||
| Defaulting | `internal/infrastructure/configuration/defaults.go:74-82` | three `if cfg.Services.X.Y == ""` branches |
|
||||
| Consumption | `internal/app/archied/{bootstrap.go,state_store.go,gateway.go}`, `internal/app/archieui/config.go:80-81` | `cfg.Services.State` / `cfg.Services.Gateway` field access |
|
||||
|
||||
Adding a service means editing all three. The drift this permits is already visible:
|
||||
`stateStoreResolvedToken` (`state_store_client.go:17-23`) and `gatewayResolvedToken`
|
||||
(`chat_service.go:20-26`) are byte-identical apart from the env var name, and
|
||||
`gateway.Target` is defaulted while `state.Target` is a startup error, with nothing
|
||||
stating that asymmetry in one place.
|
||||
|
||||
`resolveServiceListen(service, flagValue, configured)` (`listen.go:24-34`) is already
|
||||
name-parameterised. It is the shape the rest should follow.
|
||||
|
||||
## Decision
|
||||
|
||||
**Key services by name, and carry per-service asymmetry as registration data.**
|
||||
|
||||
### 1. Declaration collapses to a map
|
||||
|
||||
```go
|
||||
// internal/config/services.go
|
||||
type Services map[string]ServiceConnection
|
||||
```
|
||||
|
||||
`ServiceConnection` is unchanged. The TOML shape is unchanged, so no deployment profile,
|
||||
`config.example.toml`, or `install.sh` edit is required. An unrecognised `[services.foo]`
|
||||
decodes without a code edit, satisfying criterion 5.
|
||||
|
||||
### 2. Registration is the single entry point
|
||||
|
||||
```go
|
||||
// internal/config/servicespec.go
|
||||
func RegisterService(context, name, target, listen, tokenEnv string)
|
||||
```
|
||||
|
||||
registered once per service, at package init in `internal/config`:
|
||||
|
||||
```go
|
||||
RegisterService("both", "gateway", "127.0.0.1:8585", "127.0.0.1:8585", "GATEWAY_TOKEN")
|
||||
RegisterService("client", "state", "", "127.0.0.1:9090", "STATE_STORE_TOKEN")
|
||||
```
|
||||
|
||||
Positional, five strings, as the story specifies. Each argument is data the current code
|
||||
states in prose or in a branch:
|
||||
|
||||
- `context` is `client`, `server`, or `both`, and decides which fields must resolve
|
||||
non-empty. `RegisterService` enforces it: an unknown context, or a hosted service with
|
||||
no default `listen`, panics at registration. Registrations come from this repository's
|
||||
own `init()`, never from operator input, so an invalid one is a programming error with
|
||||
no caller positioned to handle an error return. A documented-but-unread `Context` would
|
||||
be worse than no field at all.
|
||||
- `target` is the **default**, and an empty default means the operator must supply one.
|
||||
That single convention replaces the `state.target` required / `gateway.target` defaulted
|
||||
asymmetry with no branch: `state` registers `""`, `gateway` registers an address.
|
||||
- `listen` is the default listen address, feeding the existing
|
||||
flag → `[services.<name>].listen` → default precedence unchanged.
|
||||
- `tokenEnv` names the fallback env var, replacing the two copied resolvers with one.
|
||||
|
||||
### 3. Defaulting and consumption become loops and lookups
|
||||
|
||||
`applyDefaults` iterates the registry instead of naming services. Consumers read
|
||||
`cfg.Services.Get("state")`, returning a `ServiceConnection` plus the spec, so
|
||||
`stateStoreResolvedToken` and `gatewayResolvedToken` collapse into
|
||||
`Services.ResolvedToken(name, secrets)`.
|
||||
|
||||
## Criteria satisfied
|
||||
|
||||
1. Declared once, in the `RegisterService` call.
|
||||
2. No second location can contradict it; the map has no per-service fields to disagree with.
|
||||
3. Registration is the entry point, with the five fields a service has.
|
||||
4. A new service is one `RegisterService` line: no field, no default branch, no consumer edit.
|
||||
5. The set of services is registry data, not a struct definition.
|
||||
|
||||
## Scope and risk
|
||||
|
||||
- `state-store-contract.md` §10 must be revised in the same change, or the tree contradicts
|
||||
its own ratified authority. Its summary (`:7`) already says `[services.<name>]`.
|
||||
- A typo'd `[services.gatway]` is **reported today** (`UnknownKeys = [services.gatway,
|
||||
services.gatway.target]`), because the struct form leaves it in `toml.MetaData.Undecoded()`.
|
||||
A map decodes any section, so preserving that is a requirement, not an optional extra:
|
||||
`unregisteredServiceKeys` asks the registry which names exist. This costs nothing in
|
||||
extensibility, because the answer comes from registration data rather than a fixed list.
|
||||
(An earlier draft of this document claimed the typo was silently ignored either way. It
|
||||
was not; the behaviour was measured.)
|
||||
- Existing tests reference `cfg.Services.State` directly (`state_store_client_test.go:82`,
|
||||
`setup_test.go:278`, and others). They move to `Get`, mechanically.
|
||||
- No wire contract, no RPC, and no persisted format is touched. The 42-RPC State Store
|
||||
contract is unaffected.
|
||||
|
||||
## Acceptance
|
||||
|
||||
- Adding a third service is a one-line diff plus its consumer, proven by a test that
|
||||
registers a throwaway service and asserts its defaults and token fallback resolve.
|
||||
- `grep -rn 'Services\.\(State\|Gateway\)' --include='*.go'` returns nothing.
|
||||
- The existing `services_test.go` default and precedence assertions pass unchanged in
|
||||
behaviour, rewritten only to the new accessor.
|
||||
@@ -1,6 +1,9 @@
|
||||
# State Store — contract boundary & transport (ratification)
|
||||
|
||||
**Status:** Ratified (rev. 2c). Rev. 1 was marked *conditionally ratified*; the three
|
||||
**Status:** Ratified (rev. 2d). Rev. 2d revises §10 only: the `State ServiceConnection`
|
||||
struct-field instruction is withdrawn in favour of name-keyed services
|
||||
(`docs/prds/service-registry.md`). The contract, its 42 RPCs, and the listener topology are
|
||||
unchanged. Rev. 1 was marked *conditionally ratified*; the three
|
||||
reviewer conditions it raised are resolved (rev. 2), and the two third-pass findings are
|
||||
resolved here: (a) the stale Q3 migration wording in `service-decomposition.md`
|
||||
(`store.WorkflowStore`, `mode = "inproc" | "remote"`) now matches the ratified ownership split
|
||||
@@ -535,16 +538,17 @@ an explicit operator decision.
|
||||
|
||||
**Follow the gateway's presence-based `target` seam, not the NATS `mode` enum.**
|
||||
|
||||
- `internal/config/services.go` gains a `State ServiceConnection` field:
|
||||
- **Revised (rev. 2d).** This section previously instructed that
|
||||
`internal/config/services.go` gain a `State ServiceConnection` *struct field*. That
|
||||
instruction is withdrawn: naming each service as a field is the duplication
|
||||
`docs/prds/service-registry.md` removes, and this document's own summary (`:7`) already
|
||||
describes the seam as `[services.<name>]`. Services are keyed by name:
|
||||
```go
|
||||
type Services struct {
|
||||
Gateway ServiceConnection `toml:"gateway" yaml:"gateway"`
|
||||
State ServiceConnection `toml:"state" yaml:"state"`
|
||||
}
|
||||
type ServiceConnection struct {
|
||||
Target string `toml:"target" yaml:"target"`
|
||||
}
|
||||
type Services map[string]ServiceConnection
|
||||
```
|
||||
registered once via `RegisterService(context, name, target, listen, tokenEnv)`. The TOML
|
||||
shape below is unchanged, so nothing else in this section is affected; read
|
||||
`cfg.Services.Get("state")` wherever it says `cfg.Services.State`.
|
||||
- **Empty `Target` → local** `*store.Store` adapter (the default; State Store not yet
|
||||
extracted). **Set `Target` → dial gRPC** and use `*staterpc.Client`. This differs from the
|
||||
gateway, where `Target` is always defaulted to `127.0.0.1:8585` because the gateway is already
|
||||
|
||||
@@ -0,0 +1,291 @@
|
||||
# Per-run task detail: attempts, stages, changes, config, debug
|
||||
|
||||
**Status:** Settled design, landing with this change set (workflow run
|
||||
`76f8e877`). The persistence foundation is already in the tree
|
||||
(`events.attempt`, the two new event kinds, the two proto fields); the read
|
||||
endpoints and the page land with it. The surface contract itself is
|
||||
`docs/architecture/observability.md`.
|
||||
**Date:** 2026-09-18
|
||||
**Compounds with:** `docs/prds/task-logs-pagination.md` (a bounded read says
|
||||
what it does not show), `docs/prds/status-health-surface.md` (no surface that
|
||||
answers something already answered elsewhere).
|
||||
|
||||
## Decision
|
||||
|
||||
A task gets one detail page that answers "what did this run actually do?" per
|
||||
**attempt**: an ordered stage rail, the change each commit/push produced, the
|
||||
effective configuration the attempt ran under, the attempt's log, and the raw
|
||||
record behind all of it.
|
||||
|
||||
The single organising idea is **attempt attribution**. Today the dashboard
|
||||
renders a task's whole event stream as one flat timeline, so a retried task
|
||||
reads as one long run with two of everything. Every new panel is scoped to one
|
||||
attempt and says which one.
|
||||
|
||||
The second organising idea is **provenance, not re-derivation**. What a run
|
||||
produced is captured at the producer, while the evidence exists, and persisted
|
||||
durably. Nothing in this surface tries to reconstruct a past run from state
|
||||
that has since moved on.
|
||||
|
||||
## The requirement set
|
||||
|
||||
| # | Requirement | Mechanism |
|
||||
| --- | --- | --- |
|
||||
| R1 | Per-attempt stage rail: stages with name, start, duration, terminal status and error, ordered within one attempt | `GET /api/tasks/{id}/attempts` reads the task's events and groups them by `attempt` |
|
||||
| R2 | Events carry an attempt, migrated safely and carried on the wire | `events.attempt` column + presence-gated migrator arm; `Event.attempt = 11` |
|
||||
| R3 | Changed files captured at commit/push, persisted per task, exposed, shown with repo/PR links | `changes_captured` durable event written by the commit/push steps; `GET /api/tasks/{id}/changes` |
|
||||
| R4 | The effective configuration an attempt ran under, secrets redacted, shown | `config_captured` durable event written once per attempt; read from the events response the page already holds |
|
||||
| R5 | Log pane filters by attempt, stage and level; absence stays distinct from an unreadable deployment | `logging.Query.Stage` + `ReadTaskLogRequest.stage = 9`; the pane keeps `disabled` and `found=false` apart |
|
||||
| R6 | Retry is reachable from the run view and produces a new attempt shown as a new run | Existing retry action, labelled as a NEW run whose confirm states the previous attempt's commits are discarded |
|
||||
| R7 | Raw JSON of the task record and its events for the selected attempt | `GET /api/tasks/{id}/debug` |
|
||||
| R8 | Deep-linkable, reload-safe per-task detail page that keeps existing URLs working | `#/tasks/{id}` route beside the existing `#/tasks?task=N` and `#/tasks?status=...` |
|
||||
| R9 | Design polish: hierarchy, tokens, both themes, responsive rail, a11y, loading/empty/error states | UI lane; measured at 480px and 700px in both themes |
|
||||
| R10 | Documentation of record | This document plus `docs/architecture/observability.md` |
|
||||
| R11 | Red-first tests for every new behaviour, full gate, `task ui`, forced `go build ./...`, `go test -race` on touched packages | Per lane; the anti-cost-cutting requirement lives here |
|
||||
|
||||
## Attempt attribution: a column, not a guess
|
||||
|
||||
`events.Event.Attempt`, persisted by `internal/store` as the `events.attempt`
|
||||
column (`internal/store/events.go`, `eventsSchema`), is a real column,
|
||||
`NOT NULL DEFAULT 0`. It was chosen over segmenting the stream on `task_queued` /
|
||||
`task_retried` because a fold would have to guess which side of a boundary an
|
||||
event belongs to when the daemon restarts mid-attempt, when `RecoverStale`
|
||||
requeues, or when two attempts interleave across a crash. A guess rendered as
|
||||
structure is exactly the false fidelity this surface exists to avoid; a column
|
||||
is durable, queryable and ordered by construction.
|
||||
|
||||
**`0` means "not attributable".** It is every row written before this change
|
||||
plus the deliberately task-agnostic producers. It is not an attempt number and
|
||||
is never rendered as one. The attempts endpoint reports the count of
|
||||
unattributed events so the page can say so instead of presenting old history as
|
||||
attempt 1.
|
||||
|
||||
## Migration against an existing `archie.db`
|
||||
|
||||
The store's migrator (`migrateTasks` in `internal/store/store.go`) already reads
|
||||
`PRAGMA table_info` through `tableColumns` and applies a presence-gated
|
||||
`ALTER TABLE ... ADD COLUMN` list. This change adds an `events` arm: a
|
||||
`tableColumns(ctx, tx, "events")` read beside the other two, and the entry
|
||||
`ALTER TABLE events ADD COLUMN attempt INTEGER NOT NULL DEFAULT 0`.
|
||||
|
||||
Three consequences a future maintainer must not get wrong:
|
||||
|
||||
- `eventsSchema` is `CREATE TABLE IF NOT EXISTS` (`internal/store/events.go`),
|
||||
so on an existing database it is a **no-op**. The migrator arm is the only
|
||||
thing that adds the column there. This is why the red test builds a raw
|
||||
SQLite file with the pre-change `events` DDL and must fail before the arm
|
||||
exists: every temp-database test passes either way.
|
||||
- **`user_version` stays 3.** The loop is presence-gated, not version-gated;
|
||||
bumping it would force an edit to the test that exists to prove a newer
|
||||
schema is refused.
|
||||
- **No backfill, ever.** Existing rows keep `attempt = 0`. Inferring an attempt
|
||||
number for them would be fabrication.
|
||||
|
||||
## Changed files: captured at the producer
|
||||
|
||||
The measurement is taken inside the shared step library immediately after a
|
||||
successful commit and after a successful push (`StageCommit` and
|
||||
`StageCommitPush` in `internal/domain/workflow/steps.go`) — the one place
|
||||
where the worktree, the branch, the base, the task and the store are all in
|
||||
scope, and the only place that knows a push actually happened.
|
||||
|
||||
Both alternatives were rejected on evidence, not taste:
|
||||
|
||||
- **Reading the diff on demand** is impossible. The worktree is deleted on
|
||||
merge, close and no-PR terminal states (`internal/worktree.(*Manager).Cleanup`,
|
||||
called from the daemon's terminal paths) and a retry resets the branch onto
|
||||
its base (`internal/worktree.(*Manager).refresh` → `resetOnto`). There is
|
||||
nothing left to read.
|
||||
- **Reading it from the forge** is impossible today. The forge contract exposes
|
||||
no changed-file capability, and adding one would cost three implementations
|
||||
plus an RPC and would still fail for chat-sourced tasks with no PR.
|
||||
|
||||
Binding consequences:
|
||||
|
||||
- Capture **degrades, never parks**. A `Trees` implementation without the
|
||||
capture seam captures nothing, logs, and lets the run continue. A reporting
|
||||
failure must never fail a task.
|
||||
- The value types live in `internal/domain/workflow/task` (`changes.go`), not in
|
||||
package `workflow` and not in `internal/worktree`. Package `workflow` has no
|
||||
import of `internal/worktree`, and this subpackage is not projected into the
|
||||
interpreted-stage symbol table, so declaring the types here widens nothing and
|
||||
needs no symbol-table regeneration. The capture method stays off that surface
|
||||
entirely.
|
||||
- `files` is capped at 200 entries because an event's `data` is not
|
||||
length-limited by the store. `totals` always covers the **full** set and
|
||||
`truncated: true` says when entries were dropped.
|
||||
- `binary` means "no textual hunks", not "a binary file". Rename pairing is
|
||||
go-git behaviour the lane pins with a test; where the repository records a
|
||||
rename as add + delete, the surface reports what was recorded.
|
||||
|
||||
## Per-run configuration: a durable event, not a table
|
||||
|
||||
**Decision.** The effective configuration an attempt ran under is persisted as a
|
||||
`config_captured` durable event (`internal/events.KindConfigCaptured`), on the
|
||||
same attempt key R2 adds — not in a table, and not behind new RPCs.
|
||||
|
||||
**Why.** Three reasons, in order of weight:
|
||||
|
||||
1. Events are already this system's durable per-attempt provenance stream, and
|
||||
they demonstrably carry aggregation (`StageStats`, `TokensByDay` both
|
||||
aggregate over persisted events). R3 puts its diffstat there in this same
|
||||
change. A table plus two RPCs would have given one feature **two provenance
|
||||
mechanisms for one purpose**.
|
||||
2. It adds no RPC, so the ratified state-store surface is untouched and nothing
|
||||
in `docs/prds/state-store-contract.md` (rev 2c) changes.
|
||||
3. The page already fetches the task's events to build the rail (R1) and to read
|
||||
the diffstat (R3), so the document arrives in a fetch it already makes. There
|
||||
is nothing to join.
|
||||
|
||||
The single-row `config_snapshot` table is deliberately **left alone**. It
|
||||
answers "what is the running configuration now", is replaced on every publish,
|
||||
and is pinned to one row by a test. It could not answer "what did attempt 2 run
|
||||
under" in any case.
|
||||
|
||||
**Payload.** The result of `config.Config.ForTask()` — the non-secret
|
||||
task-runtime subset — plus the schema constant `archie/task-config@1`. Not the
|
||||
dashboard's configuration view: that is a larger projection carrying the full
|
||||
schema catalog, and it is the wrong object for this. Stored shape and the tab's
|
||||
read rule are in `docs/architecture/observability.md`.
|
||||
|
||||
**Binding conditions.** It is emitted through the durable path, never the
|
||||
lossy bus; it is written once per attempt, not once per stage; redaction is
|
||||
proven **positively** by a canary-secrets test rather than assumed from the
|
||||
producer's contract; the timeline gains one human line for it rather than
|
||||
dumping a JSON blob; and an attempt with no such event renders "not captured for
|
||||
this run", never an empty table implying defaults applied.
|
||||
|
||||
**Documented residual — the honest trust claim.** A task-scoped grant may insert
|
||||
events on its own task ID; that is how `tool_call` and `agent_finish` already
|
||||
work, so a task can in principle write its own `config_captured` event. This
|
||||
**widens no capability** — the grant could already insert arbitrary events on
|
||||
itself — but it does mean this provenance is exactly as trustworthy as the rest
|
||||
of that task's event stream, and no more. It is not tamper-proofing and must
|
||||
never be described as such.
|
||||
|
||||
## No new RPC and no new table
|
||||
|
||||
The entire wire change is two fields on existing messages:
|
||||
|
||||
```proto
|
||||
// proto/state/v1/state.proto
|
||||
message Event { int64 attempt = 11; }
|
||||
message ReadTaskLogRequest { string stage = 9; }
|
||||
```
|
||||
|
||||
No RPC was added, no store table was added, and no new configuration field was
|
||||
introduced. `docs/prds/state-store-contract.md` is unchanged because no ratified
|
||||
contract changed; the JSON document rides an existing `data` column over an
|
||||
existing RPC.
|
||||
|
||||
Both fields are tolerant in both directions, and the degrade is stated rather
|
||||
than hidden: an old server makes `attempt` read as `0` and `stage` match
|
||||
nothing, so the page must say the deployment cannot attribute events to attempts
|
||||
rather than show one run labelled "attempt 1". An old client shows
|
||||
`config_captured` as an unknown kind, and the Config tab must then say "this
|
||||
deployment cannot read per-run configuration" — a different claim from "not
|
||||
captured for this attempt".
|
||||
|
||||
## Retry is a new run
|
||||
|
||||
The retry action is reachable from the run view and produces a new attempt that
|
||||
appears as a new run. It is a **fresh** run: it resets the branch onto
|
||||
`origin/<base>` (`internal/worktree.(*Manager).refresh` → `resetOnto`) and
|
||||
**discards the previous attempt's commits**. Labelling it "restart" would imply
|
||||
resumption that does not happen, so the control and its confirm copy say so.
|
||||
|
||||
## Honest limits the surface carries
|
||||
|
||||
These are the claims that would otherwise be overstated. Each is a copy or
|
||||
rendering rule, not a caveat in a comment:
|
||||
|
||||
- **There is no exit code, so no stage shows pass/fail.** `stage_finish` carries
|
||||
a duration and an optional error string and nothing else. A stage `ok` means
|
||||
"returned without error", not "the work was correct". The agent's own verdict
|
||||
is shown separately from the rail. A stage that parks after finishing cleanly
|
||||
leaves that stage `ok` on a failed task, so attempt status is read together
|
||||
with task status.
|
||||
- **The log stage filter only matches lines the workflow bound a stage to.**
|
||||
Agent and tool output carries no stage and never matches. The pane states that
|
||||
coverage limit next to the control rather than presenting a filtered view as
|
||||
the whole story.
|
||||
- **Absence and unreadability are different answers.** A deployment that cannot
|
||||
read task logs says so; an attempt whose log does not exist says that. They
|
||||
are never collapsed, in either direction, for logs or for configuration.
|
||||
- **An empty changed-files view never means "nothing changed".** No capture
|
||||
exists for runs predating this change and the forge cannot supply one, so the
|
||||
empty state reads "not captured for this run".
|
||||
- **No run-duration figure is shown.** Per-stage durations only: a run can spend
|
||||
days in `waiting_human`, and one number would understate wall time.
|
||||
- **No duration is invented** for a stage with no `stage_start`; it reads "not
|
||||
recorded".
|
||||
- **Unattributed history is never presented as an attempt.** Events with
|
||||
`attempt = 0` are reported as a count, not guessed into a run.
|
||||
- **The configuration shown is the attempt's non-secret task-runtime subset** —
|
||||
bot identity, models, limits, budgets, dispatch, diff cap, notifications,
|
||||
forge host, tool policy. It is not the full dashboard configuration and must
|
||||
never imply it contains providers, repositories, identities or credentials.
|
||||
|
||||
## Route and compatibility
|
||||
|
||||
`#/tasks/{id}` is the detail route; it is deep-linkable and reload-safe.
|
||||
`#/tasks?task=N` and `#/tasks?status=...` keep working and keep their existing
|
||||
behaviour, including the nav highlight. The debug view is why the raw view
|
||||
exists at all: the task list response is capped, so a client-side join has no
|
||||
row for an older task, and a debug view that silently hid events would be worse
|
||||
than useless.
|
||||
|
||||
## What this deliberately does not do
|
||||
|
||||
- **No new RPC, table, store interface or configuration field.** Nothing here
|
||||
needed one, and each would have widened a ratified surface.
|
||||
- **No exit status, no pass/fail gate badge, no "steps" in the CI sense.** The
|
||||
reference layout is a CI pipeline; archie's stages are agent runs and the page
|
||||
must not borrow CI's claims.
|
||||
- **No backfill** of attempts, change captures or configurations onto runs that
|
||||
predate the change.
|
||||
- **No client-side join for configuration.** It arrives in the events response
|
||||
the page already fetches; there is nothing to join.
|
||||
- **No change to `docs/prds/state-store-contract.md`.** No ratified contract
|
||||
moved.
|
||||
|
||||
## Files this change touches
|
||||
|
||||
- `internal/store/`: the `events.attempt` column, its migrator arm, and the
|
||||
schema-presence test.
|
||||
- `internal/events/`: `Event.Attempt`, `KindChangesCaptured`,
|
||||
`KindConfigCaptured`, `ConfigCapturedSchema`.
|
||||
- `internal/domain/workflow/task/changes.go`: the change value types.
|
||||
- `internal/worktree/` + `internal/app/agentworker/`: the capture primitive and
|
||||
its production forwarding.
|
||||
- `internal/domain/workflow/steps.go`: the capture at commit and push.
|
||||
- `internal/daemon/`: the per-attempt configuration emit at dispatch.
|
||||
- `internal/logging/`: `Query.Stage`.
|
||||
- `internal/webui/`: the three read endpoints and the `stage` log parameter.
|
||||
- `proto/state/v1/state.proto` + generated stubs: the two field additions.
|
||||
- `ui/src/`: the detail page, the tab primitive, the rail, and the panel copy.
|
||||
- `docs/`: this document and `docs/architecture/observability.md`.
|
||||
|
||||
## Acceptance
|
||||
|
||||
1. Two attempts of one task render as two runs, and attempt 1's rail excludes
|
||||
attempt 2's stages.
|
||||
2. A task with no stages renders "no stages recorded", never an unexplained
|
||||
empty rail.
|
||||
3. A pre-change `archie.db` gains the `attempt` column with `user_version`
|
||||
still 3, and its old events are reported as unattributed.
|
||||
4. An attempt with a capture shows per-file added/deleted counts, status, repo
|
||||
and PR links; an attempt without one says so and never says "no changes".
|
||||
5. The Config tab shows the attempt's document for the selected attempt only,
|
||||
with no secret value present in the serialized document.
|
||||
6. Retry from the run view produces a new attempt shown as a new run, with copy
|
||||
stating the previous attempt's commits are discarded.
|
||||
7. The log stage filter narrows to stage-bound lines and the pane states the
|
||||
coverage limit; `disabled` and `found=false` remain distinguishable.
|
||||
8. `#/tasks/{id}` survives reload, and `#/tasks?task=N` / `#/tasks?status=...`
|
||||
are unchanged.
|
||||
9. The debug view returns the task record and its unfiltered events, each
|
||||
carrying `attempt`.
|
||||
10. Run the gate and the dashboard build: `task check` passes clean, `task ui`
|
||||
has been run so `ui/dist` matches the sources, and every touched package
|
||||
builds and passes under `-race`.
|
||||
Reference in new issue
Block a user