Repository navigation
Self-host: umask-safe upgrade/rollback; show SAM AI usage limit - #3012
simple-agent-manager[bot] wants to merge 8 commits into
Conversation
Operator entry points set umask 022 for their children, and every checkout the upgrade, its rollbacks and legacy adoption make re-applies git's file modes, so a umask 077 shell cannot leave the key agent's sources 0600. Private writers keep explicit 0600/0700 modes (tested under umask 000). Idea 01M89H1MQHJH432BFT2N43GHJJ. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A 429 from SAM's own AI proxy limit (monthly spending limit or daily token budget) was reported by the VM agent as provider_overloaded, so the chat showed "Provider overloaded · Recoverable". The VM agent now reports sam_ai_usage_limit_reached when the refusal carries the proxy's limit message, and does not park it as a provider plan limit. The failure card labels it "AI usage limit reached", not retryable, and hides the Recoverable badge for non-retryable failures. Real provider overloads are unchanged (tested). Settings > Usage: wording no longer claims AI Gateway traffic only, and the selected period button and bars use the defined bg-accent token (bg-accent-emphasis does not exist, so the label was invisible). The AI usage visual audit's stale budget mock and onboarding overlay are fixed and it leaves the quarantine. Idea 01M89JXTFHW4W3PQ65GTED6D0K. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
Merging this PR will not alter performance
Comparing Footnotes
|
…, tighter 429 evidence - restoreTrackedModes also makes directories holding tracked files traversable, never follows a symlinked parent out of the repository, and reports (never throws) per-path errors so a rollback cannot stop. - Entry points are proven by spawning them under umask 077; manual rollback is tested with real git under umask 077; legacy adoption uses an explicit checkout helper and an enumeration test covers all. - The VM agent needs typed 429 evidence (Claude rate_limit, a Codex turn error, or an API Error: 429 prefix) plus a standalone 429; SAM limit text is never parked as a provider reset. - FailureCard shows a neutral 'session still open' line for non-retryable failures; the last two bg-accent-emphasis uses are fixed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… calls Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
… upgrader Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 01881c5016
ℹ️ 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".
| retryable: false, | ||
| diagnosable: false, |
There was a problem hiding this comment.
Keep usage-limit failures diagnosable
When a non-conversation task terminates after hitting this limit, setting diagnosable: false makes the failure look like a normal lifecycle ending rather than an actionable failure. apps/api/src/services/inbox/system-errors.ts consequently skips the system-error item and notification, while apps/web/src/lib/chat-session-utils.ts places the failed session in stopped instead of failed; users can therefore miss the task failure entirely. Keep this classification diagnosable while leaving retryable: false.
Useful? React with 👍 / 👎.
| _, codex := data["codexErrorInfo"].(string) | ||
| return data["errorKind"] == "rate_limit" || (codex && isSAMUsageLimitText(message)) || apiError429(message) |
There was a problem hiding this comment.
Stop retrying recognized SAM limit failures
For a recognized SAM 429, ClassifyProviderLimit now deliberately returns nil, but shouldRetryPromptError only suppresses retries when promptProviderLimit is non-nil. It then falls through to isTransientProviderPromptError, which matches the same rate_limit_error/429 text, so the default configuration still makes two doomed retries after 15 and 30 seconds before reporting this explicitly non-retryable limit. Wire this predicate into the retry guard so a detected SAM limit fails immediately.
Useful? React with 👍 / 👎.
Seen live on the box: its user's umask is 002, so tracked files were 0664 and the exact-mode repair rewrote 12,581 of them to 0644. The repair now adds the bits everyone needs (read; execute for 100755) and never removes any, so a 0600 file still becomes 0644 and a 0664 file is left alone. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An opt-in test (SAM_LIVE_CLAUDE_ACP) runs claude-agent-acp 0.102.0 against a
local server answering with SAM's exact 429 bodies. All three refusals
classify as sam_ai_usage_limit_reached and a provider 429 stays
provider_overloaded. The adapter's real wire shape ('API Error: Request
rejected (429) · <message>', errorKind rate_limit) is now in the unit table.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 34d8a6ec82
ℹ️ 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".
| Usage from model calls made through SAM will appear here. Calls with your own API keys | ||
| or subscriptions are not tracked here. |
There was a problem hiding this comment.
Correct the claim that own-key calls are untracked
When a user or project API key is used through SAM's passthrough routes, attachUpstreamTokenUsageAccounting still records its token and provider usage, and GET /api/usage/ai merges those records into the totals. The page can therefore display requests made with the user's own key while this empty-state copy says such calls are not tracked; qualify this as calls made directly outside SAM instead.
Useful? React with 👍 / 👎.
- useOperatorUmask clears only the umask bits stricter than 022 (077 -> 022, 002 stays 002) instead of setting a fixed mask. - auth_failure.go names its provider prefixes once (hasProviderErrorPrefix). - The live Claude adapter test moves its setup into a helper. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 71f9042027
ℹ️ 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".
| if (!stat || !(kind === 'file' ? stat.isFile() : stat.isDirectory())) return; | ||
| if (want(stat.mode & 0o777) === (stat.mode & 0o777)) return; | ||
| if (!inside(path)) throw new Error('outside the repository'); | ||
| chmodSync(path, want(stat.mode & 0o777)); |
There was a problem hiding this comment.
Preserve special permission bits while repairing modes
When a tracked directory has the setgid bit, such as a shared operator checkout using mode 2700, this repair passes only the lower 0777 bits to chmodSync, so adding traversal access changes it to 0755 and silently removes setgid. Files created by later checkouts then stop inheriting the repository group and may become inaccessible to other operators, contradicting the helper's only-add guarantee; preserve the existing special bits when constructing the new mode.
Useful? React with 👍 / 👎.
|



