Skip to content

Expose workflow node summaries in verbose JSON - #2408

Closed
Wirasm wants to merge 3 commits into
devfrom
archon/task-archon-fix-github-issue-experimental-1785745942552
Closed

Expose workflow node summaries in verbose JSON#2408
Wirasm wants to merge 3 commits into
devfrom
archon/task-archon-fix-github-issue-experimental-1785745942552

Conversation

@Wirasm

@Wirasm Wirasm commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Problem: verbose JSON from workflow status and workflow get exposed raw lifecycle events, forcing API consumers to recreate the CLI's node-state fold.
  • Why it matters: consumers need a compact, ordered node view, including start times for nodes still running.
  • What changed: verbose JSON now returns shared nodes summaries by default; --events preserves access to raw event rows; CLI docs and parity coverage define the contract.
  • What did not change (scope boundary): no workflow engine, database schema, API, or web-console behavior changed. Existing text verbose output continues to use the same reducer.

UX Journey

Before

CLI JSON consumer             Archon CLI                 Workflow events
───────────────               ──────────                 ───────────────
workflow status/get --json ─▶ fetches raw rows ────────▶ returns lifecycle events
recreates node states ◀────── prints `events`

After

CLI JSON consumer             Archon CLI                 Workflow events
───────────────               ──────────                 ───────────────
workflow status/get --json ─▶ [shared node fold] ─────▶ reads ordered lifecycle events
uses ordered nodes ◀───────── [prints `nodes`, including `startedAt`]
workflow status/get --events ▶ [prints raw `events` for debugging]

Architecture Diagram

Before

packages/cli/src/cli.ts ──▶ packages/cli/src/commands/workflow.ts ──▶ @archon/core/db/workflow-events
                                    │
                                    ├── text: build node summaries
                                    └── verbose JSON: raw events

After

packages/cli/src/cli.ts [~] ──▶ packages/cli/src/commands/workflow.ts [~] ──▶ @archon/core/db/workflow-events
                                         │
                                         ├── text: shared buildNodeSummaries [~]
                                         ├── verbose JSON: shared `nodes` [~]
                                         └── --events: raw events escape hatch [~]
packages/cli/src/commands/workflow.test.ts [~] ──▶ workflow command contract
packages/docs-web/src/content/docs/reference/cli.md [~] ──▶ CLI users

Connection inventory (list every module-to-module edge, mark changes):

From To Status Notes
cli.ts commands/workflow.ts modified Parses and forwards --events for status and get.
commands/workflow.ts @archon/core/db/workflow-events unchanged Fetches ordered workflow event rows.
commands/workflow.ts JSON CLI consumers modified Default verbose payload is folded nodes; raw rows require --events.
workflow.test.ts commands/workflow.ts modified Covers parity, ordering, timestamps, truncation, states, and fetch failures.
reference/cli.md CLI users modified Documents the JSON contract and escape hatch.

Label Snapshot

  • Risk: risk: low
  • Size: size: S
  • Scope: cli, docs, tests
  • Module: cli:workflow

Change Metadata

  • Change type: feature
  • Primary scope: cli

Linked Issue

Validation Evidence (required)

Commands and result summary:

bun run validate
  • Evidence provided (test/log/trace/screenshot): implementation artifacts report a passing clean-snapshot bun run validate; CLI package tests, type check, lint, formatting, whitespace check, and manual status/get --verbose --json checks also passed. Manual checks verified default nodes, --events raw rows, node states, and running startedAt.
  • If any command is intentionally skipped, explain why: none. The clean snapshot was used because unrelated live-worktree .archon/ edits made bundled-default validation stale.

Security Impact (required)

  • New permissions/capabilities? (No)
  • New external network calls? (No)
  • Secrets/tokens handling changed? (No)
  • File system access scope changed? (No)
  • If any Yes, describe risk and mitigation: N/A.

