Implement the following plan: Plan: Handle droid exec missing UserPromptSubmit Context…
- User
Implement the following plan:
Plan: Handle
droid execmissing UserPromptSubmitContext
droid execfiresSessionStart → Stop → SessionEndwithoutUserPromptSubmit. SinceUserPromptSubmitmaps toTurnStart(which creates session state, transitions IDLE→ACTIVE, captures pre-prompt state), the session lifecycle is broken:- Phase stays IDLE — PrepareCommitMsg/PostCommit hooks won't properly link mid-exec commits (Droid CAN auto-commit with
--auto medium/high) - No session state created until SaveStep's late fallback (after agent is done)
- No PrePromptState — pre-untracked file baseline is lost
Approach: Install
user-prompt-submiton Droid's SessionStart event typeThe fix is entirely within Droid's hook installation code. When installing hooks, register the
user-prompt-submitcommand as a second hook under theSessionStartevent type in.factory/settings.json. This way, when Droid fires its SessionStart event, both commands run:entire hooks factoryai-droid session-start→ SessionStart event → banner, concurrent session checkentire hooks factoryai-droid user-prompt-submit→ TurnStart event → session initialized, ACTIVE phase
Why this works:
userPromptSubmitRawis a superset ofsessionInfoRaw(same fields +prompt). When SessionStart sends{session_id, transcript_path},json.Unmarshalsucceeds —Promptis just"".- If
UserPromptSubmitfires later (interactive/stream-jsonrpc mode), it's a benign ACTIVE→ACTIVE transition - If it doesn't fire (exec mode), the session is already ACTIVE from SessionStart
removeEntireHooksmatches by"entire "prefix — both commands are properly removed during uninstall
Resulting
.factory/settings.jsonSessionStart entry:json"SessionStart": [{ "matcher": "", "hooks": [ {"type": "command", "command": "entire hooks factoryai-droid session-start"}, {"type": "command", "command": "entire hooks factoryai-droid user-prompt-submit"} ] }] - Phase stays IDLE — PrepareCommitMsg/PostCommit hooks won't properly link mid-exec commits (Droid CAN auto-commit with
Assistant
★ Insight ─────────────────────────────────────This plan addresses a lifecycle gap in Droid'sexecmode. The key insight is thatdroid execskipsUserPromptSubmit(which maps toTurnStart), leaving the session in IDLE phase. Rather than adding new event types or modifying the state machine, we piggybackuser-prompt-submitonto the existingSessionStartevent in the hooks config — a minimal, elegant fix that leverages JSON unmarshalling's tolerance of missing fields.─────────────────────────────────────────────────Let me start by reading the relevant source files.
Assistant
Now let me check the event parsing to confirm
parseTurnStarthandles missingpromptgracefully, and look at the types.Assistant
Good. I can see that
userPromptSubmitRawis a superset ofsessionInfoRaw(both havesession_idandtranscript_path, withuserPromptSubmitRawaddingprompt). When SessionStart's stdin is unmarshalled intouserPromptSubmitRaw, thePromptfield will simply default to"". This confirms the plan's approach is sound.Let me also check the lifecycle test for any relevant parseTurnStart tests.
Assistant
Now I have all the context. Let me implement the changes.
Assistant
★ Insight ─────────────────────────────────────TheaddHookToMatcherfunction (line 454 of hooks.go) looks for an existing matcher with the given name before creating a new one. Since bothsession-startanduser-prompt-submituse matcher"", the second call will find the existing empty-matcher entry and append to itsHooksslice. This meanslen(settings.Hooks.SessionStart)stays at 1 (one matcher), but that matcher now has 2 hook entries.─────────────────────────────────────────────────Assistant
Now update the tests. The fresh install count changes from 7 to 8 since we're adding an extra hook command. Let me update
TestInstallHooks_FreshInstall:Assistant
Now add the assertion that SessionStart also contains the user-prompt-submit command:
Assistant
Now update the idempotent test — the first install count changes from 7 to 8:
Assistant
Update the local dev test to also verify the user-prompt-submit under SessionStart:
Assistant
Update the force reinstall test — count changes from 7 to 8:
Assistant
Now update the
TestInstallHooks_PreservesUserHooksOnSameTypeSessionStart subtest to also verify the user-prompt-submit command:Assistant
Now add the test in lifecycle_test.go that verifies
parseTurnStarthandles SessionStart-format stdin (missingpromptfield):Assistant
Now let's run fmt, lint, and tests.
Assistant
This lint error is pre-existing (in
manual_commit_condensation.go, not in my changes). Let me verify it's not from my changes by checking git diff:Assistant
Confirmed — the lint error is pre-existing in
manual_commit_condensation.go, not from my changes. Let me now run the tests for the factoryaidroid package specifically:Assistant
All 56 tests pass, including the new
TestParseHookEvent_TurnStart_SessionStartFormattest. Let me also run the full test suite and integration tests:Assistant
There are integration tests that also check the hook count. Let me fix those too.
Assistant
That's the Claude Code test at line 124 — it's fine, it's testing Claude Code (7 hooks is correct for Claude Code). The failing tests are at lines 913 and 1086 which are for Factory AI Droid. Let me read those:
Assistant
Now let me update both locations in the integration test:
Assistant
Now let me also check if there are any other assertions about SessionStart hook content in the integration tests that need updating:
Assistant
Good — the integration tests only check the count and the presence of hook types in the JSON (via
strings.Contains), both of which are fine. Let me re-run the full test suite:Assistant
All tests pass (unit + integration).
Assistant
★ Insight ─────────────────────────────────────Why this works without any parser changes: Go'sjson.Unmarshalsilently ignores missing fields — they get their zero values. SinceuserPromptSubmitRawembeds , unmarshalling SessionStart's into it just yields . This is a deliberate feature of Go's JSON handling that makes it safe to use a "wider" struct to parse a "narrower" input.