Summary
Two self-host hardening fixes. Part 1 affects self-hosting only. Part 2 changes shared code, so hosted SAM also gets it: spending-limit refusals get a clearer label. Real provider overloads are unchanged, and tests prove it.
1. Upgrade and rollback no longer depend on the operator's umask (idea 01M89H1MQHJH432BFT2N43GHJJ). Self-hosting only.
umask 077checked out 111 tracked files as 0600. The key agent (non-root) got EACCES, and the automatic rollback failed the same way.scripts/selfhost/operator-files.ts:useOperatorUmask()clears every umask bit stricter than 022 (077 → 022; a looser 002 is kept) at the start ofupgrade.ts(including--rollback-from),deploy.ts,rebuild.tsandrestore.ts. Child git, pnpm and docker steps inherit it.checkoutWithTrackedModes()makes every tracked file world-readable (100755 files also world-executable) and every directory holding one traversable, after every checkout. It only adds bits, so a 0600 file becomes 0644 and a 0664 file is left alone. That covers the upgrade, both automatic rollback branches, manual rollback (upgrade-rollback.ts) and legacy adoption.secret-files.ts,backup-encryption.ts,backup-destination.ts). A test proves they stay 0600/0700 under umask 022 and 000.2. A spending-limit 429 no longer shows "Provider overloaded · Recoverable" (idea 01M89JXTFHW4W3PQ65GTED6D0K).
internal/acp/sam_usage_limit.go): when a 429 carries the SAM AI proxy's own refusal message (monthly spending limit or daily token budget), the reason issam_ai_usage_limit_reachedinstead ofprovider_overloaded.ClassifyProviderLimitno longer parks this as a provider plan limit.model-unavailableandunsupported-loopback-auth, where retrying likewise cannot help.bg-accent-emphasis, which is not a defined token, so the label was white on nothing. They now usebg-accent.apps/api/tests/unit/routes/ai-proxy-usage-limit-markers.test.tspins every proxy refusal builder to the Go markers, so wording drift fails CI.Validation
pnpm lint(changed files), selfhosttsc, web/shared typecheckpnpm test: selfhost suite 1327 passed (metadata-proxy.test.tsneedsnpm cilocally, as on main).pnpm selfhost:live-test, real Docker) locally on this branch: 19/19 files, 289 tests (legacy-adoption 12/12 after its fake git learned the mode-repair calls in 01881c5).internal/acpandinternal/serverpass. New shared, web and api tests pass.runUpgradepaths, the real-git manual rollback, and 3 real-git checkout tests).useOperatorUmask()fromrestore.tsturns its entry-point test red (entry points are spawned underumask 077).ClassifyPromptErrorcheck turns 6 SAM-limit cases red.ClassifyProviderLimitguard turns the parking test red.Staging Verification (REQUIRED for all code changes — merge-blocking)
Health Checkstep failed (run 45682370388), the known Cloudflare challenge to runners;https://api.sammy.party/healthanswered 200 from the workspace.Staging Verification Evidence
Self-host box (app.vmtest.sam2.party), all PASS. Encrypted backup was taken first; the run is posted on the channel.
umask 077shell, upgrade the PR head → a test ref that rewrotekey-agent/bundle-store.ts. The key agent was rebuilt and is healthy, health 200, and every tracked file is at its git mode.umask 077shell, run the printed--rollback-fromcommand, starting from the incident state (key-agent/*.ts0600, directory 0700). It printed "restored git file modes on 13 tracked paths" and "manual rollback completed". The key agent is healthy and health is 200.umask 077, upgrade to main. It repaired 14 paths and is healthy.The box is left on main
428f26206: sealed (gcp-kms), bundle head unchanged, replaceable, git clean, no pending journal. Its temporary SSH access is removed.Live run finding, fixed here in
cb9014856: the box user's umask is 002, and the first repair narrowed 12,581 files from 0664 to 0644. The repair now only adds bits.Local self-host live suite (
pnpm selfhost:live-test, real Docker): 19/19 files, 289 tests.Spending-limit refusal through the real agent adapter: the opt-in
TestLiveClaudeAdapterSAMUsageLimitran the pinnedclaude-agent-acp0.102.0 against a local server returning SAM's exact 429 bodies.Internal error: API Error: Request rejected (429) · <SAM message>witherrorKind: rate_limit.sam_ai_usage_limit_reached.provider_overloaded.Staging (hosted):
exceeded: true), both chats still ran: that user's Claude uses its own connected credential, not the SAM proxy (spend did not move).UI Compliance Checklist (Required for UI changes)
aria-pressedbuttons kept. The badge text is not the only signal; the label carries it.ai-usage-audit.spec.ts30/30; new chat failure cases 4/4)UI Screenshot Evidence
All screenshots below were taken with Playwright (local Vite preview with mocked API data,
apps/web/tests/playwright/).Surface: Settings > Usage period selector and subtitle
ai-usage-audit.spec.ts: normal data, long model names, 15 models, 30 days, empty state, API error, and light and dark themes. Selected-button contrast is asserted by computed colours.assertNoOverflowincluding the clipped-overflow walk). No issues found.Surface: Project chat failure card (AI usage limit vs provider overload)
project-chat-recoverable-error-audit.spec.ts: an active conversation task withsam_ai_usage_limit_reachedand, as a control,provider_overloaded, in the real chat shell.End-to-End Verification (Required for multi-component changes)
TestSAMUsageLimitPromptPathReportsTheLimitCodedrivesfinishPromptWithError→ broadcast/callback reason. The FailureCard and Playwright tests render that code in the real chat shell.umask 077on the self-host box; real pinned Claude adapter against SAM's 429 bodiesData Flow Trace
ai-proxy-admission.ts/ai-proxy-passthrough-errors.ts, usingmonthlyCostCapMessage.RequestError.session_host_prompt.go:finishPromptAttemptWithErrorcallsClassifyPromptError, which returnssam_ai_usage_limit_reached(fromsam_usage_limit.go).server.go:taskCallbackErrorMessage→ task callback →tasks.error_message.FloatingHeader/FailureCardcallclassifyFailure, which returnssam-ai-usage-limit.Untested Gaps
A live spending-limit 429 has not been run through a real VM to the chat card on a deployed installation. Staging's smoke user does not route Claude through the SAM proxy. The box would need the fake upstream enabled, a real node and an OTP sign-in. Each segment is covered instead:
taskCallbackErrorMessage);Post-Mortem (Required for bug fix PRs)
What broke
umask 077left the key agent's sources 0600. Both the upgrade and its automatic rollback failed, and the shared box was down for about 10 minutes.Root cause
git checkoutwrites files using the process umask, and the upgrade inherited the operator shell's umask.errorKind: rate_limittoprovider_overloaded, without separating SAM's own limit.Class of bug
Why it wasn't caught
All checkout tests used fake runners or ran under a default umask. No 429 test fed SAM's own refusal body.
Process fix included in this PR
Real-git tests under
umask 077, a pin test tying the proxy messages to the Go markers, and the usage audit taken off the quarantine.Post-mortem file
tasks/active/2026-11-25-selfhost-umask-and-spending-limit-label.mdSpecialist Review Evidence (Required for agent-authored PRs)
needs-human-reviewlabel added and merge deferred to human (N/A: all completed)API Error: 429prefix), standalone 429, new controls; LOW: SAM text never parked by the text pathbg-accent-emphasisuses; neutral "session still open" line for non-retryable failures; shorter subtitle and plainer explanation. Dark-theme accent contrast (3.3:1) is the existing design-system token, not this changeCodeRabbit Review Evidence (Required for agent-authored PRs)
CodeRabbit Notes
Requested at 19:09Z by adding the
coderabbit-reviewlabel when the PR was marked ready. The trusted request workflow failed at once withHTTP 401: Bad credentials, so the wait ended. That is the same token failure reported on #3009, and no CodeRabbit review arrived.Exceptions (If any)
Agent Preflight (Required)
Classification
External References
N/A: no external API changes. Node
process.umaskand git index modes (git ls-files --stage) are standard behaviour, verified by real-git tests.Codebase Impact Analysis
scripts/selfhost(upgrade, rollback, deploy, rebuild, restore, legacy adoption),packages/vm-agent/internal/acp(prompt error classification),packages/shared(failure classification),apps/web(FailureCard, Settings > Usage),apps/apitests only.Documentation & Specs
deploy/selfhost/README.md(umask note) andapps/www/src/content/docs/docs/reference/configuration.md(how a refused call is reported).Constitution & Risk Check
Principle XI: the umask value is a named constant, and the limit markers are a curated table cross-referenced with the TS source and pinned by a test. Risk: the marker match depends on the proxy wording. The pin test fails CI if it drifts.
🤖 Generated with Claude Code