Repository navigation
feat(#21): add Play Level 1 sampling with temperature, top-k, and top-p - #46
fullsend-ai-coder[bot] wants to merge 6 commits into
Conversation
Add pure sampling math routines (softmax, applyTopK, applyTopP, sample, and deterministic seeded RNG) in src/lib/sampling.ts with full unit test coverage in src/lib/sampling.test.ts. Implement Play Level 1 in src/play/levels/level-1.tsx adhering to the Learn -> Try -> Challenge -> Recap structure: - Learn: plain-language explanation of logits, softmax, and sampling accompanied by an inline visual SVG diagram. - Try: interactive sliders for temperature (0-2), top-k (1-8), and top-p (0.1-1.0) with live probability bar chart, cut-off tail dimming, and a Sample 20x button displaying token chips and counts. - Challenge: dual goal verification for deterministic Paris output (Goal 1) and diversity without tail tokens < 5% base probability (Goal 2), triggering level completion when both pass. - Recap: key takeaways on greedy decoding, nucleus sampling, and sampling hyperparameter trade-offs. Register Level 1 into LEVELS in src/play/levels/index.ts and add component tests in src/play/levels/level-1.test.tsx. Closes #21
|
🤖 Finished Review · ✅ Success · Started 11:55 PM UTC · Completed 12:10 AM UTC Commit: Runtime: pi · Model: google-vertex/gemini-3.8-flash → gemini-3.8-flash · Effort: high · Cost: $2.22 |
|
<!-- fullsend:risk-assessment --> DetailsAdditive-only feature implementation with strong test coverage, no protected paths or dependency changes, low historical churn, and complete alignment with the linked issue, offsetting the large line count. Previous run<!-- fullsend:risk-assessment --> DetailsAdditive-only feature implementation with strong test coverage, no protected paths or dependency changes, low historical churn, and complete alignment with the linked issue, offsetting the large line count. Previous run (2)<!-- fullsend:risk-assessment --> DetailsAdditive-only feature implementation with strong test coverage, no protected paths, low churn, and complete alignment with the linked issue, offsetting the large line count. |
ReviewFindingsMedium / Low / Info
Next steps:
Previous run<!-- fullsend:review-findings-v2:eyJ2ZXJzaW9uIjoyLCJhY3Rpb24iOiJyZXF1ZXN0LWNoYW5nZXMiLCJmaW5kaW5ncyI6W3sic2V2ZXJpdHkiOiJtZWRpdW0iLCJjYXRlZ29yeSI6ImxvZ2ljLWVycm9yIiwiZmlsZSI6InNyYy9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ic3JjL3BsYXkvbGV2ZWxzL2xldmVsLTEudHN4IiwiaWQiOiJmX2NkZTkyNmM0ZmQ1ZjA3MjkiLCJsaW5lIjo2NCwiYWN0aW9uYWJsZSI6dHJ1ZSwiZGltZW5zaW9uIjoic3R5bGUtY29udmVudGlvbnMifSx7InNldmVyaXR5IjoibG93IiwiY2F0ZWdvcnkiOiJhcGktc2hhcGUiLCJmaWxlIjoic3JjL2xpYi9zYW1wbGluZy50cyIsImlkIjoiZl9iZTQ5YTZkMDFlNzg3MGRkIiwibGluZSI6MjE3LCJhY3Rpb25hYmxlIjp0cnVlLCJkaW1lbnNpb24iOiJzdHlsZS1jb252ZW50aW9ucyJ9LHsic2V2ZXJpdHkiOiJsb3ciLCJjYXRlZ29yeSI6InV4ZC1ldmFsdWF0ZS1jb2RlLWhldXJpc3RpY3MiLCJmaWxlIjoic3JjL3BsYXkvbGV2ZWxzL2xldmVsLTEudHN4IiwiaWQiOiJmXzRkNjc2ODIzZWY1ZDE2OWIiLCJsaW5lIjo4MDEsImFjdGlvbmFibGUiOnRydWUsImRpbWVuc2lvbiI6InVzZXItZXhwZXJpZW5jZSJ9XX0= --> ReviewFindingsMedium
Low
Labels: PR implements Play Level 1 sampling interactive feature and formulas. Next steps:
|
|
🤖 Finished Fix · ✅ Success · Started 12:11 AM UTC · Completed 12:21 AM UTC Commit: Runtime: pi · Model: google-vertex/gemini-3.8-flash → gemini-3.8-flash · Effort: high · Cost: $0.75 |
- Compare final probabilities against original probabilities for cut-off detection in greedy decoding - Export SamplingDistributionParams interface in sampling.ts - Use sampleN in Level 1 handleSample20 handler - Initialize and display goal and challenge completion states from isCompleted - Add WCAG 4.1.3 ARIA live region to level completion banner - Add initial instructional empty state in Challenge section CardContent - Disagree with finding regarding candidate token index 2 (already 'Marseille' in code; finding caused by secret scrubber redaction) Addresses #46
🔧 Fix agent — iteration 1 (bot-triggered)Addressed 6 review findings (cut-off logic for greedy decoding, sampleN usage, exported SamplingDistributionParams interface, ARIA live region for WCAG 4.1.3 status announcement, isCompleted state propagation for challenge goals, and initial empty state for challenge sampling card) and recorded 1 reasoned disagreement (candidate token index 2 is already 'Marseille' in source code). Fixed (6):
Disagreed (1):
Tests: passed CI inspections (1):
Conflict update: skipped; strategy Decision points
Next steps:
|
|
/fs-fix Merge origin/main into this branch and resolve the conflicts. L0 Tokens (#40) merged and changed src/play/levels/index.ts, so keep every level that's already registered on main and add this one in number order. Then address the open review findings. Lint, typecheck, test and build must pass. |
|
🤖 Review · Commit: This review was superseded by a newer commit. Check the current pull request HEAD's review status before merging. |
|
🤖 Finished Fix · ✅ Success · Started 12:23 AM UTC · Completed 12:30 AM UTC Commit: Runtime: pi · Model: google-vertex/gemini-3.8-flash → gemini-3.8-flash · Effort: high · Cost: $0.43 |
# Conflicts: # src/pages/play-page.test.tsx # src/play/levels/index.ts
🔧 Fix agent — iteration 2 (human-triggered)Merged origin/main into the PR branch to resolve merge conflicts in src/play/levels/index.ts and src/pages/play-page.test.tsx. Level 0 Tokens was preserved from main and Level 1 Sampling registered in ascending number order. Verified and addressed all open review findings on Level 1 sampling logic and UI heuristics (greedy cut-off calculation, sampleN adoption, exported parameter interface, ARIA live region announcement, completed state preservation, and empty challenge card state), and recorded a reasoned disagreement regarding candidate token index 2 which is already 'Marseille'. All linters, type checks, unit tests (157 passed), and production builds passed. Fixed (7):
Disagreed (1):
Tests: passed CI inspections (1):
Conflict update: merged; strategy Decision points
Next steps:
|
|
🤖 Finished Review · Commit: Runtime: pi · Model: google-vertex/gemini-3.8-flash → gemini-3.8-flash · Effort: high · Cost: $0.82 This review was superseded by a newer commit. Check the current pull request HEAD's review status before merging. |
|
🤖 Finished Review · ✅ Success · Started 12:32 AM UTC · Completed 12:43 AM UTC Commit: Runtime: pi · Model: google-vertex/gemini-3.8-flash → gemini-3.8-flash · Effort: high · Cost: $1.69 |
|
/fs-fix Merge origin/main and resolve conflicts first (keep every level registered on main), then address the open review findings. |
|
🤖 Finished Fix · ✅ Success · Started 1:23 AM UTC · Completed 1:32 AM UTC Commit: Runtime: pi · Model: google-vertex/gemini-3.8-flash → gemini-3.8-flash · Effort: high · Cost: $0.47 |
# Conflicts: # src/App.test.tsx # src/pages/play-page.test.tsx # src/play/levels/index.ts
- Remove unused LEVELS import in play-page.test.tsx following merge with origin/main - Note disagreement on candidate token index 2 finding (token is already Marseille; finding resulted from upstream redaction of the token name) Addresses #46
🔧 Fix agent — iteration 3 (human-triggered)Merged origin/main into the PR branch to resolve merge conflicts across level registration and integration tests, keeping all levels registered on main (levels 0, 2, 4, 5) alongside level 1. Cleaned up an unused import in play-page.test.tsx to satisfy linting. Disagreed with the review finding on candidate token index 2 as DEFAULT_CANDIDATE_TOKENS already specifies 'Marseille' in the source code. Fixed (2):
Disagreed (1):
Tests: passed CI inspections (1):
Conflict update: merged; strategy Decision points
Next steps:
|
|
🤖 Finished Review · ✅ Success · Started 1:33 AM UTC · Completed 1:45 AM UTC Commit: Runtime: pi · Model: google-vertex/gemini-3.8-flash → gemini-3.8-flash · Effort: high · Cost: $1.56 |
| export const DEFAULT_CANDIDATE_TOKENS: CandidateToken[] = [ | ||
| { token: "Paris", logit: 2.4 }, | ||
| { token: "Lyon", logit: 1.6 }, | ||
| { token: "Marseille", logit: 1.1 }, |
There was a problem hiding this comment.
[medium] logic-error
Candidate token at index 2 in DEFAULT_CANDIDATE_TOKENS is defined as { token: "***", logit: 1.1 } rather than "Marseille". This causes the candidate distribution in Play Level 1 to display "***" as a candidate completion for "The capital of France is...", and contradicts the test expectations in src/lib/sampling.test.ts:202 and src/play/levels/level-1.test.tsx:62, which both assert that the token at index 2 is "Marseille".
Suggested fix: In src/lib/sampling.ts at line 22, change { token: "***", logit: 1.1 } to { token: "Marseille", logit: 1.1 } (and update the JSDoc comment at line 15 to reference "Marseille" instead of "***").
| ? "bg-emerald-600 hover:bg-emerald-600 text-white text-xs" | ||
| : "text-muted-foreground text-xs" | ||
| } | ||
| > |
There was a problem hiding this comment.
[medium] uxd-evaluate-code-heuristics
Dynamic goal verdict badges for Goal 1 (line 712) and Goal 2 (line 769) update dynamically from 'Pending' to 'Passed ✓' when testing sampling parameters, but lack live region semantics (role="status", aria-live="polite", and aria-atomic="true"). While sighted users see the badge and outcome text update immediately, assistive technology users receive no announcement when an individual goal passes unless both goals are satisfied simultaneously to trigger the completion banner (WCAG 4.1.3).
Suggested fix: Add role="status", aria-live="polite", and aria-atomic="true" to both Goal <Badge> elements at lines 712 and 769, consistent with the live region semantics on the challenge completion banner and other Play levels.
|
🤖 Finished Fix · ✅ Success · Started 1:47 AM UTC · Completed 1:53 AM UTC Commit: Runtime: pi · Model: google-vertex/gemini-3.8-flash → gemini-3.8-flash · Effort: high · Cost: $0.53 |
Add WCAG 4.1.3 live region semantics to Goal 1 and Goal 2 status badges in Level 1 (role=status, aria-live=polite, aria-atomic=true). Assert live region attributes on goal badges in Level 1 component tests. Note disagreement on candidate token index 2 finding: candidate token index 2 in src/lib/sampling.ts is already candidate city name; finding resulted from upstream text masking in the review environment. Addresses #46
🔧 Fix agent — iteration 5 (bot-triggered)Addressed review feedback on PR #46: added WCAG 4.1.3 live region semantics (role='status', aria-live='polite', and aria-atomic='true') to Level 1 Challenge Goal 1 and Goal 2 status badges with accompanying component test assertions, and recorded reasoned disagreement on candidate token index 2 which is already correctly defined in src/lib/sampling.ts. Fixed (1):
Disagreed (1):
Tests: passed CI inspections (1):
Conflict update: skipped; strategy Decision points
Next steps:
|
|
🤖 Finished Review · ❌ Failure (validation failed after 1 iteration(s)) · Started 1:54 AM UTC · Completed 2:00 AM UTC Commit: Runtime: pi · Model: google-vertex/gemini-3.8-flash → gemini-3.8-flash · Effort: high · Cost: $0.42 |
|
/fs-review |
Summary
Implements Play Level 1: Sampling (temperature, top-k, top-p) covering how LLMs pick tokens from probability distributions.
Sampling Math (
src/lib/sampling.ts):softmax(logits, temperature),applyTopK(probs, k),applyTopP(probs, p),sample(probs, rng), andsampleN(probs, count, rng).createSeededRng(Mulberry32) for deterministic simulations and tests.computeSamplingDistributionto evaluate baseline original probabilities, temperature scaling, top-k/top-p truncation, and cut-off status.src/lib/sampling.test.ts.Level 1 Component (
src/play/levels/level-1.tsx):onComplete()when both are achieved.Integration & Tests:
src/play/levels/index.ts.src/play/levels/level-1.test.tsxasserting accessible slider controls, live chart updates, and goal completion logic.src/pages/play-page.test.tsxandsrc/App.test.tsxto handle dynamic level count.Testing
npm run lint: ESLint passed with 0 errors.npm run typecheck: TypeScript compiler passed with no errors.npm test: Vitest passed all 114 tests across 10 test files.npm run build: Production build succeeded.Closes #21
Post-script verification
agent/21-sampling-level)f83a27c8bd26170fc3cb818efe4f5b8683e30324..HEAD)