Skip to content

fix: stop resetting an emptied custom agent id mid-typing - #362

Merged
RAIT-09 merged 1 commit into
devfrom
fix/custom-agent-id-typing
Jul 15, 2026
Merged

fix: stop resetting an emptied custom agent id mid-typing#362
RAIT-09 merged 1 commit into
devfrom
fix/custom-agent-id-typing

Conversation

@RAIT-09

@RAIT-09 RAIT-09 commented Jul 15, 2026

Copy link
Copy Markdown
Owner

Description

Retyping a custom agent's ID was nearly impossible: the moment the field went empty (deleting the last character), the per-keystroke onChange regenerated the default id (custom-agent) and wrote it straight back into the input. Deleting custom-agent character by character snapped back to custom-agent on the last backspace — the only workaround was select-all-and-overwrite.

The repair logic itself is legitimate (ids are keys — section open-state, defaultAgentId retargeting, and every keystroke persists via flushSettings() — so settings must never hold an empty id), but it ran at the wrong time. The same field already established the right timing for exactly this reason: the preset-collision check validates on blur, with a comment noting that per-keystroke validation misfires because onChange commits every intermediate value.

This PR moves the empty handling to the same model:

  • onChange skips empty values entirely. An empty field is a transient state while retyping; settings keep the last valid id, so the "no empty id in settings" invariant is now guaranteed by never committing one rather than by regenerating.
  • Blur restores an abandoned-empty field. Since settings always hold the last valid id, the field just gets it back — no regeneration, no rekey, no save. The restore falls through to the existing preset-collision check, so the edge case "type a reserved preset id (committed), select-all delete, blur" still gets the suffix-rename repair.

The Display name field is deliberately left unchanged: its blank-means-fallback model suits a derived cosmetic value, while an identity key that is referenced elsewhere (fence agent: pins, saved sessions, per-agent last-used maps) should conservatively restore rather than silently swap to a generated default.

Related issue

None (reported during manual testing).

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Refactor
  • Other

Checklist

  • npm run lint passes ("Use sentence case for UI text" errors are acceptable for brand names)
  • npm run build passes
  • Tested in Obsidian
  • Existing functionality still works
  • Documentation updated if needed (no docs describe the old reset behavior)

Testing environment

  • Agent: N/A (settings tab input handling only). Verified: deleting an id character by character no longer snaps back, abandoning an empty field restores the last valid id on blur, the preset-collision repair still fires after an empty-field blur, open sections survive renames, and the default agent follows a rename
  • OS: macOS

Screenshots

N/A

Summary by CodeRabbit

  • Bug Fixes
    • Improved custom agent ID editing by allowing the field to remain temporarily empty while typing.
    • Prevented unintended ID changes when an empty value is abandoned.
    • Restored the last valid custom agent ID when leaving the field without entering a replacement.

The per-keystroke onChange regenerated the default id and wrote it back
into the field the moment it went empty, so retyping an id required
select-all. Empty is now a transient state: nothing commits while empty,
and blur restores the last valid id if the field is abandoned.
@RAIT-09 RAIT-09 self-assigned this Jul 15, 2026
@coderabbitai

coderabbitai Bot commented Jul 15, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 9acfb304-e028-4d9f-86d5-2b6492141d55

📥 Commits

Reviewing files that changed from the base of the PR and between 28a4265 and 5f3b54d.

📒 Files selected for processing (1)
  • src/ui/SettingsTab.ts

📝 Walkthrough

Walkthrough

Custom agent ID editing now treats empty input as a transient state, preserving the committed ID until a non-empty value is entered and restoring it when the field loses focus.

Changes

Custom agent ID editing

Layer / File(s) Summary
Empty ID editing and blur restoration
src/ui/SettingsTab.ts
Empty changes no longer commit generated IDs or rekey state; blur restores the last committed ID before the existing collision and rename flow.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Suggested reviewers: donivatamazondotcom

Poem

I cleared the field, then paused my hop,
The saved ID stayed safely atop.
No phantom name was born anew,
Blur brought back the value true.
A tidy setting, bright and neat! 🐇

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately describes the main behavior change to custom agent ID editing.
Description check ✅ Passed The description follows the template and includes the change summary, issue, type, checklist, testing environment, and screenshots status.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/custom-agent-id-typing

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@RAIT-09
RAIT-09 merged commit 63b3cd4 into dev Jul 15, 2026
2 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.

1 participant