Skip to content

refactor: replace new Promise with Promise.withResolvers per AGENTS.md#3336

Open
oldschoola wants to merge 3 commits into
can1357:mainfrom
oldschoola:refactor/with-resolvers-cleanup
Open

refactor: replace new Promise with Promise.withResolvers per AGENTS.md#3336
oldschoola wants to merge 3 commits into
can1357:mainfrom
oldschoola:refactor/with-resolvers-cleanup

Conversation

@oldschoola

Copy link
Copy Markdown
Contributor

Summary

Replaces new Promise((resolve, reject) => ...) with Promise.withResolvers() in 4 files, per the AGENTS.md convention: "use Promise.withResolvers() instead of new Promise((resolve, reject) => ...)".

Files changed

  • packages/ai/src/registry/oauth/callback-server.ts#waitForCallback assigns resolve/reject to instance fields
  • packages/ai/src/auth-storage.tsraceUsageWithSignal wraps promise + abort signal
  • packages/ai/src/auth-broker/remote-store.ts#raceWithSignal wraps promise + abort signal
  • packages/coding-agent/src/modes/print-mode.ts — stdout flush wrapper

Verification

  • bun check passes
  • 16 tests pass across auth-broker-refresher, auth-storage-usage-cache, callback-server-manual-input

@github-actions github-actions Bot added the vouched Passed the vouch gate label Jun 23, 2026
@roboomp roboomp added auth Authentication and login flows refactor review:p1 triaged labels Jun 23, 2026

@roboomp roboomp left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks @oldschoola — clean, scoped follow-up to the Promise.withResolvers() convention in AGENTS.md. Rank p1: semantics are preserved across all four helpers (the abort-listener wiring in callback-server.ts, auth-storage.ts, and auth-broker/remote-store.ts is observably identical, and print-mode.ts's sync-throw path stays equivalent under the async wrapper). Affected tests (auth-broker-refresher, auth-storage-usage-cache, callback-server-manual-input, auth-broker-remote-store, remote-auth-store) pass locally.

One should-fix nit: both changelog entries are missing the external-contribution attribution ([#3336] + [@oldschoola]) called out in AGENTS.md. One nit on print-mode.ts documenting the (harmless) shift in where a synchronous stdout.write throw surfaces. Neither blocks merge.

Comment thread packages/ai/CHANGELOG.md Outdated

### Changed

- Replaced `new Promise((resolve, reject) => ...)` with `Promise.withResolvers()` in `callback-server.ts` and `auth-storage.ts`/`auth-broker/remote-store.ts` race-with-signal helpers, per the project convention.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

should-fix: per AGENTS.md ("External contributions: Added feature X ([#456](https://github.com/can1357/oh-my-pi/pull/456) by [@username](https://github.com/username))"), this entry should carry the PR + author attribution. Suggest appending ([#3336](https://github.com/can1357/oh-my-pi/pull/3336) by [@oldschoola](https://github.com/oldschoola)). Same for packages/coding-agent/CHANGELOG.md.

else resolve();
});
const { promise, resolve, reject } = Promise.withResolvers<void>();
process.stdout.write("", err => {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: small semantic shift worth a glance — in the previous form, a synchronous throw from process.stdout.write(...) was caught by the Promise executor and surfaced as a rejection. After the refactor it propagates synchronously out of the call before await promise runs. Because runPrintMode is async the caller still observes a rejected promise, so the contract is unchanged — flagging only so reviewers don't have to re-verify. No change requested.

@oldschoola

Copy link
Copy Markdown
Contributor Author

Both review comments addressed in the latest push:

  1. CHANGELOG attribution: Added ([#3336](https://github.com/can1357/oh-my-pi/pull/3336) by [@oldschoola](https://github.com/oldschoola)) to both CHANGELOG entries.

  2. Sync-throw safety: Wrapped process.stdout.write(...) in a try-catch so synchronous throws (e.g. destroyed stdout) are converted to rejections, matching the original new Promise executor behavior.

Replaced new Promise((resolve, reject) => ...) with
Promise.withResolvers() in 4 files:
- packages/ai/src/registry/oauth/callback-server.ts
- packages/ai/src/auth-storage.ts (raceUsageWithSignal)
- packages/ai/src/auth-broker/remote-store.ts (#raceWithSignal)
- packages/coding-agent/src/modes/print-mode.ts
…bution

- Wrap process.stdout.write in try-catch so synchronous throws
  (e.g. destroyed stdout) are converted to rejections, matching
  the original Promise executor behavior.
- Add PR + author attribution to both CHANGELOG entries per AGENTS.md.
@oldschoola oldschoola force-pushed the refactor/with-resolvers-cleanup branch from 958dbef to b2748c5 Compare June 23, 2026 23:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auth Authentication and login flows refactor review:p1 triaged vouched Passed the vouch gate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants