fix(org-import): started event emits after YAML parse so name is populated #142

Merged
claude-ceo-assistant merged 1 commits from fix/org-import-started-event-name into main 2026-05-08 23:30:03 +00:00

Summary

The org.import.started event was firing immediately after request body bind, before the YAML at body.Dir was loaded. Payload name was "" whenever the caller passed dir (the common path — canvas and all live imports use dir, not inline template). Three started rows already in the local platform's structure_events have empty name.

Follow-up to PR #137; called out as a follow-up in that PR's body.

Fix

Move the started emit (and importStart timestamp) to after the YAML unmarshal / inline-template fallthrough, where tmpl.Name is guaranteed populated.

Bonus side-effect

Pre-parse error returns (invalid body, traversal-rejected dir, file-not-found, YAML expansion fail, YAML unmarshal fail, neither dir nor template provided) no longer emit an orphan started row. Every started is now guaranteed a paired completed/failed — semantically "we couldn't even start an import" doesn't claim it started.

Verification

  • Local Postgres E2E: re-imported molecule-dev-only; new started row in structure_events carries "Molecule AI Dev Team (dev-only)" instead of ""
  • go test ./internal/handlers/... green
  • go build clean
SELECT to_char(created_at,'HH24:MI:SS'), event_type, payload->>'name'
FROM structure_events
WHERE event_type LIKE 'org.import%' ORDER BY created_at DESC LIMIT 4;
--    23:23:52 | org.import.completed | Molecule AI Dev Team (dev-only)
--    23:23:36 | org.import.started   | Molecule AI Dev Team (dev-only)  ← was "" before fix
--    22:01:27 | org.import.completed | Molecule AI Dev Team (dev-only)
--    22:01:11 | org.import.started   |                                   ← old shape

🤖 Generated with Claude Code

## Summary The `org.import.started` event was firing immediately after request body bind, before the YAML at `body.Dir` was loaded. Payload `name` was `""` whenever the caller passed `dir` (the common path — canvas and all live imports use `dir`, not inline `template`). Three started rows already in the local platform's `structure_events` have empty `name`. Follow-up to PR #137; called out as a follow-up in that PR's body. ## Fix Move the started emit (and `importStart` timestamp) to after the YAML unmarshal / inline-template fallthrough, where `tmpl.Name` is guaranteed populated. ## Bonus side-effect Pre-parse error returns (invalid body, traversal-rejected `dir`, file-not-found, YAML expansion fail, YAML unmarshal fail, neither `dir` nor `template` provided) no longer emit an orphan `started` row. Every `started` is now guaranteed a paired `completed`/`failed` — semantically "we couldn't even start an import" doesn't claim it started. ## Verification - [x] Local Postgres E2E: re-imported `molecule-dev-only`; new started row in `structure_events` carries `"Molecule AI Dev Team (dev-only)"` instead of `""` - [x] `go test ./internal/handlers/...` green - [x] `go build` clean ```sql SELECT to_char(created_at,'HH24:MI:SS'), event_type, payload->>'name' FROM structure_events WHERE event_type LIKE 'org.import%' ORDER BY created_at DESC LIMIT 4; -- 23:23:52 | org.import.completed | Molecule AI Dev Team (dev-only) -- 23:23:36 | org.import.started | Molecule AI Dev Team (dev-only) ← was "" before fix -- 22:01:27 | org.import.completed | Molecule AI Dev Team (dev-only) -- 22:01:11 | org.import.started | ← old shape ``` 🤖 Generated with [Claude Code](https://claude.com/claude-code)
claude-ceo-assistant added 1 commit 2026-05-08 23:25:41 +00:00
fix(org-import): emit started event after YAML parse so name is populated
All checks were successful
CodeQL / Analyze (${{ matrix.language }}) (go) (pull_request) Successful in 1s
CodeQL / Analyze (${{ matrix.language }}) (javascript-typescript) (pull_request) Successful in 1s
CodeQL / Analyze (${{ matrix.language }}) (python) (pull_request) Successful in 1s
Block internal-flavored paths / Block forbidden paths (pull_request) Successful in 5s
E2E Staging Canvas (Playwright) / detect-changes (pull_request) Successful in 7s
Secret scan / Scan diff for credential-shaped strings (pull_request) Successful in 6s
CI / Detect changes (pull_request) Successful in 8s
Handlers Postgres Integration / detect-changes (pull_request) Successful in 7s
Runtime PR-Built Compatibility / detect-changes (pull_request) Successful in 7s
Harness Replays / detect-changes (pull_request) Successful in 7s
E2E API Smoke Test / detect-changes (pull_request) Successful in 9s
CI / Shellcheck (E2E scripts) (pull_request) Successful in 1s
CI / Python Lint & Test (pull_request) Successful in 3s
CI / Canvas (Next.js) (pull_request) Successful in 4s
Runtime PR-Built Compatibility / PR-built wheel + import smoke (pull_request) Successful in 3s
E2E Staging Canvas (Playwright) / Canvas tabs E2E (pull_request) Successful in 4s
CI / Canvas Deploy Reminder (pull_request) Has been skipped
Harness Replays / Harness Replays (pull_request) Successful in 59s
Handlers Postgres Integration / Handlers Postgres Integration (pull_request) Successful in 1m45s
E2E API Smoke Test / E2E API Smoke Test (pull_request) Successful in 1m53s
CI / Platform (Go) (pull_request) Successful in 2m51s
b3041c13d3
The org.import.started event was firing immediately after request body
bind, before the YAML at body.Dir was loaded. Result: payload.name was
"" whenever the caller passed `dir` (the common path — the canvas and
all live imports use dir, not inline template). Three started rows
already in the local platform's structure_events have empty name.

Fix: move the started emit (and importStart timestamp) to after the
YAML unmarshal / inline-template fallthrough, where tmpl.Name is
guaranteed populated.

Bonus: pre-parse error returns (invalid body, traversal-rejected dir,
file-not-found, YAML expansion fail, YAML unmarshal fail, neither dir
nor template provided) no longer emit an orphan started row — every
started is now guaranteed a paired completed/failed.

Verified live against running platform: re-imported molecule-dev-only,
new started row in structure_events carries
"Molecule AI Dev Team (dev-only)" instead of "".

Tests: full handler suite green (`go test ./internal/handlers/`).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
claude-ceo-assistant merged commit a93c4ce177 into main 2026-05-08 23:30:03 +00:00
Sign in to join this conversation.
No reviewers
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: molecule-ai/molecule-core#142
No description provided.