Compatibility / Migration

  • Backward compatible? (Yes)
  • Config/env changes? (No)
  • Database migration needed? (No)
  • If yes, exact upgrade steps: N/A.

Human Verification (required)

What was personally validated beyond CI:

  • Verified scenarios: workflow status --verbose --json and workflow get --verbose --json emit ordered node summaries; the same commands with --events emit raw events.
  • Edge cases checked: completed, skipped, and running nodes; running startedAt; summary ordering; output truncation; non-fatal event fetch failures.
  • What was not verified: no production deployment or external integration testing was needed for this CLI-only payload change.

Side Effects / Blast Radius (required)

  • Affected subsystems/workflows: CLI workflow status and get verbose JSON output, CLI help/argument forwarding, command tests, and CLI reference documentation.
  • Potential unintended effects: consumers that implicitly depended on raw events in default verbose JSON must opt in with --events.
  • Guardrails/monitoring for early detection: exact JSON-shape and parity tests cover both default and escape-hatch behavior; raw events remain available for debugging.

Rollback Plan (required)

  • Fast rollback command/path: revert commit a414f7d9 from dev after merge.
  • Feature flags or config toggles (if any): none; --events is an explicit per-invocation compatibility escape hatch.
  • Observable failure symptoms: automated consumers fail to find an expected payload key or receive incorrect node state/timing data.

Risks and Mitigations

  • Risk: changing the default verbose JSON shape can affect consumers expecting events.
    • Mitigation: retain raw event output behind --events, document it, and test both payloads.
  • Risk: lifecycle rows can be incomplete or arrive in unusual order.
    • Mitigation: reuse the established ordered reducer and cover terminal-only, running, ordering, and truncation cases.

Fixes #2359

Summary by CodeRabbit

  • New Features
    • Added the --events option to verbose JSON workflow status and get commands for raw event output.
    • Verbose workflow output now provides per-node summaries, including states, timestamps, durations, errors, and output previews.
  • Bug Fixes
    • Ensured workflow events are returned in a consistent order when timestamps match.
    • Preserved parseable JSON output when event retrieval fails.
  • Documentation
    • Added examples and details for verbose workflow JSON output and raw event retrieval.

Verbose workflow JSON returned raw event streams, forcing consumers to duplicate the CLI's lifecycle fold and leaving running nodes without start timestamps.

Changes:
- Reuse the shared node-summary reducer for verbose JSON output
- Add startedAt metadata and an explicit --events escape hatch
- Document and test ordering, truncation, lifecycle states, and failure behavior

Fixes #2359
@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The CLI adds --events for raw workflow event output. Verbose JSON status/get commands now return node summaries by default, with failure fallbacks. Workflow event queries use deterministic timestamp and ID ordering. Tests and CLI documentation cover the new behavior.

Changes

Workflow verbose output

Layer / File(s) Summary
Deterministic workflow event ordering
packages/core/src/db/workflow-events.ts, packages/core/src/db/workflow-events.test.ts, packages/core/src/db/workflow-events.since.integration.test.ts
Workflow event queries now order by created_at and then id. Tests cover timestamp ties.
Node summary and raw event output
packages/cli/src/commands/workflow.ts, packages/cli/src/commands/workflow.test.ts
Verbose JSON status/get output returns derived node summaries by default. The --events option returns raw event rows. Event retrieval failures produce empty JSON payloads while preserving failure signals. Node summaries retain startedAt values. Detached log cleanup uses a shared helper.
CLI option wiring and documentation
packages/cli/src/cli.ts, packages/docs-web/src/content/docs/reference/cli.md
The CLI recognizes and forwards --events for workflow status/get. The reference documentation describes verbose node summaries and raw event output.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related issues

Possibly related PRs

Suggested labels: area: workflows

