Skip to content

fix(app): migrate app id helper off the legacy 0x1000-shifted 48-bit encoding (#271) - #273

Merged
LeXwDeX merged 1 commit into
devfrom
fix/app-id-encoder
Aug 15, 2026
Merged

fix(app): migrate app id helper off the legacy 0x1000-shifted 48-bit encoding (#271)#273
LeXwDeX merged 1 commit into
devfrom
fix/app-id-encoder

Conversation

@LeXwDeX

@LeXwDeX LeXwDeX commented Aug 15, 2026

Copy link
Copy Markdown
Owner

Why

packages/app carried a private legacy ts*0x1000 + counter 48-bit id generator while core/schema moved to raw 48-bit-ms time-prefix ids (PR #265) — divergent generators risk cross-package ordering breakage and drift.

What

  • generateID now wraps the shared @opencode-ai/schema/identifier create() (raw 48-bit ms + monotonic latch); the Identifier.ascending/descending public API is preserved.
  • rg '0x1000' packages/app → no matches.

Tests

Raw-ms decode pinned against legacy 12-bit shift · 6-prefix shape · burst ascending · strict descending · given-id passthrough · wrong-prefix throw · wrap-boundary + clock-regression suite mirroring packages/schema/test/identifier.test.ts (same WRAP_BOUNDARY) · app-vs-core same-wall-clock decode (drift 0-5ms).

Gates

app 453/0 (78 files) · desktop 49/0 · schema 16/0 · app+desktop typecheck exit 0 · lint 4849/0.

Review: independent verify + standards/intent arbitration ACCEPT.

Closes #271.

… encoding

Root cause: packages/app/src/utils/id.ts still encoded timestamp * 4096 +
counter into the 48-bit id prefix — the scheme that wrapped at epoch
1786706395136 (2026-08-14 19:19:55.136 +08) and was replaced everywhere else
by the shared fixed generator (PR #265). The app generates message and part
ids client-side, so every app-created id after the wrap carried a restarted
prefix: it no longer decoded back to wall-clock time and sorted against
core-generated ids as if it came from a different era.

Migration: generateID now delegates to the shared fixed generator in
@opencode-ai/schema/identifier (raw 48-bit ms behind a monotonic latch), so
app ids share one encoding with core ids. The Identifier namespace API is
unchanged — ascending/descending with the app prefix map and given-id
passthrough/validation. The legacy module had no timestamp() decode API with
live callers in app/desktop, so nothing needed re-implementing there.

Coverage: id.test.ts pins the app boundary — raw-ms decode of live ids,
prefix/shape for all six prefixes, app-vs-core same-wall-clock sort
consistency, burst and descending ordering, given-id passthrough and
validation; two probes were red against the legacy encoder (decoded prefix
189982101517 vs 1786752772485 wall-clock; app-vs-core drift ~1.6e12 ms) and
are green after. id-wrap-boundary.test.ts mirrors
packages/schema/test/identifier.test.ts through the app's generator seam.
Declared @opencode-ai/schema as an app workspace dependency.

Evidence: app unit 453/453, desktop 49/49, schema 16/16, typecheck green in
packages/app and packages/desktop, rg 0x1000 packages/app clean, root lint
4849 warnings (budget untouched), spot-check app vs core msg_ prefix drift
1 ms.

Refs #271
@LeXwDeX
LeXwDeX merged commit 994f0a3 into dev Aug 15, 2026
5 checks passed
@LeXwDeX
LeXwDeX deleted the fix/app-id-encoder branch August 15, 2026 02:13
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