Skip to content

fix: guard autoresearch shutdown context - #57

Open
nqh-packages wants to merge 1 commit into
davebcn87:mainfrom
nqh-packages:fix/stale-context-shutdown
Open

fix: guard autoresearch shutdown context#57
nqh-packages wants to merge 1 commit into
davebcn87:mainfrom
nqh-packages:fix/stale-context-shutdown

Conversation

@nqh-packages

Copy link
Copy Markdown

Why

Autoresearch stores delayed auto-resume work and updates UI state from lifecycle handlers. In fresh Pi print-mode shutdown, those handlers can observe a stale Pi extension context if another extension still has async teardown work in flight.

What changed

  • Add stale-context guards around UI cleanup, lifecycle handlers, and delayed resume callbacks.
  • Cancel pending auto-resume timers before shutdown UI cleanup.
  • Keep stale-context teardown races as no-ops instead of extension errors.
  • Add source-level regression checks for the shutdown guard and cleanup ordering.

Verification

  • node --test tests/*.mjs → 8/8 pass
  • PATH=/opt/homebrew/bin:/usr/bin:/bin:/usr/sbin:/sbin bash tests/finalize_test.sh → 18/18 pass
  • Fresh Pi smoke with this patched extension: exit=0, stderr_lines=0, stdout=ok
  • Fresh Pi smoke with prompt-suggester + prompt-template-model + autoresearch patched together: exit=0, stderr_lines=0, stdout=ok

Commit-Queue-Session: cq_20260426235232_ecf71f8eb10a211a19af3f6b
Coding-Agent: pi
Coding-Agent-Session: pi-019dcbcc-b152-70a0-b167-aeaaaf7a9b32
@nqh-packages

Copy link
Copy Markdown
Author

Small human note from me because the original PR description was written by my coding agent and reads like a robot filed a ticket.

What I ran into with autoresearch: fresh Pi print mode printed the expected answer, ok, but the process could still exit with code 1 if extension cleanup touched a stale ctx after Pi had already disposed the session. In autoresearch, the risky parts are the delayed auto-resume timer and the UI cleanup during session shutdown.

That makes scripting around Pi weird. The useful work finished, but the process still looks failed.

This PR is just trying to make that shutdown path boring. If Pi is already tearing down a session, autoresearch should cancel pending resume work first, avoid using stale UI/context, and treat stale context during teardown as a no-op instead of an extension error.

No feature change intended. Just making print-mode startup/shutdown less noisy and less surprising.

@davebcn87

Copy link
Copy Markdown
Owner

thanks I'll give it a review, feels a lot of changes for what it does, so might be worth seeing if there's a simpler way to achieve it.

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.

2 participants