continuedev / continue

⏩ Continue is the leading open-source AI code assistant. You can connect any models and any context to build custom autocomplete and chat experiences inside VS Code and JetBrains
https://docs.continue.dev/
Apache License 2.0
15.81k stars 1.2k forks source link

CTRL+L suggests mass deletions for non-suggested code when you apply the fix to the file #2037

Open kyleboddy opened 3 weeks ago

kyleboddy commented 3 weeks ago

Before submitting your bug report

Relevant environment info

- OS: Windows 11
- Continue: v0.8.46
- IDE: VS Code 1.92.2 (user setup)
- Model: Anthropic Sonnet-3.5, API key
- config.json:

mocap@mocaphelper:~/.continue$ cat config.json
{
  "models": [
    {
      "model": "claude-3-5-sonnet-20240620",
      "contextLength": 200000,
      "title": "Claude 3.5 Sonnet",
      "apiKey": "sk-ant-howaboutno",
      "provider": "anthropic"
    }
  ],
  "customCommands": [
    {
      "name": "test",
      "prompt": "{{{ input }}}\n\nWrite a comprehensive set of unit tests for the selected code. It should setup, run tests that check for correctness including important edge cases, and teardown. Ensure that the tests are complete and sophisticated. Give the tests just as chat output, don't edit any file.",
      "description": "Write unit tests for highlighted code"
    }
  ],
  "tabAutocompleteModel": {
    "title": "Autocomplete Trial",
    "provider": "free-trial",
    "model": "codestral-latest"
  },
  "contextProviders": [
    {
      "name": "code",
      "params": {}
    },
    {
      "name": "docs",
      "params": {}
    },
    {
      "name": "diff",
      "params": {}
    },
    {
      "name": "terminal",
      "params": {}
    },
    {
      "name": "problems",
      "params": {}
    },
    {
      "name": "folder",
      "params": {}
    },
    {
      "name": "codebase",
      "params": {}
    }
  ],
  "slashCommands": [
    {
      "name": "edit",
      "description": "Edit selected code"
    },
    {
      "name": "comment",
      "description": "Write comments for the selected code"
    },
    {
      "name": "share",
      "description": "Export the current chat session to markdown"
    },
    {
      "name": "cmd",
      "description": "Generate a shell command"
    },
    {
      "name": "commit",
      "description": "Generate a git commit message"
    }
  ],
  "embeddingsProvider": {
    "provider": "free-trial"
  },
  "reranker": {
    "name": "free-trial"
  }

Description

Hitting CTRL+L and going through the chat interface, then clicking apply on 90% of code suggestions applies the fix and then deletes a ton of other code that is marked with "leave other code unchanged" or similar prompt message. Basically the fix is applied and Continue/VSCode interprets the rest of the instructions to delete the other code rather than leave it alone.

I can repro this consistently in Python but have had mixed results in PHP. I am using CTRL+I only now, or CTRL+L and manually copy/pasting.

To reproduce

  1. Hit CTRL+L
  2. Ask for partial code refactoring
  3. Apply the fix
  4. See a ton of code deleted

https://github.com/user-attachments/assets/ec34bad8-f32f-48d2-b2be-a678ade5e0a9

image

Log output

Console logs:

Error: Trying to add a disposable to a DisposableStore that has already been disposed of. The added object will be leaked!
    at r.add (lifecycle.ts:425:18)
    at y.B (lifecycle.ts:497:22)
    at y.addAction (contentHoverStatusBar.ts:44:23)
    at markerHoverParticipant.ts:238:23
add @ lifecycle.ts:425
console.ts:137 [Extension Host] rejected promise not handled within 1 second: Error: No such branch: master.
y @ console.ts:137
console.ts:137 [Extension Host] stack trace: Error: No such branch: master.
    at N.getBranch (/home/mocap/.vscode-server/cli/servers/Stable-fee1edb8d6d72a0ddff41e5f71a671c23ed924b9/server/extensions/git/dist/main.js:2:936645)
    at async T.retryRun (/home/mocap/.vscode-server/cli/servers/Stable-fee1edb8d6d72a0ddff41e5f71a671c23ed924b9/server/extensions/git/dist/main.js:2:1032124)
    at async T.run (/home/mocap/.vscode-server/cli/servers/Stable-fee1edb8d6d72a0ddff41e5f71a671c23ed924b9/server/extensions/git/dist/main.js:2:1031728)
    at async T.getBranch (/home/mocap/.vscode-server/cli/servers/Stable-fee1edb8d6d72a0ddff41e5f71a671c23ed924b9/server/extensions/git/dist/main.js:2:1020077)
    at async T.getBranchBase (/home/mocap/.vscode-server/cli/servers/Stable-fee1edb8d6d72a0ddff41e5f71a671c23ed924b9/server/extensions/git/dist/main.js:2:1020363)
    at async t.GitHistoryProvider.resolveHEADMergeBase (/home/mocap/.vscode-server/cli/servers/Stable-fee1edb8d6d72a0ddff41e5f71a671c23ed924b9/server/extensions/git/dist/main.js:2:948043)
    at async t.GitHistoryProvider.onDidRunGitStatus (/home/mocap/.vscode-server/cli/servers/Stable-fee1edb8d6d72a0ddff41e5f71a671c23ed924b9/server/extensions/git/dist/main.js:2:941421)
y @ console.ts:137
mainThreadExtensionService.ts:78 [vscode.git]No such branch: master.
$onExtensionRuntimeError @ mainThreadExtensionService.ts:78
mainThreadExtensionService.ts:79 Error: No such branch: master.
    at N.getBranch (vscode-file://vscode-app/home/mocap/.vscode-server/cli/servers/Stable-fee1edb8d6d72a0ddff41e5f71a671c23ed924b9/server/extensions/git/dist/main.js:2:936645)
    at async T.retryRun (vscode-file://vscode-app/home/mocap/.vscode-server/cli/servers/Stable-fee1edb8d6d72a0ddff41e5f71a671c23ed924b9/server/extensions/git/dist/main.js:2:1032124)
    at async T.run (vscode-file://vscode-app/home/mocap/.vscode-server/cli/servers/Stable-fee1edb8d6d72a0ddff41e5f71a671c23ed924b9/server/extensions/git/dist/main.js:2:1031728)
    at async T.getBranch (vscode-file://vscode-app/home/mocap/.vscode-server/cli/servers/Stable-fee1edb8d6d72a0ddff41e5f71a671c23ed924b9/server/extensions/git/dist/main.js:2:1020077)
    at async T.getBranchBase (vscode-file://vscode-app/home/mocap/.vscode-server/cli/servers/Stable-fee1edb8d6d72a0ddff41e5f71a671c23ed924b9/server/extensions/git/dist/main.js:2:1020363)
    at async t.GitHistoryProvider.resolveHEADMergeBase (vscode-file://vscode-app/home/mocap/.vscode-server/cli/servers/Stable-fee1edb8d6d72a0ddff41e5f71a671c23ed924b9/server/extensions/git/dist/main.js:2:948043)
    at async t.GitHistoryProvider.onDidRunGitStatus (vscode-file://vscode-app/home/mocap/.vscode-server/cli/servers/Stable-fee1edb8d6d72a0ddff41e5f71a671c23ed924b9/server/extensions/git/dist/main.js:2:941421)
$onExtensionRuntimeError @ mainThreadExtensionService.ts:79
webviewElement.ts:482 An iframe which has both allow-scripts and allow-same-origin for its sandbox attribute can escape its sandboxing.
mountTo @ webviewElement.ts:482
console.ts:137 [Extension Host] No corresponding diffInfo found for newFilepath

LLM output (with full code deleted for security):

==========================================================================
==========================================================================
Settings:
contextLength: 200000
model: claude-3-5-sonnet-20240620
maxTokens: 4096
raw: true
log: undefined

############################################

The user has requested a section of code in a file to be rewritten.

This is the code to rewrite:

.... [redacted] ....

The user's request is: "The following code was suggested as an edit:

try:
    logger.info("===== Starting main script execution =====")
    asyncio.run(main())
    logger.info("===== Main script completed successfully =====")
except KeyboardInterrupt:
    logger.warning("===== Script manually interrupted by user (KeyboardInterrupt) =====")
    logger.info("Initiating graceful shutdown...")
except Exception as e:
    logger.critical(f"===== Critical error: Script terminated unexpectedly =====")
    logger.error(f"Error type: {type(e).__name__}")
    logger.error(f"Error message: {str(e)}")
    logger.error("Detailed traceback:")
    logger.error(traceback.format_exc())
    logger.info("Attempting to perform cleanup operations...")
finally:
    if ser is not None:
        logger.info("Closing the serial port connection...")
        try:
            ser.close()
            logger.info("Serial port closed successfully")
        except Exception as close_error:
            logger.error(f"Error while closing serial port: {str(close_error)}")
    logger.info("===== Script execution ended =====")

Please apply it to the previous code."

sestinj commented 3 weeks ago

thanks for sharing the extra detail. I have it on my short list to make improvements to our Claude prompt, so this example will be helpful. I'll let you know as soon as we have something better to share here!

kyleboddy commented 3 weeks ago

Awesome - thank you! Love the tool and appreciate your responsiveness. Let me know how I can help with any testing.