Workflow remains running after session rebuild, then fails on app shutdown
- Dominant language
- No language data
- Stars
- 2.1k
- Forks
- 153
- PR merge metrics
- No merged PRs in 30d
Description
### Short summary
A scheduled Workflow can successfully call `task_complete`, but a same-second live-session rebuild drops the Workflow completion listener. The run remains `pending/running`, blocks later cron ticks, and is eventually mislabeled `failed: Interrupted by app shutdown`.
### Affected version or release
GitHub Copilot App `1.0.73`
### Installation context
Windows desktop App, project Workflow attached to `cloga/Trinity-Alpha`, running in `autopilot` mode on cron `0 */4 * * *`. The affected Workflow workspace had been manually triggered and taken over in the UI.
### What happened?
The Workflow's business task completed successfully and called `task_complete`, but the App did not persist the Workflow run as completed. A UI `resume_session` immediately triggered `Rebuilding live session after enabled experiments changed`. During reconstruction, the original SDK event loop and the Workflow run's `session_handler_subscription_forwarder` were stopped. A new ordinary session listener started, but the completion observer for the original Workflow run was not restored.
The run therefore remained `pending/running`. Every later scheduler tick was skipped with `Skipping workflow tick: prior run is still pending/running`. When the App/CLI later shut down, cleanup incorrectly finalized the already-successful run as `failed` with `Interrupted by app shutdown`.
### Steps to reproduce
1. Create a project Workflow scheduled on a cron and run it in `autopilot` mode.
2. Manually trigger the Workflow and open/take over its workspace session.
3. Let the agent complete its work and invoke `task_complete`.
4. At completion, cause or observe a live-session reconstruction, for example when enabled experiments change and the UI resumes the session.
5. Observe that the agent session has a durable `task_complete` event, but the Workflow run remains `pending/running`.
6. Wait for the next cron tick and observe `Skipping workflow tick: prior run is still pending/running`.
7. Shut down/restart the App and observe the stale run becoming `failed` with `Interrupted by app shutdown`.
### Expected behavior
A terminal `task_complete` or completed agent turn should durably finalize the Workflow run before session reconstruction can replace listeners. If reconstruction occurs, the Workflow completion subscription should be rebound by `run_id` or reconciled from durable session events. App shutdown must not overwrite an already-completed run as failed, and a stale listener must not indefinitely suppress future scheduled runs.
### Additional context
- Affected run ID: `e2b06e69-17cc-4fd1-8348-2a1c44be421d`
- Affected session ID: `65fe97d1-0f1c-41d4-a2a2-305b10177946`
- `task_complete`: `2026-07-30T15:59:38.646Z`
- `agentStop` / end turn: `2026-07-30T15:59:39.716Z`
- UI session resume/rebuild: approximately `2026-07-30T15:59:40Z`
- App/CLI shutdown: approximately `2026-07-30T20:10Z`
- Secondary shutdown errors included `Hook callback invocation failed; ... connection closed`, `unknown taskRegistry handle`, and `TaskRegistryHandle has been disposed`.
- The business verifier confirmed success before the control-plane failure, so this is a false-negative Workflow status plus scheduler starvation, not a failed task.
- Related Community report: https://github.com/orgs/community/discussions/203514
Suggested safeguards: persist terminal state before rebuilding; rebind the run completion listener after reconstruction; add lease/heartbeat expiry and terminal-event reconciliation for stale active runs; reconcile durable completion events before assigning shutdown failure.
Contributor guide
Research direction
Reproduce the scheduled Workflow in autopilot mode while observing the durable task_complete event, live-session reconstruction, and shutdown finalization. Trace where the original completion listener is stopped and where the rebuilt session handles the run, then verify that completion is reconciled, later cron ticks proceed, and shutdown does not mark the run failed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- github
- Domain
- backend, desktop
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100