Skip to content

fix(management): preserve auth metadata and Codex priority on save#3843

Open
drwpls wants to merge 4 commits into
router-for-me:devfrom
drwpls:pr/preserve-auth-metadata
Open

fix(management): preserve auth metadata and Codex priority on save#3843
drwpls wants to merge 4 commits into
router-for-me:devfrom
drwpls:pr/preserve-auth-metadata

Conversation

@drwpls

@drwpls drwpls commented Jun 14, 2026

Copy link
Copy Markdown

Summary

When updating an auth file via the management API (status/fields patch), the save path previously serialized only the in-memory metadata payload. Any field that existed only on disk — and was not part of the update — was silently dropped. For Codex accounts this notably lost the account priority and subscription metadata on a simple enable/disable toggle.

This PR makes the save merge the existing on-disk metadata with the incoming update, so fields the caller did not send are preserved.

Behavior

  • On save, existing metadata is read from the auth file and merged under the incoming metadata (incoming wins).
  • The provider type is backfilled only when missing/unknown, and the disabled flag is always written.
  • Status/fields patches preserve unspecified metadata (including Codex priority) instead of overwriting the record wholesale.

Changes

  • sdk/auth/filestore.go — add mergeAuthMetadataForSave(path, metadata, provider, disabled); the token store Save now merges with on-disk metadata before writing.
  • internal/api/handlers/management/auth_files.gomergeAuthFileStatusMetadata / readAuthMetadataForStatusPatch preserve existing metadata and Codex priority on a status patch.
  • internal/api/handlers/management/config_lists.go — keep metadata intact on the related delete path.
  • Unit tests: disabled-flag persistence, partial-metadata merge, and a regression test asserting an on-disk priority survives a partial-metadata save.

Testing

  • go build ./...
  • go test ./internal/api/handlers/management/... ./sdk/auth/... — all pass
  • gofmt/go vet clean

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request introduces metadata merging capabilities when updating auth file statuses and adds support for updating the priority of Codex keys. Specifically, it updates the PatchAuthFileStatus handler and the file token store to merge existing on-disk metadata with incoming request metadata, preventing the loss of existing fields. It also adds corresponding unit tests. The review feedback suggests extending this metadata merging logic to the auth.Storage != nil case in the file token store to prevent potential data loss during token saves, and simplifying the merging logic in the handler by removing redundant conditional branches.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread sdk/auth/filestore.go Outdated
Comment thread internal/api/handlers/management/auth_files.go

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a6ca9ea607

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread sdk/auth/filestore.go Outdated
The token store previously re-merged on-disk metadata on every save. That
preserved fields omitted from a partial update, but it also resurrected keys
a caller intentionally removed: clearing all custom headers via
PATCH /auth-files/fields would reappear after the next save/reload.

Field preservation already happens at the handler layer, where intent is
known: mergeAuthFileStatusMetadata reads the on-disk metadata and merges it
under the in-memory record and the request before persisting. The store now
writes exactly the metadata it is given (only backfilling type and setting
disabled), so deletions stick while existing fields are still preserved by the
handler.

Also layer the status-patch merge as disk -> in-memory -> request so an
in-memory update (e.g. a token refresh not yet flushed) is not overwritten by
the on-disk baseline.

Tests:
- store writes metadata verbatim and drops keys absent from the update
- clearing all headers via the fields patch persists to disk
- existing status-patch preservation still holds
@drwpls drwpls force-pushed the pr/preserve-auth-metadata branch from a6ca9ea to 7eee71f Compare June 14, 2026 11:29

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7eee71f236

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread internal/api/handlers/management/auth_files.go
…patch

The scheduler derives an account's priority from Attributes["priority"], not
Metadata. When the status patch merged a priority preserved from disk into the
record's metadata, it did not mirror it into attributes, so re-enabling an
account whose in-memory attributes lacked the priority scheduled it at 0 until
the next reload. Sync the merged priority into attributes (as the fields patch
already does).

Test: status patch on a partial record syncs the disk priority into attributes.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f18c00232e

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread internal/api/handlers/management/auth_files.go Outdated
Extend the status-patch repair beyond priority: when the merge pulls metadata
off disk into a partial in-memory record, mirror every runtime-affecting root
(custom headers, proxy_url, prefix, priority, note, websockets) into the
runtime fields/attributes via syncAuthFileMetadataFields. Otherwise a
re-enabled credential could run without its configured headers or proxy until a
later file reload, since executors read those from attributes/Auth fields.

Test: status patch on a partial record syncs priority, proxy_url and custom
headers from the merged metadata.
@drwpls

drwpls commented Jun 14, 2026

Copy link
Copy Markdown
Author

@hkfires bro can you have a look

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.

1 participant