Skip to content

fix(server): include home-scoped workflows in GET /api/workflows/:name#1560

Closed
thecodeartificerX wants to merge 1 commit into
coleam00:devfrom
thecodeartificerX:fix/api-workflow-get-home-scoped
Closed

fix(server): include home-scoped workflows in GET /api/workflows/:name#1560
thecodeartificerX wants to merge 1 commit into
coleam00:devfrom
thecodeartificerX:fix/api-workflow-get-home-scoped

Conversation

@thecodeartificerX

@thecodeartificerX thecodeartificerX commented May 4, 2026

Copy link
Copy Markdown

Summary

  • Problem: GET /api/workflows/:name returns 404 for any workflow at ~/.archon/workflows/. The Web UI then renders an empty workflow object, surfacing misleading Zod errors ("workflow name is required", "workflow description is required", "at least one node is required") even though the same workflow loads and runs correctly via the CLI.
  • Why it matters: Home-scoped workflows are the documented user-level storage path (per CLAUDE.md "Home-scoped workflows"). They appear in archon workflow list with source: 'global', validate cleanly, and execute end-to-end — but cannot be opened in the workflow builder UI.
  • What changed: Added a home-scoped lookup tier to the GET route between the existing project-scoped and bundled-defaults tiers. Mirrors the PUT route, which already defaults saves to getArchonHome() when no cwd matches.
  • What did NOT change: The route's project > global > bundled priority (matches discoverWorkflows() in packages/workflows/src/workflow-discovery.ts). No subfolder lookup added — that would be a separate change touching PUT too.

UX Journey

Before

User opens workflow builder ──▶ UI calls GET /api/workflows/<name>
                                 │
                                 └─▶ Server checks cwd/.archon/workflows/  ❌
                                     Server checks bundled defaults        ❌
                                     (skips ~/.archon/workflows/)
                                 │
                                 ◀── 404
UI renders empty {} ──────────▶ Zod errors:
                                 "workflow name is required"
                                 "workflow description is required"
                                 "at least one node is required"

After

User opens workflow builder ──▶ UI calls GET /api/workflows/<name>
                                 │
                                 └─▶ Server checks cwd/.archon/workflows/  ❌
                                     [+ Server checks ~/.archon/workflows/ ✅]
                                 │
                                 ◀── 200 { workflow, source: 'global' }
UI renders editor ────────────▶ Workflow loads correctly

Architecture Diagram

Before

GET /api/workflows/:name   ───┐
                              ├─▶ project (cwd/.archon/workflows/)
                              └─▶ bundled (BUNDLED_WORKFLOWS map / dev fs)

PUT /api/workflows/:name   ───┐
                              ├─▶ project (if cwd)
                              ├─▶ codebase[0].default_cwd
                              └─▶ getArchonHome() ✅
(asymmetric — GET missing the home-scoped tier)

After

GET /api/workflows/:name   ───┐
                              ├─▶ project (cwd/.archon/workflows/)
                              ├─▶ [+] global (getHomeWorkflowsPath())
                              └─▶ bundled

PUT /api/workflows/:name   (unchanged)
(symmetric — both routes now reach home-scoped storage)

Connection inventory:

From To Status Notes
api.ts:GET /workflows/:name getHomeWorkflowsPath() new Reads <ARCHON_HOME>/workflows/<name>.yaml
api.ts:GET /workflows/:name parseWorkflow() unchanged Same loader used for all tiers

Label Snapshot

  • Risk: risk: low
  • Size: size: XS
  • Scope: server
  • Module: server:routes-api-workflows

Change Metadata

  • Change type: bug
  • Primary scope: server

Linked Issue

  • Closes #
  • Related #
  • Depends on #
  • Supersedes #

(No issue filed — discovered during dogfooding by a user authoring a home-scoped workflow per the documented ~/.archon/workflows/ flow.)

Validation Evidence (required)

bun run type-check    # all 10 packages exit 0
bun run lint          # clean
bun run format:check  # clean
bun --filter '@archon/server' test  # 4 files / 118 tests pass, 0 fail

Full bun run validate was run; 4 pre-existing failures in @archon/workflows (DAG Loader -- cycle detection > accepts valid DAG … ×3 and one script-node test) are present on origin/dev without this patch and are unrelated to this change (verified by stashing the patch and re-running). This PR touches only packages/server/src/routes/api.ts.

Manual verification:

$ curl -s http://localhost:3090/api/workflows/<home-scoped-workflow-name>
{ "workflow": {...full definition...}, "filename": "...", "source": "global" }
HTTP 200  (was 404 before)

Web UI workflow builder now opens the workflow without Zod errors.

Security Impact (required)

  • New permissions/capabilities? No
  • New external network calls? No
  • Secrets/tokens handling changed? No
  • File system access scope changed? No — only reads from getHomeWorkflowsPath() which is already read by discoverWorkflows(). Filename is derived from a route param that already passes isValidCommandName(), so no new path-traversal surface is introduced.

Compatibility / Migration

  • Backward compatible? Yes — strictly additive. Existing project and bundled lookups are untouched. Routes that previously returned 404 for home-scoped names now succeed; nothing that previously succeeded changes.
  • Config/env changes? No
  • Database migration needed? No

Human Verification (required)

What was personally validated beyond CI:

  • Verified scenarios:
    • Home-scoped workflow → GET returns 200 with source: 'global'
    • Project-scoped workflow → still returns 200 with source: 'project'
    • Bundled workflow → still returns 200 with source: 'bundled'
    • Nonexistent name → still returns 404
  • Edge cases checked: ENOENT on home dir is swallowed and falls through to bundled (matches existing project-tier behavior); other read errors log and 500 (also matches existing project-tier behavior).
  • What was not verified: Subfolder discovery (e.g. ~/.archon/workflows/personal/foo.yaml) — discovery surfaces these but GET still 404s. PUT also writes only to top level. Out of scope for this PR; would need a paired GET+PUT change.

Side Effects / Blast Radius (required)

  • Affected subsystems/workflows: Only GET /api/workflows/:name. The Web UI workflow builder benefits; the CLI was already correct.
  • Potential unintended effects: A home-scoped file with the same name as a bundled default will now win over the bundled version on GET — matching the priority documented in workflow-discovery.ts. This was already the case in archon workflow list and execution; the GET route was the outlier.
  • Guardrails/monitoring: Existing Pino logging (workflow.fetch_home_failed) added for non-ENOENT read errors.

Rollback Plan (required)

  • Fast rollback: git revert <this commit>. Single-file, additive change with no migrations.
  • Feature flags or config toggles: None.
  • Observable failure symptoms: 500s on GET /api/workflows/:name for any user with a home-scoped workflow → check workflow.fetch_home_failed log entries.

Risks and Mitigations

  • Risk: Home-scoped file shadows a same-named bundled default after this patch (where it didn't shadow on GET before).
    • Mitigation: This matches existing discovery / list / execute behavior, so the fix removes inconsistency rather than introducing it. The GET route was the only path that didn't honor the documented priority.

Summary by CodeRabbit

Release Notes

  • New Features
    • Workflows can now be stored and accessed from a global home location. The system automatically checks your home directory for workflows and falls back to project-specific or bundled versions as needed.

The GET route only checked project-scoped (cwd/.archon/workflows/) and
bundled defaults, falling through to 404 for workflows at ~/.archon/workflows/.
The Web UI then rendered an empty workflow object and produced misleading
Zod errors ("workflow name is required", "workflow description is required",
"at least one node is required") even though the workflow loads fine in
the CLI and the discovery layer (which correctly lists it with source:
'global').

Mirror the PUT /api/workflows/:name route (which already defaults saves
to getArchonHome() when no cwd matches) by adding a home-scoped lookup
between the project and bundled tiers, returning source: 'global'.
Discovery priority (project > global > bundled) is preserved.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented May 4, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a8bde39e-514d-4011-a591-11fca9d3fbad

📥 Commits

Reviewing files that changed from the base of the PR and between ee8fcbf and a8d48d8.

📒 Files selected for processing (1)
  • packages/server/src/routes/api.ts

📝 Walkthrough

Walkthrough

The API's GET /api/workflows/:name endpoint now supports fetching workflow definitions from a home-scoped location before falling back to bundled defaults. A new resolution layer reads from <ARCHON_HOME>/workflows/<name>.yaml, parses the YAML, and returns it marked as source: 'global'; non-existent files continue to the existing fallback path.

Changes

Home-Scoped Workflow Resolution

Layer / File(s) Summary
Imports
packages/server/src/routes/api.ts
getHomeWorkflowsPath added from @archon/paths module.
Endpoint Logic
packages/server/src/routes/api.ts
GET /api/workflows/:name inserts home-scoped lookup: reads <ARCHON_HOME>/workflows/<name>.yaml, parses as YAML, returns with source: 'global'; handles parse/read errors with 500, skips to bundled fallback on ENOENT.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related issues

Poem

🐰 A warren of workflows, both near and far,
Home paths now blossom, shining like a star,
No more just bundled, now we can roam,
To fetch our definitions from the global home! 🏠✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically summarizes the main change: adding home-scoped workflow support to the GET /api/workflows endpoint.
Description check ✅ Passed The description comprehensively covers all template sections including summary, UX journey, architecture diagrams, validation evidence, security impact, compatibility, human verification, side effects, and rollback plan with excellent detail and clarity.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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
Review rate limit: 7/8 reviews remaining, refill in 7 minutes and 30 seconds.

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

@blankse

blankse commented May 4, 2026

Copy link
Copy Markdown
Contributor

@thecodeartificerX Duplicate of #1525

@thecodeartificerX

Copy link
Copy Markdown
Author

Closing as duplicate of #1525 — I missed this when searching open PRs before opening mine, sorry for the noise. #1525 also covers PUT and DELETE plus adds test coverage, so it's the better fix to land. 🙏

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.

2 participants