Skip to content

Add workflow discovery diagnostics#1975

Merged
Wirasm merged 4 commits into
devfrom
archon/task-fix-issue-1959
Jun 12, 2026
Merged

Add workflow discovery diagnostics#1975
Wirasm merged 4 commits into
devfrom
archon/task-fix-issue-1959

Conversation

@Wirasm

@Wirasm Wirasm commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator

Summary

Describe this PR in 2-5 bullets:

  • Problem: archon workflow run could be hard to diagnose when workflow discovery found only bundled workflows, and resume/approve/reject re-entry could silently fall back to worktree discovery when a stored codebase lookup failed.
  • Why it matters: project workflow YAMLs can be absent from isolated worktrees, so silent fallback can make workflow run disagree with workflow list and hide the actionable root cause.
  • What changed: fresh runs now print the effective discovery root and source-count breakdown, and codebase-backed resume/approve/reject re-entry now fails loudly if the codebase row cannot be resolved.
  • What did not change (scope boundary): this does not change the /workflow run silently auto-resumes failed runs with stale args, hijacking fresh requests #1549 silent auto-resume behavior being handled separately in PR Gate stale workflow resumes #1935, and it does not alter workflow discovery order or engine semantics.

UX Journey

Before

User                         Archon CLI                         Workflow discovery
────                         ──────────                         ──────────────────
runs workflow ────────────▶  resolves cwd
                             loads workflows ─────────────────▶ root may be implicit
                             continues with sparse diagnostics

resume/approve/reject ────▶  loads run
                             codebase lookup fails or missing
                             logs warning only
                             re-enters run ───────────────────▶ falls back to worktree root
sees confusing missing workflow/error

After

User                         Archon CLI                         Workflow discovery
────                         ──────────                         ──────────────────
runs workflow ────────────▶  resolves cwd
                             [prints discovery root + counts]
                             loads workflows ─────────────────▶ [known effective root]

resume/approve/reject ────▶  loads run
                             codebase lookup fails or missing
                             [throws actionable error]
sees fixable codebase/discovery message instead of degraded discovery

Architecture Diagram

Before

packages/cli/src/commands/workflow.ts
  workflowRunCommand ─────────────▶ discoverWorkflowsWithConfig
  workflowResumeCommand ─────────▶ codebaseDb.getCodebase
          │                         └─ warning on failure, continue
          └───────────────────────▶ workflowRunCommand(discoveryCwd undefined)
  workflowApproveCommand ────────▶ codebaseDb.getCodebase
          │                         └─ warning on failure, continue
          └───────────────────────▶ workflowRunCommand(discoveryCwd undefined)
  workflowRejectCommand ─────────▶ codebaseDb.getCodebase
          │                         └─ warning on failure, continue
          └───────────────────────▶ workflowRunCommand(discoveryCwd undefined)

After

packages/cli/src/commands/workflow.ts [~]
  workflowRunCommand [~] =========▶ discoverWorkflowsWithConfig
          │
          └=======================▶ [logs effective root + bundled/global/project counts]
  workflowResumeCommand [~] =====▶ resolveDiscoveryCwdForCodebase [+]
  workflowApproveCommand [~] ====▶ resolveDiscoveryCwdForCodebase [+]
  workflowRejectCommand [~] =====▶ resolveDiscoveryCwdForCodebase [+]
          │
          └──────────────────────▶ workflowRunCommand(verified discoveryCwd)

packages/cli/src/commands/workflow.test.ts [~]
  tests discovery diagnostics, fail-fast lookup errors, and detached cwd preservation

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

From To Status Notes
workflowRunCommand discoverWorkflowsWithConfig modified Uses the same loader path but now records the effective root before loading and logs source counts after discovery.
workflowRunCommand CLI stdout modified Emits Discovery: root=... workflows=... bundled=... global=... project=... for non-JSON, non-quiet runs.
workflowResumeCommand codebaseDb.getCodebase modified Missing or failed lookup now throws an actionable error instead of warning and continuing.
workflowApproveCommand codebaseDb.getCodebase modified Same fail-fast behavior for approval auto-resume re-entry.
workflowRejectCommand codebaseDb.getCodebase modified Same fail-fast behavior for reject on_reject re-entry.
detached workflow run parent detached child invocation unchanged Existing resolved repo-root --cwd preservation was verified and covered by a stronger test.

Label Snapshot

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

Change Metadata

  • Change type: bug
  • Primary scope: cli

Linked Issue

Validation Evidence (required)

Commands and result summary:

bun install
bun run type-check
bun test packages/cli/src/commands/workflow.test.ts
bun run lint --max-warnings 0
bun run format:check
bun run validate
  • Evidence provided (test/log/trace/screenshot): validation artifact reports bun run validate passed with 5126 passed, 0 failed, 1 skipped; focused workflow CLI test file passed with 130 tests.
  • If any command is intentionally skipped, explain why: no requested validation was skipped.

Security Impact (required)

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

Compatibility / Migration

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

Human Verification (required)

What was personally validated beyond CI:

  • Verified scenarios: discovery diagnostics are emitted for normal non-JSON workflow runs; resume, approve, and reject codebase lookup failure paths throw actionable errors; no-codebase fallback behavior remains covered; detached child invocation preserves the resolved repo-root --cwd.
  • Edge cases checked: codebase lookup returning null; codebase lookup throwing; discovery source breakdown includes bundled/global/project counts; quiet/JSON output remains protected from the new human diagnostic.
  • What was not verified: end-to-end manual execution against a live project with missing untracked workflow YAMLs, because the unit coverage directly targets the failing control-flow paths.

Side Effects / Blast Radius (required)

  • Affected subsystems/workflows: CLI workflow run/re-entry paths and CLI workflow tests.
  • Potential unintended effects: users resuming a run whose stored codebase row is missing now receive a hard error instead of degraded fallback; this is intentional fail-fast behavior.
  • Guardrails/monitoring for early detection: new unit tests cover the fail-fast paths and discovery diagnostic output; users will see the exact discovery root and count breakdown on normal runs.

Rollback Plan (required)

  • Fast rollback command/path: revert commit efc585d6 or revert the two changed files, packages/cli/src/commands/workflow.ts and packages/cli/src/commands/workflow.test.ts.
  • Feature flags or config toggles (if any): none.
  • Observable failure symptoms: unexpected CLI hard errors during resume/approve/reject or unwanted discovery diagnostic output in non-human output modes.

Risks and Mitigations

  • Risk: A codebase-backed run with a transient database lookup failure now stops instead of retrying with worktree discovery.
    • Mitigation: the error message identifies the run and codebase and explains that worktree discovery may be unsafe; retrying after restoring DB/codebase access preserves correctness.
  • Risk: Extra discovery diagnostics could affect consumers that parse human CLI output.
    • Mitigation: the diagnostic is suppressed for JSON and quiet modes, preserving machine-oriented output surfaces.

Summary by CodeRabbit

Release Notes

  • New Features

    • Workflow discovery now displays source-count diagnostics during execution.
  • Bug Fixes

    • Improved error handling and messaging for workflow resume, approve, and reject operations when codebase lookup fails.
    • Diagnostics properly suppressed in --json and --quiet modes.

Workflow re-entry could silently fall back to worktree discovery when a stored codebase lookup failed, making project workflows disappear from resume/approve/reject paths.

Changes:
- Log the effective workflow discovery root and bundled/global/project counts for every non-JSON, non-quiet workflow run
- Fail fast when codebase-backed resume/approve/reject re-entry cannot load the stored codebase
- Add tests for discovery diagnostics, fail-fast lookup handling, and detached child cwd preservation

Fixes #1959
@coderabbitai

coderabbitai Bot commented Jun 12, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: dbfbb5cc-f718-4e5a-80b0-939866a92d18

📥 Commits

Reviewing files that changed from the base of the PR and between 438db9e and 41fc80a.

📒 Files selected for processing (2)
  • packages/cli/src/commands/workflow.test.ts
  • packages/cli/src/commands/workflow.ts

📝 Walkthrough

Walkthrough

This PR adds discovery diagnostic logging to workflow runs showing bundled/global/project source counts, centralizes codebase lookup error handling across resume/approve/reject commands with fail-loudly behavior, and expands test coverage for discovery state and codebase lookup failures.

Changes

Workflow Discovery Diagnostics and Error Handling

Layer / File(s) Summary
Discovery diagnostics infrastructure
packages/cli/src/commands/workflow.ts, packages/cli/src/commands/workflow.test.ts
Import refactoring, new countWorkflowSources helper, and workflowRunCommand updated to use effective discovery CWD with Discovery diagnostic output suppressed in --json and --quiet modes. Tests verify discovery diagnostic content and CWD override behavior.
Codebase lookup centralization
packages/cli/src/commands/workflow.ts
New resolveDiscoveryCwdForCodebase helper centralizes codebase lookup for control-plane commands, throws detailed errors for missing codebases, and logs cli.workflow_${action}_codebase_lookup_failed before rethrowing wrapped errors.
Control-plane command refactoring
packages/cli/src/commands/workflow.ts
Resume, approve, and reject commands refactored to use resolveDiscoveryCwdForCodebase for discovery CWD resolution instead of prior inline warn/continue logic, enabling fail-loudly behavior.
Error handling test coverage
packages/cli/src/commands/workflow.test.ts
New failure and recovery tests for resume/approve/reject verify loud exceptions on codebase lookup failure, appropriate error logging, and no discovery invocation from run working paths.
Detached execution wiring assertions
packages/cli/src/commands/workflow.test.ts
Detached run test refactored to capture Bun.spawn call details and assert both the --cwd argument in spawned argv and corresponding spawnOptions.cwd.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • coleam00/Archon#1743: Introduces the initial discoveryCwd threading mechanism through workflowRunCommand; this PR extends that foundation with discovery diagnostics and centralizes codebase-lookup error handling across control-plane commands.

Poem

🐰 A discovery so fine, with sources counted true,
Bundled, global, project—each gets its due,
When codebases fail, we cry out loud and clear,
No silent warnings here, just errors we revere!

✨ Finishing Touches
📝 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-fix-issue-1959

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 timed out. The project may have too many dependencies for the sandbox.


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 and usage tips.

Wirasm commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator Author

🔍 Comprehensive PR Review

PR: #1975
Reviewed by: 2 available specialized agent artifacts (3 expected artifacts missing)
Date: 2026-06-12T06:34:54Z


Summary

PR #1975 is narrowly scoped and generally aligns with the requested workflow discovery diagnostics and fail-fast codebase lookup behavior. The available review artifacts found no critical or high-severity issues, and the source/test changes are mostly behavior-focused. The main concern is a medium-severity approve/reject recovery path where codebase lookup can fail after a decision has already been persisted, leaving the user with incomplete recovery instructions.

Verdict: REQUEST_CHANGES

Severity Count
🔴 CRITICAL 0
🟠 HIGH 0
🟡 MEDIUM 2
🟢 LOW 1

Note: error-handling-findings.md, comment-quality-findings.md, and docs-impact-findings.md were not present in the review artifact directory, so this synthesis includes the available code-review and test-coverage artifacts only.


🔴 Critical Issues

None.


🟠 High Issues

None.


🟡 Medium Issues (Needs Decision)

Approve/Reject Codebase Lookup Errors Hide That The Decision Was Already Recorded

📍 packages/cli/src/commands/workflow.ts:1626

workflowApproveCommand and the on_reject path in workflowRejectCommand record the approval/rejection before resolving discoveryCwd. If codebase lookup fails after that mutation, the user sees a generic lookup error and is not told the decision was already recorded or that the right recovery path is workflow resume.

Options: Fix now | Create issue | Skip

View details

Recommended fix: move resolveDiscoveryCwdForCodebase(...) inside the existing approve/reject auto-resume try blocks so lookup failures are wrapped by the existing partial-success message:

try {
  const discoveryCwd = result.codebaseId
    ? await resolveDiscoveryCwdForCodebase(runId, result.codebaseId, 'approve')
    : undefined;

  await workflowRunCommand(result.workingPath, result.workflowName, result.userMessage ?? '', {
    resume: true,
    codebaseId: result.codebaseId ?? undefined,
    conversationId: platformConversationId,
    discoveryCwd,
  });
} catch (error) {
  const err = error as Error;
  throw new Error(
    `Approved but failed to resume workflow '${result.workflowName}': ${err.message}\n` +
      `The approval was recorded. Run 'bun run cli workflow resume ${runId}' to retry.`
  );
}

Apply the same shape to the reject on_reject auto-resume path.

Option Approach Effort Risk if Skipped
Fix Now Wrap discovery-CWD lookup in the existing partial-success resume error handling. LOW Users can be told to retry approve/reject after the decision was already persisted.
Create Issue Defer recovery-message cleanup. LOW Current PR ships a confusing state-changing CLI failure mode.
Skip Accept generic codebase lookup error. NONE Users must infer the decision was recorded and manually resume.

Recommendation: Fix now.


Discovery Diagnostic Suppression Is Only Indirectly Covered

📍 packages/cli/src/commands/workflow.ts:418 / packages/cli/src/commands/workflow.test.ts

The new discovery diagnostic is gated by !options.json && !options.quiet, but tests directly assert only the human-mode printed path. Foreground json: true and quiet: true suppression are not explicitly covered.

Options: Fix now | Create issue | Skip

View details

Recommended test:

it.each([
  ['json', { json: true, noWorktree: true }],
  ['quiet', { quiet: true, noWorktree: true }],
])('does not print discovery diagnostic in %s mode', async (_mode, options) => {
  const { discoverWorkflowsWithConfig } = await import('@archon/workflows/workflow-discovery');
  (discoverWorkflowsWithConfig as ReturnType<typeof mock>).mockResolvedValueOnce({
    workflows: [makeTestWorkflowWithSource({ name: 'assist' }, 'project')],
    errors: [],
  });

  try {
    await workflowRunCommand('/repo/root', 'assist', 'hello', options);
  } catch {
    // downstream failure is acceptable; this test only verifies diagnostic suppression
  }

  expect(consoleSpy).not.toHaveBeenCalledWith(expect.stringContaining('Discovery: root='));
});
Option Approach Effort Risk if Skipped
Fix Now Add a table-style suppression test for JSON and quiet modes. LOW Future changes could break JSON consumers or quiet mode without a direct regression test.
Create Issue Defer explicit suppression coverage. LOW Contract remains less visible.
Skip Accept current indirect coverage. NONE Suppression remains partly implicit.

Recommendation: Fix now if touching tests in this PR.


🟢 Low Issues

View 1 low-priority suggestion
Issue Location Suggestion
Codebase lookup failure matrix is not symmetric across re-entry commands packages/cli/src/commands/workflow.ts:1409 / packages/cli/src/commands/workflow.test.ts Add command-level coverage for getCodebase throws during approve and missing codebase row during reject.

✅ What's Good

  • The implementation keeps the discovery diagnostic out of --json and --quiet modes.
  • The source-count helper uses the existing WorkflowSource union, keeping source changes type-visible.
  • The PR preserves workflow engine semantics and discovery order.
  • Tests exercise public CLI command functions and cover effective discovery root, source counts, fail-fast errors, logger event names, and detached child --cwd preservation.
  • The code-review artifact reports focused validation passed: bun test packages/cli/src/commands/workflow.test.ts with 130 passing tests and 0 failures.

📋 Suggested Follow-up Issues

Issue Title Priority Related Finding
Make approve/reject auto-resume codebase lookup failures report recorded decisions P1 Medium issue #1
Add explicit workflow discovery diagnostic suppression tests for JSON and quiet modes P2 Medium issue #2
Complete approve/reject codebase lookup failure parity tests P3 Low issue #1

Next Steps

  1. No CRITICAL or HIGH issues were found in the available artifacts.
  2. Review the MEDIUM issues above and decide whether to fix now, create follow-up issues, or skip.
  3. Investigate the missing expected agent artifacts if full five-agent coverage is required.

Reviewed by Archon comprehensive-pr-review workflow
Artifacts: /Users/rasmus/.archon/workspaces/coleam00/Archon/artifacts/runs/e23bc4b42aa05f8f9a052a471d69cf38/review/

Fixed:\n- Wrap approve/reject codebase discovery failures in recorded-decision recovery errors\n- Add explicit JSON/quiet discovery diagnostic suppression tests\n- Complete approve/reject codebase lookup failure coverage\n\nTests added:\n- workflow CLI suppression and codebase lookup recovery cases\n\nSkipped:\n- none
@Wirasm

Wirasm commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator Author

Fix Report: PR #1975

Date: 2026-06-12T06:40:58Z
Status: COMPLETE
Branch: archon/task-fix-issue-1959
Commit: b03e35d
Philosophy: Aggressive fix - lean towards fixing everything


Summary

All three review findings were addressed. Approve/reject auto-resume now reports recorded decisions when codebase discovery lookup fails after mutation, and the CLI tests now directly cover diagnostic suppression plus the missing approve/reject lookup failure variants. Nothing was skipped or blocked.


Fixes Applied

Severity Finding Location What Was Done
MEDIUM Approve/Reject Codebase Lookup Errors Hide That The Decision Was Already Recorded packages/cli/src/commands/workflow.ts:1626 Moved approve/reject codebase discovery lookup inside the existing auto-resume try blocks so lookup failures are wrapped with the recorded approval/rejection recovery message and resume command.
MEDIUM Discovery Diagnostic Suppression Is Only Indirectly Covered packages/cli/src/commands/workflow.ts:418 / packages/cli/src/commands/workflow.test.ts Added explicit JSON and quiet mode tests asserting the discovery diagnostic is not printed.
LOW Codebase Lookup Failure Matrix Is Not Symmetric Across Re-Entry Commands packages/cli/src/commands/workflow.ts:1409 / packages/cli/src/commands/workflow.test.ts Added approve thrown-lookup coverage and reject missing-codebase coverage, including logger assertions and no worktree-fallback discovery assertions.

Tests Added

File Test Cases
packages/cli/src/commands/workflow.test.ts JSON mode discovery diagnostic suppression; quiet mode discovery diagnostic suppression; approve auto-resume thrown codebase lookup reports recorded approval recovery; reject auto-resume missing codebase reports recorded rejection recovery.

Docs Updated

(none)


Skipped Findings

(none)


Blocked (Could Not Fix)

(none)


Suggested Follow-up Issues

(none)


Validation

Check Status
Type check bun run type-check
Lint bun run lint
Tests bun test packages/cli/src/commands/workflow.test.ts (134 passed) and bun run test

The simplify step refactored three console web files this PR never touched
(when-grammar.ts, ModelPickerField.tsx, model-options.ts). Behavior-preserving
or not, they are out of scope for a CLI discovery fix — restore them to the
merge-base state.
@Wirasm Wirasm marked this pull request as ready for review June 12, 2026 08:51
@Wirasm Wirasm merged commit e250e7a into dev Jun 12, 2026
4 checks passed
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.

1 participant