Skip to content

[P1][Business Hub] Fix terminal completion, child-contract invalidation, and authoritative rollup freshness #484

Description

@richard-devbot

Parent: #476

Outcome

The Business Hub shows authoritative harness truth within a bounded delay, including terminal completion and background-worker writes. Cached rollups cannot remain active/stalled after the run is DONE.

Audit finding

The UI has polling/WebSocket mechanisms, but cache invalidation and terminal semantics are incomplete:

  • The run signature covers selected top-level files/directories, but omits changing child contracts such as builder, validation, prompt, and stage artifact files.
  • Once a run is cached as unchanged, terminal runs may not be reparsed unless a scoped request forces it.
  • In-memory “events behind” repair is only attached in a narrow path, while the rollup index can preattach a pipeline rollup and bypass that fallback.
  • The status path can stamp the manifest as DONE without persisting a reliable completed_at.
  • Run-status derivation can ignore or underweight manifest terminal state, so a completed run becomes active and later stalled.
  • Harness persistence/invalidation is coupled to successful tool-return paths. A background worker or direct control-plane write can complete a stage without emitting the same UI invalidation signal.

The dashboard is therefore not purely hallucinating from mission records, but it can display stale derived truth instead of current authoritative harness state.

Required design

Single authoritative change signal

Every committed harness transition must atomically increment a monotonically increasing state_generation and emit an outbox event. The dashboard signature should depend on that generation/event cursor rather than guessing which child files might have changed.

Terminal-state correctness

  • Persist completed_at atomically with status: DONE.
  • Derive terminal status directly from authoritative manifest/state-machine truth.
  • Never apply generic staleness classification to a terminal run.
  • Surface corruption or partial state as an explicit degraded/error state, not cached success.

Reactive delivery

  • Publish committed transition events to all Business Hub instances.
  • Retain bounded polling as reconciliation, not as the primary source of truth.
  • Invalidate per-run and aggregate caches on the same transaction/outbox event.
  • Reconcile event cursor against state generation after reconnect/restart.

Acceptance criteria

  • Every committed transition changes the dashboard-observed generation.
  • Builder/validator/stage artifact completion by a background worker refreshes the UI without a user click.
  • DONE and completed_at are persisted in the same commit.
  • A completed run remains completed indefinitely and never degrades to stalled.
  • Aggregate and scoped run views converge to the same generation and status.
  • WebSocket reconnect catches up from the last event cursor.
  • Polling detects a missed event within the configured reconciliation interval.
  • Partial/corrupt control-plane state is rendered as degraded/error with diagnostics.
  • No mission-record heuristic can override a newer harness generation.

Required integration tests

  • Complete a stage through the normal API path.
  • Complete a stage through a background worker with no browser request.
  • Modify a child validation contract and verify generation-driven refresh.
  • Complete all 15 stages; verify terminal state before and after cache TTL/restart.
  • Drop a WebSocket event, reconnect, and reconcile.
  • Run two dashboard instances with independent caches.
  • Inject malformed state and verify fail-visible behavior.

Likely implementation surface

  • Business Hub rollup cache/signature
  • server polling/WebSocket broadcaster
  • harness state commit/outbox
  • run status derivation and terminal timestamps
  • pipeline-state/rollup adapters

Dependencies

Use the transactional transition/outbox foundation from #481.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingbusiness-hubBusiness Hub dashboard/UXdata-durabilityRun data integrity, locking, schema, retentionpriority-p1Core end-user journey; next implementation wavetestingTests requiredui-improvementsDashboard UI/UX improvements

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions