Skip to content

Fix App Studio first-turn integration conflicts - #1077

Merged
cwilhit merged 2 commits into
mainfrom
codex/app-studio-first-turn-conflict
Nov 12, 2026
Merged

cwilhit merged 2 commits into
mainfrom
codex/app-studio-first-turn-conflict

Conversation

@cwilhit

@cwilhit cwilhit commented Nov 11, 2026

Copy link
Copy Markdown
Collaborator

Summary

Project creation can succeed while the first assistant request fails with a conflict. Automatic integration discovery previously saved the whole Project using its resource version, which can change while the controller reconciles status.

  • Patch only spec.environments, guarded by the Project UID and generation. Reload and merge after a concurrent spec edit so existing bindings and revocations survive.
  • Return HTTP 409 when confirmed generation conflicts exhaust the retry limit. Preserve schema validation errors and their field details.
  • Cover concurrent status reconciliation, binding revocation, Project replacement, retry exhaustion, and structured validation errors.

Verification

  • App Studio API test suite
  • Server-side dry runs against the regular Tilt kcp API confirmed that a stale generation returns a generic 422 and schema validation returns a 422 with field-level causes.

@cwilhit

cwilhit commented Nov 11, 2026

Copy link
Copy Markdown
Collaborator Author

@mjudeikis-bot review

@mjudeikis mjudeikis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One Note, no Critical or Warning findings.

What the PR does vs. the code: replaces the whole-Project Update with a JSON Patch (test uid, test generation, add /spec/environments), reloads and re-merges on a stale guard, and maps exhausted confirmed conflicts to 409. The code matches that description.

Checked

  • Read beyond the diff: materializeAutomaticProjectIntegrations and its caller flow (projectIdentityToken refresh), writeAssistantThreadError (assistant_threads.go), writeProjectError (projects.go), writeError (http.go: Conflict->409, Invalid->400), TypedResource.Patch in providers/app-studio/client.
  • Correctness: retry loop terminates (bounded by automaticIntegrationUpdateAttempts); the last-attempt, UID-change and deletion-timestamp exits all break with the right error; the retry now materializes the filtered materializable set (the old code used unfiltered targets on retry). No defect found.
  • Concurrency: status-only updates do not bump generation, so the guard does not trip on status reconciliation. A spec edit trips the guard and the reload merges onto the latest object. No defect found.
  • Tenancy/kcp: the client is the caller-scoped per-request client; no fixed workspace, no new credential. Not applicable beyond that.
  • Provider contract, API/codegen, portal, security: not applicable (no manifest, chart, API type, route or portal change; no credential reaches an error string).
  • Tests: new tests cover concurrent status, concurrent revocation, replacement Project (UID), retry exhaustion -> 409, and validation error preserved without reload. The classification of the stale-guard 422 is only tested with a synthetic error built to match the heuristic (see the Note).
  • Commands: cd providers/app-studio && go build ./... OK; go vet ./api/ OK; go test -count=1 ./api/ OK. Root make lint and the e2e suites were not run: the change is confined to the standalone provider module and its unit tests, and the e2e needs a Tilt/kcp stack.

return nil, fmt.Errorf("persist automatic provider integrations: %w", lastErr)
}

func isAutomaticIntegrationPatchRejection(err error) bool {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: Stale-guard detection depends on kcp returning a detail-less 422
isAutomaticIntegrationPatchRejection treats any 422 with empty Details as a failed test op. The unit tests feed it a synthetic NewGenericServerResponse(422) built to match, so only the manual dry run backs the real kcp shape. A different 422 with no details (for example from an admission webhook) is also reloaded once. It is bounded and returns the original error when the generation is unchanged, so this is contained. When the generation is unchanged, the caller gets that raw 422 mapped to 400 by writeError. Consider noting the kcp assumption next to the function, or covering it in an e2e that races a spec edit against a first turn.

// kcp reports a failed JSON Patch `test` op as a detail-less 422; see e2e <name>.

@cwilhit
cwilhit merged commit 8d977cb into main Nov 12, 2026
41 checks passed
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