Public: anyone can read this; the crew can change it.

A token's last-used time shows on its row in settings, so an unused token is easy to spot and revoke #14165

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

Most of this already existed on main: token.lastusedat was stored, verifyToken wrote it, the settings row showed it, and MCP tokens and GET /api/v1/tokens already returned lastUsedAt. This pull fills the three gaps the issue names.

Notes

shipped production is serving it deploy 4adf612

opened this

Most of this already existed on main: token.last_used_at was stored, verifyToken wrote it, the settings row showed it, and MCP tokens and GET /api/v1/tokens already returned lastUsedAt. This pull fills the three gaps the issue names.

  • Hourly write: TOUCH_EVERY_MS in src/core/tokens.ts changes from one minute to one hour, so each token gets at most one write an hour. The check compares against the token row verifyToken already reads, so it adds no query. A refused token (unknown, expired, or belonging to a suspended person) returns before the write, so it is never marked as used.
  • Settings wording: the row in Settings › Access codes (src/web/pages/account.ts) now reads "last used 3d ago" or "never used". Before, an unused token read "last used never".
  • Tests: the new test/token-last-used.test.ts checks that:
    • a use is written once, not again within 59 minutes, and again after 61;
    • an expired or suspended person's token, and an expired token sent over HTTP (answered 401), never write the timestamp;
    • the settings row shows "last used 3d ago" and "never used";
    • the MCP tokens answer carries the same lastUsedAt, including null for an unused token.

    The existing test in test/scale.test.ts was written for the one-minute window, so I moved its backdated time to two hours ago. The test was right for the old rule; the rule changed. The oauth_grants.ts comment now says hourly.

Left out:

  • The time reads "3d ago" rather than "3 days ago". That is the format timeAgo uses everywhere, and the issue's wording is close enough that I kept the shared helper.
  • A request refused later for its scope (for example a read-only token trying to write) still counts as a use, because the token itself is valid.
  • No new MCP tool and no API change; the field was already there.

Checks run: the gate, tsc, design-lint and mcp-size are green. scripts/fast.ts named 2,339 files for this change, so instead I ran the 32 test files that touch tokens, the settings tokens page or lastUsedAt: 309 pass, 0 fail.

Try it: open /settings/tokens and make an access code; its row reads "never used". Call the API with it and reload; the row reads "last used just now".

🤖 Generated with Claude Code

Closes #14120

6 earlier comments
commented

Most of this already existed on main: token.last_used_at was stored, verifyToken wrote it, the settings row showed it, and MCP tokens and GET /api/v1/tokens already returned lastUsedAt. This pull fills the three gaps the issue names.

  • Hourly write: TOUCH_EVERY_MS in src/core/tokens.ts changes from one minute to one hour, so each token gets at most one write an hour. The check compares against the token row verifyToken already reads, so it adds no query. A refused token (unknown, expired, or belonging to a suspended person) returns before the write, so it is never marked as used.
  • Settings wording: the row in Settings › Access codes (src/web/pages/account.ts) now reads "last used 3d ago" or "never used". Before, an unused token read "last used never".
  • Tests: the new test/token-last-used.test.ts checks that:
    • a use is written once, not again within 59 minutes, and again after 61;
    • an expired or suspended person's token, and an expired token sent over HTTP (answered 401), never write the timestamp;
    • the settings row shows "last used 3d ago" and "never used";
    • the MCP tokens answer carries the same lastUsedAt, including null for an unused token.

    The existing test in test/scale.test.ts was written for the one-minute window, so I moved its backdated time to two hours ago. The test was right for the old rule; the rule changed. The oauth_grants.ts comment now says hourly.

Left out:

  • The time reads "3d ago" rather than "3 days ago". That is the format timeAgo uses everywhere, and the issue's wording is close enough that I kept the shared helper.
  • A request refused later for its scope (for example a read-only token trying to write) still counts as a use, because the token itself is valid.
  • No new MCP tool and no API change; the field was already there.

Checks run: the gate, tsc, design-lint and mcp-size are green. scripts/fast.ts named 2,339 files for this change, so instead I ran the 32 test files that touch tokens, the settings tokens page or lastUsedAt: 309 pass, 0 fail.

Try it: open /settings/tokens and make an access code; its row reads "never used". Call the API with it and reload; the row reads "last used just now".

🤖 Generated with Claude Code

commented

<!-- look-pages 50e144594949 --> Look pages for 50e1445, from the gate:

  • look pages (none): this pull changes src/web/pages/account.ts but the forge could not trace the route of /settings/security/controls (an inline or wrapped handler), so it could not infer a page; the reviewer decides. A "Looks: <path>" line naming the nearest page, or a "No look: <why>" line (10+ characters), says it
commented

A token's last use is now saved at most once an hour per token, and its row on Settings › Tokens reads "last used 3d ago", or "never used" until the token first answers a request. The terminal's Signed in screen now shows token rows the same way. Browser and terminal-key rows there still read "last seen …". A token that is refused (unknown, expired, or its person suspended) is never recorded as used.

  • Write throttle: TOUCH_EVERY_MS in src/core/tokens.ts went from a minute to an hour. A token is checked by reading its row anyway, so the throttle adds no extra query. This needed matching changes in src/core/oauth_grants.ts and test/scale.test.ts.
  • Page row: the wording change is in src/web/pages/account.ts.
  • Terminal row: the matching change is in src/tui/screens/signins.ts.
  • How-to: docs/features/token-last-used.md is new.
  • Commit-message lines: one commit names a page the forge can screenshot (Looks: /settings/security/controls), because /settings/tokens is not in the screenshot list in forge.json. It also carries a Direction: line for the gate's "pipeline first" rule, which a new features doc triggers.

Tests:

  • test/token-last-used.test.ts covers the hourly write, refused tokens, and the page row.
  • A new case in test/tui-signins-token.test.ts checks that the terminal row reads "never used", then "last used just now" once the token is used.

The gate, tsc --noEmit and those three test files pass (14 tests); the full suite was not run here.

Not done:

  • The other "used" lines in the terminal (computer keys, passkeys, cloud) keep their own wording.
  • The over-length comment lines in src/core/tokens.ts and src/tui/screens/signins.ts are left for the nightly rewrap.

Try it: open /settings/tokens and make an access code; its row reads "never used". Call the API with it and reload: it reads "last used just now". In the terminal, open the palette with ctrl-k and choose Signed in: the token's row reads the same.

🤖 Generated with Claude Code

commented

<!-- look-pages a3c290d12412 --> Look pages for a3c290d, from the gate:

  • look pages (named): this pull changes src/web/pages/account.ts; a commit names /settings/security/controls
commented

A token's last use is now saved at most once an hour per token, and its row reads "last used 3d ago", or "never used" until the token first answers a request. Settings › Tokens and the terminal's Signed in screen both show it this way; browser and terminal-key rows there still read "last seen …". A token that is refused (unknown, expired, or its person suspended) is never recorded as used.

Code:

  • Write throttle: TOUCH_EVERY_MS in src/core/tokens.ts went from a minute to an hour. A token is checked by reading its row anyway, so the throttle adds no extra query. This needed matching changes in src/core/oauth_grants.ts and test/scale.test.ts.
  • Page row: the wording change is in src/web/pages/account.ts.
  • Terminal row: the matching change is in src/tui/screens/signins.ts.
  • How-to: docs/features/token-last-used.md is new, with a row in docs/features/README.md.

Tests:

  • test/token-last-used.test.ts covers the hourly write, refused tokens, and the page row.
  • A new case in test/tui-signins-token.test.ts checks that the terminal row reads "never used", then "last used just now" once the token is used.
  • test/tui-token-make.test.ts was out of date, not the code: it expected the old "last seen never" on a token row, and now expects "never used".

test/attention.test.ts ("each page stays inside its first-view budget") failed on the previous check, but it passes here on this branch and with current main merged in, so I couldn't reproduce it. The settings page is at 144 of 146 words in that budget.

The gate, tsc --noEmit and the six affected test files pass (31 tests); the full suite was not run here.

Commit-message lines: one commit names a page the forge can screenshot (Looks: /settings/security/controls), because /settings/tokens is not in the screenshot list in forge.json. It also carries a Direction: line for the gate's "pipeline first" rule, which a new features doc triggers.

Not done: the other "used" lines in the terminal (computer keys, passkeys, cloud) keep their own wording.

Try it: open /settings/tokens and make an access code; its row reads "never used". Call the API with it and reload: it reads "last used just now". In the terminal, open the palette with ctrl-k and choose Signed in: the token's row reads the same.

🤖 Generated with Claude Code

commented

<!-- look-pages 2401dd703ec5 --> Look pages for 2401dd7, from the gate:

  • look pages (named): this pull changes src/web/pages/account.ts; a commit names /settings/security/controls
commented

Each token row on Settings › Tokens now shows when the token was last used: "last used 3d ago", or "never used" if it has never been used. That makes an idle token easy to spot and revoke. The last-used time is saved at most once an hour per token, not on every request, so busy API callers don't cause a database write each time (src/core/tokens.ts, src/core/oauth_grants.ts). The terminal's Signed in screen uses the same words for each token (src/tui/screens/signins.ts). The how-to is docs/features/token-last-used.md, listed in docs/features/README.md.

test/tui-token-make.test.ts expected the old "last seen never" text, so I changed that test to expect "never used"; the code was right and the test was out of date. The tsc type check passes, and so do test/token-last-used.test.ts, test/tui-signins-token.test.ts and test/tui-token-make.test.ts. test/scale.test.ts also changed and was not re-run with the last push; the forge's check runs it.

Pictures: an earlier commit pointed the before/after pictures at /settings/security/controls. That page shows no token rows, so its pictures would show no change. The only change under src/web/ is one line of a token row on /settings/tokens, and that page is not in app.looks. Old commit messages can't be rewritten without a force push, so the last commit adds a No look: line instead, which replaces the wrong page. I chose not to add /settings/tokens to app.looks: its picture slots are kept deliberately few, and the preview owner has no tokens, so the picture wouldn't show this text anyway.

The desk note asking to hold changes while production rolls out doesn't affect this pull, because nothing lands until a person merges it.

To try it: open /settings/tokens and make an access code; its row reads "never used". Call the API with it and reload; the row reads "last used just now".

🤖 Generated with Claude Code

Approved

Clean, small, and does what the issue asks. The throttle moves to an hour on the row verifyToken already reads (no extra query); refused tokens return before the write; the settings row and the terminal Signed in screen read the same words; the how-to is in docs/features, not README. Tests would fail without the change (hourly boundary at 59/61 min, refused expired/suspended/HTTP 401, settings row, MCP lastUsedAt, TUI row). Minor, non-blocking: the new test header says Settings › Access codes while the doc says Tokens; one new comment line in signins.ts is over-length (nightly rewrap). Box 2: the MCP/API field already existed and is ISO, the same stored value the page renders; the test proves it carries lastUsedAt incl. null.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs