Hold on — the test pre-creates session state via strategy.SaveSessionState, which saves to .git/entire-sessions/. But the prompt.txt check is at .entire/metadata/<sessionID>/prompt.txt. These are completely different directories. So the backfill SHOULD fire.
But wait — the test BackfillUpdatesSessionState also runs handleLifecycleTurnEnd which calls handleLifecycleTurnStart? No, it doesn't. handleLifecycleTurnEnd is a separate handler.
Oh wait, the real production flow for Factory Droid exec mode is:
SessionStart hook fires → triggers session-start handler AND user-prompt-submit handler
- The
user-prompt-submit handler calls handleLifecycleTurnStart which creates prompt.txt (even empty)
So in production, prompt.txt IS created (empty) by the SessionStart→user-prompt-submit path! The backfill at turn-end would see an existing (empty) file and NOT backfill.
This means my entire backfill approach doesn't actually work for the Factory Droid exec case, because prompt.txt IS created (empty) by the SessionStart→user-prompt-submit hook!
Let me reconsider. The SessionStart hook installs user-prompt-submit handler, which fires handleLifecycleTurnStart with empty prompt. My change to turn-start now creates prompt.txt (empty). At turn-end, os.Stat finds the file → no backfill.
So I need to change the detection: instead of "file doesn't exist", it should be "file exists but is empty". Let me revert the turn-start change and the stat check approach.
Actually wait — let me reconsider. The whole point of the "always create prompt.txt" change was to distinguish "hooks fired with no prompt" from "hooks never fired". But in the Factory Droid exec case:
SessionStart fires user-prompt-submit → TurnStart with empty prompt → creates empty prompt.txt
UserPromptSubmit NEVER fires (exec mode)
- So prompt.txt exists but is empty
And a "genuine no prompt" scenario would also have prompt.txt exist but empty.
These two cases are indistinguishable with the file-existence approach. The real distinguishing signal is: did the transcript contain user prompts that weren't captured?
The simplest correct approach: just check if prompt.txt is empty (not missing), and if the agent can extract prompts from the transcript, backfill. If there genuinely were no prompts, ExtractPrompts will return empty too.