Skip to content

fix(daemon): recover stash target oid when last stash is popped - #59

Draft
posthog[bot] wants to merge 1 commit into
mainfrom
posthog-self-driving/fixdaemon-resolve-stash-target-oid-when-4561a9
Draft

posthog[bot] wants to merge 1 commit into
mainfrom
posthog-self-driving/fixdaemon-resolve-stash-target-oid-when-4561a9

Conversation

@posthog

@posthog posthog Bot commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Problem

  • Users who pop or drop their last remaining stash trip two error-level daemon exceptions every time — grouped by message, ~150 across 4 users in a month, on Linux, macOS, and Windows.
  • Git deletes both .git/refs/stash and .git/logs/refs/stash when the last stash leaves the stack. Both trace-payload resolvers read those files from disk, so both fail on the same command and each logs at error level; the telemetry bridge turns each into an $exception. That is why the two issues always arrive as a pair, ~1s apart, for the same worktree.
  • Per-issue counts look tiny only because the worktree path enters the fingerprint, which splits one bug across many issues.

Changes

  • Route both payload resolvers through a shared recover_top_stash_target_oid_from_history helper that reuses the daemon's existing rewrite-history fallback (inferred_top_stash_sha_from_rewrite_history) — the same recovery the event builder already relied on.
  • resolve_stash_target_oid_for_command and the pop/drop/branch arm of resolve_stash_target_oid_for_terminal_payload: on an on-disk miss for a top-of-stack target, recover the sha from history, or return a benign None (which the event builder still fills) instead of erroring.
  • Non-top-of-stack targets (e.g. stash@{2}) still return an error — those genuinely cannot be recovered from history.
  • Point the pre-existing StashOperation::Apply fallback at the new helper too, so there is one copy of the recovery expression.

Impact

  • No behaviour change to authorship attribution — the event builder already had the fallback, so the final data was already correct. This removes the error-level telemetry noise and populates the intermediate autter_stash_target_oid on the affected traces.

Tests

  • Added two lib unit tests: one asserts both payload resolvers recover the target sha when refs/stash and its reflog are absent; one asserts a non-top-of-stack reference still errors.
  • cargo check --locked --all-targets (the CI job) and the existing stash integration suite pass.

Agent context

  • Considered folding the top-of-stack gate + error arms into one shared function, but the two resolvers carry distinct error messages, so a recover_* helper plus an inline gate reads cleaner than a combinator.
  • Left the rare unrecoverable-and-terminal double read of the rewrite log alone: the common recoverable path reads once (the first resolver succeeds and the second is skipped), and memoizing across the large augmentation function would add cross-cutting state beyond this fix.

Created with PostHog Desktop from this inbox report.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

Popping or dropping the last stash deletes both `refs/stash` and its reflog.
Both trace-payload stash resolvers read those files from disk, so each returned
an error and logged at error level, which the telemetry bridge reported as an
exception — two per occurrence, on an ordinary action.

Wire the daemon's existing rewrite-history fallback
(`inferred_top_stash_sha_from_rewrite_history`, already used by the event
builder) into both payload resolvers via a shared
`recover_top_stash_target_oid_from_history` helper. For a top-of-stack target,
an on-disk miss now recovers the sha from history, or returns a benign `None`
that the event builder still fills, instead of erroring. Non-top-of-stack
targets still surface as errors.

Attribution was already correct because the event builder had the fallback;
this removes the error-level telemetry noise and populates the intermediate
stash target oid on the affected traces.

Generated-By: PostHog Desktop
Task-Id: 398311fd-9505-4892-8aea-aa1f97fddd24
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.

0 participants