Skip to content

Commit 87bc1e9

Browse files
ScottArbeitScott Arbeit
andauthored
Rewrite client-side GraceStatus storage to use SQLite (#61)
* WIP: moving worktree, rebasing on main * Improve local state DB schema and tests * Rewrite of the client-side GraceStatus storage from compressed MsgPack to SQLite. Improvements to Aspire setup. Doc updates. More tests. --------- Co-authored-by: Scott Arbeit <scottarbeit@github.com>
1 parent a75f110 commit 87bc1e9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+4138
-675
lines changed

.grace/graceconfig.json

Lines changed: 0 additions & 38 deletions
This file was deleted.

AGENTS.md

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,9 @@ More context:
2828

2929
## Issue Tracking
3030

31-
This project uses **bd (beads)** for issue tracking.
32-
Always use `bd` commands to manage your work.
33-
When creating beads, include a description.
34-
Run `bd prime` for workflow context, or install hooks (`bd hooks install`) for auto-injection.
35-
36-
**Quick reference:**
37-
38-
- `bd ready` - Find unblocked work
39-
- `bd create "Title" --type task --priority 2` - Create issue
40-
- `bd close <id>` - Complete work
41-
- `bd sync` - Sync with git (run at session end)
42-
43-
For full workflow details: `bd prime`
31+
- Use the repository’s issue tracker (or the ticket/work item provided in the prompt) to scope and reference work, or follow other explicit work-tracking instructions provided in the prompt.
32+
- Keep work items small and independently verifiable.
33+
- Reference the relevant issue/ticket/work item ID in PR descriptions and (when applicable) commit messages.
4434

4535
## Markdown guidelines
4636

@@ -61,10 +51,13 @@ When updating documentation files, follow these guidelines:
6151
- Show all scripting examples in both (first) PowerShell and (then, second) bash/zsh, where applicable. bash and zsh are always spelled in lowercase. Good example:
6252

6353
PowerShell:
54+
6455
```powershell
6556
$env:GRACE_SERVER_URI="http://localhost:5000"
6657
```
58+
6759
bash / zsh:
60+
6861
```bash
6962
export GRACE_SERVER_URI="http://localhost:5000"
7063
```

docs/Authentication.md

Lines changed: 139 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -687,17 +687,147 @@ You can create Auth0 resources non-interactively.
687687

688688
## Troubleshooting
689689

690-
### `grace auth login` fails and mentions refresh tokens
691-
692-
Ensure:
690+
### `grace auth login` fails and mentions refresh tokens
691+
692+
Ensure:
693693

694694
* the Auth0 API has **Allow Offline Access** enabled
695-
* the Auth0 Native app allows refresh tokens and is configured to issue them
696-
* `grace__auth__oidc__cli_scopes` includes `offline_access`
697-
698-
### Headless environments / CI
699-
700-
Use:
695+
* the Auth0 Native app allows refresh tokens and is configured to issue them
696+
* `grace__auth__oidc__cli_scopes` includes `offline_access`
697+
698+
### `grace status` returns `Unauthorized` and Grace.Server logs look empty
699+
700+
This usually means the CLI sent branch status requests without a usable token.
701+
702+
Common causes:
703+
704+
* No interactive token is cached yet.
705+
* `GRACE_TOKEN` is not set (or is invalid).
706+
* You are expecting endpoint handler logs, but the request is rejected by authentication middleware first.
707+
708+
Quick checks:
709+
710+
PowerShell:
711+
712+
```powershell
713+
grace auth status --output Verbose
714+
grace auth token status --output Verbose
715+
grace status --output Verbose
716+
```
717+
718+
bash / zsh:
719+
720+
```bash
721+
grace auth status --output Verbose
722+
grace auth token status --output Verbose
723+
grace status --output Verbose
724+
```
725+
726+
If `GRACE_TOKEN` is false and interactive token is false, authenticate first:
727+
728+
PowerShell:
729+
730+
```powershell
731+
grace auth login --auth device
732+
# or
733+
grace auth login --auth pkce
734+
```
735+
736+
bash / zsh:
737+
738+
```bash
739+
grace auth login --auth device
740+
# or
741+
grace auth login --auth pkce
742+
```
743+
744+
If you are using a PAT:
745+
746+
PowerShell:
747+
748+
```powershell
749+
$env:GRACE_TOKEN="grace_pat_v1_..."
750+
grace auth token status --output Verbose
751+
```
752+
753+
bash / zsh:
754+
755+
```bash
756+
export GRACE_TOKEN="grace_pat_v1_..."
757+
grace auth token status --output Verbose
758+
```
759+
760+
Why logs may look empty:
761+
762+
* `grace status` maps to `branch status`, which calls `/branch/Get` and `/branch/GetParentBranch`.
763+
* Those routes require authentication and are rejected with `401` before business handlers run.
764+
* You might see little or no endpoint-level logging for these failures.
765+
766+
Where to look for proof of `401`:
767+
768+
* W3C request logs under `%TEMP%\Grace.Server.Logs` (Windows) show request-level status codes.
769+
* Look for entries like `POST /branch/Get` and `POST /branch/GetParentBranch` with `401`.
770+
771+
Also note:
772+
773+
* `--output` values are case-sensitive in current CLI behavior. Use `Verbose`, not `verbose`.
774+
* During development, TestAuth may be available. See this file for setup details:
775+
`docs/Authentication.md` -> **Development without Auth0 (TestAuth)**.
776+
777+
### You can see `SystemAdmin` in Cosmos, but `grace access check` says denied
778+
779+
If `grace auth whoami` shows your expected `GraceUserId`, but:
780+
781+
* `grace access check --operation SystemAdmin --resource system --output Json`
782+
returns `Denied: missing permission SystemAdmin.`,
783+
784+
and you can also see a `SystemAdmin` assignment document in Cosmos, the most common cause is a **runtime context mismatch**.
785+
786+
Typical mismatch causes:
787+
788+
* The running server is using a different Orleans `serviceid` than the one that wrote the document.
789+
* You inspected a different Cosmos database or container than the running server is using.
790+
* The AccessControl grain loaded state before manual Cosmos edits (stale in-memory state until restart).
791+
792+
Why this happens:
793+
794+
* System-scope role assignments are read from the AccessControl actor state keyed by scope and Orleans identity.
795+
* A document such as `grace-dev__accesscontrolactor_system` applies only to the matching Orleans service context.
796+
* If the active server context differs, authorization reads a different actor record.
797+
798+
What to verify first:
799+
800+
PowerShell:
801+
802+
```powershell
803+
grace auth whoami --output Json
804+
grace access check --operation SystemAdmin --resource system --output Json
805+
```
806+
807+
bash / zsh:
808+
809+
```bash
810+
grace auth whoami --output Json
811+
grace access check --operation SystemAdmin --resource system --output Json
812+
```
813+
814+
Then verify server configuration:
815+
816+
* `GRACE_SERVER_URI` points to the server you think you are testing.
817+
* The running server's Orleans `serviceid` matches the service prefix of the AccessControl actor document.
818+
* The running server's Cosmos database/container match the place where you inspected the document.
819+
820+
Recommended recovery steps:
821+
822+
1. Restart `Grace.Server` (or your Aspire app host) to clear any stale grain state.
823+
2. Re-run the two checks above.
824+
3. Re-open Cosmos and confirm the `system` AccessControl actor document for the active service context
825+
contains your user principal.
826+
4. If needed, use a current `SystemAdmin` principal to grant your role again via `grace access grant-role`.
827+
828+
### Headless environments / CI
829+
830+
Use:
701831

702832
* M2M auth (client credentials env vars), or
703833
* PATs (`GRACE_TOKEN`), or

0 commit comments

Comments
 (0)