Skip to content

Commit 981791a

Browse files
committed
chore: sync spec-driven workflows
1 parent 54858b4 commit 981791a

Some content is hidden

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

62 files changed

+1080
-5681
lines changed

.claude-skills/backend-debugging_skill/SKILL.md

Lines changed: 35 additions & 391 deletions
Large diffs are not rendered by default.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Common Failures
2+
3+
| Symptom | Likely Cause | Resolution |
4+
| --- | --- | --- |
5+
| Run stuck in `queued` | Worker subscription not imported | Add `import "../agent/orchestrator/subscription";` at top of test. |
6+
| Service call hangs | Required service module not imported | Import relevant services, e.g. `../artifacts/store`, `../graph/encore.service.ts`. |
7+
| `~encore/clients` alias missing | Vitest config lacks alias | Update `backend/vitest.config.ts` with `resolve.alias['~encore'] = resolve(__dirname, './encore.gen')`. |
8+
| `projectedScreens: 0` | Projector queried before finishing | Poll status until `completed`, then wait ~5s before reading projector results. |
9+
| `budget_exhausted` after few steps | `maxSteps` too low | Increase `maxSteps` (e.g., to 20) to allow retries/backtracking. |
10+
11+
## Fast-Fail Checks
12+
1. Confirm `task backend:logs` shows structured log entries for the run.
13+
2. Ensure Appium/device is running when the scenario requires the agent.
14+
3. Re-run with `encore test ./run/start.integration.test.ts -- --runInBand` for consistent reproduction.
15+
4. Document root cause and fix in Graphiti once resolved.
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Debug Queries
2+
3+
Use these queries inside `task backend:db:shell` or via `encore-mcp_query_database`.
4+
5+
## Run Status & Ownership
6+
```sql
7+
SELECT run_id, status, worker_id, stop_reason, created_at, updated_at
8+
FROM runs
9+
WHERE run_id = '<runId>';
10+
```
11+
- Confirms worker claimed the run (`worker_id IS NOT NULL`).
12+
- Check `stop_reason` for early exits.
13+
14+
## Event Timeline
15+
```sql
16+
SELECT seq, kind, node_name, created_at
17+
FROM run_events
18+
WHERE run_id = '<runId>'
19+
ORDER BY seq;
20+
```
21+
- Expect contiguous `seq` values.
22+
- Missing events indicate a stalled worker or failed subscription.
23+
24+
## Graph Projector Outcomes
25+
```sql
26+
SELECT outcome_id, upsert_kind, screen_id, step_ordinal, created_at
27+
FROM graph_persistence_outcomes
28+
WHERE run_id = '<runId>'
29+
ORDER BY step_ordinal;
30+
```
31+
- At least one `upsert_kind = 'discovered'` when screens exist.
32+
33+
## Projection Lag Analysis
34+
```sql
35+
SELECT
36+
r.run_id,
37+
r.status,
38+
COUNT(re.seq) AS events_count,
39+
COUNT(gpo.outcome_id) AS projections_count,
40+
(COUNT(re.seq) - COUNT(gpo.outcome_id)) AS lag
41+
FROM runs r
42+
LEFT JOIN run_events re ON r.run_id = re.run_id
43+
LEFT JOIN graph_persistence_outcomes gpo ON r.run_id = gpo.run_id
44+
WHERE r.run_id = '<runId>'
45+
GROUP BY r.run_id, r.status;
46+
```
47+
- Non-zero `lag` indicates projector backlog.
48+
49+
## Agent Snapshot
50+
```sql
51+
SELECT snapshot->>'nodeName' AS node,
52+
snapshot->>'status' AS status,
53+
created_at
54+
FROM run_state_snapshots
55+
WHERE run_id = '<runId>'
56+
ORDER BY step_ordinal DESC
57+
LIMIT 1;
58+
```
59+
- Validates the last known agent state before failure.
60+
61+
## Recent Runs
62+
```sql
63+
SELECT run_id, status, stop_reason
64+
FROM runs
65+
ORDER BY created_at DESC
66+
LIMIT 5;
67+
```
68+
- Quickly compare recent outcomes for pattern spotting.
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Detailed Debugging Examples
2+
3+
## Case Study: "0 Screens Discovered"
4+
```typescript
5+
// 1. Confirm completion
6+
const run = await db.queryRow`
7+
SELECT status, stop_reason FROM runs WHERE run_id = ${runId}
8+
`;
9+
10+
// 2. Inspect events
11+
const events = await db.queryAll`
12+
SELECT seq, kind FROM run_events WHERE run_id = ${runId} ORDER BY seq
13+
`;
14+
15+
// 3. Ensure perception event exists
16+
const perceived = events.find((event) => event.kind === 'agent.event.screen_perceived');
17+
18+
// 4. Check projector outcomes
19+
const outcomes = await db.queryAll`
20+
SELECT upsert_kind FROM graph_persistence_outcomes WHERE run_id = ${runId}
21+
`;
22+
```
23+
**Diagnosis:** Projector lagged behind event stream.
24+
**Fix:** Increase polling window or delay projector assertions by ~5 seconds.
25+
26+
## Case Study: Subscription Not Loaded
27+
- Symptom: Run remains `queued` and no events emitted.
28+
- Fix: Import worker subscription inside the test file **before** calling the service.
29+
30+
```typescript
31+
import '../agent/orchestrator/subscription';
32+
33+
it('dispatches work to the agent', async () => {
34+
await start({ runId });
35+
await expectRunToComplete(runId);
36+
});
37+
```
38+
39+
## Case Study: Path Alias Missing
40+
- Symptom: `Error: Failed to load ~encore/clients`.
41+
- Fix: Update `backend/vitest.config.ts`:
42+
```typescript
43+
resolve: {
44+
alias: {
45+
'~encore': resolve(__dirname, './encore.gen')
46+
}
47+
}
48+
```
49+
50+
## RCA Template
51+
1. **Symptom:** Brief description + log snippet
52+
2. **Impact:** Tests affected / services failing
53+
3. **Root Cause:** What broke (missing import, bad config, etc.)
54+
4. **Fix:** Code/infra change applied
55+
5. **Prevention:** Follow-up actions (tests, scripts, docs)
56+
6. **Graphiti Entry:** Add episode with log excerpts + links
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Diagnostic Scripts Arsenal
2+
3+
All scripts live in `backend/scripts/` and can be executed with `bunx tsx`.
4+
5+
## `inspect-run.ts`
6+
```bash
7+
bunx tsx backend/scripts/inspect-run.ts <runId>
8+
```
9+
Outputs run events, graph outcomes, and cursor state in chronological order. Use to confirm event sequencing and projector activity.
10+
11+
## `check-agent-state.ts`
12+
```bash
13+
bunx tsx backend/scripts/check-agent-state.ts <runId>
14+
```
15+
Prints agent state snapshots (node name, status, counters, budgets). Ideal for tracking where a state machine stalled.
16+
17+
## `check-cursor-ordering.ts`
18+
```bash
19+
bunx tsx backend/scripts/check-cursor-ordering.ts
20+
```
21+
Validates graph projector cursor health—identifies stuck cursors or ordering gaps.
22+
23+
## `find-latest-run.ts` / `find-completed-runs.ts`
24+
```bash
25+
bunx tsx backend/scripts/find-latest-run.ts
26+
bunx tsx backend/scripts/find-completed-runs.ts
27+
```
28+
Locate recent runs for comparison when debugging regressions.
29+
30+
## `test-projector.ts`
31+
```bash
32+
bunx tsx backend/scripts/test-projector.ts <runId>
33+
```
34+
Exercises the graph projector in isolation to validate output without rerunning the full agent flow.
35+
36+
## Usage Tips
37+
- Run scripts from repo root or backend directory.
38+
- Combine with SQL queries to cross-check database observations.
39+
- Capture output snippets in Graphiti episodes when documenting RCA.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
---
2+
name: backend-development
3+
description: Integration-first development patterns for Encore.ts backend services. Focuses on importing subscriptions, polling async flows, verifying database state, and keeping diagnostic tooling close at hand.
4+
---
5+
6+
# Backend Development Skill
7+
8+
## Mission
9+
Ship reliable Encore.ts services by exercising the full flow—API call, worker execution, projector persistence, and database validation—inside every test cycle. This skill outlines the core loop and points to detailed playbooks in `references/`.
10+
11+
## When to Use
12+
- Creating or updating Encore.ts services or subscriptions
13+
- Writing integration tests that cover PubSub + database interactions
14+
- Diagnosing flaky backend tests before handing off to QA or FE
15+
- Preparing backend changes for CI, smoke tests, or release gates
16+
17+
## Development Loop
18+
1. **Plan the flow** – Identify required subscriptions, services, and database tables; note expectations in Graphiti.
19+
2. **Import dependencies** – Bring subscriptions/services into the test runtime to mirror production wiring.
20+
3. **Execute via Encore client** – Call the service using generated types, not manual fetches.
21+
4. **Poll for completion** – Use polling helpers (no fixed sleeps) until the worker finishes or times out.
22+
5. **Assert database + logs** – Verify rows, outcomes, and structured log fields against expectations.
23+
6. **Clean up + document** – Remove test data, note findings in Graphiti, and link any new scripts or helpers.
24+
25+
## Quick Command Set
26+
```bash
27+
cd backend && encore dev # Local dev server
28+
cd backend && encore test # Full test suite
29+
cd backend && encore test path/to.test.ts # Focused integration test
30+
cd .cursor && task backend:test # Automation layer entry point
31+
cd .cursor && task backend:logs # Stream structured logs
32+
```
33+
34+
## Quality Gates
35+
- Subscriptions imported for every PubSub interaction
36+
- Services and repositories typed end-to-end (no `any` or untyped SQL results)
37+
- Polling loops with bounded timeouts instead of `setTimeout`
38+
- Database cleaned after each integration test run
39+
- Structured logging uses `encore.dev/log` with `module`, `actor`, and identifiers
40+
41+
## Reference Library
42+
- `references/integration_test_patterns.md` – Step-by-step pattern for polling, cleanup, and database verification
43+
- `references/api_testing_examples.md` – Example tests covering multi-service flows and assertions
44+
- `references/encore_mcp_testing_patterns.md` – How to combine Encore MCP with tests for live introspection
45+
- `WEBDRIVER_SESSION_ERRORS.md` – Known Appium/WebDriver error catalog used during agent-driven tests
46+
47+
## Related Skills
48+
- `backend-debugging_skill` – Deep-dive diagnostics when runs stall or regressions persist
49+
- `e2e-testing_skill` – Playwright automation that consumes backend APIs end-to-end
50+
- `graphiti-mcp-usage_skill` – Document backend architecture and test discoveries in Graphiti

.claude-skills/backend-testing_skill/WEBDRIVER_SESSION_ERRORS.md renamed to .claude-skills/backend-development_skill/WEBDRIVER_SESSION_ERRORS.md

File renamed without changes.

.claude-skills/backend-testing_skill/references/api_testing_examples.md renamed to .claude-skills/backend-development_skill/references/api_testing_examples.md

File renamed without changes.

.claude-skills/backend-testing_skill/references/encore_mcp_testing_patterns.md renamed to .claude-skills/backend-development_skill/references/encore_mcp_testing_patterns.md

File renamed without changes.

.claude-skills/backend-testing_skill/references/integration_test_patterns.md renamed to .claude-skills/backend-development_skill/references/integration_test_patterns.md

File renamed without changes.

0 commit comments

Comments
 (0)