Suggested reviewers: coleam00

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR adds node summaries and shared reducer coverage, but it removes default raw events required by issue #2359. Keep events alongside nodes in default verbose JSON output, or update issue #2359 to explicitly approve the breaking behavior change.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the primary change: exposing workflow node summaries in verbose JSON output.
Description check ✅ Passed The description completes the required template sections and provides scope, validation, compatibility, risks, and rollback details.
Out of Scope Changes check ✅ Passed The CLI, documentation, tests, and deterministic event ordering changes support the linked workflow JSON objectives.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing Touches 💡 1
⚔️ Resolve merge conflicts 💡
  • Resolve merge conflict in branch archon/task-archon-fix-github-issue-experimental-1785745942552
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch archon/task-archon-fix-github-issue-experimental-1785745942552

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install failed: dependency version conflict. Check your lock file or package.json.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Wirasm

Wirasm commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator Author

Consolidated Review: PR #2408

Date: 2026-08-03T09:04:30.000Z
Available agent artifacts: code-review
Expected agent artifacts unavailable: error-handling, test-coverage, comment-quality, docs-impact


Executive Summary

The available code-review report finds the CLI change focused, typed, and well aligned across command wiring, tests, raw-event compatibility, and documentation. It identifies one medium-severity contract issue: the newly documented node ordering is not deterministic when multiple lifecycle events share the same timestamp. SQLite records event timestamps at second precision, so this can occur for concurrently started DAG nodes. The other four specialist artifacts required for a complete five-agent synthesis were not present when this report was generated, so their review areas cannot be represented or attributed.

Overall Verdict: REQUEST_CHANGES

Auto-fix Candidates: 0 CRITICAL + HIGH issues
Manual Review Needed: 1 MEDIUM issue


Artifact Availability

Agent Artifact Status Findings
Code Review code-review-findings.md Available 1
Error Handling error-handling-findings.md Unavailable Not assessed
Test Coverage test-coverage-findings.md Unavailable Not assessed
Comment Quality comment-quality-findings.md Unavailable Not assessed
Docs Impact docs-impact-findings.md Unavailable Not assessed

Statistics

Agent CRITICAL HIGH MEDIUM LOW Total
Code Review 0 0 1 0 1
Error Handling Not assessed
Test Coverage Not assessed
Comment Quality Not assessed
Docs Impact Not assessed
Available total 0 0 1 0 1

CRITICAL Issues (Must Fix)

None found in the available artifact.


HIGH Issues (Should Fix)

None found in the available artifact.


MEDIUM Issues (Options for User)

Issue 1: Node summary order is nondeterministic for timestamp ties

Source Agent: code-review
Location: packages/cli/src/commands/workflow.ts:2126
Category: bug

Problem:

Verbose JSON exposes nodes as an ordered integration surface, but the underlying listWorkflowEvents() query orders only by created_at ASC. SQLite records workflow event timestamps at second precision, so simultaneous lifecycle events—especially for parallel DAG nodes—can tie. SQL does not guarantee a relative order for tied values, despite the documentation promising order by first event.

Options:

Option Approach Effort Risk if Skipped
Fix Now Add a stable secondary ordering key and cover tied timestamps. LOW Consumers can receive unstable node arrays for the same run.
Create Issue Defer the ordering-contract fix to a focused PR. LOW The documented API contract remains unreliable until addressed.
Skip Accept nondeterministic order. NONE Breaks stable JSON comparisons and progression assumptions.

Recommendation: Fix now. Add id ASC as a stable secondary key to the shared event query, then test equal created_at values. This is small, cross-dialect, requires no migration, and makes all consumers deterministic.

// packages/core/src/db/workflow-events.ts
const result = await pool.query<WorkflowEventRow>(
  `SELECT * FROM remote_agent_workflow_events
   WHERE workflow_run_id = $1
   ORDER BY created_at ASC, id ASC`,
  [workflowRunId]
);

LOW Issues (For Consideration)

None found in the available artifact.


Positive Observations

  • The JSON path reuses the existing node-state reducer, avoiding divergence from text verbose output.
  • startedAt behavior is covered for running, completed, failed, skipped, and terminal-only states.
  • --events deliberately retains raw lifecycle rows as a debugging and compatibility escape hatch.
  • Event-fetch failure tests preserve parseable empty JSON payloads.

Suggested Follow-up Issues

Issue Title Priority Related Finding
Make workflow event ordering deterministic for timestamp ties P2 MEDIUM issue 1

Next Steps

  1. Add deterministic secondary ordering and a tied-timestamp test.
  2. Produce the missing four specialist artifacts before treating this as a complete comprehensive review.

Metadata

  • Synthesized: 2026-08-03T09:04:30.000Z
  • Artifact: /Users/rasmus/.archon/workspaces/coleam00/Archon/artifacts/runs/557362cf1c9740948e03957b8f9a136c/review/consolidated-review.md

@Wirasm

Wirasm commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator Author

⚡ Self-Fix Report (Aggressive)

Status: COMPLETE
Pushed: ✅ Changes pushed to archon/task-archon-fix-github-issue-experimental-1785745942552
Philosophy: Fix everything unless clearly a new concern


Fixes Applied (1 total)

Severity Count
🔴 CRITICAL 0
🟠 HIGH 0
🟡 MEDIUM 1
🟢 LOW 0
View all fixes
  • Node summary order is nondeterministic for timestamp ties (packages/core/src/db/workflow-events.ts:124) — added id ASC as a stable tie-breaker and covered it with a real SQLite integration test.

Tests Added

  • packages/core/src/db/workflow-events.since.integration.test.ts — equal-timestamp events are ordered by ID.

Skipped (0)

(none — all findings addressed)


Suggested Follow-up Issues

(none)


Validation

✅ Type check | ✅ Lint | ✅ Full workspace test suite


Self-fix by Archon · aggressive mode · fixes pushed to archon/task-archon-fix-github-issue-experimental-1785745942552

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/cli/src/commands/workflow.ts (1)

2001-2050: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Reset summary state on node_started re-entry.

node_started preserves an existing summary’s state when it updates only startedAt, while terminal branches replace the full summary. If the same step_name enters a new run after a prior terminal result, that path reports the old terminal state instead of the current running state. Set the existing summary to running here, and clear/reset derived fields only on terminal completion.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/cli/src/commands/workflow.ts` around lines 2001 - 2050, Update the
node_started branch in the event-summary loop so an existing entry in summaries
is reset to state running when a step re-enters. Clear stale terminal-derived
fields such as durationMs, outputPreview, and error while preserving the new
startedAt; keep terminal branches responsible for populating those fields.
🧹 Nitpick comments (2)
packages/cli/src/commands/workflow.ts (2)

2106-2131: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick win

JSON verbose output cannot distinguish "no events" from "event fetch failed" in either command. Both workflowStatusCommand and workflowGetCommand fall back to an empty nodes/events array on a fetchVerboseEvents failure, with no field signaling the failure to a JSON consumer, even though text mode prints an explicit '(node events unavailable — see logs)' line for the same failure.

  • packages/cli/src/commands/workflow.ts#L2106-L2131: in the workflowStatusCommand JSON branch, add an explicit indicator (for example nodesUnavailable: true) to the per-run object when fetchVerboseEvents reports failed.
  • packages/cli/src/commands/workflow.ts#L2217-L2225: apply the same indicator to the workflowGetCommand JSON branch when eventsFailed is true.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/cli/src/commands/workflow.ts` around lines 2106 - 2131, Update the
JSON verbose branches of workflowStatusCommand
(packages/cli/src/commands/workflow.ts:2106-2131) and workflowGetCommand
(packages/cli/src/commands/workflow.ts:2217-2225) to add an explicit
nodesUnavailable indicator to each per-run result when fetchVerboseEvents
reports failed or eventsFailed is true; preserve the existing empty nodes/events
fallback for successful fetches and genuinely eventless runs.

2106-2110: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick win

Consider signaling event-fetch failure explicitly in JSON output.

When fetchVerboseEvents fails, runEvents falls back to [], and the JSON payload gets an empty nodes (or events) array with no other indication of the failure. Text mode prints ' (node events unavailable — see logs)', but JSON mode has no equivalent field. A JSON consumer cannot tell a genuine empty-events run apart from a fetch failure.

This is documented as an intentional fallback (see the comment above fetchVerboseEvents) and is covered by tests, so it is not a functional defect. Consider adding a small explicit field (for example nodesUnavailable: true) to the per-run object when the fetch failed, so automated consumers do not need to guess.

Also applies to: 2121-2131

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/cli/src/commands/workflow.ts` around lines 2106 - 2110, The JSON
branch of workflowStatusCommand should explicitly indicate when
fetchVerboseEvents fails instead of representing the failure only as an empty
nodes/events array. Track the runEvents fallback outcome and add a per-run
unavailability field such as nodesUnavailable: true only for failed event
fetches, while preserving the existing payload for successful fetches and
genuine empty results.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@packages/cli/src/commands/workflow.ts`:
- Around line 2001-2050: Update the node_started branch in the event-summary
loop so an existing entry in summaries is reset to state running when a step
re-enters. Clear stale terminal-derived fields such as durationMs,
outputPreview, and error while preserving the new startedAt; keep terminal
branches responsible for populating those fields.

---

Nitpick comments:
In `@packages/cli/src/commands/workflow.ts`:
- Around line 2106-2131: Update the JSON verbose branches of
workflowStatusCommand (packages/cli/src/commands/workflow.ts:2106-2131) and
workflowGetCommand (packages/cli/src/commands/workflow.ts:2217-2225) to add an
explicit nodesUnavailable indicator to each per-run result when
fetchVerboseEvents reports failed or eventsFailed is true; preserve the existing
empty nodes/events fallback for successful fetches and genuinely eventless runs.
- Around line 2106-2110: The JSON branch of workflowStatusCommand should
explicitly indicate when fetchVerboseEvents fails instead of representing the
failure only as an empty nodes/events array. Track the runEvents fallback
outcome and add a per-run unavailability field such as nodesUnavailable: true
only for failed event fetches, while preserving the existing payload for
successful fetches and genuine empty results.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 9be5f735-95c3-4c51-825a-6658978ea0dd

📥 Commits

Reviewing files that changed from the base of the PR and between 5c137d1 and 9cebf06.

📒 Files selected for processing (7)
  • packages/cli/src/cli.ts
  • packages/cli/src/commands/workflow.test.ts
  • packages/cli/src/commands/workflow.ts
  • packages/core/src/db/workflow-events.since.integration.test.ts
  • packages/core/src/db/workflow-events.test.ts
  • packages/core/src/db/workflow-events.ts
  • packages/docs-web/src/content/docs/reference/cli.md

@Wirasm

Wirasm commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator Author

Closing in favour of a fresh run against current dev.

This PR implements the #2365 contract correctly — nodes replacing events, the --events escape hatch, startedAt, and first-appearance ordering documented and tested. That part is right and was the proof that #2404's planning fix works.

It cannot merge as-is: #2389 landed in between and both touch packages/cli/src/commands/workflow.ts. The production conflict is resolvable (keep writeJsonLine, take the nodes/events shape), but workflow.test.ts has 130 consoleSpy references against dev's stdoutSpy, and the spy target differs — console.log vs process.stdout.write. That is not a rename, and hand-merging it risks silently reverting #2384's truncation fix.

Re-running #2359 against current dev, which now carries both #2389 and the planning fix, so the same work lands without the conflict.

@Wirasm Wirasm closed this Aug 3, 2026
@Wirasm
Wirasm deleted the archon/task-archon-fix-github-issue-experimental-1785745942552 branch August 3, 2026 10:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(cli): --json --verbose emits raw events while the text path prints a node fold no machine consumer can reach

1 participant