Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Sep 16, 2025

Problem

The frontend was calling the changes_in_branch endpoint with stackId: "null" (string) instead of stackId: null (actual null value), causing API failures. The backend expects Option<StackId> but was receiving the string "null", which cannot be deserialized into the expected type.

Example of the failing API call:

{
  "projectId": "6b9eb2cd-016d-427d-872c-ec4e482b2387",
  "stackId": "null",
  "branch": "refs/heads/master"
}

Root Cause

URL parameters are always strings in web APIs. When a URL contains ?stackId=null, the URLSearchParams.get('stackId') method returns the string "null" instead of the actual null value. This string then gets passed through the application state and eventually to API calls where it should be null.

Solution

1. Fixed URL parameter processing

  • Updated workspace page to convert string "null" to actual null when reading URL parameters
  • Added comprehensive documentation explaining the web API behavior

2. Fixed API method calls

  • Updated branchChanges, branchChange, and branchChangesByPaths methods in stackService.svelte.ts to sanitize stackId parameters
  • Added conversion logic: stackId === 'null' ? null : stackId
  • Updated TypeScript types to accept string | null for stackId parameters

3. Updated mock backend

  • Modified validation functions to accept null values for stackId parameters
  • Ensures test environment matches the fixed behavior

Result

The backend now correctly receives:

{
  "projectId": "6b9eb2cd-016d-427d-872c-ec4e482b2387",
  "stackId": null,
  "branch": "refs/heads/master"
}

This resolves the API failure while maintaining backward compatibility with existing valid stackId values. The fix is defensive and only converts the specific problematic case while preserving all other values unchanged.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • esm.ubuntu.com
    • Triggering command: /usr/lib/apt/methods/https (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@Copilot Copilot AI assigned Copilot and Byron Sep 16, 2025
Copy link

vercel bot commented Sep 16, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
gitbutler-web Skipped Skipped Sep 16, 2025 1:35pm

@Copilot Copilot AI changed the title [WIP] When the frontend called the changes_in_branch endpoint with {"projectId":"6b9eb2cd-016d-427d-872c-ec4e482b2387","stackId":"null","branch":"refs/heads/master"}, it fails as "stack_id" should be null, not "null". Fix this. Fix stackId null handling in frontend API calls Sep 16, 2025
@Copilot Copilot AI requested a review from Byron September 16, 2025 11:30
Copilot finished work on behalf of Byron September 16, 2025 11:30
Copilot AI and others added 2 commits September 16, 2025 15:34
- Fix URL parameter parsing converting null to "null" string
- Update branchChanges methods to convert "null" string to null
- Update type signatures to accept string | null for stackId
- Update mock backend validation to accept null stackId values

Co-authored-by: Byron <[email protected]>
- linting
@Byron Byron force-pushed the copilot/fix-d84408ff-73d0-4c77-a4c1-11a587434065 branch from 1a9f42a to d441f04 Compare September 16, 2025 13:35
@Byron
Copy link
Collaborator

Byron commented Sep 16, 2025

The issue occurs in single-branch mode, a 'null' string sneaks in and can't be decoded in the backend, and I'd hope this can be type-safe in the frontend as well.

Before

I am seeing:

API error: (changes_in_branch)
An asynchronous operation failed.
invalid args `stackId` for command `changes_in_branch`: UUID parsing failed: invalid character: expected an optional prefix of `urn:uuid:` followed by [0-9a-fA-F-], found `n` at 1
Screenshot 2025-09-16 at 15 32 23

After

It works

Screenshot 2025-09-16 at 15 34 46

Conclusion

I think this is worth a look @mtsgrd, the PR fixes the issue, even though I have a feeling that the solution isn't good or optimal. I'd the fix here can be salvaged though. Thanks.

@Byron Byron requested a review from mtsgrd September 16, 2025 13:37
@Byron Byron marked this pull request as ready for review September 16, 2025 13:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants