Skip to content

fix: SessionEnd hook crash when script outputs no JSON - #10

Merged
dahai80 merged 1 commit into
mainfrom
fix/sessionend-hook-crash
Jul 28, 2026
Merged

dahai80 merged 1 commit into
mainfrom
fix/sessionend-hook-crash

Conversation

@dahai80

@dahai80 dahai80 commented Jul 28, 2026

Copy link
Copy Markdown
Owner

Summary

Fixes #9

When exiting fusion-code, if a SessionEnd hook script exits with code 0 but produces no JSON on stdout, the hook framework crashes with:

SessionEnd hook [...] failed: undefined is not an object (evaluating 'R.hookSpecificOutput')

Root Cause

src/utils/hooks.ts line 3388 in executeHooksOutsideREPL:

const hso2 = (json as TypedHookJSON).hookSpecificOutput;

parseHookOutput returns json = null when hook stdout is not valid JSON. Accessing .hookSpecificOutput on null throws TypeError.

Fix

Add null guard so hso2 is undefined when json is null:

const hso2 = json
    ? (json as TypedHookJSON).hookSpecificOutput
    : undefined;

Also includes a minor format fix in src/Tool.ts (line break in TOOL_DEFAULTS.renderToolUseMessage).

Testing

  • bun run typecheck — 0 errors
  • bun run build:dev — passes
  • Exit fusion-code with SessionEnd hook configured — no crash

🤖 Generated with Claude Code

When a SessionEnd hook script exits 0 with no JSON stdout,
parseHookOutput returns json=null. Accessing .hookSpecificOutput
on null crashed with 'undefined is not an object'.

Fixes #9

Co-Authored-By: Claude <[email protected]>
@dahai80
dahai80 merged commit 4b39f0e into main Jul 28, 2026
1 check passed
@dahai80
dahai80 deleted the fix/sessionend-hook-crash branch July 28, 2026 09:07
dahai80 added a commit that referenced this pull request Jul 30, 2026
….4.1) (#16)

- Add WebSocket /ws/chat to projectApiServer for streaming chat
  (subprocess mode: fusion-code --output-format=stream-json)
- Protocol: chat.stream/chat.cancel → chat_event/chat_done NDJSON
  (compatible with StreamingBridge)
- Add start.sh for UpstreamServiceManager auto-start
- Update README with WS endpoint docs
- Bump version to 0.4.1

Fusion-Studio issues filed:
- #9 Layer 1: upstream service registration
- #10 Layer 2: FusionCodeAPIClient
- #11 Layer 3: StreamingBridge WS integration
- PR #12: Layer 1+2 implementation

🤖 Generated with [Claude Code](https://claude.com/claude-code)
dahai80 added a commit that referenced this pull request Jul 31, 2026
….4.1)

- Add WebSocket /ws/chat to projectApiServer for streaming chat
  (subprocess mode: fusion-code --output-format=stream-json)
- Protocol: chat.stream/chat.cancel → chat_event/chat_done NDJSON
  (compatible with StreamingBridge)
- Add start.sh for UpstreamServiceManager auto-start
- Update README with WS endpoint docs
- Bump version to 0.4.1

Fusion-Studio issues filed:
- #9 Layer 1: upstream service registration
- #10 Layer 2: FusionCodeAPIClient
- #11 Layer 3: StreamingBridge WS integration
- PR #12: Layer 1+2 implementation

🤖 Generated with [Claude Code](https://claude.com/claude-code)
dahai80 added a commit that referenced this pull request Aug 20, 2026
enhance-0819.md §P4.2 定 7 项 /doctor 本地健康检查。审计 (iter #9/#10):
- ✅ #5 CLAUDE.md 裁剪 (已覆盖)
- ✅ #6 配置冲突 (PR #90)
- ⏳ #4 OOM/内存 (跨仓: MLX 无 memory 端点, 仅 POST /api/v1/gc mutating)
- ⏳ #7 一键修复 (远期)
- **真 gap = #1 MLX 网关连通 + #3 模型加载状态** — /doctor 此前完全不探 MLX

落地 detectMlxHealth(): 复用 model-status.ts 的 fetchMlxStatus
(/api/tags) + fetchMlxPs (/api/ps), 3s timeout。Gating: 仅当
shouldAutoUseFusionMlx() (MLX 配置 provider) — cloud-active 时跳过
避免 3s 浪费 + 噪音。两 warning: 不可达 (含 URL + 起服命令) / 已连通
但无模型 loaded (含可用模型名截断 + load 命令)。

不改 Doctor.tsx — diagnostic.warnings 已数据驱动渲染。#4 OOM 跨仓
延后 (fusion-mlx 需加 status 端点, 遵循 "上游问题先提 issue")。

验证: typecheck 0, 6 单测 pass, 122 全测 pass 无回归, build +
build:dev:full pass, git diff -w +62/-0 纯插入零 churn。

Co-authored-by: Claude Fable 5 <[email protected]>
dahai80 added a commit that referenced this pull request Aug 28, 2026
…into rewindMessageState (audit 1.1.1) (#180)

Slice #10 of the REPL.tsx god-module split (audit §1.1.1). Extract the
rewindConversationTo + restoreMessageSync useCallback bodies (~90 LOC) into a
pure-helper bundle at src/utils/rewindMessageState.ts. No React, no JSX, no
hooks — calls only passed setters + direct pure-fn imports.

REPL keeps thin useCallback wrappers (deps arrays verbatim, ref-assign
preserved) so downstream reads the same const names → byte-identical.
setConversationId wrapped with a lambda to satisfy Dispatch<SetStateAction>
contravariance (useState(randomUUID()) infers a template-literal UUID type;
helper param typed ReturnType<typeof randomUUID>).

feature("CONTEXT_COLLAPSE") dynamic require relocates verbatim (bun:bundle
macro, string-literal arg, cross-file DCE safe). Removed two now-unused REPL
imports (resetMicrocompactState, ImageBlockParam).

Gates: typecheck 0 / 842 tests pass (+12 new helper tests) / lint clean /
build:dev ok. REPL 6628 → 6565 (−63).

Co-authored-by: Claude Fable 5 <[email protected]>
dahai80 added a commit that referenced this pull request Aug 28, 2026
…it slice #11) (#181)

audit §1.1.1 god-module split. Extract the 35-LOC spinner-tip pick
useCallback body from REPL.tsx into src/utils/spinnerTipPicker.ts as a
pure-helper bundle (no React, no JSX, no hooks). REPL keeps a thin
useCallback wrapper (deps array [setAppState, theme] unchanged verbatim)
that passes refs + setters via a typed SpinnerTipPickerSetters object;
downstream reads the same const name (byte-identical).

Also fixes 3 pre-existing typecheck errors in the slice #10 test file
rewindMessageState.test.ts (committed in PR #180), per the rule that any
failing case must be located+fixed regardless of relation to the current
change:
- makeSetters messagesRef typed {current: Message[]} not {current: unknown[]}
- promptSuggestion toEqual cast to Record<string, unknown> (prev literal
  narrowed the type, excess-prop check on the 5-field literal failed)
- spyOn logSpy dropped 'as never' so .mockRestore() is not on 'never'

REPL 6565 → 6538 (−27); cumulative off 7096 now −558.
Gates: typecheck 0 / test 842 pass / lint clean / build:dev pass.

Co-authored-by: Claude Fable 5 <[email protected]>
dahai80 added a commit that referenced this pull request Dec 1, 2026
Method sections final (pin route, watcher modes, cost metrics);
results/forensics/ADAPT sections fill after the 20:00 CST run.

Co-authored-by: Claude Code <[email protected]>
@dahai80 dahai80 mentioned this pull request Dec 1, 2026
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.

fix: SessionEnd hook crash when script outputs no JSON

1 participant