<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Shubham Rasal - Portfolio &amp; Blog</title><description>Technical blog posts, devlogs, and insights on AI, programming, and technology</description><link>https://shubhamrasal.com/</link><language>en-us</language><lastBuildDate>Sun, 07 Jun 2026 04:20:40 GMT</lastBuildDate><managingEditor>Shubham Rasal</managingEditor><webMaster>Shubham Rasal</webMaster><item><title>Notes on RL Questions</title><link>https://shubhamrasal.com/writing/undefined/</link><guid isPermaLink="true">https://shubhamrasal.com/writing/undefined/</guid><description>A blog post by undefined</description><pubDate>Sun, 07 Jun 2026 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;35 questions covering LLM RL algorithms and infrastructure. Compiled as a personal reference — answers are deliberately brief and can be extended much further with follow-ups.&lt;/p&gt;
&lt;p&gt;Sources: arXiv preprints, official GitHub repos, &lt;a href=&quot;https://lilianweng.github.io&quot;&gt;Lilian Weng&apos;s blog&lt;/a&gt;. Based on Xiuyu Li (@sheriyuo).&lt;/p&gt;
&lt;hr /&gt;
&lt;h2&gt;Algorithm (Q1–Q19)&lt;/h2&gt;
&lt;h3&gt;Q1. Why use Actor-Critic instead of a pure Critic approach?&lt;/h3&gt;
&lt;p&gt;Pure critic (value-only) methods like DQN require discretizing the action space or expensive optimization at every step. Actor-Critic separates policy (actor) from value estimation (critic), enabling continuous action spaces and lower-variance gradient estimates via the baseline. The actor directly parameterizes the policy, which is more sample-efficient in high-dimensional or continuous spaces.&lt;/p&gt;
&lt;h3&gt;Q2. What is the relationship between KL divergence, cross entropy, and MLE?&lt;/h3&gt;
&lt;p&gt;&lt;code&gt;KL(P||Q) = H(P,Q) − H(P)&lt;/code&gt;. Minimizing cross entropy H(P,Q) (as in MLE on data distribution P) is equivalent to minimizing KL(P||Q) when H(P) is constant. In RL, KL from the reference policy acts as a regularizer equivalent to a log-ratio penalty.&lt;/p&gt;
&lt;h3&gt;Q3. How should rewards be designed in different RL scenarios?&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Sparse:&lt;/strong&gt; outcome-only (pass/fail). Simple but high-variance.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Dense:&lt;/strong&gt; shaped per-step rewards. Faster learning but risks reward hacking.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;PRM (Process Reward Model):&lt;/strong&gt; reward per reasoning step — useful for math/code.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;ORM (Outcome Reward Model):&lt;/strong&gt; reward only the final answer.&lt;/li&gt;
&lt;li&gt;For LLMs: format rewards + verifiable outcome rewards (exact match, code execution) preferred to avoid hacking.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Q4. How do importance sampling, rejection sampling, and other Monte Carlo methods fit into RL?&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Importance sampling (IS):&lt;/strong&gt; reweights off-policy samples; used in PPO&apos;s surrogate ratio &lt;code&gt;π_θ/π_old&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Rejection sampling:&lt;/strong&gt; accept/reject samples from a proposal; used in RLHF data filtering and best-of-N selection.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Monte Carlo rollouts:&lt;/strong&gt; estimate returns by full-trajectory sampling; high variance but unbiased.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Q5. How is advantage computed in PPO and GRPO? Why subtract a baseline? Is std normalization necessary?&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;PPO (GAE):&lt;/strong&gt; &lt;code&gt;A_t = Σ (γλ)^k δ_{t+k}&lt;/code&gt; where &lt;code&gt;δ_t = r_t + γV(s_{t+1}) − V(s_t)&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;GRPO:&lt;/strong&gt; group-relative — &lt;code&gt;A_i = (r_i − mean(group)) / std(group)&lt;/code&gt;, no value network needed.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Baseline:&lt;/strong&gt; subtracting a baseline reduces variance without introducing bias (REINFORCE theorem).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Std normalization:&lt;/strong&gt; empirically stabilizes training but theoretically optional; DAPO and Dr.GRPO question its necessity.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Q6. How do RL training and test-time scaling perform exploration differently?&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Training:&lt;/strong&gt; exploration via stochastic sampling (temperature, entropy bonus, ε-greedy). The policy is updated to reinforce rewarded trajectories.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Test-time scaling:&lt;/strong&gt; best-of-N, beam search, MCTS, or repeated sampling with a verifier — no gradient updates. Exploration is over the fixed policy&apos;s distribution.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Q7. How does PPO clipping work? Why take the minimum? What happens without clipping? How does CISPO differ?&lt;/h3&gt;
&lt;p&gt;PPO clips the IS ratio: &lt;code&gt;L = min(r·A, clip(r, 1−ε, 1+ε)·A)&lt;/code&gt;. Taking the &lt;code&gt;min&lt;/code&gt; is a pessimistic bound — it only updates when the clipped and unclipped objectives agree on direction.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Without clipping:&lt;/strong&gt; the policy can take excessively large steps, destabilizing training (the original TRPO problem).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;CISPO:&lt;/strong&gt; replaces clipping with importance-weighted SFT on accepted samples — smoother optimization, avoids the discontinuity in PPO&apos;s gradient.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Q8. Why does GRPO include a KL penalty? How is KL computed? Why do DAPO and GSPO remove it?&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;KL penalty prevents the policy from drifting too far from the reference (SFT model), acting as a regularizer against reward hacking.&lt;/li&gt;
&lt;li&gt;Computed as token-level KL: &lt;code&gt;KL(π_θ || π_ref) = Σ_t log(π_θ(a_t)/π_ref(a_t))&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;DAPO:&lt;/strong&gt; removes KL because token-level KL is an imprecise constraint and interferes with entropy-driven exploration.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;GSPO:&lt;/strong&gt; uses sequence-level KL instead of token-level, arguing it better aligns with the RL objective.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Q9. During LLM training, what happens if loss is accidentally All Reduced multiple times?&lt;/h3&gt;
&lt;p&gt;All Reduce averages gradients across ranks. Doing it multiple times effectively divides the gradient by &lt;code&gt;world_size&lt;/code&gt; each extra time — the effective learning rate shrinks exponentially. Can silently cause training to stall or converge to suboptimal solutions. Hard to detect without gradient norm logging.&lt;/p&gt;
&lt;h3&gt;Q10. What is the reward function in DPO? Can reward hacking occur? How can it be mitigated?&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;DPO implicitly defines reward: &lt;code&gt;r(x,y) = β log(π_θ(y|x)/π_ref(y|x))&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Reward hacking:&lt;/strong&gt; the model can exploit distribution shift from π_ref without improving actual quality.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Mitigations:&lt;/strong&gt; IPO (identity transform), cDPO (conservative), iterative DPO with updated reference, or hybrid DPO+RM.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Q11. What methods address train-inference mismatch in MoE models, and how do they work?&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Expert choice routing&lt;/strong&gt; at train vs. &lt;strong&gt;token choice&lt;/strong&gt; at inference causes load imbalance.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Auxiliary load-balancing loss:&lt;/strong&gt; penalizes uneven expert utilization.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;DeepSeek MoE:&lt;/strong&gt; uses fine-grained expert splitting and shared experts.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;OPD / Expert-parallel fine-tuning:&lt;/strong&gt; aligns routing distributions between train and serving.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Q12. How should group size, learning rate, PPO epochs, and generation length be selected during RL training?&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Group size (G):&lt;/strong&gt; larger G reduces variance of advantage estimate but increases memory; 8–64 typical.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;LR:&lt;/strong&gt; typically 1e-6 to 5e-6 for LLM RL; lower than SFT to avoid policy collapse.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;PPO epochs:&lt;/strong&gt; 1–4; more epochs risk over-optimization on old data.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Generation length:&lt;/strong&gt; should match target task; too short truncates reasoning, too long wastes compute. Cap with length penalty if needed.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Q13. Compared with GRPO, how do Dr.GRPO, DAPO, GSPO, CISPO, SAPO, DPPO, MaxRL, and SimKO improve training?&lt;/h3&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Method&lt;/th&gt;
&lt;th&gt;Key Improvement&lt;/th&gt;
&lt;th&gt;Limitation&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Dr.GRPO&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Removes length bias; per-token normalization&lt;/td&gt;
&lt;td&gt;Minor gain over GRPO&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;DAPO&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;No KL, clip-higher, token-level loss&lt;/td&gt;
&lt;td&gt;Careful entropy tuning needed&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;GSPO&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Sequence-level KL constraint&lt;/td&gt;
&lt;td&gt;More complex reference computation&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;CISPO&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Replaces clip with IS-weighted SFT&lt;/td&gt;
&lt;td&gt;Requires careful accept threshold&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;SAPO&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Separates actor/critic updates; better stability&lt;/td&gt;
&lt;td&gt;Extra hyperparameters&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;DPPO&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Distributed PPO with async rollout&lt;/td&gt;
&lt;td&gt;Staleness risk&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;MaxRL&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Reward maximization with explicit diversity&lt;/td&gt;
&lt;td&gt;Experimental&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;SimKO&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Simplified KL objective, no reference model&lt;/td&gt;
&lt;td&gt;Weaker regularization&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h3&gt;Q14. How do TRPO, DPPO, and AReaL enforce trust-region constraints?&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;TRPO:&lt;/strong&gt; hard KL constraint via conjugate gradient + line search. Computationally expensive.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;DPPO:&lt;/strong&gt; separates rollout workers from training, enforces trust region via clipping asynchronously.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;AReaL:&lt;/strong&gt; uses partially stale rollouts with bounded staleness as an implicit trust region; monitors KL drift to trigger rollout refresh.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Q15. Can RL fundamentally expand the capability frontier of LLMs?&lt;/h3&gt;
&lt;p&gt;Debated. RL can unlock latent capabilities (e.g., step-by-step reasoning in R1) and improve reliability on verifiable tasks. However, it likely cannot introduce genuinely new knowledge — it redistributes probability mass over already-learned behaviors. Capability frontier expansion requires the base model to have learned the skill implicitly during pre-training.&lt;/p&gt;
&lt;h3&gt;Q16. Based on ProRL, how should we think about scaling RL training?&lt;/h3&gt;
&lt;p&gt;ProRL shows that prolonged RL training (&amp;gt;1000 steps) with curriculum and diverse task mixing continues to improve — contradicting early saturation beliefs. Key findings: task diversity prevents forgetting, reward signal quality matters more than quantity, and entropy maintenance is critical for sustained improvement.&lt;/p&gt;
&lt;h3&gt;Q17. What improvements does OPD introduce over traditional RL and SFT?&lt;/h3&gt;
&lt;p&gt;OPD (Online Preference Distillation) combines online rollouts with preference-based distillation from a stronger teacher. It avoids the cold-start problem of pure RL and overcomes SFT&apos;s distribution shift by continuously generating on-policy data. Applications: math reasoning, code generation with execution feedback.&lt;/p&gt;
&lt;h3&gt;Q18. At which stage of training does reasoning ability emerge in LLMs?&lt;/h3&gt;
&lt;p&gt;Evidence suggests reasoning emerges during &lt;strong&gt;pre-training&lt;/strong&gt; at scale (chain-of-thought is latent in the base model). RL (e.g., R1-Zero) can surface and amplify it without SFT cold-start. However, the &lt;em&gt;reliability&lt;/em&gt; and &lt;em&gt;length&lt;/em&gt; of reasoning chains are shaped by post-training.&lt;/p&gt;
&lt;h3&gt;Q19. From DeepSeek R1 to V3.2 and future V4, what RL-related improvements have been introduced?&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;R1:&lt;/strong&gt; GRPO-based RL on math/code with sparse verifiable rewards; &quot;aha moment&quot; self-reflection.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;V3:&lt;/strong&gt; MoE base + multi-token prediction + RL alignment pipeline.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;V3.2 / V4 (speculative):&lt;/strong&gt; longer context RL, improved MoE routing stability, process reward models, agentic RL with tool use. MoE adds expert load-balancing loss during RL.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr /&gt;
&lt;h2&gt;Infrastructure (Q20–Q35)&lt;/h2&gt;
&lt;h3&gt;Q20. Ignoring CPU offload, how many model copies exist in memory during GRPO training?&lt;/h3&gt;
&lt;p&gt;At minimum: &lt;strong&gt;reference model&lt;/strong&gt; (frozen π_ref) + &lt;strong&gt;actor&lt;/strong&gt; (π_θ) + &lt;strong&gt;optimizer states&lt;/strong&gt; (Adam: 2× params in fp32). For GRPO without a value network: ~2 model copies (actor + reference) + optimizer states ≈ &lt;strong&gt;3–4× parameter memory&lt;/strong&gt; in practice. With a critic: add another copy.&lt;/p&gt;
&lt;h3&gt;Q21. Distributed inference: KV cache transfer optimization and multi-GPU communication strategies.&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Prefill-decode disaggregation:&lt;/strong&gt; separate GPU pools for prefill vs. decode; KV cache transferred over NVLink/RDMA.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Chunked prefill:&lt;/strong&gt; interleaves prefill chunks with decode steps to reduce head-of-line blocking.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Paged KV cache (vLLM):&lt;/strong&gt; non-contiguous memory blocks, reduces fragmentation.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Communication:&lt;/strong&gt; NCCL all-reduce for TP; P2P send/recv for PP; RDMA for cross-node KV transfer.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Q22. INT8 versus FP8. What are the tradeoffs? Which precisions are preferred for training and inference?&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;INT8:&lt;/strong&gt; simpler quantization, well-supported, but limited dynamic range for activations.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;FP8 (E4M3/E5M2):&lt;/strong&gt; better dynamic range than INT8, natively supported on H100. E4M3 for weights/activations, E5M2 for gradients.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Training:&lt;/strong&gt; FP8 master weights risky; typically BF16 weights + FP8 compute (Transformer Engine).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Inference:&lt;/strong&gt; FP8 or INT8 (W8A8) for throughput; INT4 for memory-bound generation.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Q23. What is the long-tail problem in RL rollouts, and how can it be addressed?&lt;/h3&gt;
&lt;p&gt;Some prompts generate much longer sequences than others, causing GPU idle time while waiting for the longest sequence in a batch. Solutions:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Sequence packing:&lt;/strong&gt; bin-pack sequences to fill fixed-length buffers.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Dynamic batching:&lt;/strong&gt; group by similar length.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Async rollout:&lt;/strong&gt; decouple generation from training; discard or requeue long stragglers.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Length penalty in reward:&lt;/strong&gt; discourage excessively long outputs.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Q24. What issues does continuous batching introduce in RL training? How do vLLM and SGLang differ?&lt;/h3&gt;
&lt;p&gt;Continuous batching mixes sequences at different stages — problematic for RL because you need complete trajectories before computing rewards. Solutions: track per-request state, flush complete sequences.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;vLLM:&lt;/strong&gt; PagedAttention, flexible scheduling, chunked prefill; rollout API via &lt;code&gt;AsyncLLMEngine&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;SGLang:&lt;/strong&gt; RadixAttention for prefix caching, faster TTFT, optimized for structured generation (multi-turn, tool calls).&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Q25. How do you measure utilization in vLLM and SGLang? How do you evaluate KV cache utilization during training?&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;GPU utilization:&lt;/strong&gt; &lt;code&gt;nvidia-smi&lt;/code&gt;, but MFU (model FLOP utilization) is more meaningful.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;vLLM metrics:&lt;/strong&gt; &lt;code&gt;/metrics&lt;/code&gt; endpoint exposes &lt;code&gt;gpu_cache_usage_perc&lt;/code&gt;, &lt;code&gt;num_running_requests&lt;/code&gt;, &lt;code&gt;num_waiting_requests&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;SGLang:&lt;/strong&gt; similar Prometheus metrics endpoint.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Training KV cache:&lt;/strong&gt; monitor cache hit rate (prefix reuse) and eviction rate; high eviction → increase cache budget or reduce batch size.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Q26. How is backpropagation implemented in large-scale multi-node RL training?&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Tensor Parallelism (TP):&lt;/strong&gt; split weight matrices across GPUs; all-reduce after each layer.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Pipeline Parallelism (PP):&lt;/strong&gt; micro-batches flow through stages; gradient accumulation across micro-batches.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;FSDP / ZeRO-3:&lt;/strong&gt; shard optimizer states, gradients, and params across DP ranks; all-gather before forward, reduce-scatter after backward.&lt;/li&gt;
&lt;li&gt;RL-specific: actor backward pass only on accepted tokens; reference model kept frozen (no backward).&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Q27. What asynchronous RL frameworks exist, and what synchronization bottlenecks do they solve?&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;IMPALA:&lt;/strong&gt; async actor-learner; solves GPU idle from slow environment steps.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;DPPO / RLHF async:&lt;/strong&gt; decouples rollout workers from training; solves the generation bottleneck (~3–10× slower than training step).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;AReaL:&lt;/strong&gt; partially async — rollouts from slightly stale policy, bounded by KL; solves the sync barrier between inference and training clusters.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;slime:&lt;/strong&gt; fully async with Megatron backend; uses shared memory ring buffers for data flow.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Q28. In AReaL or other partially rollout frameworks, are KV caches from previous policies preserved?&lt;/h3&gt;
&lt;p&gt;No, in general. When policy weights update, the KV cache computed under the old policy is stale and would produce incorrect attention outputs. AReaL refreshes the inference engine (or restarts vLLM workers) after weight sync. Some systems use speculative decoding-style checks, but recomputation is the safe default.&lt;/p&gt;
&lt;h3&gt;Q29. How does Expert Parallelism affect MoE throughput?&lt;/h3&gt;
&lt;p&gt;Expert Parallelism (EP) shards experts across GPUs — each GPU holds a subset of experts. For a token routed to expert &lt;em&gt;i&lt;/em&gt;, it must be sent to the GPU holding that expert via All-to-All communication. This adds latency proportional to &lt;code&gt;message_size × num_experts / bandwidth&lt;/code&gt;. High EP degree → lower memory per GPU but higher communication overhead. Optimal EP degree balances compute vs. network saturation.&lt;/p&gt;
&lt;h3&gt;Q30. In long-context training, how should compute-communication overlap be designed? How do Megatron and FSDP differ in parallelism strategies?&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Overlap strategy:&lt;/strong&gt; pipeline communication behind computation using CUDA streams; prefetch next micro-batch while computing current.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Megatron:&lt;/strong&gt; interleaved 1F1B pipeline schedule with virtual stages; sequence parallelism (layernorm/dropout split across TP ranks); explicit all-gather/compute overlap.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;FSDP:&lt;/strong&gt; lazy all-gather via forward hooks; &lt;code&gt;forward_prefetch&lt;/code&gt; and &lt;code&gt;backward_prefetch&lt;/code&gt; options. Less efficient for long context due to larger all-gather buckets.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Q31. How do you enable deterministic execution? What is batch invariance? What causes it? Is atomic add involved?&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Deterministic execution:&lt;/strong&gt; &lt;code&gt;torch.use_deterministic_algorithms(True)&lt;/code&gt;, set seeds, disable TF32.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Batch invariance:&lt;/strong&gt; result should not change depending on how data is batched (e.g., same sequences in one batch vs. split across two). Violated by operations depending on batch statistics or non-deterministic reductions.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Cause:&lt;/strong&gt; &lt;code&gt;atomicAdd&lt;/code&gt; in CUDA reductions is non-deterministic across thread orderings. Flash attention, softmax, and layer norm are common culprits.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Mitigation:&lt;/strong&gt; deterministic CUDA kernels (&lt;code&gt;CUBLAS_WORKSPACE_CONFIG=:4096:8&lt;/code&gt;) or avoid atomic reductions in critical paths. Atomic add alone cannot solve batch invariance — it addresses within-kernel ordering, not cross-sample dependencies.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Q32. How do AReaL and slime differ in their understanding of the RL rollout bottleneck?&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;AReaL:&lt;/strong&gt; bottleneck is the synchronization barrier between rollout and training. Solution: allow bounded-stale rollouts so training never waits for generation to finish.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;slime:&lt;/strong&gt; bottleneck is KV cache memory and inference engine throughput under RL workload (variable lengths, frequent weight updates). Solution: tight Megatron integration with shared memory, avoiding vLLM restart overhead on weight sync.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Q33. How should we think about staleness in fully asynchronous RL training? What are typical values in practice?&lt;/h3&gt;
&lt;p&gt;Staleness = number of gradient updates between when a rollout was generated and when it&apos;s used for training. High staleness → IS ratio &lt;code&gt;π_θ/π_old&lt;/code&gt; drifts → clipping becomes too aggressive or too permissive. Typical practice: track staleness per sample, discard or reweight samples beyond a threshold (e.g., 2–4 updates stale). AReaL monitors per-sample KL to bound staleness implicitly. In practice, staleness of 1–3 steps is generally acceptable for LLM RL workloads.&lt;/p&gt;
&lt;h3&gt;Q34. How does data flow through slime? How is it integrated with Megatron? How is the loss computed?&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Data flow:&lt;/strong&gt; Megatron handles training; slime manages rollout workers (vLLM-based). After each training step, updated weights are broadcast to rollout workers via shared memory or NCCL. Rollout workers generate trajectories, queued in a ring buffer and consumed by the Megatron training loop.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Megatron integration:&lt;/strong&gt; slime hooks into Megatron&apos;s training loop via a custom data iterator that pulls from the rollout queue instead of a static dataset.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Loss:&lt;/strong&gt; standard PPO/GRPO loss computed over log-probs from Megatron&apos;s forward pass; reference log-probs either recomputed or stored during rollout.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Q35. If you had to choose among VeRL, TRL, Unsloth, AReaL, and slime, which one would you use and why?&lt;/h3&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Framework&lt;/th&gt;
&lt;th&gt;Best For&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;TRL&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Rapid prototyping, small models, research experiments&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Unsloth&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Single-GPU fine-tuning, memory efficiency (QLoRA), low-budget&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;VeRL&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Production LLM RL at scale, Ray-based, good vLLM integration&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;AReaL&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Async RL research, studying staleness, academic scale&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;slime&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Megatron-native shops, largest-scale training, MoE models&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;strong&gt;Recommendation:&lt;/strong&gt; VeRL for most industry use cases (mature, well-documented, Ray ecosystem). slime if you&apos;re training &amp;gt;100B parameter MoE models with Megatron already in your stack.&lt;/p&gt;
</content:encoded><category>rl</category><category>ml</category><category>notes</category></item><item><title>DEVLOG #6</title><link>https://shubhamrasal.com/writing/undefined/</link><guid isPermaLink="true">https://shubhamrasal.com/writing/undefined/</guid><description>A blog post by undefined</description><pubDate>Fri, 22 May 2026 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Spent the afternoon benchmarking Carbon, a new family of genomic foundation models from HuggingFace trained on 1 trillion tokens of DNA sequences.&lt;/p&gt;
&lt;h3&gt;What is Carbon&lt;/h3&gt;
&lt;p&gt;Carbon is a causal language model for DNA. It uses a hybrid tokenizer that switches between BPE for text and 6-mer encoding for DNA sequences, triggered by a &lt;code&gt;&amp;lt;dna&amp;gt;&lt;/code&gt; tag. The family has three sizes: 500M, 3B, and 8B. The 500M model is explicitly designed as a draft model for speculative decoding with the 3B.&lt;/p&gt;
&lt;h3&gt;Throughput on T4 GPU&lt;/h3&gt;
&lt;p&gt;I ran inference benchmarks for Carbon-500M on a Colab T4 GPU. The model is 512M parameters in bfloat16 precision.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Config&lt;/th&gt;
&lt;th&gt;Prompt&lt;/th&gt;
&lt;th&gt;Generated&lt;/th&gt;
&lt;th&gt;Throughput&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;128bp context&lt;/td&gt;
&lt;td&gt;23 tokens&lt;/td&gt;
&lt;td&gt;64 tokens&lt;/td&gt;
&lt;td&gt;27.2 tok/s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;128bp context&lt;/td&gt;
&lt;td&gt;23 tokens&lt;/td&gt;
&lt;td&gt;256 tokens&lt;/td&gt;
&lt;td&gt;25.0 tok/s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;512bp context&lt;/td&gt;
&lt;td&gt;87 tokens&lt;/td&gt;
&lt;td&gt;64 tokens&lt;/td&gt;
&lt;td&gt;26.6 tok/s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;512bp context&lt;/td&gt;
&lt;td&gt;256 tokens&lt;/td&gt;
&lt;td&gt;256 tokens&lt;/td&gt;
&lt;td&gt;26.3 tok/s&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;The throughput is remarkably flat across prompt lengths, which makes sense given the model size. No attention bottleneck at these context lengths on T4.&lt;/p&gt;
&lt;h3&gt;Speculative Decoding&lt;/h3&gt;
&lt;p&gt;Since Carbon-500M is designed as a draft for Carbon-3B, I tested speculative decoding using HuggingFace&apos;s built-in &lt;code&gt;assistant_model&lt;/code&gt; flag. Both models together use about 8 GB of VRAM on the T4.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Config&lt;/th&gt;
&lt;th&gt;3B standalone&lt;/th&gt;
&lt;th&gt;3B with spec decoding&lt;/th&gt;
&lt;th&gt;Speedup&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;128bp, 64 tokens&lt;/td&gt;
&lt;td&gt;22.3 tok/s&lt;/td&gt;
&lt;td&gt;19.4 tok/s&lt;/td&gt;
&lt;td&gt;0.87x&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;128bp, 256 tokens&lt;/td&gt;
&lt;td&gt;22.3 tok/s&lt;/td&gt;
&lt;td&gt;20.1 tok/s&lt;/td&gt;
&lt;td&gt;0.90x&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;512bp, 64 tokens&lt;/td&gt;
&lt;td&gt;21.4 tok/s&lt;/td&gt;
&lt;td&gt;18.6 tok/s&lt;/td&gt;
&lt;td&gt;0.87x&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;512bp, 256 tokens&lt;/td&gt;
&lt;td&gt;22.0 tok/s&lt;/td&gt;
&lt;td&gt;19.7 tok/s&lt;/td&gt;
&lt;td&gt;0.89x&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Speculative decoding is about 10 to 13 percent slower than running 3B alone. This is not surprising on T4 for a few reasons.&lt;/p&gt;
&lt;p&gt;First, the T4 is memory bandwidth bound, not compute bound. Loading weights for two models per round costs more than the verification saves. Second, HuggingFace&apos;s naive &lt;code&gt;assistant_model&lt;/code&gt; implementation is not the optimized parallel speculative decoding used in production systems like vLLM. It runs draft tokens one at a time without batching the verification step. Third, speculative decoding gains are larger on A100 or H100 class hardware where the verifier is compute bound and the parallel draft verification comes essentially for free.&lt;/p&gt;
&lt;p&gt;The design intention still makes sense though. A proper implementation with vLLM&apos;s speculative decoding backend on an A100 should show meaningful speedup. The 6x size ratio between draft and verifier, plus the shared tokenizer and training data, are all ideal conditions for high draft acceptance rates, which is where the actual wall clock improvement comes from.&lt;/p&gt;
&lt;h3&gt;What is next&lt;/h3&gt;
&lt;p&gt;Want to test Carbon on actual biology tasks rather than synthetic ATCG repeats. The evaluation suite includes variant effect prediction and sequence recovery tasks which would give a better picture of where the model actually stands relative to Evo2 and GENERator.&lt;/p&gt;
</content:encoded><category>ai</category><category>devlog</category><category>genomics</category></item><item><title>Chasing 1.18 BPB: Parameter Golf in 10 Minutes</title><link>https://shubhamrasal.com/writing/undefined/</link><guid isPermaLink="true">https://shubhamrasal.com/writing/undefined/</guid><description>A blog post by undefined</description><pubDate>Thu, 30 Apr 2026 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;OpenAI dropped a challenge in mid-March: train the best language model that fits in 16MB and runs in under 10 minutes on 8×H100s. Scored by bits-per-byte on FineWeb. Lower is better.&lt;/p&gt;
&lt;p&gt;The baseline scores 1.2244 BPB. The current record is 1.1194. That gap looks small. It is not small.&lt;/p&gt;
&lt;h2&gt;What I Found Reading the Leaderboard&lt;/h2&gt;
&lt;p&gt;The repo has a records/ directory where every submission explains exactly what they did. Weirdly generous for a live competition.&lt;/p&gt;
&lt;p&gt;Some things are basically free — LeakyReLU², orthogonal init, EMA on the weights. EMA surprised me because the gain isn&apos;t just better generalization — the averaged weights quantize more cleanly to int8. It&apos;s doing two jobs.&lt;/p&gt;
&lt;p&gt;Then there&apos;s SmearGate. 512 parameters total. A single learned gate per embedding dim that blends the current token with the previous one. The BPB per parameter ratio is absurd.&lt;/p&gt;
&lt;p&gt;The real unlock is int6 quantization. Pack weights into 6 bits, compress with zstd at level 22. This shrinks the model ~25% more than int8+zlib, which is what lets you run 3× wider MLPs while still fitting under 16MB. The wider MLP is apparently the single biggest contributor to score improvements.&lt;/p&gt;
&lt;h2&gt;Day 2 and 3: Implementation&lt;/h2&gt;
&lt;p&gt;Started with the MLX version locally. SmearGate and BigramHash went in cleanly. 200-step smoke test: val BPB dropped from 4.1 to 1.92. Just warmup, but promising.&lt;/p&gt;
&lt;p&gt;Porting to CUDA was mostly mechanical. Then came RunPod.&lt;/p&gt;
&lt;p&gt;SCP doesn&apos;t work through their SSH proxy — fails silently. You need &lt;code&gt;runpodctl send/receive&lt;/code&gt;. Spot instances got terminated three times mid-run. The Docker image has almost nothing installed, so every new pod needs a git clone, 8GB of shard downloads, and a pip install before you can do anything. When you have 15 minutes of H100 credits, this stings.&lt;/p&gt;
&lt;p&gt;Lesson: always &lt;code&gt;nohup ... &amp;amp;&lt;/code&gt; your training run. Learned this the hard way.&lt;/p&gt;
&lt;h2&gt;The Run That Counted&lt;/h2&gt;
&lt;p&gt;Eventually a stable 8×H100 run finished.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;step:8268/20000 val_bpb:1.2173 train_time:600058ms stopping_early: wallclock_cap
pre_quant_sliding val_bpb:1.1823
Total submission size int8+zlib: 16362289 bytes
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;1.1823 pre-quant BPB. Better than 12 of the 19 leaderboard entries.&lt;/p&gt;
&lt;p&gt;The problem: 16.36MB. The limit is 16MB. 360KB over.&lt;/p&gt;
&lt;p&gt;The fix was clear — switch to zstd or int6. I added zstd support. The run that would have used it got terminated by another spot eviction.&lt;/p&gt;
&lt;h2&gt;Where This Lands&lt;/h2&gt;
&lt;p&gt;1.1823 would rank around 10th if it had fit. Not a record, but a real result built from scratch.&lt;/p&gt;
&lt;p&gt;The thing that surprised me most was how much co-design matters. Every architectural decision — MLP width, layers, embedding size — has to be evaluated through &quot;does this fit after compression?&quot; The best submissions are designing the model and the compression scheme together.&lt;/p&gt;
&lt;p&gt;The int6 path is clear. No good reason 1.1194 should be the floor.&lt;/p&gt;
</content:encoded><category>ml</category><category>devlog</category></item><item><title>From Prompt to Pixels — SAM 3.1 as a Local Video Operator</title><link>https://shubhamrasal.com/writing/undefined/</link><guid isPermaLink="true">https://shubhamrasal.com/writing/undefined/</guid><description>A blog post by undefined</description><pubDate>Sun, 26 Apr 2026 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;&lt;em&gt;Notes from running Meta’s Segment Anything 3.1 on Apple Silicon via MLX&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;While experimenting with &lt;strong&gt;SAM 3.1&lt;/strong&gt; (Segment Anything Model 3.1) on local hardware, I hit a moment that felt less like “running a model” and more like &lt;strong&gt;having an operator I could steer in English&lt;/strong&gt;. I pointed it at dashcam footage of a busy highway interchange and asked—not for a caption—for a &lt;strong&gt;directional vehicle count&lt;/strong&gt;. The stack answered. The numbers matched what I could verify by eye.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;./blog_highway_01.jpg&quot; alt=&quot;Highway interchange: prompt “a car” with per-instance masks, boxes, and confidence scores&quot; /&gt;&lt;/p&gt;
&lt;p&gt;If you had to build &lt;strong&gt;traffic flow analytics or layer-aware compositing&lt;/strong&gt; from raw video, how would you do it?&lt;/p&gt;
&lt;p&gt;One workable answer today is: &lt;em&gt;treat segmentation + tracking as the primitive&lt;/em&gt;, and push semantics (left vs. right, foreground vs. background) into a thin layer of code on top.&lt;/p&gt;
&lt;hr /&gt;
&lt;h2&gt;Mental Model: Classification vs. Operator&lt;/h2&gt;
&lt;p&gt;Most people’s picture of “vision AI” is &lt;strong&gt;classification&lt;/strong&gt;: image in, label out. That was remarkable in 2012; in 2026 it is baseline.&lt;/p&gt;
&lt;p&gt;SAM 3.1 is doing something closer to &lt;strong&gt;instance geometry&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;You specify what you care about in &lt;strong&gt;natural language&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;The model returns &lt;strong&gt;masks&lt;/strong&gt;—exact outlines—not just categories&lt;/li&gt;
&lt;li&gt;Those masks &lt;strong&gt;persist across frames&lt;/strong&gt; as tracks (IDs, colors, continuity)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;So the useful abstraction is not “what is this frame &lt;em&gt;about&lt;/em&gt;?” but “&lt;strong&gt;which pixels belong to which object over time?&lt;/strong&gt;”&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Traditional mental model          SAM 3.1 mental model
        |                                  |
   Photo → Label                    Video + Prompt → Masks + Tracks
        |                                  |
   &quot;car&quot; (one tag)                 Car₁, Car₂, … Carₙ per frame
                                         |
                                  Stable IDs across time
&lt;/code&gt;&lt;/pre&gt;
&lt;hr /&gt;
&lt;h2&gt;What the Stack Optimizes For (Locally)&lt;/h2&gt;
&lt;p&gt;The runs I care about here are &lt;strong&gt;offline-friendly&lt;/strong&gt; and &lt;strong&gt;privacy-preserving&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;No cloud&lt;/strong&gt; — weights and inference on the machine&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;No API round-trips&lt;/strong&gt; — latency is compute-bound, not network-bound&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Plain-English prompts&lt;/strong&gt; — the interface is language, not hand-tuned CV pipelines&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Concretely: &lt;strong&gt;mlx-community/sam3.1-bf16&lt;/strong&gt; on &lt;strong&gt;MLX&lt;/strong&gt;, &lt;strong&gt;873M parameters&lt;/strong&gt;, on &lt;strong&gt;Apple Silicon&lt;/strong&gt;.&lt;/p&gt;
&lt;hr /&gt;
&lt;h2&gt;Experiment 1 — Highway: From Masks to a Directed Count&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Input:&lt;/strong&gt; ~53 seconds of 720p overpass footage.&lt;br /&gt;
&lt;strong&gt;Prompt:&lt;/strong&gt; &lt;code&gt;&quot;a car&quot;&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;./blog_highway_02.jpg&quot; alt=&quot;Same clip: dense traffic with color-coded instance masks under the “a car” prompt&quot; /&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Observation:&lt;/strong&gt; Per-frame instance counts bounced in a band (roughly &lt;strong&gt;19–28 vehicles&lt;/strong&gt;), which is expected—occlusion, merge/split, and frame boundaries are hard. What mattered more was &lt;strong&gt;track continuity&lt;/strong&gt;: each vehicle kept an ID, mask, and trajectory long enough to reason about &lt;strong&gt;dominant side of frame / road&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;./blog_highway_03.jpg&quot; alt=&quot;Another frame: overlapping vehicles still get distinct masks and scores—continuity matters more than a single-frame count&quot; /&gt;&lt;/p&gt;
&lt;p&gt;I wrote a small post-processing step: from track geometry, classify which side of a split line each track &lt;strong&gt;spent most of its lifetime&lt;/strong&gt; on, then aggregate.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Result:&lt;/strong&gt;&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Direction&lt;/th&gt;
&lt;th&gt;Count&lt;/th&gt;
&lt;th&gt;Share&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Left lane&lt;/td&gt;
&lt;td&gt;408&lt;/td&gt;
&lt;td&gt;70.1%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Right lane&lt;/td&gt;
&lt;td&gt;174&lt;/td&gt;
&lt;td&gt;29.9%&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;img src=&quot;./blog_highway_04.jpg&quot; alt=&quot;Frame from the same run: the segmentation layer that feeds the left/right heuristic&quot; /&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Raw frames
    |
    v
SAM 3.1 (prompt: &quot;a car&quot;)
    |
    v
Per-frame masks + track IDs
    |
    v
Heuristic: dominant side of split line per track
    |
    v
Directional flow statistics
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&quot;./blog_highway_05.jpg&quot; alt=&quot;Later moment in the clip: same prompt and stack—what changes frame-to-frame is geometry, not the pipeline&quot; /&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Takeaway:&lt;/strong&gt; the “heavy” part—&lt;strong&gt;find instances and keep them coherent&lt;/strong&gt;—is delegated to the model. The “thin” part—&lt;strong&gt;geometry + aggregation&lt;/strong&gt;—is ordinary code. That split is the design win.&lt;/p&gt;
&lt;hr /&gt;
&lt;h2&gt;Experiment 2 — Detection Cadence: Trading Accuracy for Throughput&lt;/h2&gt;
&lt;p&gt;Default behavior effectively &lt;strong&gt;re-detects every frame&lt;/strong&gt;. On &lt;strong&gt;720p&lt;/strong&gt; hardware here, that landed near &lt;strong&gt;~0.5 fps&lt;/strong&gt;—fine for batch analysis, unusable for interactive loops.&lt;/p&gt;
&lt;p&gt;SAM exposes a &lt;strong&gt;&lt;code&gt;--every N&lt;/code&gt;&lt;/strong&gt; knob: full detection every &lt;em&gt;N&lt;/em&gt; frames, &lt;strong&gt;propagation&lt;/strong&gt; in between.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Detection cadence&lt;/th&gt;
&lt;th&gt;Approx. speed (720p)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Every frame&lt;/td&gt;
&lt;td&gt;~0.5 fps&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Every 5 frames&lt;/td&gt;
&lt;td&gt;~3.0 fps&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Every 15 frames&lt;/td&gt;
&lt;td&gt;~7.8 fps&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;At &lt;strong&gt;every 15&lt;/strong&gt;, the tracker’s interpolation is smooth enough that, for many UIs, the shortcut is invisible—until you freeze-frame and hunt for edge cases.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Every frame                    Every N frames
     |                               |
 Full detect each step            Detect ──► Propagate ──► Propagate ──► …
     |                               |
 High fidelity masks              Lower CPU/GPU duty cycle
     |                               |
 ~0.5 fps (here)                   ~7–8 fps (here, N=15)
&lt;/code&gt;&lt;/pre&gt;
&lt;hr /&gt;
&lt;h2&gt;Experiment 3 — Compositing: A Depth List Instead of One Mask&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Goal:&lt;/strong&gt; the “text sandwiched between environment and subject” effect (background → text → foreground).&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Naive approach:&lt;/strong&gt; segment the person; paste text behind. Works until &lt;strong&gt;desk, mic, bottle, tablet&lt;/strong&gt; should also occlude the text—you either fight with rotoscoping or you &lt;strong&gt;enumerate foreground&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Better approach:&lt;/strong&gt; define a &lt;strong&gt;foreground set&lt;/strong&gt;; union masks; composite in three layers.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;FOREGROUND_OBJECTS = [
    &quot;a person&quot;,
    &quot;a wooden table&quot;,
    &quot;a bottle&quot;,
    &quot;an iPad&quot;,
    &quot;a microphone&quot;,
]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;SAM segments &lt;strong&gt;all prompts in one pass&lt;/strong&gt;; the compositor does &lt;strong&gt;background → typography → union(foreground masks)&lt;/strong&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Layer stack (bottom → top):

[ Environment pixels ]
        |
        v
[ Text ]
        |
        v
[ Union(person, table, bottle, iPad, mic) ]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Takeaway:&lt;/strong&gt; once masks are cheap and prompt-driven, &lt;strong&gt;compositing becomes a configuration problem&lt;/strong&gt;, not a hand-drawn matte problem.&lt;/p&gt;
&lt;hr /&gt;
&lt;h2&gt;The Insight That Actually Generalizes&lt;/h2&gt;
&lt;p&gt;What stuck is not any single demo. It is that SAM collapses the distance between &lt;strong&gt;intent&lt;/strong&gt; (“these things belong in front”) and &lt;strong&gt;machine-manipulable state&lt;/strong&gt; (per-pixel ownership over time).&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Prompt → mask → program.&lt;/strong&gt;&lt;br /&gt;
You stop hand-authoring detectors for every object class; you &lt;strong&gt;name&lt;/strong&gt; what matters and operate on the pixels the model hands back.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;That is closer to &lt;strong&gt;writing constraints for an operator&lt;/strong&gt; than to classic OpenCV plumbing—different skill, different failure modes.&lt;/p&gt;
&lt;hr /&gt;
&lt;h2&gt;Limits (Honest Accounting)&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Wall time:&lt;/strong&gt; a &lt;strong&gt;53 s&lt;/strong&gt; clip at conservative settings was on the order of &lt;strong&gt;~6 minutes&lt;/strong&gt; end-to-end here. “Real-time” at &lt;strong&gt;full HD&lt;/strong&gt; is still aspirational; &lt;strong&gt;lower resolution&lt;/strong&gt; (e.g. &lt;strong&gt;224 px&lt;/strong&gt; short side) is where live-ish tracking becomes plausible.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Temporal noise:&lt;/strong&gt; fast edges &lt;strong&gt;flicker&lt;/strong&gt; without smoothing; an &lt;strong&gt;EMA across masks&lt;/strong&gt; fixes a lot of it but needs tuning.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Semantics:&lt;/strong&gt; the model gives you &lt;strong&gt;shapes and categories&lt;/strong&gt;, not &lt;strong&gt;causality&lt;/strong&gt;. It will not explain &lt;em&gt;why&lt;/em&gt; the left lane is busier—only that &lt;strong&gt;the pixels were there&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr /&gt;
&lt;h2&gt;Where This Goes&lt;/h2&gt;
&lt;p&gt;The trajectory is unambiguous: &lt;strong&gt;faster silicon&lt;/strong&gt;, &lt;strong&gt;better propagation&lt;/strong&gt;, &lt;strong&gt;tighter integration with capture pipelines&lt;/strong&gt;. Tomorrow’s constraint is less “can it segment?” and more “&lt;strong&gt;what do you ask it to pay attention to?&lt;/strong&gt;”&lt;/p&gt;
&lt;p&gt;That question is already the interface SAM forces you to answer—&lt;strong&gt;one English prompt at a time&lt;/strong&gt;.&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;&lt;strong&gt;End result:&lt;/strong&gt; a local, prompt-driven &lt;strong&gt;video operator&lt;/strong&gt; that turns “describe what matters” into &lt;strong&gt;masks and tracks&lt;/strong&gt; you can feed normal code—counts, dashboards, editors—without standing up a CV lab first.&lt;/p&gt;
&lt;hr /&gt;
&lt;h2&gt;References&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://huggingface.co/mlx-community/sam3.1-bf16&quot;&gt;mlx-community/sam3.1-bf16&lt;/a&gt; (weights)&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/ml-explore/mlx&quot;&gt;MLX&lt;/a&gt; (Apple Silicon framework)&lt;/li&gt;
&lt;li&gt;Meta’s SAM family (Segment Anything) — see official docs and model cards for capability boundaries&lt;/li&gt;
&lt;/ul&gt;
</content:encoded><category>ml</category><category>systems</category></item><item><title>DEVLOG: Fine-tuning Evo2 with RLVR for Regulatory DNA Design</title><link>https://shubhamrasal.com/writing/undefined/</link><guid isPermaLink="true">https://shubhamrasal.com/writing/undefined/</guid><description>A blog post by undefined</description><pubDate>Fri, 24 Apr 2026 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;This is a planning devlog for a project I&apos;ve been thinking about for a while — using reinforcement learning with verifiable rewards (RLVR) to fine-tune Evo2 for targeted regulatory DNA design.&lt;/p&gt;
&lt;h2&gt;The Problem&lt;/h2&gt;
&lt;p&gt;Designing regulatory DNA sequences that activate in a specific cell type is hard. Current generative models — including Evo2, which I&apos;ve worked with before — can produce plausible sequences, but they&apos;re not steered toward any particular functional objective. You get diversity, not specificity.&lt;/p&gt;
&lt;p&gt;The standard approach is to train a supervised model on MPRA (Massively Parallel Reporter Assay) data and hope it generalizes. But MPRA datasets now have 150M+ labeled sequences with measured regulatory activity across cell types. That&apos;s enough signal to build a reward model — and if you have a reward model, you can do RL.&lt;/p&gt;
&lt;h2&gt;The Idea&lt;/h2&gt;
&lt;p&gt;The core loop is straightforward:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Evo2 generates&lt;/strong&gt; candidate regulatory sequences&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A reward model&lt;/strong&gt; trained on MPRA data scores each sequence for actual regulatory activity in a target cell type&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;RLVR updates&lt;/strong&gt; Evo2 toward sequences that score high&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The reward is grounded in real experimental measurements, not another model&apos;s predictions. That&apos;s what makes it &quot;verifiable&quot; in the RLVR sense — similar to how math RL uses a checker rather than a judge.&lt;/p&gt;
&lt;p&gt;Top candidates from the RL loop get validated against Borzoi as a secondary oracle (a sequence-to-activity model trained on ENCODE data, Nature Genetics 2024).&lt;/p&gt;
&lt;p&gt;This is inspired by the recent &lt;a href=&quot;https://x.com/JorgeMe87234182&quot;&gt;RL for Crystal Relaxation&lt;/a&gt; work — same philosophy: use a physically grounded reward instead of a learned proxy.&lt;/p&gt;
&lt;h2&gt;Why This Hasn&apos;t Been Done&lt;/h2&gt;
&lt;p&gt;I looked through the literature and nobody has combined Evo2-scale generation (~7B parameters, trained on 2.7M genomes) with MPRA-grounded reward models under RLVR. A few reasons this gap exists:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Evo2 only dropped in early 2025&lt;/li&gt;
&lt;li&gt;MPRA datasets at this scale are very recent (the 150M+ collection is from March 2025)&lt;/li&gt;
&lt;li&gt;Most bio ML work still treats sequence design as a supervised problem&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The pieces are all available now. The RLVR framework from Prime Intellect&apos;s verifiers library maps cleanly onto this — you just swap out the math verifier for an MPRA-trained reward model.&lt;/p&gt;
&lt;h2&gt;Prior Work I&apos;m Building On&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://www.nature.com/articles/s41586-026-10176-5&quot;&gt;Evo2 paper (Nature 2026)&lt;/a&gt; — the base model and weights&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://arxiv.org/abs/2503.07981&quot;&gt;RL for regulatory DNA design&lt;/a&gt; — closest prior work, but uses a weaker base model and synthetic rewards&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://www.biorxiv.org/content/10.1101/2025.03.11.642630v1&quot;&gt;MPRA Dataset Collection&lt;/a&gt; — 150M+ labeled sequences, the reward model training data&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://www.nature.com/articles/s41588-024-02053-6&quot;&gt;Borzoi&lt;/a&gt; — secondary oracle for validation&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I&apos;ve already shipped one application on top of Evo1, so I have a practical sense of where generative DNA models fail on functional sequence design. That experience is what made this problem obvious to me.&lt;/p&gt;
&lt;h2&gt;Compute Plan&lt;/h2&gt;
&lt;p&gt;Rough estimate: &lt;strong&gt;100–150 H100 hours&lt;/strong&gt; total.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Reward model training on MPRA data: ~30–50 hours&lt;/li&gt;
&lt;li&gt;RLVR fine-tuning of Evo2-7B: ~50–80 hours&lt;/li&gt;
&lt;li&gt;Borzoi validation passes: ~10–20 hours&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Starting with Evo2-7B. If the reward signal is strong, scaling up to larger checkpoints is the obvious next step.&lt;/p&gt;
&lt;h2&gt;Next Steps&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;[ ] Set up MPRA data pipeline and train initial reward model&lt;/li&gt;
&lt;li&gt;[ ] Implement RLVR training loop using Prime Intellect&apos;s verifiers framework&lt;/li&gt;
&lt;li&gt;[ ] Baseline: compare RLVR outputs vs. pure Evo2 generation on target cell type activity&lt;/li&gt;
&lt;li&gt;[ ] Validate top-K sequences against Borzoi&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Will post updates as I make progress.&lt;/p&gt;
</content:encoded><category>devlog</category><category>biology</category><category>rl</category><category>ml</category></item><item><title>Cody — my personal background coding agent</title><link>https://shubhamrasal.com/writing/undefined/</link><guid isPermaLink="true">https://shubhamrasal.com/writing/undefined/</guid><description>A blog post by undefined</description><pubDate>Sat, 11 Apr 2026 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;&lt;img src=&quot;./cody-robot.png&quot; alt=&quot;Cody&quot; /&gt;&lt;/p&gt;
&lt;p&gt;For the last few months, I have been running a background coding agent built using OpenCode on a VPS.&lt;/p&gt;
&lt;p&gt;I was inspired by &lt;a href=&quot;https://builders.ramp.com/post/why-we-built-our-background-agent&quot;&gt;Ramp Inspect&lt;/a&gt; and other implementations and wanted to see how far I can push it.&lt;/p&gt;
&lt;p&gt;I started with a tall order for the agent to be useful and worth investing my time in.&lt;/p&gt;
&lt;h2&gt;What I want the agent to do&lt;/h2&gt;
&lt;p&gt;I want the coding agent to handle the following tasks (almost) autonomously:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Fix minor issues like formatting, creating a new REST API endpoint, creating a new page, etc.&lt;/li&gt;
&lt;li&gt;Build the project, update dependencies, and fix any errors that come up&lt;/li&gt;
&lt;li&gt;Deploy to the given instance&lt;/li&gt;
&lt;li&gt;Build n8n workflows and test whether they are correct or not&lt;/li&gt;
&lt;li&gt;Inform me when the work is done&lt;/li&gt;
&lt;li&gt;Has access to all my GitHub repos and is easy to deploy on a VPS&lt;/li&gt;
&lt;li&gt;Use a browser to check the output visually and fix any issues&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;The litmus test&lt;/h2&gt;
&lt;p&gt;What would make this agent actually useful to me? It needs to be able to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Add a new blog post to my personal site&lt;/li&gt;
&lt;li&gt;Create a non-trivial automation workflow without my help&lt;/li&gt;
&lt;li&gt;Add a new feature like CLI enhancements to a complex Golang project&lt;/li&gt;
&lt;li&gt;Add features to itself&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Enter OpenCode&lt;/h2&gt;
&lt;p&gt;&lt;img src=&quot;./cody-opencode.png&quot; alt=&quot;OpenCode terminal&quot; /&gt;&lt;/p&gt;
&lt;p&gt;OpenCode is a really great agent. It exposes an HTTP interface and you can spawn as many instances as you want. But managing multiple sessions and projects was getting complex, so I built a small script used for high-level project management.&lt;/p&gt;
&lt;h2&gt;Caddy setup&lt;/h2&gt;
&lt;p&gt;In order to expose multiple projects on custom subdomains, I decided to use a proxy server. I started with nginx but didn&apos;t like the setup. Then I found Caddy — really simple and straightforward.&lt;/p&gt;
&lt;p&gt;Here&apos;s a sample config that reverse-proxies to OpenCode instances running on different ports for better isolation:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;*.example.com {
    tls {
        dns digitalocean {env.DO_AUTH_TOKEN}
    }

    @app1 host app1.example.com
    handle @app1 {
        reverse_proxy localhost:4096
    }

    @app2 host app2.example.com
    handle @app2 {
        reverse_proxy localhost:4097
    }

    handle {
        abort
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Tools&lt;/h2&gt;
&lt;p&gt;In the default setup, OpenCode can only make changes locally on the server. But I wanted it to use the same tools I have access to as a dev. So I set up:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;gh&lt;/code&gt; (GitHub CLI)&lt;/li&gt;
&lt;li&gt;n8n skills and MCP&lt;/li&gt;
&lt;li&gt;&lt;code&gt;browser-use&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;ffmpeg&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;docker&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;gws&lt;/code&gt; (Google Workspace CLI)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;gemini-cli&lt;/code&gt; (for image gen via Nano Banana)&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Using OpenClaw as an orchestrator&lt;/h2&gt;
&lt;p&gt;&lt;img src=&quot;./cody-raspi.png&quot; alt=&quot;BerryClaw on Raspberry Pi&quot; /&gt;&lt;/p&gt;
&lt;p&gt;I gave this setup to BerryClaw — my personal OpenClaw instance running on a Raspberry Pi — and used it to manage multiple projects.&lt;/p&gt;
&lt;h2&gt;Results&lt;/h2&gt;
&lt;p&gt;BerryClaw, with the help of this background coding agent:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Created 2 n8n workflows that worked end to end&lt;/li&gt;
&lt;li&gt;Sent 3 minor PRs to my personal sites&lt;/li&gt;
&lt;li&gt;Wrote 2 blog posts (I gave it the rough content)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I&apos;ll keep improving this agent, but I&apos;m happy with where it is now.&lt;/p&gt;
&lt;h2&gt;References&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://github.com/ColeMurray/background-agents&quot;&gt;background-agents by ColeMurray&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://builders.ramp.com/post/why-we-built-our-background-agent&quot;&gt;Why we built our background agent — Ramp&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://stripe.dev/blog/minions-stripes-one-shot-end-to-end-coding-agents&quot;&gt;Minions: Stripe&apos;s one-shot end-to-end coding agents&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content:encoded><category>devlog</category><category>ai</category></item><item><title>Inside Cursor&apos;s Agent Traces</title><link>https://shubhamrasal.com/writing/undefined/</link><guid isPermaLink="true">https://shubhamrasal.com/writing/undefined/</guid><description>A blog post by undefined</description><pubDate>Sat, 11 Apr 2026 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Cursor ships with a surprisingly detailed telemetry system for tracking AI-generated code. It stores everything locally in two SQLite databases - one that logs every code chunk the AI writes, another that holds your entire chat history as JSON blobs. Neither was designed as a training dataset, but together they contain the raw materials for one.&lt;/p&gt;
&lt;p&gt;This is a writeup of me sniffing around the &lt;code&gt;~/.cursor&lt;/code&gt; folder to see whether Cursor records enough data to reconstruct accept/reject preference signals.&lt;/p&gt;
&lt;p&gt;Spoiler: there&apos;s no explicit signal. But there&apos;s enough to reconstruct meaningful ones implicitly.&lt;/p&gt;
&lt;h2&gt;The Two Databases&lt;/h2&gt;
&lt;p&gt;Cursor persists two relevant stores on disk:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;~/.cursor/ai-tracking/ai-code-tracking.db          # code provenance tracking
~/Library/Application Support/Cursor/User/
  globalStorage/state.vscdb                         # chat history + KV store
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The first is specific to Cursor&apos;s AI tracking extension. The second is the standard VSCode global state database - Cursor uses it for chat history on top of the usual IDE state.&lt;/p&gt;
&lt;h3&gt;ai-code-tracking.db - Six Tables&lt;/h3&gt;
&lt;p&gt;The tracking database has six tables, two of which are empty but revealing in their intent:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Table&lt;/th&gt;
&lt;th&gt;Rows&lt;/th&gt;
&lt;th&gt;Notes&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;ai_code_hashes&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;86,763&lt;/td&gt;
&lt;td&gt;One row per code chunk written by AI&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;scored_commits&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;301&lt;/td&gt;
&lt;td&gt;Per-commit AI attribution percentages&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;ai_deleted_files&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;31&lt;/td&gt;
&lt;td&gt;AI-written files that were later deleted&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;tracking_state&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;Config row - stores &lt;code&gt;trackingStartTime&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;conversation_summaries&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Empty.&lt;/strong&gt; Would have been the richest signal.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;tracked_file_content&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Empty.&lt;/strong&gt; Would store full file content per session.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;The &lt;code&gt;ai_code_hashes&lt;/code&gt; schema is the core of the system. Each row records the chunk content hash, the source (&lt;code&gt;composer&lt;/code&gt; vs &lt;code&gt;human&lt;/code&gt;), the file it was written to, the model that generated it, and critically - a &lt;code&gt;requestId&lt;/code&gt; that links back to the originating chat turn.&lt;/p&gt;
&lt;h3&gt;state.vscdb - The Chat Store&lt;/h3&gt;
&lt;p&gt;The chat history lives in the &lt;code&gt;cursorDiskKV&lt;/code&gt; table inside VSCode&apos;s global state database. Each row is a JSON blob keyed with one of two patterns:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;bubbleId:&amp;lt;conversationId&amp;gt;:&amp;lt;messageId&amp;gt;   # one row per chat message
agentKv:blob:&amp;lt;hash&amp;gt;                     # composer session blobs
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A &quot;bubble&quot; is Cursor&apos;s term for a single message in the chat - either a user turn (&lt;code&gt;type: 1&lt;/code&gt;) or an AI turn (&lt;code&gt;type: 2&lt;/code&gt;). The AI turn is actually split across several bubbles: one for the thinking block, one per tool call, one per tool result, and one for the final text response.&lt;/p&gt;
&lt;h2&gt;The Foreign Key: requestId&lt;/h2&gt;
&lt;p&gt;The most important thing I found was a genuine join key between the two databases. The user-prompt bubble stores a &lt;code&gt;requestId&lt;/code&gt; field in its JSON. The &lt;code&gt;ai_code_hashes&lt;/code&gt; table stores the same &lt;code&gt;requestId&lt;/code&gt; on every code chunk written during that request. This is a hard, verifiable link - not an inferred one.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note on conversationId.&lt;/strong&gt; It&apos;s tempting to join on &lt;code&gt;conversationId&lt;/code&gt; instead, since it appears in both stores. But the &lt;code&gt;conversationId&lt;/code&gt; is not stored inside the bubble&apos;s JSON - it&apos;s only encoded in the key string (&lt;code&gt;bubbleId:&amp;lt;conversationId&amp;gt;:&amp;lt;messageId&amp;gt;&lt;/code&gt;). The &lt;code&gt;requestId&lt;/code&gt; field is the actual foreign key.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Coverage isn&apos;t perfect. Of 581 distinct &lt;code&gt;requestId&lt;/code&gt;s in &lt;code&gt;ai_code_hashes&lt;/code&gt;, 512 (88%) have a matching bubble in &lt;code&gt;state.vscdb&lt;/code&gt;. The 12% gap is most likely old chat bubbles that were pruned from the rolling retention window while the tracking DB kept its code hashes indefinitely.&lt;/p&gt;
&lt;h2&gt;A Complete Trace&lt;/h2&gt;
&lt;p&gt;Here&apos;s a concrete example - a real request reconstructed from the two databases. The conversation ID is &lt;code&gt;11325bee&lt;/code&gt;, the request is a UI tweak to a loading screen component.&lt;/p&gt;
&lt;p&gt;&amp;lt;div class=&quot;trace not-prose&quot;&amp;gt;
&amp;lt;div class=&quot;trace-header&quot;&amp;gt;
&amp;lt;div class=&quot;trace-dot&quot;&amp;gt;&amp;lt;/div&amp;gt;
Conversation 11325bee  ·  2026-03-15  ·  composer-1.5
&amp;lt;/div&amp;gt;&lt;/p&gt;
&lt;p&gt;&amp;lt;div class=&quot;trace-step&quot;&amp;gt;
&amp;lt;div class=&quot;trace-time&quot;&amp;gt;
&amp;lt;span class=&quot;trace-kind user&quot;&amp;gt;user&amp;lt;/span&amp;gt;
08:50:14Z
&amp;lt;/div&amp;gt;
&amp;lt;div class=&quot;trace-body&quot;&amp;gt;
&amp;lt;span class=&quot;hi&quot;&amp;gt;&quot;the @LoadingScreen.tsx screen text is too light.&amp;lt;br&amp;gt;
 Make it larger, brighter&quot;&amp;lt;/span&amp;gt;&amp;lt;br&amp;gt;
&amp;lt;span class=&quot;dim&quot;&amp;gt;fileSelections: [LoadingScreen.tsx]&amp;lt;/span&amp;gt;&amp;lt;br&amp;gt;
&amp;lt;span class=&quot;dim&quot;&amp;gt;requestId: f8f61054-8500-49ff-b521-140ec847fcc4&amp;lt;/span&amp;gt;
&amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;&lt;/p&gt;
&lt;p&gt;&amp;lt;div class=&quot;trace-step&quot;&amp;gt;
&amp;lt;div class=&quot;trace-time&quot;&amp;gt;
&amp;lt;span class=&quot;trace-kind thinking&quot;&amp;gt;thinking&amp;lt;/span&amp;gt;
08:50:16Z
&amp;lt;/div&amp;gt;
&amp;lt;div class=&quot;trace-body&quot;&amp;gt;
&amp;lt;span class=&quot;dim&quot;&amp;gt;&quot;Adjusting text styling... increasing font sizes&amp;lt;br&amp;gt;
 and brightness for phase captions, legend items...&quot;&amp;lt;/span&amp;gt;&amp;lt;br&amp;gt;
&amp;lt;span class=&quot;dim&quot;&amp;gt;thinkingDurationMs: 48&amp;lt;/span&amp;gt;
&amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;&lt;/p&gt;
&lt;p&gt;&amp;lt;div class=&quot;trace-step&quot;&amp;gt;
&amp;lt;div class=&quot;trace-time&quot;&amp;gt;
&amp;lt;span class=&quot;trace-kind tool&quot;&amp;gt;tool&amp;lt;/span&amp;gt;
08:50:16Z
&amp;lt;/div&amp;gt;
&amp;lt;div class=&quot;trace-body&quot;&amp;gt;
&amp;lt;span class=&quot;em&quot;&amp;gt;read_file_v2&amp;lt;/span&amp;gt;(&amp;lt;span class=&quot;hi&quot;&amp;gt;&quot;LoadingScreen.tsx&quot;&amp;lt;/span&amp;gt;)&amp;lt;br&amp;gt;
&amp;lt;span class=&quot;dim&quot;&amp;gt;→ 647 lines&amp;lt;/span&amp;gt;
&amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;&lt;/p&gt;
&lt;p&gt;&amp;lt;div class=&quot;trace-step&quot;&amp;gt;
&amp;lt;div class=&quot;trace-time&quot;&amp;gt;
&amp;lt;span class=&quot;trace-kind tool&quot;&amp;gt;tool&amp;lt;/span&amp;gt;
08:50:24Z
&amp;lt;/div&amp;gt;
&amp;lt;div class=&quot;trace-body&quot;&amp;gt;
&amp;lt;span class=&quot;em&quot;&amp;gt;edit_file&amp;lt;/span&amp;gt; - &amp;lt;span class=&quot;ts&quot;&amp;gt;applies diff to LoadingScreen.tsx&amp;lt;/span&amp;gt;&amp;lt;br&amp;gt;
&amp;lt;span class=&quot;dim&quot;&amp;gt;phase captions, legend, eyebrow, title, tagline, button&amp;lt;/span&amp;gt;
&amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;&lt;/p&gt;
&lt;p&gt;&amp;lt;div class=&quot;trace-step&quot;&amp;gt;
&amp;lt;div class=&quot;trace-time&quot;&amp;gt;
&amp;lt;span class=&quot;trace-kind ai&quot;&amp;gt;response&amp;lt;/span&amp;gt;
08:50:26Z
&amp;lt;/div&amp;gt;
&amp;lt;div class=&quot;trace-body&quot;&amp;gt;
Phase captions: &amp;lt;span class=&quot;hi&quot;&amp;gt;0.52rem → 0.72rem&amp;lt;/span&amp;gt;, &amp;lt;span class=&quot;ok&quot;&amp;gt;rgba(168,144,96,0.55) → rgba(245,217,106,0.92)&amp;lt;/span&amp;gt;&amp;lt;br&amp;gt;
Legend items: &amp;lt;span class=&quot;hi&quot;&amp;gt;0.42rem → 0.58rem&amp;lt;/span&amp;gt; + &amp;lt;span class=&quot;ok&quot;&amp;gt;filter: brightness(1.15)&amp;lt;/span&amp;gt;&amp;lt;br&amp;gt;
Title: &amp;lt;span class=&quot;hi&quot;&amp;gt;clamp(58px,11vw,108px) → clamp(72px,13vw,128px)&amp;lt;/span&amp;gt;&amp;lt;br&amp;gt;
&amp;lt;span class=&quot;dim&quot;&amp;gt;... 6 components updated total&amp;lt;/span&amp;gt;
&amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;&lt;/p&gt;
&lt;p&gt;&amp;lt;div class=&quot;trace-step&quot;&amp;gt;
&amp;lt;div class=&quot;trace-time&quot;&amp;gt;
&amp;lt;span class=&quot;trace-kind data&quot;&amp;gt;hashes&amp;lt;/span&amp;gt;
08:50:21Z
&amp;lt;/div&amp;gt;
&amp;lt;div class=&quot;trace-body&quot;&amp;gt;
&amp;lt;span class=&quot;ok&quot;&amp;gt;18 chunks&amp;lt;/span&amp;gt; written to &amp;lt;span class=&quot;em&quot;&amp;gt;ai_code_hashes&amp;lt;/span&amp;gt;&amp;lt;br&amp;gt;
&amp;lt;span class=&quot;dim&quot;&amp;gt;requestId: f8f61054-8500-49ff-b521-140ec847fcc4 ✓ matches bubble&amp;lt;/span&amp;gt;&amp;lt;br&amp;gt;
&amp;lt;span class=&quot;dim&quot;&amp;gt;timestamp delta: +7s from user prompt&amp;lt;/span&amp;gt;
&amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;&lt;/p&gt;
&lt;p&gt;&amp;lt;div class=&quot;trace-step&quot;&amp;gt;
&amp;lt;div class=&quot;trace-time&quot;&amp;gt;
&amp;lt;span class=&quot;trace-kind user&quot;&amp;gt;user&amp;lt;/span&amp;gt;
08:51:06Z
&amp;lt;/div&amp;gt;
&amp;lt;div class=&quot;trace-body&quot;&amp;gt;
&amp;lt;span class=&quot;hi&quot;&amp;gt;&quot;stop the actions of any agent that is not running...&quot;&amp;lt;/span&amp;gt;&amp;lt;br&amp;gt;
&amp;lt;span class=&quot;dim&quot;&amp;gt;→ no revert, no pushback - moved to next task&amp;lt;/span&amp;gt;&amp;lt;br&amp;gt;
&amp;lt;span class=&quot;ok&quot;&amp;gt;implicit acceptance signal (+40s)&amp;lt;/span&amp;gt;
&amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;&lt;/p&gt;
&lt;p&gt;The timestamps close the loop. The bubble was created at 08:50:14Z. The code chunks in &lt;code&gt;ai_code_hashes&lt;/code&gt; carry a timestamp of 08:50:21Z - seven seconds later, consistent with the time to read the file and apply the edit. The same &lt;code&gt;requestId&lt;/code&gt; links them unambiguously.&lt;/p&gt;
&lt;h2&gt;The Missing Signal: Accept vs. Reject&lt;/h2&gt;
&lt;p&gt;I wanted to build a dataset from these traces but the available signals are too weak to be reliable on their own.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Signal&lt;/th&gt;
&lt;th&gt;Source&lt;/th&gt;
&lt;th&gt;Quality&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;User continues after AI edit&lt;/td&gt;
&lt;td&gt;Next bubble timestamp&lt;/td&gt;
&lt;td&gt;Weak positive&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;AI-written file later deleted&lt;/td&gt;
&lt;td&gt;&lt;code&gt;ai_deleted_files&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Weak negative&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;High &lt;code&gt;composerLinesDeleted&lt;/code&gt; in commit&lt;/td&gt;
&lt;td&gt;&lt;code&gt;scored_commits&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Weak negative&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Low churn - AI lines survive commit&lt;/td&gt;
&lt;td&gt;&lt;code&gt;scored_commits&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Weak positive&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Explicit thumbs up/down&lt;/td&gt;
&lt;td&gt;-&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Not present&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Per-suggestion accept/dismiss&lt;/td&gt;
&lt;td&gt;-&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Not present&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;The closest usable signal is pairing &lt;code&gt;ai_deleted_files&lt;/code&gt; and high &lt;code&gt;composerLinesDeleted&lt;/code&gt; commits as negative examples, and low-churn commits with high &lt;code&gt;composerLinesAdded&lt;/code&gt; retained as positive ones. It&apos;s a stretch.&lt;/p&gt;
&lt;p&gt;The two empty tables - &lt;code&gt;conversation_summaries&lt;/code&gt; and &lt;code&gt;tracked_file_content&lt;/code&gt; - are the real pity here. The schemas suggest Cursor intended to store full file snapshots and summaries per conversation, which would enable before/after diffs per request. Neither table has ever been populated, at least on this machine. Either the feature was removed, or it was never shipped.&lt;/p&gt;
&lt;p&gt;Cursor almost certainly does have explicit accept/dismiss events internally - the tab-completion UI tracks these to report the per-seat acceptance rates that appear on enterprise dashboards. But that data does not surface in either local database.&lt;/p&gt;
&lt;h2&gt;The Join Graph&lt;/h2&gt;
&lt;p&gt;For anyone wanting to build on this, here&apos;s the complete chain of joins across the two databases and the filesystem:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;-- Step 1: pull the user prompt from a bubble
cursorDiskKV[&quot;bubbleId:&amp;lt;convId&amp;gt;:&amp;lt;msgId&amp;gt;&quot;]
  → json.text          -- the prompt
  → json.requestId     -- the foreign key  ← THIS IS THE JOIN

-- Step 2: find code chunks written during that request
ai_code_hashes WHERE requestId = &apos;&amp;lt;requestId&amp;gt;&apos;
  → fileName, hash, model, timestamp

-- Step 3: infer survival via git (indirect)
scored_commits
  WHERE commitDate ≈ timestamp
  AND   branchName = current branch
  → composerLinesDeleted   -- high = negative signal
  → v2AiPercentage         -- context

-- Step 4: explicit deletion (strongest negative signal)
ai_deleted_files WHERE conversationId = &apos;&amp;lt;convId&amp;gt;&apos;
  → gitPath    -- was this file written then deleted?
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Warning:&lt;/strong&gt; The &lt;code&gt;scored_commits&lt;/code&gt; join is not a hard join. There is no &lt;code&gt;requestId&lt;/code&gt; in &lt;code&gt;scored_commits&lt;/code&gt; - only git commit hashes. Linking a specific AI request to a specific commit requires matching on file path plus timestamp proximity, which will produce false positives on active repos with many small commits.&lt;/p&gt;
&lt;h2&gt;What This Is Actually Good For&lt;/h2&gt;
&lt;p&gt;Despite not having an explicit reward signal, the database is genuinely useful for a few things that aren&apos;t RL training:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Code attribution auditing.&lt;/strong&gt; The &lt;code&gt;hash&lt;/code&gt; in &lt;code&gt;ai_code_hashes&lt;/code&gt; is a content hash of each code chunk. Given a file at any point in git history, you can check whether its chunks appear in the tracking DB and recover which model wrote them, when, and in response to which conversation.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Model comparison.&lt;/strong&gt; The database spans multiple models across the same codebase and the same developer workflow. Comparing chunk survival rates per model - how much of what &lt;code&gt;composer-2&lt;/code&gt; wrote ended up deleted vs. retained versus &lt;code&gt;claude-sonnet-4-6&lt;/code&gt; - would be a meaningful if noisy quality signal.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Workflow reconstruction.&lt;/strong&gt; The bubble JSON is rich. It stores attached files, terminal selections, tool call sequences, thinking blocks, and the full context window configuration for every turn. Reconstructing the full trajectory of how a feature was built - including the order of AI requests, what context was provided, and how the conversation evolved - is entirely possible from these two databases.&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;&lt;em&gt;Notes:&lt;/em&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;All data examined was from a single machine. Database schema and content will vary across Cursor versions and per-user configuration.&lt;/li&gt;
&lt;li&gt;The 88% requestId coverage figure reflects bubbles available in &lt;code&gt;state.vscdb&lt;/code&gt; at time of query. Cursor likely prunes old bubbles; the tracking DB does not prune hashes.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;ai_code_hashes.hash&lt;/code&gt; is 8 characters, suggesting a truncated SHA or CRC of the chunk content. Not a full SHA-256; collisions are possible at scale.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;agentKv:blob:*&lt;/code&gt; rows in &lt;code&gt;cursorDiskKV&lt;/code&gt; are binary-encoded protobuf or similar - not examined in this session.&lt;/li&gt;
&lt;/ol&gt;
</content:encoded><category>ai</category><category>reverse-engineering</category><category>cursor</category></item><item><title>BYOA — Bring Your Own Agent</title><link>https://shubhamrasal.com/writing/undefined/</link><guid isPermaLink="true">https://shubhamrasal.com/writing/undefined/</guid><description>A blog post by undefined</description><pubDate>Tue, 31 Mar 2026 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Recently Alex Hormozi talked about how jobs are changing and what is being done to automate roles in a business.&lt;/p&gt;
&lt;p&gt;Each job role has a description of what the person will do in that role. Most roles are workflow-based — essentially a set of tasks that need to get done.&lt;/p&gt;
&lt;h2&gt;The anatomy of a role&lt;/h2&gt;
&lt;p&gt;Consider a software engineer. The role requires someone to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Read and write code&lt;/li&gt;
&lt;li&gt;Review other people&apos;s code&lt;/li&gt;
&lt;li&gt;Design software&lt;/li&gt;
&lt;li&gt;Coordinate with team members&lt;/li&gt;
&lt;li&gt;Report to manager&lt;/li&gt;
&lt;li&gt;Write specs, docs, emails&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;These are some high-level tasks that can be broken down further if required. These tasks, along with the unique knowledge and context of the company or product, make a software engineer.&lt;/p&gt;
&lt;h2&gt;What can be automated right now&lt;/h2&gt;
&lt;p&gt;The core idea is to think about which parts of these tasks can be automated.&lt;/p&gt;
&lt;p&gt;For example:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Merge conflicts&lt;/strong&gt; — takes up a significant amount of time&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Preliminary code review&lt;/strong&gt; — lint issues, flagging company policy violations, etc.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;These are just two very small tasks that can be automated right away with an AI agent and the right tools.&lt;/p&gt;
&lt;h2&gt;BYOA is becoming the expectation&lt;/h2&gt;
&lt;p&gt;I have been looking at many job posts recently, and most of them expect the applicant to bring their own workflows, agents, and tools — to make it easier and faster for them to do their job and get outcomes faster.&lt;/p&gt;
&lt;p&gt;This trend is something I suspect will keep growing. What I am doing right now:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Encode my knowledge base&lt;/strong&gt; (doing it for the last 3 years)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Provide agents with tools&lt;/strong&gt; to make them better at doing their job&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Write, write, write&lt;/strong&gt; — SOPs, workflow specs, instructions, prompts&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;The proactive framing&lt;/h2&gt;
&lt;p&gt;This line of thinking makes you proactive:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&quot;How can I automate myself out of my job in the next two months?&quot;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;If this is something you are already doing or care about, you are already on the right track.&lt;/p&gt;
</content:encoded><category>ai</category><category>philosophy</category></item><item><title>Web3Compass x BYOS Experience</title><link>https://shubhamrasal.com/writing/undefined/</link><guid isPermaLink="true">https://shubhamrasal.com/writing/undefined/</guid><description>A blog post by undefined</description><pubDate>Mon, 30 Mar 2026 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;So recently I started the learning path for understanding Filecoin Onchain Cloud and what I can do with it. It was hosted on this platform called - &lt;a href=&quot;https://www.web3compass.xyz/&quot;&gt;Web3Compass&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;./web3compass-platform.png&quot; alt=&quot;Web3Compass platform&quot; /&gt;&lt;/p&gt;
&lt;p&gt;First of all the platform is really well crafted. There are so many things I like about it:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;the way the program is structured&lt;/li&gt;
&lt;li&gt;quizes&lt;/li&gt;
&lt;li&gt;progress tracking&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;All work as expected.&lt;/p&gt;
&lt;p&gt;I am doing the BYOS learning path and I was specifically interested in the trustless agent section since I have already been familiar with FOC concepts.&lt;/p&gt;
&lt;p&gt;One good thing about this path is that all the required code and starter packs are all linked in the chapters itself, making it easy for me to integrate in the project while I am learning a concept.&lt;/p&gt;
&lt;p&gt;To test the concepts I have learnt in the course, I decided to build an ambitious project - FilCraft.&lt;/p&gt;
&lt;p&gt;FilCraft is an AI agent economy where the agents have to buy their own storage by delivering valuable artifacts. I want to see how far I can push the autonomy of these agents.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;./filcraft-agents.png&quot; alt=&quot;FilCraft agents&quot; /&gt;&lt;/p&gt;
&lt;p&gt;To keep track of their memory and reputation, I adopted ERC-8004 and also deployed custom contracts on Filcoin Calibration network for the same.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;./filcraft-contracts.png&quot; alt=&quot;FilCraft contracts&quot; /&gt;&lt;/p&gt;
&lt;p&gt;I am still experimenting with a lot of things in the project and plan to progressively add features as I learn more.&lt;/p&gt;
&lt;p&gt;You can try out the agents here - &lt;a href=&quot;https://filcraft.vercel.app&quot;&gt;filcraft.vercel.app&lt;/a&gt;&lt;/p&gt;
</content:encoded><category>web3</category><category>ai</category></item><item><title>The Region Beta Paradox of Modern Coding</title><link>https://shubhamrasal.com/writing/undefined/</link><guid isPermaLink="true">https://shubhamrasal.com/writing/undefined/</guid><description>A blog post by undefined</description><pubDate>Thu, 26 Feb 2026 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;You would have experienced this paradox in scenarios other than coding.&lt;/p&gt;
&lt;p&gt;You would walk half a mile to reach somewhere in 10 minutes, whereas you would drive to reach your workplace 2 miles away and get there faster. A minor back pain is ignored for years, while an acute fracture is immediately taken care of.&lt;/p&gt;
&lt;p&gt;The mild inconvenience never triggers a response. The intense one forces you to act, and acting makes things better.&lt;/p&gt;
&lt;p&gt;Something similar is happening in the coding agents space.&lt;/p&gt;
&lt;h2&gt;The comfortable middle&lt;/h2&gt;
&lt;p&gt;Earlier, users started using tab complete models extensively. They provided the right amount of control and productivity boost. The feedback loop was tight: you typed, the model predicted, you accepted or rejected. It felt like a natural extension of how developers already worked.&lt;/p&gt;
&lt;p&gt;Now with better long-horizon models, users have increasingly adopted agentic workflows. Michael Truell&apos;s recent thread about Cursor&apos;s evolution captures this shift clearly: in March 2025, Cursor had roughly 2.5x as many Tab users as agent users. That ratio has now flipped — they have 2x as many agent users as Tab users, with agent usage growing over 15x in a single year.&lt;/p&gt;
&lt;h2&gt;The paradox&lt;/h2&gt;
&lt;p&gt;When you use tab completion, you write code 20–30% faster. That feels good. You&apos;re still walking in the rain, just slightly faster.&lt;/p&gt;
&lt;p&gt;But when you hand off 35% of your PRs to autonomous cloud agents — as Cursor&apos;s own team now does — everything has to change. Your tests can&apos;t be flaky. Your environments can&apos;t be brittle. Your task descriptions need to be precise enough for a non-human teammate to act on independently.&lt;/p&gt;
&lt;p&gt;The pain of that reorganisation is sharp enough to actually trigger a deeper structural response — and that&apos;s exactly what makes it productive.&lt;/p&gt;
&lt;p&gt;This is the paradox. The mild productivity boost of tab completion was comfortable enough to never demand change. Autonomous agents are disruptive enough that they force it.&lt;/p&gt;
&lt;h2&gt;The agent-first developer&lt;/h2&gt;
&lt;p&gt;The amount of code generated by agents is increasing rapidly, making agents the default option for coding.&lt;/p&gt;
&lt;p&gt;Truell describes developers who have fully embraced this shift as having three traits:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Agents write almost 100% of their code&lt;/li&gt;
&lt;li&gt;They spend their time breaking down problems and reviewing artifacts&lt;/li&gt;
&lt;li&gt;They spin up multiple agents simultaneously instead of handholding one to completion&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The adoption curve is probably skewed toward power users. Lots of programmers have not yet experienced the capabilities of the latest coding agents. Many are still in the tab completion zone — productive enough to feel modern, not disrupted enough to transform.&lt;/p&gt;
&lt;h2&gt;What comes next&lt;/h2&gt;
&lt;p&gt;Agentic coding patterns require a lot of structural changes in organisations that have traditionally been slow to move.&lt;/p&gt;
&lt;p&gt;I predict new companies will skip tab-completion-based coding entirely and directly start with an agent-first approach for building software. They won&apos;t carry the baggage of workflows designed around human keystroke productivity. They&apos;ll structure their codebases, their specs, and their review processes for agents from day one — and that head start will compound fast.&lt;/p&gt;
&lt;p&gt;The region beta paradox tells us that the comfortable middle is often the trap. In coding, that trap is tab completion.&lt;/p&gt;
&lt;p&gt;The teams and companies that push through to the acute discomfort of agent-first development will be the ones that come out faster on the other side.&lt;/p&gt;
</content:encoded><category>ai</category><category>philosophy</category></item><item><title>Defining the Hairy Problem</title><link>https://shubhamrasal.com/writing/undefined/</link><guid isPermaLink="true">https://shubhamrasal.com/writing/undefined/</guid><description>A blog post by undefined</description><pubDate>Sat, 10 Jan 2026 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;This is the fundamental issue each knowledge worker needs to solve on a daily basis.&lt;/p&gt;
&lt;h4&gt;Entropy reduction&lt;/h4&gt;
&lt;p&gt;If you see a random day in a knowledge worker&apos;s job, it would sound something like this—&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&quot;Boss has asked me to fix the sales numbers. What does that even mean?&quot;&lt;/li&gt;
&lt;li&gt;&quot;This design does not drive conversions, and I have no idea what to do.&quot;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Entropy is why an email with the subject line &lt;em&gt;&quot;Quick sync?&quot;&lt;/em&gt; ruins your morning.&lt;/p&gt;
&lt;p&gt;The job of a knowledge worker is to reduce the entropy in the system—to act like a funnel that takes in high entropy (chaos) and converts it into low entropy (order).&lt;/p&gt;
&lt;p&gt;Articulation is the tool with which one can achieve this. It is not just writing the problem down; it is constraint identification.&lt;/p&gt;
&lt;h4&gt;Clarity of thought vs intelligence&lt;/h4&gt;
&lt;p&gt;Standardized tests (SATs, GREs) are designed to measure raw intelligence, but they cheat: they give you well-defined problems. They remove the noise. Real life is nothing but noise. Therefore, real-world success is a function of &lt;code&gt;Raw Intelligence&lt;/code&gt; × &lt;code&gt;Clarity of Thought&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Clarity of thought and intelligence seem to be two different things. While one is largely innate, the other is an acquired skill.&lt;/p&gt;
&lt;p&gt;Articulation is a skill, as it is trainable. The skill can be defined as the ability to define the shape of a problem. So, how do we train this &quot;clarity of thought&quot;? It starts by visualizing the problem physically.&lt;/p&gt;
&lt;h4&gt;The shape of the problem&lt;/h4&gt;
&lt;p&gt;A shapeless problem is a source of stress. It might look like—&quot;My work is boring!&quot;&lt;/p&gt;
&lt;p&gt;A better problem statement would be—&quot;I need to negotiate for two interesting tasks that help me improve my Python coding skills without increasing my total working hours.&quot;&lt;/p&gt;
&lt;p&gt;Let&apos;s take a really complex, hairy issue—something that has a lot of moving variables, like deciding a career or finding the right house.&lt;/p&gt;
&lt;p&gt;We can take inspiration from computers and try to solve it algorithmically. This would mean breaking down the problem into smaller ones until we hit a trivial problem with a known solution. This is called recursive decomposition and is a well-studied concept that is heavily used while designing solutions for complex problems in computer science.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Vague:&lt;/strong&gt; Deciding a career&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Decomposed:&lt;/strong&gt; &quot;Need to find a role that pays at least $X, requires no more than $Y$ hours of travel, and utilizes skill $Z$, within the next six months.&quot;&lt;/p&gt;
&lt;p&gt;This makes the problem far more solvable, which is exactly what we are trying to do.&lt;/p&gt;
&lt;p&gt;Math is very rigorous when it comes to defining problems. Jacques Hadamard suggested the concept of well-posed problems.&lt;/p&gt;
&lt;p&gt;A problem is only &quot;well-posed&quot; if:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A solution exists&lt;/li&gt;
&lt;li&gt;The solution is unique&lt;/li&gt;
&lt;li&gt;The solution depends continuously on the data&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;While life doesn&apos;t always have a &lt;em&gt;unique&lt;/em&gt; solution like math, we should strive for the &lt;em&gt;clarity&lt;/em&gt; that math demands.&lt;/p&gt;
&lt;p&gt;This gives us an algorithm to convert a mess into a better-organized problem:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Define constraints that the desired solution should have&lt;/li&gt;
&lt;li&gt;Restrict the scope of the solution&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The cool thing about defining a problem is that it is a very effective tool for understanding the problem.&lt;/p&gt;
&lt;h3&gt;Automate the articulation&lt;/h3&gt;
&lt;p&gt;The highest form of this skill is when articulation becomes automated. Great problem solvers are really just framework developers. They find themselves defining the same problem types repeatedly, so they crystallize their methodology.&lt;/p&gt;
&lt;p&gt;For example, Elon&apos;s framework for solving hard problems is:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Make the requirements less dumb.&lt;/strong&gt; (Question the constraints immediately.)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Delete the part or process.&lt;/strong&gt; (If you are not adding back at least 10% of the time, you aren&apos;t deleting enough.)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Simplify or optimize.&lt;/strong&gt; (Only do this &lt;em&gt;after&lt;/em&gt; steps 1 and 2.)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Accelerate cycle time.&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Automate.&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Or &lt;strong&gt;Jack Dorsey&apos;s protocol:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Perfect every detail.&lt;/li&gt;
&lt;li&gt;Limit the number of details.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;The payoff&lt;/h3&gt;
&lt;p&gt;&quot;A problem well put is half solved.&quot; — John Dewey&lt;/p&gt;
&lt;p&gt;The hidden benefit of articulation is that once a problem is constrained and defined, you no longer have to be the one to solve it. A vague problem requires &lt;em&gt;you&lt;/em&gt; to stress over it. A well-articulated problem can be outsourced—to a junior employee, to code, or to AI.&lt;/p&gt;
</content:encoded><category>philosophy</category></item><item><title>Designing a High-Performance OLTP Database from First Principles</title><link>https://shubhamrasal.com/writing/undefined/</link><guid isPermaLink="true">https://shubhamrasal.com/writing/undefined/</guid><description>A blog post by undefined</description><pubDate>Tue, 06 Jan 2026 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;&lt;em&gt;A deep dive inspired by TigerBeetle and Viewstamped Replication&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;While reading about &lt;strong&gt;Viewstamped Replication (VSR)&lt;/strong&gt;, I came across &lt;strong&gt;TigerBeetle&lt;/strong&gt;, which uses this replication protocol to achieve extremely high reliability. Little did I know how fascinating the design of such a database would turn out to be.&lt;/p&gt;
&lt;p&gt;If you had to design a &lt;strong&gt;highly efficient OLTP database from first principles&lt;/strong&gt;, how would you do it?&lt;/p&gt;
&lt;p&gt;One strong answer is: &lt;em&gt;do what TigerBeetle did&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;TigerBeetle builds its system by tightly integrating the four primary dimensions of computer science—&lt;strong&gt;network, storage, memory, and compute&lt;/strong&gt;—to arrive at a configuration that is radically more optimal than conventional databases.&lt;/p&gt;
&lt;hr /&gt;
&lt;h2&gt;Design Goals&lt;/h2&gt;
&lt;p&gt;The system starts with a set of aggressive but clear goals:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;No horizontal scaling—optimize &lt;strong&gt;orders of magnitude&lt;/strong&gt; of ops/sec on a single node&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;1000× performance&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;10× safety&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;10× developer and operator experience&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;code&gt;                    Design Goals
                         |
        +----------------+----------------+
        |                |                |
    1000× Perf      10× Safety    10× Dev/Ops Exp
        |                |                |
  Orders of mag    Data Integrity    Simplicity
   more ops/sec     &amp;amp; Durability     &amp;amp; Reliability
                         |
              Single Node Optimization
                         |
            No Horizontal Scaling Complexity
&lt;/code&gt;&lt;/pre&gt;
&lt;hr /&gt;
&lt;h2&gt;Rethinking OLTP Workloads&lt;/h2&gt;
&lt;p&gt;The nature of OLTP workloads has changed drastically over time.&lt;/p&gt;
&lt;p&gt;Originally, OLTP systems handled simple debit/credit operations, primarily for financial data. These operations are essentially &lt;strong&gt;database transactions derived from business transactions&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;If we conceptually split OLTP into:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;OLGP&lt;/strong&gt; – general-purpose workloads&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;OLTP&lt;/strong&gt; – pure transaction processing&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;we can target scale far more effectively.&lt;/p&gt;
&lt;h3&gt;Inverting Query Amplification&lt;/h3&gt;
&lt;p&gt;Traditional financial databases often require &lt;strong&gt;~10 database queries per business transaction&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;What if we invert this relationship?&lt;/p&gt;
&lt;p&gt;Because OLTP workloads are fundamentally accounting workloads:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;1 database query = 1000 business transactions&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;This inversion fundamentally changes scalability.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Traditional Approach:
    1 Business Transaction  →  ~10 Database Queries
    ❌ High overhead, many round trips

Inverted Approach (TigerBeetle):
    1 Database Query  →  ~1000 Business Transactions
    ✅ Massive batching, optimal throughput
&lt;/code&gt;&lt;/pre&gt;
&lt;hr /&gt;
&lt;h2&gt;Exploiting the Four Axes&lt;/h2&gt;
&lt;pre&gt;&lt;code&gt;           TigerBeetle Architecture
                    |
    +-------+-------+-------+-------+
    |       |       |       |       |
 Network Storage Memory  Compute
    |       |       |       |
    |       |       |       +-- Viewstamped Replication
    |       |       |       +-- Deterministic Leader Election
    |       |       |
    |       |       +-- Zero-copy
    |       |       +-- Zero-allocation
    |       |       +-- No runtime malloc
    |       |
    |       +-- 1 MiB WAL writes
    |       +-- Direct I/O
    |
    +-- Batching: 8000 txns/batch
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;Network&lt;/h3&gt;
&lt;p&gt;With batching:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;One &lt;code&gt;recv()&lt;/code&gt; call can ingest ~1 MiB of data&lt;/li&gt;
&lt;li&gt;This corresponds to roughly &lt;strong&gt;8000 transactions&lt;/strong&gt; per batch&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Storage&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;One &lt;code&gt;write()&lt;/code&gt; call writes a 1 MiB WAL entry&lt;/li&gt;
&lt;li&gt;Low latency via &lt;code&gt;fsync()&lt;/code&gt; or direct I/O&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt;
Direct I/O is now often faster than buffered I/O due to modern storage hardware. The real bottleneck has shifted to &lt;strong&gt;memory&lt;/strong&gt;, which must be addressed via:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Zero-copy&lt;/li&gt;
&lt;li&gt;Zero-allocation&lt;/li&gt;
&lt;li&gt;No &lt;code&gt;malloc&lt;/code&gt; during runtime&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Compute&lt;/h3&gt;
&lt;p&gt;Distributed systems must handle &lt;strong&gt;leader election&lt;/strong&gt; when the primary node fails—which is inevitable.&lt;/p&gt;
&lt;p&gt;Common consensus algorithms include Paxos and Raft. Here, we focus on &lt;strong&gt;Viewstamped Replication (VSR)&lt;/strong&gt;, which handles primary failure while preserving operation order and data correctness.&lt;/p&gt;
&lt;hr /&gt;
&lt;h2&gt;Viewstamped Replication (VSR)&lt;/h2&gt;
&lt;h3&gt;Key Notes&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Use VSR on a &lt;em&gt;single-node&lt;/em&gt; system to turn it into a &lt;strong&gt;highly available distributed system&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Fault tolerance is achieved through &lt;strong&gt;redundancy in space and time&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Based on &lt;strong&gt;state machine replication&lt;/strong&gt;: initial state + replicated operation log → identical final state&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;TigerBeetle uses VSR instead of Paxos or Raft primarily because &lt;strong&gt;leader election is deterministic&lt;/strong&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;VSR Protocol Flow:

Client ────Request───&amp;gt; Primary
                         |
                      Prepare
                         |
          +--------------+---------------+
          |                              |
    Prepare Msg                    Prepare Msg
          |                              |
          v                              v
      Replica 1                      Replica 2
          |                              |
     Prepare OK                     Prepare OK
          |                              |
          +--------------+---------------+
                         |
                         v
                      Primary
                         |
                      Commit
                         |
          +--------------+---------------+
          |              |               |
      Response      Commit Msg      Commit Msg
          |              |               |
          v              v               v
       Client        Replica 1       Replica 2
&lt;/code&gt;&lt;/pre&gt;
&lt;hr /&gt;
&lt;h2&gt;The Performance Result&lt;/h2&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;4 syscalls, 4 memory copies, 3 network requests → ~8000 TPS&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;The biggest win is actually the &lt;strong&gt;reduction of row locks&lt;/strong&gt;—from ~16k down to effectively zero.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Request Batch → recv syscall → write WAL syscall → send ack syscall → read state syscall
                                                                              |
                                                                         8000 TPS ✅
&lt;/code&gt;&lt;/pre&gt;
&lt;hr /&gt;
&lt;h2&gt;Why Only Four Syscalls?&lt;/h2&gt;
&lt;p&gt;In a typical processing cycle, the system needs to:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Receive&lt;/strong&gt; batched requests from the network&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Write&lt;/strong&gt; them to the WAL&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Send&lt;/strong&gt; acknowledgments&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Read&lt;/strong&gt; state for processing&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Instead of issuing a syscall per packet or block, TigerBeetle aggregates all operations.&lt;/p&gt;
&lt;p&gt;Using &lt;code&gt;io_uring&lt;/code&gt;, the application submits a batch of reads and writes and enters the kernel &lt;strong&gt;once&lt;/strong&gt;. This allows a &lt;strong&gt;single execution thread&lt;/strong&gt; to saturate modern NVMe drives and 100 GbE network links.&lt;/p&gt;
&lt;hr /&gt;
&lt;h2&gt;Durability Considerations&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;More scale demands more durability&lt;/li&gt;
&lt;li&gt;Even &lt;strong&gt;0.5% disk corruption over two years&lt;/strong&gt; becomes catastrophic at large scale&lt;/li&gt;
&lt;li&gt;Durability issues grow &lt;strong&gt;exponentially&lt;/strong&gt; with workload size&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;code&gt;Scale
  └─&amp;gt; More Data
       └─&amp;gt; Higher Risk of Corruption
            └─&amp;gt; Exponential Impact
                 └─&amp;gt; Need Cryptographic Guarantees
&lt;/code&gt;&lt;/pre&gt;
&lt;hr /&gt;
&lt;h2&gt;Replication Concerns with Raft&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Raft does not exploit global redundancy&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;In a 1-primary, 2-replica setup:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;One replica missing data&lt;/li&gt;
&lt;li&gt;One replica corrupted&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;If the primary fails, Raft cannot determine a new leader and stalls&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;TigerBeetle avoids this by using &lt;strong&gt;cryptographic hash chains&lt;/strong&gt; for replication integrity.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Raft Limitation:
    Replica 1: Missing Data
    Replica 2: Corrupted
    Primary Fails
      └─&amp;gt; Cannot Elect New Leader
           └─&amp;gt; System Stalls ❌

TigerBeetle Solution:
    Cryptographic Hash Chains
      └─&amp;gt; Verify Data Integrity
           └─&amp;gt; Safe Leader Election ✅
&lt;/code&gt;&lt;/pre&gt;
&lt;hr /&gt;
&lt;h2&gt;Codebase Deep Dive&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Written in &lt;strong&gt;Zig&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Explicit control flow&lt;/li&gt;
&lt;li&gt;Strict, static resource allocation&lt;/li&gt;
&lt;li&gt;Extensive use of &lt;em&gt;&quot;checksums to check the checksums&quot;&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Every data structure—from protocol headers to on-disk state—is fortified with cryptographic checksums.&lt;/p&gt;
&lt;h3&gt;Core Components&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;VSR implementation:&lt;/strong&gt; &lt;code&gt;src/vsr.zig&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Replica state machine:&lt;/strong&gt; &lt;code&gt;src/vsr/replica.zig&lt;/code&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Acts as the CPU of a TigerBeetle node&lt;/li&gt;
&lt;li&gt;Transitions state based on VSR messages (Prepare, Commit, ViewChange, etc.)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;One interesting finding from &lt;a href=&quot;https://github.com/tigerbeetle/tigerbeetle/issues/1590&quot;&gt;this crash report&lt;/a&gt;
is how the &lt;code&gt;quorum_headers&lt;/code&gt; function tallies cluster responses.&lt;/p&gt;
&lt;p&gt;Time is measured not in wall-clock seconds, but in &lt;strong&gt;logical ticks&lt;/strong&gt;—processed messages via &lt;code&gt;replica.tick()&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Because state is a pure function of the log, &lt;strong&gt;state transfer&lt;/strong&gt; is as simple as sending snapshots or data files.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Replica State Machine:

    [Start]
       |
       v
   ┌────────┐
   │ Normal │&amp;lt;─────────────┐
   └────────┘              |
       |                   |
  Primary Failure          |
       |                   |
       v                   |
   ┌───────────┐           |
   │ ViewChange │          |
   └───────────┘           |
       |                   |
  log_view &amp;lt; view?         |
       |                   |
    +──+──+                |
    |     |                |
   Yes   No                |
    |     |                |
    v     v                |
DoViewChange  StartView    |
    |          |           |
    |          |           |
    +────┬─────+           |
         |                 |
    New Primary Elected    |
         |                 |
         └─────────────────┘
&lt;/code&gt;&lt;/pre&gt;
&lt;hr /&gt;
&lt;h2&gt;Handling Leader Failure&lt;/h2&gt;
&lt;p&gt;To initiate leader change, a replica transitions from &lt;strong&gt;normal mode&lt;/strong&gt; to &lt;strong&gt;participation mode&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;This is handled in &lt;code&gt;src/vsr/superblock.zig&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;pub fn view_headers(superblock: *const SuperBlockHeader) vsr.Headers.ViewChangeSlice {
    return vsr.Headers.ViewChangeSlice.init(
        if (superblock.vsr_state.log_view &amp;lt; superblock.vsr_state.view)
           .do_view_change
        else
           .start_view,
        superblock.view_headers_all[0..superblock.view_headers_count],
    );
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If &lt;code&gt;log_view &amp;lt; view&lt;/code&gt;, the system infers a transition state and executes &lt;code&gt;do_view_change&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The critical insight: &lt;strong&gt;view state is persisted in the superblock&lt;/strong&gt;, not volatile memory.&lt;/p&gt;
&lt;hr /&gt;
&lt;h2&gt;Storage as the Anchor of Trust&lt;/h2&gt;
&lt;p&gt;TigerBeetle does not rely on filesystem guarantees—because they effectively do not exist.&lt;/p&gt;
&lt;p&gt;Instead, it implements its own transactional guarantees using a &lt;strong&gt;cryptographic hash chain&lt;/strong&gt;, capable of reconstructing a universal state even from partially corrupted replicas.&lt;/p&gt;
&lt;h3&gt;SuperBlockHeader&lt;/h3&gt;
&lt;p&gt;Defined in &lt;a href=&quot;https://github.com/tigerbeetle/tigerbeetle/blob/main/src/vsr/superblock.zig&quot;&gt;src/vsr/superblock.zig&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Uses Zig&apos;s &lt;code&gt;extern struct&lt;/code&gt; to guarantee precise on-disk layout.&lt;/p&gt;
&lt;p&gt;Key fields include:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Field&lt;/th&gt;
&lt;th&gt;Type&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;checksum&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;u128&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Checksum of remaining fields&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;copy&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;u16&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Superblock copy index (0–3)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;sequence&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;u64&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Monotonic version counter&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;cluster&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;u128&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Cluster UUID&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;parent&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;u128&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Hash of previous superblock&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;vsr_state&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;VSRState&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Embedded consensus state&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Embedding &lt;code&gt;VSRState&lt;/code&gt; directly into storage solves &lt;strong&gt;split-brain at the storage layer&lt;/strong&gt;. On startup, the node immediately knows its latest consensus state—no log replay needed.&lt;/p&gt;
&lt;p&gt;The superblock is physically duplicated &lt;strong&gt;four times on disk&lt;/strong&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;        SuperBlock
            |
    +-------+-------+-------+
    |       |       |       |
  Copy 0  Copy 1  Copy 2  Copy 3
    |       |       |       |
    +-------+-------+-------+
            |
        Redundancy
            |
   Survives Partial Corruption
&lt;/code&gt;&lt;/pre&gt;
&lt;hr /&gt;
&lt;h2&gt;Journal (WAL) as a Hash Chain&lt;/h2&gt;
&lt;p&gt;TigerBeetle&apos;s WAL—called the &lt;em&gt;journal&lt;/em&gt;—is not a simple append log.&lt;/p&gt;
&lt;p&gt;Each entry contains:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A sequence number&lt;/li&gt;
&lt;li&gt;A checksum pointing to the previous entry&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This forms a hash chain similar to a blockchain.&lt;/p&gt;
&lt;p&gt;The function &lt;code&gt;valid_hash_chain_between&lt;/code&gt; verifies integrity across log ranges. If corruption is detected (e.g., torn writes), the system repairs itself by fetching clean blocks from peers.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Journal Hash Chain:

[Entry 1] --checksum--&amp;gt; [Entry 2] --checksum--&amp;gt; [Entry 3] --checksum--&amp;gt; [Entry 4] --checksum--&amp;gt; [Entry 5]

Each entry contains:
  - Sequence number
  - Checksum of previous entry
  - Transaction data

Similar to blockchain structure for integrity verification
&lt;/code&gt;&lt;/pre&gt;
&lt;hr /&gt;
&lt;h2&gt;Storage Data Structures&lt;/h2&gt;
&lt;p&gt;Instead of a single LSM tree, TigerBeetle uses an &lt;strong&gt;LSM forest&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Object trees&lt;/strong&gt; – transfers sorted by timestamp&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Index trees&lt;/strong&gt; – primary and secondary indexes&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This improves locality and performance.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;        LSM Forest
            |
    +-------+-------+
    |               |
Object Trees   Index Trees
    |               |
Transfers by    +---+---+
 Timestamp      |       |
                |       |
            Primary  Secondary
            Indexes  Indexes
                |
                v
         Better Locality
                |
                v
        Higher Performance
&lt;/code&gt;&lt;/pre&gt;
&lt;hr /&gt;
&lt;h2&gt;I/O: Direct I/O and Determinism&lt;/h2&gt;
&lt;p&gt;TigerBeetle bypasses OS abstractions like page cache to eliminate unpredictability.&lt;/p&gt;
&lt;p&gt;From &lt;code&gt;/src/io/linux.zig&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;fn fs_supports_direct_io(dir_fd: fd_t)!bool {
    if (!@hasField(posix.O, &quot;DIRECT&quot;)) return false;
    //...
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Kernel page cache is dangerous because:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;code&gt;fsync()&lt;/code&gt; may lie about durability&lt;/li&gt;
&lt;li&gt;Memory pressure causes unpredictable eviction&lt;/li&gt;
&lt;li&gt;Cached corruption propagates silently&lt;/li&gt;
&lt;/ol&gt;
&lt;pre&gt;&lt;code&gt;Traditional I/O ❌                Direct I/O ✅
      |                                |
 Kernel Page Cache               Bypass Page Cache
      |                                |
  +---+---+                       +----+----+
  |   |   |                       |         |
fsync  Unpredictable        Deterministic  True
may lie  eviction           Behavior     Durability
      |
Silent corruption
&lt;/code&gt;&lt;/pre&gt;
&lt;hr /&gt;
&lt;h2&gt;Static Memory Allocation&lt;/h2&gt;
&lt;p&gt;Many production crashes happen under load due to allocation failures.&lt;/p&gt;
&lt;p&gt;TigerBeetle avoids this entirely:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Startup: compute maximum memory requirements&lt;/li&gt;
&lt;li&gt;Allocate one large contiguous block&lt;/li&gt;
&lt;li&gt;Runtime: pop and return buffers from a pool&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;See &lt;code&gt;src/message_pool.zig&lt;/code&gt; and &lt;a href=&quot;https://github.com/tigerbeetle/tigerbeetle/issues/1137&quot;&gt;this stack trace&lt;/a&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Static Memory Allocation Flow:

Startup
  └─&amp;gt; Calculate Max Memory Requirements
       └─&amp;gt; Allocate One Large Contiguous Block
            └─&amp;gt; Create Buffer Pool
                 └─&amp;gt; Runtime ✅
                      ├─&amp;gt; Pop Buffer
                      ├─&amp;gt; Use Buffer
                      └─&amp;gt; Return Buffer
                           └─&amp;gt; (cycle continues)

Benefits:
  • No allocation failures under load
  • Predictable memory usage
  • No fragmentation
  • Zero runtime malloc overhead
&lt;/code&gt;&lt;/pre&gt;
&lt;hr /&gt;
&lt;h2&gt;A Note on Programming Style&lt;/h2&gt;
&lt;p&gt;This style of programming is refreshing.&lt;/p&gt;
&lt;p&gt;Even without deep familiarity with Zig, the code is easy to follow due to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Explicit callbacks&lt;/li&gt;
&lt;li&gt;Clear control flow&lt;/li&gt;
&lt;li&gt;Descriptive struct layouts&lt;/li&gt;
&lt;li&gt;Noun-based naming (&lt;code&gt;replica.pipeline&lt;/code&gt;, &lt;code&gt;replica.preparing&lt;/code&gt;)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;It is a style that makes correctness obvious—and bugs uncomfortable.&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;&lt;strong&gt;End result:&lt;/strong&gt; a database designed from first principles, where performance, safety, and determinism are not trade-offs, but consequences of the architecture.&lt;/p&gt;
&lt;hr /&gt;
&lt;h2&gt;References&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://docs.tigerbeetle.com/concepts/&quot;&gt;TigerBeetle Documentation - Concepts&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://blog.brunobonacci.com/2018/07/15/viewstamped-replication-explained/&quot;&gt;Viewstamped Replication Explained&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://www.infoq.com/presentations/redesign-oltp/&quot;&gt;InfoQ Presentation: Redesigning OLTP&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/tigerbeetle/tigerbeetle&quot;&gt;TigerBeetle Codebase on GitHub&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content:encoded><category>systems</category></item><item><title>Understanding the will of the universe</title><link>https://shubhamrasal.com/writing/undefined/</link><guid isPermaLink="true">https://shubhamrasal.com/writing/undefined/</guid><description>A blog post by undefined</description><pubDate>Mon, 05 Jan 2026 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;import Sidenote from &apos;../components/Sidenote.tsx&apos;;&lt;/p&gt;
&lt;p&gt;If you really love something, you need to understand the language in which it speaks. For all universe lovers, especially people who are trying to understand the will of universe, it is crucial to &amp;lt;Sidenote note=&quot;Math is the universe&apos;s native tongue — dense, infinite, and largely untranslated.&quot;&amp;gt;understand math to a pretty high degree so that you can decipher it&apos;s thoughts.&amp;lt;/Sidenote&amp;gt; The problem with math as a language is that it is really dense and packed with meaning. It can be arbitrarily complex and can branch out into infinite dialects.&lt;/p&gt;
&lt;p&gt;A small fraction of math is actually usable for real world scenarios. &amp;lt;Sidenote side=&quot;left&quot; note=&quot;Most math is invented to fit observations, not the other way around.&quot;&amp;gt;Rest all is just invented just out of a need to solve a problem or fit an observation.&amp;lt;/Sidenote&amp;gt; Consider the partitions or the infinite converging series. For instance, you know that you can&apos;t divide a segment infinitely, but you do realize that we need some way to formulate or display this phenomenon using an equation which in this case is a single finite value on one side and an infinite sum on the other (x = inf)&lt;/p&gt;
&lt;p&gt;Another case would be &amp;lt;Sidenote note=&quot;i = √−1 — a hack that turned out to describe reality more accurately than &apos;real&apos; numbers.&quot;&amp;gt;imaginary numbers.&amp;lt;/Sidenote&amp;gt; They show up all the times where you least expect them to be. But mostly in math. First time I heard about them, it just felt that math nerds wanted to get their hands on the tools used by geometrical people, so they decided to invent a new dimension. But it seems to be that it is conceptually no different from extending the natural numbers into the negative side of the number line.&lt;/p&gt;
&lt;p&gt;Another interesting example is from the field of physics. &amp;lt;Sidenote side=&quot;left&quot; note=&quot;Planck didn&apos;t want to quantize energy — he did it as a mathematical trick and it worked.&quot;&amp;gt;Max Planck could not solve the ultraviolet catastrophe without using a constant in his equations that made waves quantum.&amp;lt;/Sidenote&amp;gt; Now I don&apos;t know whether he intended to invent it or discover it, but it surely did fit the description of the universe well, so much so that currently you can&apos;t explain any phenomenon without using it.&lt;/p&gt;
&lt;p&gt;Science and math have had a deep rooted relationship of what I call the &amp;lt;Sidenote note=&quot;The lancer is physics. The smith is mathematics. Each needs the other to advance.&quot;&amp;gt;lancer-smith duo.&amp;lt;/Sidenote&amp;gt; The lancer requires tools and weapons to tame seemingly impossible monsters. The smith has them but has forgotten where he has kept it. It is the job of the lancer to dig deep in the smith&apos;s workshop and find what he needs.&lt;/p&gt;
&lt;p&gt;Coming from a noob&apos;s standpoint, having done very little math personally (most math I have done is just of passing grades), I really admire mathematicians. &amp;lt;Sidenote side=&quot;left&quot; note=&quot;Math is like wine — you need a refined palate before you can appreciate the good stuff.&quot;&amp;gt;I consider math to be an acquired taste or like a higher pleasure.&amp;lt;/Sidenote&amp;gt; You need be at a certain level to admire it and understand it meaningfully.&lt;/p&gt;
&lt;p&gt;I still don&apos;t understand how creativity or innovative thinking works. &amp;lt;Sidenote note=&quot;Ramanujan claimed his theorems came to him in dreams from a goddess. Peer review was apparently optional.&quot;&amp;gt;How could Ramanujan come up with so many ground breaking equations and theorems on partitions and series with just a basic knowledge of math?&amp;lt;/Sidenote&amp;gt;&lt;/p&gt;
&lt;p&gt;It should definitely have some random functions component to it. But it has to be so refined and guardrailed that you can rely on it. Since we are playing in the knowledge world, normal rules of evolution don&apos;t apply here. &amp;lt;Sidenote side=&quot;left&quot; note=&quot;Each generation re-climbs the same mountain. No inherited memory — just textbooks.&quot;&amp;gt;The math needs to be learnt again and again from the ground up by every person who wants to further it or work on it.&amp;lt;/Sidenote&amp;gt; This I feel is a limitation that needs to be addressed but we can talk about it some other time.&lt;/p&gt;
&lt;p&gt;It is proven fact that people who are experts in a particular field, and have often spend a significant amount of time in it, &amp;lt;Sidenote note=&quot;Neuroplasticity means the brain literally rewires itself to think in the language of the domain.&quot;&amp;gt;have different neural pathways than an average human being&amp;lt;/Sidenote&amp;gt; — thanks to our surprisingly good neuroplasticity. This makes it possible for the experts to spend more time on the frontier and skilfully fill in the gaps with their specialised tools.&lt;/p&gt;
</content:encoded><category>philosophy</category></item><item><title>Khoj Progress Update</title><link>https://shubhamrasal.com/writing/undefined/</link><guid isPermaLink="true">https://shubhamrasal.com/writing/undefined/</guid><description>A blog post by undefined</description><pubDate>Sun, 21 Sep 2025 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Khoj is our platform for &lt;strong&gt;AI-powered, location-based treasure hunts&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Players solve riddles, visit physical locations, and earn onchain rewards. Each user receives a unique NFT upon registration, and completing hunts grants rewards recorded on-chain.&lt;/p&gt;
&lt;p&gt;Since our MVP at &lt;strong&gt;ETHIndia &apos;24&lt;/strong&gt;, we’ve significantly improved usability, stability, and the overall experience.&lt;/p&gt;
&lt;p&gt;This milestone focuses on making Khoj more robust, secure, and fun — while staying true to our mission of building a &lt;strong&gt;Web2-native experience that seamlessly onboards users to Web3&lt;/strong&gt;.&lt;/p&gt;
&lt;h2&gt;New Architecture&lt;/h2&gt;
&lt;p&gt;&lt;img src=&quot;khoj_arch.png&quot; alt=&quot;Khoj Architecture&quot; /&gt;&lt;/p&gt;
&lt;h2&gt;🚀 Major Updates&lt;/h2&gt;
&lt;h3&gt;1. Accurate Distance Algorithm&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Replaced the earlier naive distance logic with the &lt;code&gt;haversineDistance&lt;/code&gt; algorithm for precise geolocation checks.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Reduces error margins for location validation, with a &lt;strong&gt;sub-10m accuracy&lt;/strong&gt;, ensuring fairer gameplay.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;We also noticed that mobile phone browsers use the native GPS sensor. This leads to better user location coordinates. Since, Khoj is mobile-first, coordinates received from phones with precise location turned on, lead to much better results.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/ayush4345/Khoj/pull/36&quot;&gt;PR #36&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;hr /&gt;
&lt;h3&gt;2. Teams: Secure, Decentralized, and User-Friendly&lt;/h3&gt;
&lt;p&gt;One of the most requested features during our pilot hunts was &lt;strong&gt;support for teams&lt;/strong&gt;. Designing this was far from trivial:&lt;/p&gt;
&lt;p&gt;The original Khoj design assumed solo-only hunts.We needed a way to let users &lt;strong&gt;form teams securely&lt;/strong&gt;, without central storage, and without exposing sensitive invite codes on-chain.The final flow had to balance &lt;strong&gt;security, decentralization, and user experience&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;After several iterations, here’s the final architecture we built:&lt;/p&gt;
&lt;hr /&gt;
&lt;h4&gt;🔐 Smart Contract Responsibilities&lt;/h4&gt;
&lt;p&gt;The smart contract is the &lt;strong&gt;source of truth&lt;/strong&gt; for teams.&lt;br /&gt;
It handles creation, membership checks, and validation when new members join.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;struct Team {
    address owner;
    uint256 maxMembers;
    uint256 memberCount;
    mapping(address =&amp;gt; bool) members;
}

mapping(uint256 =&amp;gt; Team) public teams;
uint256 public nextTeamId;
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Create Team:&lt;/strong&gt;&lt;br /&gt;
&lt;code&gt;createTeam(maxMembers)&lt;/code&gt; → creates a new team, sets the owner, and stores maximum size.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Join via Invite:&lt;/strong&gt;&lt;br /&gt;
&lt;code&gt;joinWithInvite(teamId, expiry, signature)&lt;/code&gt; → verifies the invite signature and admits new members.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Validation checks:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Invite not expired (&lt;code&gt;block.timestamp &amp;lt;= expiry&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;User not already in team.&lt;/li&gt;
&lt;li&gt;Team not full (&lt;code&gt;memberCount &amp;lt; maxMembers&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;Signature must match the team owner:
&lt;ul&gt;
&lt;li&gt;Hash: &lt;code&gt;keccak256(&quot;TeamInvite&quot;, teamId, expiry, chainId, address(this))&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Verified via &lt;code&gt;ecrecover()&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;This ensures only legitimate invites signed by the team owner are accepted.&lt;/p&gt;
&lt;hr /&gt;
&lt;h4&gt;📱 Frontend Responsibilities&lt;/h4&gt;
&lt;p&gt;The frontend handles &lt;strong&gt;user interaction, invite generation, and QR code management&lt;/strong&gt;, all without relying on a centralized backend.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;khoj_creating_team.png&quot; alt=&quot;Creating a team&quot; /&gt;
&lt;em&gt;Creating a team&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;khoj_team_invite_qr.png&quot; alt=&quot;Team invite code &amp;amp; QR&quot; /&gt;
&lt;em&gt;Team invite code &amp;amp; QR&lt;/em&gt;&lt;/p&gt;
&lt;h5&gt;A. Registration&lt;/h5&gt;
&lt;ul&gt;
&lt;li&gt;User connects with &lt;strong&gt;ThirdWeb wallet&lt;/strong&gt; (can be Web3 wallet or Google/social login).&lt;/li&gt;
&lt;li&gt;Reads contract state:
&lt;ul&gt;
&lt;li&gt;If not in a team → show &lt;strong&gt;Create Team&lt;/strong&gt; / &lt;strong&gt;Join via Invite&lt;/strong&gt; options.&lt;/li&gt;
&lt;li&gt;If already in a team → show team details.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h5&gt;B. Create Team&lt;/h5&gt;
&lt;ul&gt;
&lt;li&gt;User sets max team size.&lt;/li&gt;
&lt;li&gt;Calls &lt;code&gt;createTeam(maxMembers)&lt;/code&gt; on-chain.&lt;/li&gt;
&lt;li&gt;Contract returns &lt;code&gt;teamId&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;h5&gt;C. Generate Invite (Multi-use, Ephemeral)&lt;/h5&gt;
&lt;ul&gt;
&lt;li&gt;Owner chooses expiry (e.g., hunt_start + 1hr).&lt;/li&gt;
&lt;li&gt;Frontend generates:
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;inviteHash = keccak256(&quot;TeamInvite&quot;, teamId, expiry, chainId, contractAddress)&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Signs the hash using &lt;code&gt;wallet.signMessage()&lt;/code&gt; via ThirdWeb.&lt;/li&gt;
&lt;li&gt;Bundles &lt;code&gt;{teamId, expiry, signature}&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Encodes into &lt;strong&gt;Base58&lt;/strong&gt; (shorter than hex → better QR).&lt;/li&gt;
&lt;li&gt;Generates a &lt;strong&gt;QR code&lt;/strong&gt; or short code.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;⚠️ Invite is shown &lt;strong&gt;once only&lt;/strong&gt; — never stored by backend or on-chain.&lt;/p&gt;
&lt;h5&gt;D. Join Team&lt;/h5&gt;
&lt;ul&gt;
&lt;li&gt;User scans QR or pastes invite string.&lt;/li&gt;
&lt;li&gt;Frontend decodes &lt;code&gt;{teamId, expiry, signature}&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Calls &lt;code&gt;joinWithInvite(teamId, expiry, signature)&lt;/code&gt; on-chain.&lt;/li&gt;
&lt;li&gt;Contract validates and admits user if rules are satisfied.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;👉 Detailed implementation: &lt;a href=&quot;https://github.com/ayush4345/Khoj/pull/59&quot;&gt;PR #59&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;khoj_joining_team.png&quot; alt=&quot;Joining a team&quot; /&gt;
&lt;em&gt;Joining a team&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;khoj_team_details.png&quot; alt=&quot;Team Details&quot; /&gt;
&lt;em&gt;Team details after joining a team&lt;/em&gt;&lt;/p&gt;
&lt;hr /&gt;
&lt;h3&gt;3. LLM Upgrade: Claude → Gemini 2.5&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Migrated clue generation from Claude to &lt;strong&gt;Gemini 2.5&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Benefits:
&lt;ul&gt;
&lt;li&gt;Structured outputs, easier parsing.&lt;/li&gt;
&lt;li&gt;Reduced prompt-to-clue parsing errors.&lt;/li&gt;
&lt;li&gt;More robust and consistent gameplay experience.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/ayush4345/Khoj/pull/51&quot;&gt;PR link&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;hr /&gt;
&lt;h3&gt;4. Custom NFT Images for Hunts&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Hunt creators can now upload &lt;strong&gt;custom images&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Earlier, all hunts used the same default NFT art.&lt;/li&gt;
&lt;li&gt;Each hunt’s NFT is minted via a &lt;strong&gt;the main Khoj contract&lt;/strong&gt;, making experiences more personalized.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr /&gt;
&lt;h3&gt;5. Hunt Creation UI&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;A &lt;strong&gt;full UI for hunt creation&lt;/strong&gt; now replaces the Remix IDE workflow.&lt;/li&gt;
&lt;li&gt;Creators can configure all parameters:
&lt;ul&gt;
&lt;li&gt;Hunt name, description, timeline&lt;/li&gt;
&lt;li&gt;Teams toggle + max team size&lt;/li&gt;
&lt;li&gt;Custom NFT image&lt;/li&gt;
&lt;li&gt;Clues (encrypted via Lit + uploaded to IPFS)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Smooth wallet integration powered by &lt;strong&gt;ThirdWeb&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img src=&quot;khoj_hunt_creation.png&quot; alt=&quot;khoj_hunt_creation&quot; /&gt;&lt;/p&gt;
&lt;hr /&gt;
&lt;h3&gt;6. Wallet &amp;amp; Onboarding&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Integrated &lt;strong&gt;ThirdWeb wallet&lt;/strong&gt;, allowing both &lt;strong&gt;Web3 wallets and Web2 social login (Google, etc.)&lt;/strong&gt;.  This significantly improves the user experience of our target audience.&lt;/li&gt;
&lt;li&gt;This aligns with our focus on &lt;strong&gt;Web2-native UX → Web3 rewards&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img src=&quot;khoj_wallet_integration.png&quot; alt=&quot;khoj_wallet_integration&quot; /&gt;&lt;/p&gt;
&lt;hr /&gt;
&lt;h3&gt;7. Lit Protocol + IPFS Migration&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Moved encrypted clue  storage from Walrus to &lt;strong&gt;Lit Protocol + IPFS (Pinata)&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Challenges solved:
&lt;ul&gt;
&lt;li&gt;Data passing issues between contract, Lit, and IPFS.&lt;/li&gt;
&lt;li&gt;Handling retries for failed uploads.&lt;/li&gt;
&lt;li&gt;Eliminated hardcoded logic in clue validation and encryption.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Note: Lit seems to have a lot of reliability issues and we are considering migrating from the service and explore alternatives.&lt;/p&gt;
&lt;hr /&gt;
&lt;h3&gt;8. Backend Stability &amp;amp; Testing&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Built an &lt;strong&gt;extensive test suite&lt;/strong&gt; for smart contracts to handle edge cases and prevent regressions.&lt;/li&gt;
&lt;li&gt;Added retry mechanisms for clue verification &amp;amp; clue decryption.&lt;/li&gt;
&lt;li&gt;Cleaned up legacy code → removed hardcoded values across flow.&lt;/li&gt;
&lt;li&gt;Backend deployed on &lt;strong&gt;OCI&lt;/strong&gt;, frontend on &lt;strong&gt;Netlify&lt;/strong&gt;, making Khoj fully live and testable.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Live link: &lt;a href=&quot;https://khoj-alpha.netlify.app/&quot;&gt;khoj-alpha.netlify.app&lt;/a&gt;&lt;/p&gt;
&lt;hr /&gt;
&lt;h3&gt;9. Miscellaneous Improvements&lt;/h3&gt;
&lt;p&gt;We also pushed several smaller but important updates:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Environment variable cleanup (safer, more configurable deployments).&lt;/li&gt;
&lt;li&gt;Improved error handling and UX flow for retries.&lt;/li&gt;
&lt;li&gt;Added product guide for easier onboarding.&lt;/li&gt;
&lt;li&gt;Removed unnecessary logic that caused fragility.&lt;/li&gt;
&lt;li&gt;Improved the Hunts page UI with a start and end date, pill for whether teams are enabled or not and the number of participants.&lt;/li&gt;
&lt;li&gt;Introduced 3 new states for the frontend buttons: &lt;code&gt;Register&lt;/code&gt;, &lt;code&gt;Manage&lt;/code&gt; and &lt;code&gt;Ended&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img src=&quot;khoj_discover_hunts.png&quot; alt=&quot;Hunts&quot; /&gt;
&lt;em&gt;Discover Hunts&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;khoj_hunt_states.png&quot; alt=&quot;Hunt States&quot; /&gt;
&lt;em&gt;Hunt States&lt;/em&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Added the Khoj logo and updated the favicon.&lt;/li&gt;
&lt;li&gt;Added a custom loading screen while fetching data from the contract / backend.&lt;/li&gt;
&lt;li&gt;Standardised UI across the Hunt Details, Clue and Hunt End pages.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img src=&quot;khoj_solving_clue.png&quot; alt=&quot;Solving a Clue&quot; /&gt;
&lt;em&gt;Solving a Clue&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;khoj_hunt_completion.png&quot; alt=&quot;Successful completion of a hunt&quot; /&gt;
&lt;em&gt;Successful completion of a hunt&lt;/em&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Moved all frontend type definitions to a separate directory following principles of DRY.&lt;/li&gt;
&lt;li&gt;Support PassetHub.&lt;/li&gt;
&lt;li&gt;Rename the contracts to &lt;code&gt;Khoj&lt;/code&gt; and &lt;code&gt;KhojNFT&lt;/code&gt; for consistency.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr /&gt;
&lt;h2&gt;📖 Product Guide&lt;/h2&gt;
&lt;p&gt;We’ve also added a &lt;strong&gt;full product guide&lt;/strong&gt; with screenshots and step-by-step instructions:&lt;/p&gt;
&lt;p&gt;👉 &lt;a href=&quot;https://github.com/ayush4345/Khoj/wiki/Product-Guide&quot;&gt;Read it here&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Covers:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Hunt creation&lt;/li&gt;
&lt;li&gt;Registering &amp;amp; exploring hunts&lt;/li&gt;
&lt;li&gt;Team creation &amp;amp; joining flow&lt;/li&gt;
&lt;li&gt;Solving clues&lt;/li&gt;
&lt;li&gt;Rewards&lt;/li&gt;
&lt;/ul&gt;
&lt;hr /&gt;
&lt;h2&gt;🧭 Next Steps&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Run more &lt;strong&gt;pilot hunts&lt;/strong&gt; to refine user experience.&lt;/li&gt;
&lt;li&gt;Expand testing to edge cases.&lt;/li&gt;
&lt;li&gt;Improve offline → on-chain &lt;strong&gt;reward distribution logic&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Continue focusing on &lt;strong&gt;frictionless onboarding&lt;/strong&gt; while keeping the underlying infra secure and decentralized.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;We are also actively working on the landing page and other aspects of the product to make it the best in class.&lt;/p&gt;
&lt;hr /&gt;
&lt;h2&gt;🔗 Resources&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Live app: &lt;a href=&quot;https://khoj-alpha.netlify.app/&quot;&gt;Khoj Alpha&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;GitHub repo: &lt;a href=&quot;https://github.com/ayush4345/Khoj&quot;&gt;Khoj&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;That’s the progress so far 🚀. If you’d like to try Khoj or give feedback, hop into a hunt and let us know your thoughts!&lt;/p&gt;
</content:encoded><category>ai</category><category>devlog</category></item><item><title>DEVLOG #5</title><link>https://shubhamrasal.com/writing/undefined/</link><guid isPermaLink="true">https://shubhamrasal.com/writing/undefined/</guid><description>A blog post by undefined</description><pubDate>Fri, 06 Jun 2025 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;This devlog is focused on KrishiAI and it&apos;s pivot.&lt;/p&gt;
&lt;p&gt;I had worked on KrishiAI as my undergrad major project. I realised that I was building something wrong after building a set of features for the app which include&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;a plant disease scanner (works for rice only)&lt;/li&gt;
&lt;li&gt;pesticide label scanner&lt;/li&gt;
&lt;li&gt;voice AI with grounding in agriculture knowledge&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This made me think what problem does the app really solve?&lt;/p&gt;
&lt;h3&gt;My initial hypothesis&lt;/h3&gt;
&lt;p&gt;My initial hypothesis was that with better accuracy of vision models and accessibility provided by voice AI interface (with multi-lingual support), the farmers would find it useful.&lt;/p&gt;
&lt;p&gt;I had finalised that the following were the most pressing issues for farmers in India&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Lack of access to information (especially about government subsidies and schemes)&lt;/li&gt;
&lt;li&gt;Unable to identify plant disease at the earliest&lt;/li&gt;
&lt;li&gt;Low literacy causing issues with understanding the dosage of pesticides&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;I had talked to around 4-5 farmers withing my network to understand their problems, but there is something that I missed.&lt;/p&gt;
&lt;h3&gt;What went wrong&lt;/h3&gt;
&lt;p&gt;The core issue was that I did not ask the right questions to the farmers. I was imposing a solution that I cherished and wanted to construct the problem around it -- it should have been the other way around.&lt;/p&gt;
&lt;p&gt;Another core issue was that I did not approach the problem with a first principles thinking mindset and forgot about the second and third order effects of my product decisions.&lt;/p&gt;
&lt;p&gt;Apart from this I was trying to learn app dev on the go (with the help of AI) and vibe coded the whole app. This is not a bad thing but it made be more app focused rather that solving the core problem.&lt;/p&gt;
&lt;h3&gt;Pivot&lt;/h3&gt;
&lt;p&gt;When we think about Indian farmers and Agriculture in India, the problems are systemic and need to be solved by state level actors. Not every problem can be solve by an app but there are somethings that should make the average farmers life easier.&lt;/p&gt;
&lt;p&gt;How can we reimagine an agriculture app that is enganging and solves a problem so well that people spread it with word of mouth.&lt;/p&gt;
&lt;p&gt;I have a few ideas that need to be tested with real usage by farmers. These ideas have retention built-in and rely heavily on notifications and alerts.&lt;/p&gt;
&lt;p&gt;Raw data until you process and present it in a meaningful way for the user to consume. So here are some ideas that I planning to pursue and check the waters -&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Crop Schedules&lt;/li&gt;
&lt;li&gt;Pest and Disease Alerts&lt;/li&gt;
&lt;li&gt;Post-Harvest Pricing decisions&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Now the only work left to do is to figure out a way to present this to the farmer in a useful way. To understand the problem even deeply, I will be taking to FPO (Farmer Producer Organisation) managers to understand core problems and see if the usecases I have identified fit their scenario.&lt;/p&gt;
</content:encoded><category>ai</category><category>devlog</category></item><item><title>An Agentic Browser: What It Needs To Be</title><link>https://shubhamrasal.com/writing/undefined/</link><guid isPermaLink="true">https://shubhamrasal.com/writing/undefined/</guid><description>A blog post by undefined</description><pubDate>Sat, 31 May 2025 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;I was scrolling X, as you do, and thinking: &lt;strong&gt;How do you &lt;em&gt;really&lt;/em&gt; build an AI-native agentic browser?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Browsers are our main window to the internet. Many companies are adding AI to them. But it doesn&apos;t feel right. I found this blogpost by a YC GP on how AI native applications should feel like - https://koomen.dev/essays/horseless-carriages/&lt;/p&gt;
&lt;p&gt;For me to use a new one, it needs to hit a few marks:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;All my current browser stuff (like Chrome) must work.&lt;/strong&gt; No missing features.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;It needs to be private.&lt;/strong&gt; Using local LLMs is key here.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;That&apos;s it for the basics. I&apos;m okay with new ways of doing things, even if it means changing habits.&lt;/p&gt;
&lt;h2&gt;Some featured I would like&lt;/h2&gt;
&lt;p&gt;Here are some features that would make a browser incrementally agentic:&lt;/p&gt;
&lt;h3&gt;Auto Tab Grouping&lt;/h3&gt;
&lt;p&gt;Browsers already group tabs. I want it &lt;strong&gt;supercharged&lt;/strong&gt;. A small, local LLM could group tabs based on what I&apos;m reading or doing. It would just know.&lt;/p&gt;
&lt;h3&gt;Learn Mode&lt;/h3&gt;
&lt;p&gt;This is like RLHF (Reinforcement Learning with Human Feedback). It&apos;s how models like ChatGPT got so good. This should be built into the browser. It would learn from my repetitive tasks.&lt;/p&gt;
&lt;p&gt;Think about these scenarios:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Researching a company&lt;/strong&gt; and its people.&lt;/li&gt;
&lt;li&gt;Going down &lt;strong&gt;Hackernews rabbitholes&lt;/strong&gt; to find comments or resources.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Fast, Unified Memory&lt;/h3&gt;
&lt;p&gt;My bookmarks and history need a better system. I want &lt;strong&gt;fast, unified memory&lt;/strong&gt; for them.&lt;/p&gt;
&lt;h2&gt;How To Build These Features&lt;/h2&gt;
&lt;p&gt;Now, how would these smart features actually work?&lt;/p&gt;
&lt;h3&gt;For Auto Tab Grouping: A Local Brain for Your Tabs&lt;/h3&gt;
&lt;p&gt;Imagine a mini-AI, a small LLM, right inside your browser. This &quot;local brain&quot; would constantly look at the stuff on your open tabs: the words, the titles, even the website addresses. It would learn what kinds of things you work on together.&lt;/p&gt;
&lt;p&gt;For example, if you open three tabs about &quot;new running shoes,&quot; it would see they&apos;re similar and put them in a &quot;shopping&quot; group for you. It gets smarter over time, learning your own way of organizing.&lt;/p&gt;
&lt;h3&gt;For Learn Mode: Watching and Getting Feedback&lt;/h3&gt;
&lt;p&gt;This is trickier. The browser would &quot;watch&quot; what you do.&lt;/p&gt;
&lt;p&gt;When you do something over and over, like always opening a specific set of websites to research a company, the browser notices that pattern.&lt;/p&gt;
&lt;p&gt;Then, the next time, it might pop up and ask, &quot;Hey, are you researching a company again? Want me to open those usual sites for you?&quot; If you say &quot;yes,&quot; it gets a good mark. If you say &quot;no,&quot; it learns not to do it that way next time.&lt;/p&gt;
&lt;p&gt;This feedback (your &quot;yes&quot; or &quot;no&quot;) helps it get better at helping you with your tasks, making it super personalized.&lt;/p&gt;
&lt;h3&gt;For Fast, Unified Memory: An AI Library for Everything You&apos;ve Seen&lt;/h3&gt;
&lt;p&gt;Think of your browser&apos;s history and bookmarks like a giant library.&lt;/p&gt;
&lt;p&gt;With a &lt;strong&gt;fast, unified memory&lt;/strong&gt;, when you visit a website or save a bookmark, the browser&apos;s &quot;brain&quot; (the LLM) would read and understand what that page is about. It stores this understanding, not just the link.&lt;/p&gt;
&lt;p&gt;You could ask, &quot;Find that article about running shoe reviews from last week,&quot; even if you don&apos;t remember the exact website.&lt;/p&gt;
&lt;p&gt;The agent would use its understanding of all the pages you&apos;ve seen to find exactly what you&apos;re looking for, super fast.&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;Implementing these features with current tech is &lt;strong&gt;non-trivial&lt;/strong&gt;. The current way is often using agents with an LLM.&lt;/p&gt;
&lt;p&gt;The goal is a browser that truly understands and helps you. It&apos;s about moving from just a tool to something with digital intuition.&lt;/p&gt;
</content:encoded><category>ai</category></item><item><title>Memetic Desire</title><link>https://shubhamrasal.com/writing/undefined/</link><guid isPermaLink="true">https://shubhamrasal.com/writing/undefined/</guid><description>A blog post by undefined</description><pubDate>Tue, 27 May 2025 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;import HierarchySimulator from &apos;../components/Games.tsx&apos;;&lt;/p&gt;
&lt;p&gt;None of my desires are my own. We pick up desires from our surrounding people and initially we don&apos;t have any taste in doing so. We could end up picking relatively harmless but non-productive desires.&lt;/p&gt;
&lt;p&gt;This is deeply ingrained in our DNA and what makes us human and it is hard to overcome this tendency to copy other people&apos;s desire. But there are some serious (and interesting) implications of copying others.&lt;/p&gt;
&lt;h2&gt;Infinite vs Finite Games&lt;/h2&gt;
&lt;p&gt;There are two types of games that someone can play. Wealth game or status game. The memetic desire is the latter cause if you desire something, getting it will make you superior to someone who doesn&apos;t have it - in a way it is a zero sum game.&lt;/p&gt;
&lt;p&gt;According to &lt;a href=&quot;https://nav.al/&quot;&gt;Naval Ravikant&lt;/a&gt;, it is better to play the wealth game as it is inherently non-zero game. You end up creating more value for all the people involved.&lt;/p&gt;
&lt;p&gt;Pursuing wealth tends to increase the size of pie itself whenever one achieves a breakthrough.&lt;/p&gt;
&lt;p&gt;You can&apos;t avoid memetic desire completely, since sometimes these advancements come while one is pursuing his memetic desire.&lt;/p&gt;
&lt;h2&gt;Heirarchies&lt;/h2&gt;
&lt;p&gt;This problem has plagued humanity since the beginning. As soon as you increase the size of the society, the interactions of people naturally caused this memetic desire to emerge.
Status games have this inherent property of forming hierarchical structures since the resource that everyone is going after is limited.&lt;/p&gt;
&lt;p&gt;People tend to be not happy in a hierarchy. This is because status resides at the top and getting to the top is not a fair game in the real world. Some have a head start, some cheat. But since everyone desires to be at the top, it is bound to create clashes.&lt;/p&gt;
&lt;p&gt;Now is there a way to solve this tension? Maybe have something so valuable that everyone desires it and make it ultimately unreachable in a lifetime. This is what religion tries to do. Historically, religion has been something that has kept the bottom half of the pyramid peaceful by given them a &lt;strong&gt;higher&lt;/strong&gt; purpose.&lt;/p&gt;
&lt;p&gt;&amp;lt;HierarchySimulator client:load /&amp;gt;&lt;/p&gt;
&lt;h2&gt;Solution for the time being&lt;/h2&gt;
&lt;p&gt;Till we resolve this problem, what we can do is try to pursue higher, more wealth oriented desires. This at least ensures that fulfillment of your desire will ensure that value has been provided to someone.&lt;/p&gt;
</content:encoded><category>philosophy</category></item><item><title>Guide to Engineering Colleges</title><link>https://shubhamrasal.com/writing/undefined/</link><guid isPermaLink="true">https://shubhamrasal.com/writing/undefined/</guid><description>A blog post by undefined</description><pubDate>Mon, 05 May 2025 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Navigating an engineering college can overwhelming sometimes. I am writing this from my own experiences. So take any advice in this blog with a grain of salt.&lt;/p&gt;
&lt;p&gt;disclaimer - this post is not for people who have already figured out what they are interested in or are working on something great. This is for the people who feel that they are clueless and want to make the most out of college.&lt;/p&gt;
&lt;h2&gt;The first step&lt;/h2&gt;
&lt;p&gt;If you have joined a college close to your house, then this might not be as relevant. But for those who have moved to a far away place, please make sure to fix a schedule.&lt;/p&gt;
&lt;p&gt;There is a very quote from atomic habits - &lt;strong&gt;You do not rise to the level of your goals. You fall to the level of your systems.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;One of the most essential systems in your college life will be a schedule. It doesn&apos;t mean that you have to remove the fun out of it. In fact, add it as a definitive slot. Make it as long as you want.&lt;/p&gt;
&lt;h2&gt;Go out&lt;/h2&gt;
&lt;p&gt;The best way to release any kind of mental pressure that I have found is going out.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Go for a walk (boosted if you go out with some friends)&lt;/li&gt;
&lt;li&gt;Go play a sport&lt;/li&gt;
&lt;li&gt;Go for a run or a jog&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Just leave your room and go out. Time won&apos;t matter.&lt;/p&gt;
&lt;h2&gt;Of course you need some friends&lt;/h2&gt;
&lt;p&gt;This needs no telling and I don&apos;t think you will have any trouble making friends. Just make sure that you get some that are not like minded as you. This exposure will help you grow.&lt;/p&gt;
&lt;h2&gt;Branch matters&lt;/h2&gt;
&lt;p&gt;If fact, I would go out and say that it matters a lot. The branch you have got might not be what you wanted or what fits your skillset. The branch decides&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;where you spend most of you waking time&lt;/li&gt;
&lt;li&gt;occupies a mental space that can&apos;t be discarded&lt;/li&gt;
&lt;li&gt;4 years&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Having fun&lt;/h2&gt;
&lt;p&gt;After sorting out the above mentioned points, optimise for having fun. This time is the last time where you will have no obligations to do anything. This will change in future as soon as you leave the college. Best luck with your journey&lt;/p&gt;
</content:encoded></item><item><title>Working Hard</title><link>https://shubhamrasal.com/writing/undefined/</link><guid isPermaLink="true">https://shubhamrasal.com/writing/undefined/</guid><description>A blog post by undefined</description><pubDate>Thu, 10 Apr 2025 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Long ago, I had an opinion that I should be able to get what I want without working hard -- whatever that meant to me at that time. Now that I look back at that opinion, I feel that although I wasn&apos;t wrong, I wasn&apos;t right either.&lt;/p&gt;
&lt;p&gt;I have always struggled to find meaning in this world. One way I tried to cope with it was to define short term goals and achieve them. This kept me occupied for a while. But when I stopped deriving meaning from this pursuit, I was again moving towards a nihilistic future. This is when I found &lt;a href=&quot;https://www.youtube.com/c/alexhormozi&quot;&gt;Alex Hormozi&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;Hardwork is the Goal&lt;/h2&gt;
&lt;p&gt;Defining goals is not very simple, especially when the goal are vague and amorphous -- winning at life, being successful, etc. So the key insight I got from Alex&apos;s words was that we should (again, I am using &lt;em&gt;should&lt;/em&gt; here, but none of this is a commandment) set behavior as goals. This is for mainly two reasons -&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;It is derived from the future self you desire to become.&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;For example, say you want to become more charismatic. Charisma is a bucket term for many things - talking slowly, greeting everyone when you enter a room, using people&apos;s names in the conversations often, etc. . The behavior can be to write summaries everyday. Just do it and the behavior will ensure that you become the person you desire.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Easier to track a behavior.&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Measuring long term goals is really hard. This maybe because your monkey brain is not good at calculating really long term benefits.&lt;/p&gt;
&lt;p&gt;I am particularly choosing working hard as my goal because it helps me measure myself accurately. I tend to compare myself a lot and this goal would give an outlet for that comparison. Although I still somewhat care about the outcome of the work that I put in, I plan to reduce it.&lt;/p&gt;
&lt;p&gt;This ties surprisingly well into the &lt;em&gt;Karma&lt;/em&gt; philosophy from &lt;em&gt;Bhagwat Geta&lt;/em&gt;, at least in the way I interpret it.&lt;/p&gt;
&lt;h2&gt;Defining work&lt;/h2&gt;
&lt;p&gt;This is essential since work has a lot of meanings to people. For me, I tend to define work as something that generates output. I solely try to measure the quantity work by the amount of output it gets. This works for me, since I have clearly defined goals and measurable metrics to track progress. I don&apos;t count the hours or effort (what is is really?) required to achieve the goals.&lt;/p&gt;
&lt;p&gt;All this is true for me since I am a knowledge worker. I provide value by using my mind and not physical labor. Due to this, we can use the traditional physics-based definition of work which is: distance x force.&lt;/p&gt;
&lt;p&gt;Knowledge work has huge leverage&lt;/p&gt;
</content:encoded><category>philosophy</category></item><item><title>The Final Objective Function</title><link>https://shubhamrasal.com/writing/undefined/</link><guid isPermaLink="true">https://shubhamrasal.com/writing/undefined/</guid><description>A blog post by undefined</description><pubDate>Wed, 19 Mar 2025 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Yeah the title is a little misleading if you have no context what I was thinking about the last few weeks.&lt;/p&gt;
&lt;h2&gt;The context&lt;/h2&gt;
&lt;p&gt;I have been trying to understand why current LLMs don&apos;t think like humans or why don&apos;t they yet surpass us. This lead to me reading Suchir&apos;s Balaji&apos;s view of AGI and eventually I wrote a commentary on it.&lt;/p&gt;
&lt;h2&gt;Generalization&lt;/h2&gt;
&lt;p&gt;Generalization is data efficiency. The idea is to capture all the possible causations and correlations among the data points by connecting all the dots.&lt;/p&gt;
&lt;p&gt;How to get the models to generalize?&lt;/p&gt;
&lt;p&gt;First, though, we need to confirm whether general intelligence is real or not.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;intel_cor.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Let’s define the characteristics of an architecture that will be able to acquire general intelligence. For this, we can take inspiration from our own brain -&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;We have the mammalian brain that is trained over millions of years with basic instincts&lt;/li&gt;
&lt;li&gt;The neocortex makes us humans special and adaptive to the changing world (this is the reason why we spend a significant time of development outside the womb)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;One requirement is obvious - it should be data efficient from the start. This is so that it can form a large number of internal models about that world.&lt;/p&gt;
&lt;p&gt;The second requirement would be to have the ability to reuse neurons for multiple recurrent computations that are distinct. This also ensures the data efficiency of our brain&lt;/p&gt;
&lt;p&gt;Due to my limited knowledge of the field, I am not sure if the reusable part is true or not. Need to fact-check.&lt;/p&gt;
&lt;h2&gt;What are we trying to make?&lt;/h2&gt;
&lt;p&gt;One interesting fact Suchir mentions is, people try to draw similarities between the genome and the trained LLM. This is not really true. The genome is much closer to the LLM codebase than it is to the actual trained LLM.&lt;/p&gt;
&lt;p&gt;This is because evolution can’t use the genome to store the words or situations encountered by the ancestor organisms due to the simple fact of keeping the genome short.&lt;/p&gt;
&lt;p&gt;This means that the shortness of the genome is an important condition for generalization.&lt;/p&gt;
&lt;h2&gt;AGI&lt;/h2&gt;
&lt;p&gt;What Open AI is trying to do to achieve AGI is to scale test time computing. This might work in the short term. But it doesn’t solve the generalization problem.&lt;/p&gt;
&lt;p&gt;Another problem with building AGI with current approaches, such as scaling NNs, is that the brain is a complex neural network that can learn when data is applied to it.&lt;/p&gt;
&lt;p&gt;What we want is not to replicate the brain (which can be considered proof of concept for the idea that AGI exists) but to develop a simpler model of evolution that actually learned the “meta-skill” of producing the brain when tasks across a diverse environment were applied to it.&lt;/p&gt;
&lt;p&gt;RL is also not that useful to achieve our goal which is to optimize the objective itself.&lt;/p&gt;
&lt;p&gt;Let’s take an example. Consider you have to make an agent solve a maze.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://lh7-rt.googleusercontent.com/docsz/AD_4nXeLl3c_UvWCJsWaTqnMPvT4-n2UM2OVPaJKAFV6Xb55qmRvbnf4H4T-u7KqHTjd1eYS6LPEq21I5iwuPJrwKL-e9oExCuzsWf_J_3fttx_v5SzS5ab0L4jqY3FhAd48-GOUFgmqhg?key=Z9B4isEtZ0FYkka9FI3QRF1p&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;p&gt;The loss function you might consider would be |x_agent - x_end|. Now, what if the agent gets stuck in a corner? No amount of exploration would help you. Nor will the size of the NN control the agent.&lt;/p&gt;
&lt;p&gt;This is because in pathfinding, exploration is the problem we are trying to solve.&lt;/p&gt;
&lt;p&gt;We could, as programmers, add heuristics and backtracking, but the point is to see whether the agent can come up with it.&lt;/p&gt;
&lt;h2&gt;Newer model architectures&lt;/h2&gt;
&lt;p&gt;Recently, there might be some hope - &lt;a href=&quot;https://arxiv.org/abs/2501.00663&quot;&gt;https://arxiv.org/abs/2501.00663&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The core idea of the paper is to model learning at test time by introducing neural memory modules. These structures aim to emulate human memory.&lt;/p&gt;
&lt;p&gt;The limitation of transformers is the quadratic dependency on data due to the attention mechanism. The RNNs don’t have that issue as they are linearly dependent. The researchers replace the fixed size vector used as a hidden state in an RNN with a NN that is trained during test time.&lt;/p&gt;
&lt;p&gt;The most interesting thing in the paper was how they modeled surprise -&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://lh7-rt.googleusercontent.com/docsz/AD_4nXddxI17TSwNgyySVe7vn9SAROd4SujnVY6eEjOSHrrQSEMmKc6bGrDeceNJphIomizOnlhudTAt6sRnnyO4CZHZe8X0DfKmVLrJUlwCvYkIR7YduiAgc9WdmlNvsXdPzJbHj8X9lQ?key=Z9B4isEtZ0FYkka9FI3QRF1p&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;p&gt;This approach simulates the long-term and short-term memory of humans. As a result, it performed much better on the needle-in-the-haystack benchmarks.&lt;/p&gt;
&lt;p&gt;But does this fit our criteria for intelligence?&lt;/p&gt;
&lt;p&gt;Before we go into that, let&apos;s explore another idea discussed in this paper - &lt;a href=&quot;https://www.arxiv.org/pdf/2410.02536&quot;&gt;https://www.arxiv.org/pdf/2410.02536&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The main takeaway of the paper is that certain rules that are used to generate synthetic data are much more likely to improve the model&apos;s logical reasoning capabilities than others. Does this sound familiar?&lt;/p&gt;
&lt;p&gt;This can be compared with the genome example we discussed earlier where the actual intelligence is derived from a complex adaptive meta-learning process called evolution. If you look at the rules in the paper, you can see that they are pretty simple, something like Conway’s game of life.&lt;/p&gt;
&lt;p&gt;The researchers also tried to check whether the model has learned about these simple rules from the dataset. It did not. It did have a dependence on the pattern generated by the rules which affected it’s attention mechanism, but not the rules.&lt;/p&gt;
&lt;p&gt;We do have different forms of reasoning - intuitive, logical, though, inductive, causal, search.
These are not fixed. For example, Ramanujan had a goddess-based reasoning that helped him get answers to some complex mathematical puzzles.&lt;/p&gt;
&lt;p&gt;This means that whatever mechanism we develop, it should not just memorize the simple rules it is trained on. The edge of chaos approach therefore seems promising for the future of reasoning.&lt;/p&gt;
</content:encoded><category>ai</category><category>philosophy</category></item><item><title>On Reasoning</title><link>https://shubhamrasal.com/writing/undefined/</link><guid isPermaLink="true">https://shubhamrasal.com/writing/undefined/</guid><description>A blog post by undefined</description><pubDate>Tue, 25 Feb 2025 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Disclaimer - heavily inspired by &lt;a href=&quot;https://docs.google.com/document/d/1ItRqrpgQHJ05rQx0zc26t1_NgpUcw3znwTWpXxqH8uI/edit?tab=t.0&quot;&gt;Suchir Balaji’s View&lt;/a&gt; and other recent papers. Also, this blog post is not very structured.&lt;/p&gt;
&lt;h2&gt;What is intelligence really?&lt;/h2&gt;
&lt;p&gt;Suchir defines intelligence as the rate at which you learn a capability from data points. An intelligent being will learn it faster than an unintelligent being.&lt;/p&gt;
&lt;p&gt;This definition is important because a machine trained on loads of data might be superhuman on a given task, but the generalization would be absent.&lt;/p&gt;
&lt;p&gt;These gaps of understanding between various specialized tasks can’t be filled with RL or scale. This means RLHF or a billion GPUs won’t get us to GPT-11, for example.&lt;/p&gt;
&lt;h2&gt;Generalization&lt;/h2&gt;
&lt;p&gt;Generalization is data efficiency. The idea is to capture all the possible causations and correlations among the data points by connecting all the dots.&lt;/p&gt;
&lt;p&gt;How to get the models to generalize?&lt;/p&gt;
&lt;p&gt;First, though, we need to confirm whether general intelligence is real or not.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;intel_cor.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Let’s define the characteristics of an architecture that will be able to acquire general intelligence. For this, we can take inspiration from our own brain -&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;We have the mammalian brain that is trained over millions of years with basic instincts&lt;/li&gt;
&lt;li&gt;The neocortex makes us humans special and adaptive to the changing world (this is the reason why we spend a significant time of development outside the womb)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;One requirement is obvious - it should be data efficient from the start. This is so that it can form a large number of internal models about that world.&lt;/p&gt;
&lt;p&gt;The second requirement would be to have the ability to reuse neurons for multiple recurrent computations that are distinct. This also ensures the data efficiency of our brain&lt;/p&gt;
&lt;p&gt;Due to my limited knowledge of the field, I am not sure if the reusable part is true or not. Need to fact-check.&lt;/p&gt;
&lt;h2&gt;What are we trying to make?&lt;/h2&gt;
&lt;p&gt;One interesting fact Suchir mentions is, people try to draw similarities between the genome and the trained LLM. This is not really true. The genome is much closer to the LLM codebase than it is to the actual trained LLM.&lt;/p&gt;
&lt;p&gt;This is because evolution can’t use the genome to store the words or situations encountered by the ancestor organisms due to the simple fact of keeping the genome short.&lt;/p&gt;
&lt;p&gt;This means that the shortness of the genome is an important condition for generalization.&lt;/p&gt;
&lt;h2&gt;AGI&lt;/h2&gt;
&lt;p&gt;What Open AI is trying to do to achieve AGI is to scale test time computing. This might work in the short term. But it doesn’t solve the generalization problem.&lt;/p&gt;
&lt;p&gt;Another problem with building AGI with current approaches, such as scaling NNs, is that the brain is a complex neural network that can learn when data is applied to it.&lt;/p&gt;
&lt;p&gt;What we want is not to replicate the brain (which can be considered proof of concept for the idea that AGI exists) but to develop a simpler model of evolution that actually learned the “meta-skill” of producing the brain when tasks across a diverse environment were applied to it.&lt;/p&gt;
&lt;p&gt;RL is also not that useful to achieve our goal which is to optimize the objective itself.&lt;/p&gt;
&lt;p&gt;Let’s take an example. Consider you have to make an agent solve a maze.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://lh7-rt.googleusercontent.com/docsz/AD_4nXeLl3c_UvWCJsWaTqnMPvT4-n2UM2OVPaJKAFV6Xb55qmRvbnf4H4T-u7KqHTjd1eYS6LPEq21I5iwuPJrwKL-e9oExCuzsWf_J_3fttx_v5SzS5ab0L4jqY3FhAd48-GOUFgmqhg?key=Z9B4isEtZ0FYkka9FI3QRF1p&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;p&gt;The loss function you might consider would be |x_agent - x_end|. Now, what if the agent gets stuck in a corner? No amount of exploration would help you. Nor will the size of the NN control the agent.&lt;/p&gt;
&lt;p&gt;This is because in pathfinding, exploration is the problem we are trying to solve.&lt;/p&gt;
&lt;p&gt;We could, as programmers, add heuristics and backtracking, but the point is to see whether the agent can come up with it.&lt;/p&gt;
&lt;h2&gt;Newer model architectures&lt;/h2&gt;
&lt;p&gt;Recently, there might be some hope - &lt;a href=&quot;https://arxiv.org/abs/2501.00663&quot;&gt;https://arxiv.org/abs/2501.00663&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The core idea of the paper is to model learning at test time by introducing neural memory modules. These structures aim to emulate human memory.&lt;/p&gt;
&lt;p&gt;The limitation of transformers is the quadratic dependency on data due to the attention mechanism. The RNNs don’t have that issue as they are linearly dependent. The researchers replace the fixed size vector used as a hidden state in an RNN with a NN that is trained during test time.&lt;/p&gt;
&lt;p&gt;The most interesting thing in the paper was how they modeled surprise -&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://lh7-rt.googleusercontent.com/docsz/AD_4nXddxI17TSwNgyySVe7vn9SAROd4SujnVY6eEjOSHrrQSEMmKc6bGrDeceNJphIomizOnlhudTAt6sRnnyO4CZHZe8X0DfKmVLrJUlwCvYkIR7YduiAgc9WdmlNvsXdPzJbHj8X9lQ?key=Z9B4isEtZ0FYkka9FI3QRF1p&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;p&gt;This approach simulates the long-term and short-term memory of humans. As a result, it performed much better on the needle-in-the-haystack benchmarks.&lt;/p&gt;
&lt;p&gt;But does this fit our criteria for intelligence?&lt;/p&gt;
&lt;p&gt;Before we go into that, let&apos;s explore another idea discussed in this paper - &lt;a href=&quot;https://www.arxiv.org/pdf/2410.02536&quot;&gt;https://www.arxiv.org/pdf/2410.02536&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The main takeaway of the paper is that certain rules that are used to generate synthetic data are much more likely to improve the model&apos;s logical reasoning capabilities than others. Does this sound familiar?&lt;/p&gt;
&lt;p&gt;This can be compared with the genome example we discussed earlier where the actual intelligence is derived from a complex adaptive meta-learning process called evolution. If you look at the rules in the paper, you can see that they are pretty simple, something like Conway’s game of life.&lt;/p&gt;
&lt;p&gt;The researchers also tried to check whether the model has learned about these simple rules from the dataset. It did not. It did have a dependence on the pattern generated by the rules which affected it’s attention mechanism, but not the rules.&lt;/p&gt;
&lt;p&gt;We do have different forms of reasoning - intuitive, logical, though, inductive, causal, search.
These are not fixed. For example, Ramanujan had a goddess-based reasoning that helped him get answers to some complex mathematical puzzles.&lt;/p&gt;
&lt;p&gt;This means that whatever mechanism we develop, it should not just memorize the simple rules it is trained on. The edge of chaos approach therefore seems promising for the future of reasoning.&lt;/p&gt;
</content:encoded><category>ai</category><category>philosophy</category></item><item><title>DEVLOG #4</title><link>https://shubhamrasal.com/writing/undefined/</link><guid isPermaLink="true">https://shubhamrasal.com/writing/undefined/</guid><description>A blog post by undefined</description><pubDate>Sat, 22 Feb 2025 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;I am back after a long time and this time it&apos;s different.&lt;/p&gt;
&lt;p&gt;TL;DR&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Almost got our first client for Maximal Studio&lt;/li&gt;
&lt;li&gt;My team&apos;s project won bounties @ETHIndia 24&lt;/li&gt;
&lt;li&gt;Built an exciting new project that got 2000 visitors&lt;/li&gt;
&lt;li&gt;Another project that won me a bounty&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;1. Maximal Studio and the new client&lt;/h2&gt;
&lt;p&gt;My friend whom I run the agency with got a lead referral form one of his friend. But it was not that simple.&lt;/p&gt;
&lt;p&gt;The thing was, they wanted to do social media marketing (paid) and we don&apos;t specialise in that. Nevertheless, we did not say no to the client and are in the process of closing the deal.&lt;/p&gt;
&lt;p&gt;We also shot an ad for our agency. Follow to get to see the video and BTS.&lt;/p&gt;
&lt;h2&gt;2. ETHIndia 2024&lt;/h2&gt;
&lt;p&gt;It was fun hacking at this year&apos;s ETHIndia as a team with some of my seniors.&lt;/p&gt;
&lt;p&gt;We built Khoj (meaning &apos;search&apos; or &apos;discovery&apos; in Hindi), a gamified geo-location based treasure hunt platform that combines real-world exploration with Web3 technology.&lt;/p&gt;
&lt;p&gt;Khoj transforms traditional scavenger hunts into an immersive blockchain experience with a dream to bring millions of new users to the Web3 world.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;khoj.png&quot; alt=&quot;Khoj Website&quot; /&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;khoj_arch.png&quot; alt=&quot;Khoj App&apos;s Architecture&quot; /&gt;&lt;/p&gt;
&lt;p&gt;The technical details about the project can be found in the repo &lt;a href=&quot;https://github.com/marcdhi/Khoj&quot;&gt;here&lt;/a&gt; and the demo of the project can be found on Youtube - &lt;a href=&quot;https://youtu.be/9JETJmd9TOk&quot;&gt;https://youtu.be/9JETJmd9TOk&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;3. Cardify&lt;/h2&gt;
&lt;p&gt;As part of our tool marketing strategy for Maximal Studio, I made a fun little website that can turn your website into a card.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;cardify.png&quot; alt=&quot;Cardify&quot; /&gt;&lt;/p&gt;
&lt;p&gt;I was pretty happy with the result as the site got around 2000 visitors on the day of the launch.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;cardify_visitors.png&quot; alt=&quot;Cardify Visitors&quot; /&gt;&lt;/p&gt;
&lt;h2&gt;4. Otakuverse - AI Manga Translator&lt;/h2&gt;
&lt;p&gt;I built a site that can translate any Japanese manga image into an English one.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;otakuverse.png&quot; alt=&quot;Otakuverse&quot; /&gt;&lt;/p&gt;
&lt;p&gt;This was built using Spheron Network of compute for training (https://spheron.network).&lt;/p&gt;
&lt;p&gt;I will explain how I did it in another blog post soon.&lt;/p&gt;
&lt;p&gt;This was a wrap-up of all the things I did recently. See you in the next edition!!&lt;/p&gt;
</content:encoded><category>devlog</category></item><item><title>How I built an AI Manga Translator</title><link>https://shubhamrasal.com/writing/undefined/</link><guid isPermaLink="true">https://shubhamrasal.com/writing/undefined/</guid><description>A blog post by undefined</description><pubDate>Sun, 29 Dec 2024 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;On finding out about the Spheron Network&apos;s bounty challenge, I decided to find out what I can do among the challenges - https://github.com/spheronFdn/sos-ai-bounty.&lt;/p&gt;
&lt;p&gt;Since I am into Anime, the manga translator task caught my eye.&lt;/p&gt;
&lt;p&gt;I had no idea how to do it, but I decided I would figure it out on the go.&lt;/p&gt;
&lt;h2&gt;The rough plan&lt;/h2&gt;
&lt;p&gt;The plan was to approach the problem as a human being. What would I do as a human to get the English version?&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;I would look out for the speech bubbles in the text.&lt;/li&gt;
&lt;li&gt;Get the text and mark the locations or the speech bubbles they belong to.&lt;/li&gt;
&lt;li&gt;Translate each of the texts.&lt;/li&gt;
&lt;li&gt;Put it back in the right bubbles after removing the Japanese one.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img src=&quot;otakuverse_arch.png&quot; alt=&quot;Otakuverse Architecture&quot; /&gt;&lt;/p&gt;
&lt;h2&gt;Getting those speech bubbles...&lt;/h2&gt;
&lt;p&gt;If you don&apos;t know what a Manga is, here is one of the manga panels of One Piece:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;manga_one_piece.png&quot; alt=&quot;One Piece&quot; /&gt;&lt;/p&gt;
&lt;p&gt;You will notice that most of the text is inside the blobs called speech bubbles.&lt;/p&gt;
&lt;p&gt;So first, I needed a way to extract the speech bubbles out of the manga art.&lt;/p&gt;
&lt;p&gt;This did sound like a vision challenge. Also, I was influenced by the fact that I had finished a similar surveillance project with my teammates for a college course. There, I barely did any of the ML part as it was handled by a professional.&lt;/p&gt;
&lt;p&gt;Here&apos;s the project for the curious - https://github.com/TheUndercover01/Multi-Camera-person-tracking-NITK&lt;/p&gt;
&lt;p&gt;So, I decided I would be using a similar approach of detecting speech bubbles instead of jaywalkers. For this, I would need some kind of manga image dataset... hmmmm, got it!&lt;/p&gt;
&lt;p&gt;Dataset - https://universe.roboflow.com/luciano-bastos-nunes/mangas-bubble&lt;/p&gt;
&lt;h2&gt;Training the model...&lt;/h2&gt;
&lt;p&gt;The model which is most commonly used for detection tasks is YOLO. It is good for general-purpose detection, but for my task, it was not particularly effective. It would have been a great relief otherwise.&lt;/p&gt;
&lt;h4&gt;Enter fine-tuning:&lt;/h4&gt;
&lt;p&gt;Fine-tuning the model meant that we have to train the model on specific data, which in our case is the manga speech dataset. This will enable the model to detect the speech bubbles better.&lt;/p&gt;
&lt;p&gt;The training environment was rather unconventional as it was trained on a decentralized network of GPU compute where you can freely rent any type of compute.&lt;/p&gt;
&lt;h2&gt;The translation...&lt;/h2&gt;
&lt;p&gt;Converting the text to English is pretty straightforward. I just used the &lt;code&gt;deep-translator&lt;/code&gt; package from Google to translate the Japanese.&lt;/p&gt;
&lt;h2&gt;In-painting...&lt;/h2&gt;
&lt;p&gt;In-painting is the process of filling up the missing parts of an image. There are many ways to go about this process, including the use of LaMa: Resolution-robust Large Mask Inpainting with Fourier Convolutions, which can give you pretty good results.&lt;/p&gt;
&lt;p&gt;For my fun little project though, I thought of going simpler using some Python &lt;code&gt;cv&lt;/code&gt; package.&lt;/p&gt;
&lt;p&gt;The text placement process begins by preparing the image to accept text overlays and measuring the speech bubble&apos;s dimensions to determine space constraints.&lt;/p&gt;
&lt;p&gt;Starting with default text settings for size, spacing, and wrapping, the system automatically scales down these properties if the content exceeds the available bubble space.&lt;/p&gt;
&lt;p&gt;Finally, it centers the adjusted text within the bubble boundaries, ensuring translated text fits naturally within speech bubbles of any size.&lt;/p&gt;
&lt;h2&gt;Finally, the web app&lt;/h2&gt;
&lt;p&gt;I quickly built a web app that talks to the inference server by sending in the image and getting back the translated manga image.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;otakuverse.png&quot; alt=&quot;Otakuverse Architecture&quot; /&gt;&lt;/p&gt;
&lt;p&gt;This concludes the project and it would not have been possible without the immense research that goes into building these kind of models and people who make them easy to use.&lt;/p&gt;
&lt;p&gt;Lastly, I would encourage you to look into the bounties as they have a pretty good prize pool for other tasks.&lt;/p&gt;
</content:encoded><category>ai</category></item><item><title>DEVLOG #3</title><link>https://shubhamrasal.com/writing/undefined/</link><guid isPermaLink="true">https://shubhamrasal.com/writing/undefined/</guid><description>A blog post by undefined</description><pubDate>Fri, 15 Nov 2024 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;I am back with few updates on the projects I am working on.&lt;/p&gt;
&lt;p&gt;TL;DR&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;ApnaHood UI enhancements&lt;/li&gt;
&lt;li&gt;Maximal Studio website re-design&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;1. ApnaHood&lt;/h2&gt;
&lt;p&gt;Just to introduce it to the new readers, ApnaHood is a map based experience with the exact purpose yet to be finalized. You can check it out at https://apnahood.maximalstudio.in/&lt;/p&gt;
&lt;h4&gt;Map Style Update&lt;/h4&gt;
&lt;p&gt;In the recent updates, we have updated the UI by quite a bit. We now have a adventure map style and color scheme -&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;map_style.png&quot; alt=&quot;Adventure Map Style&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Apart from these, we are working on the quests board that will show users interesting challenges from various places. This is still a work in progress, so stay tuned for the next edition.&lt;/p&gt;
&lt;h4&gt;Popup has new features&lt;/h4&gt;
&lt;p&gt;&lt;img src=&quot;pop_ui.png&quot; alt=&quot;Popup UI&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Now you can click on a message and see how popular a place is, based on the votes, how many people have been there, etc.&lt;/p&gt;
&lt;p&gt;You also have the option to show directions to that pin, which opens up in a Google Maps instance.&lt;/p&gt;
&lt;p&gt;The UI of the Popup is made to match the overall map style. The share button is currently non-functional, which when implemented, will give you the option to share the pin to someone.&lt;/p&gt;
&lt;p&gt;Minor fixes include, fixing Authentication code exchange for PKCE OAuth flow, removal of unimplemented features like the leaderboard (coming soon), responsiveness improvements.&lt;/p&gt;
&lt;h2&gt;2. Maximal Studio Website Re-design&lt;/h2&gt;
&lt;p&gt;If you don&apos;t know, I run a web development agency for building software of any kind. You can check it out here - https://www.maximalstudio.in/&lt;/p&gt;
&lt;p&gt;The old agency website was a clone of a agency website template provided by a popular themes library - &lt;a href=&quot;https://lexingtonthemes.com/&quot;&gt;Lexington Themes&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;We tried to use it as a starting point since the idea was to sell websites to local businesses. But now we are pivoting to making MVPs for people who want to go to market as quickly as possible.&lt;/p&gt;
&lt;p&gt;To fit this theme we have changed our UI from this&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;old_agency_site.png&quot; alt=&quot;Old Site&quot; /&gt;&lt;/p&gt;
&lt;p&gt;to this&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;current_agency_site.png&quot; alt=&quot;Current Site&quot; /&gt;&lt;/p&gt;
&lt;p&gt;I hope to find more clients using this site. If you want a website or a software to build quickly, then contact us through the website.&lt;/p&gt;
&lt;p&gt;That&apos;s it for this devlog. See you in the next edition!!&lt;/p&gt;
</content:encoded><category>devlog</category></item><item><title>DEVLOG #2</title><link>https://shubhamrasal.com/writing/undefined/</link><guid isPermaLink="true">https://shubhamrasal.com/writing/undefined/</guid><description>A blog post by undefined</description><pubDate>Thu, 07 Nov 2024 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Since this is the first devlog of my currently active projects, it will be a long one.
In this edition of devlog, we will be looking at the updates mainly from ApnaHood and my college major project.&lt;/p&gt;
&lt;h2&gt;1. ApnaHood&lt;/h2&gt;
&lt;p&gt;If you have not read the previous edition of this devlog, ApnaHood as a map-based app where you can leave anonymous messages that can be seen by other users.&lt;/p&gt;
&lt;h4&gt;User Feedback&lt;/h4&gt;
&lt;p&gt;One important things happened between the last update and this. We decided to get feedback from the users. This meant that we cannot do what we want to do, but will have to listen to the users.&lt;/p&gt;
&lt;p&gt;Our hypothesis for the website was that users will use it for all sorts of things including - marking special and hidden spots, putting some secret messages, etc. But none of this happened.&lt;/p&gt;
&lt;p&gt;Among other reasons, the most prominent reason was that the UI was not intuitive. This meant that the user would land on the page and did not instantly know what to do. We tried to bandage this situation by adding a pop-up which explains what actions you can take on the site, but this made us realize that the UX and the user journey is terrible.&lt;/p&gt;
&lt;h3&gt;Plans for Improvement&lt;/h3&gt;
&lt;p&gt;The idea is to address the user feedback and improving the UX of the site. First thing we changed was to make the map 3D. This makes it much more interesting and appealing.&lt;/p&gt;
&lt;p&gt;Apart from this change, we are planning to add game elements into the app and center the whole concept around it. Starting with &quot;Quests&quot;, we will be adding the functionality to add limited period quest that you can complete to get points in the site, redeemable for real cash.&lt;/p&gt;
&lt;h2&gt;2. Major Project&lt;/h2&gt;
&lt;p&gt;So me and my team are building a Agriculture focused AI chat-bot that can be used by farmers for resolving all their query. After intensive research, talking to farmers and agriculture specialists, we came up with the following architecture -&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;img src=&quot;https://lh7-rt.googleusercontent.com/slidesz/AGV_vUcn-9e3PTvmliycItoJslBepymWquIWlNBjQ8UkO0U47OjFjrmsh719Z486LG7rDhiaaV7_le5VGyDqjomG4o-U2IijWszDsO_XtC0mPum3dIQcrr30uN619YQoIiG3xvYBBBPtbA=s2048?key=sVcrpFVBvwnfG94cy3g3ZRe1&quot; alt=&quot;Architecture&quot; /&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Each module is there for a purpose. Which one to choose for a particular query will be the job of the reasoning engine which is just a fancy wrapper term for LLM function calling ;).&lt;/p&gt;
&lt;h4&gt;Chat Module&lt;/h4&gt;
&lt;p&gt;For now, I am using the OpenAI realtime API for the chat functionality which is surprisingly good at Indian languages. Pairing it up with open-whisper, I am able to get a real-time native language voice interaction.&lt;/p&gt;
&lt;h4&gt;Schemes Module&lt;/h4&gt;
&lt;p&gt;Apart from the chat module, I am building a RAG system for schemes and subsidies offered by the government for various types of crops. This information is often place in obscure locations on inaccessible government and state websites.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;img src=&quot;https://lh7-rt.googleusercontent.com/slidesz/AGV_vUftonqjwQFPdjsgdS-I6l76YCppVhtQUf1s54OupTXGacHA5cGyUVxEdZZ8sdjzxhYLZDkAclKD9CDfa-Qj4QhYpqwaQWsiyKgW8uIXrSivVMj-4_0MpJhox9e_MieXL-FatoJ23w=s2048?key=sVcrpFVBvwnfG94cy3g3ZRe1&quot; alt=&quot;&quot; /&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;I am using Supabase for this functionality. I have two edge functions - embed and search.
embed converts the scheme text into embeddings and stores it in the database with the help of a postgres extension - pg_vector. search is an edge function for semantic search using cosine similarity and returns the top-k matching results for a given query.&lt;/p&gt;
</content:encoded><category>ai</category><category>devlog</category><category>systems</category></item><item><title>DEVLOG #1</title><link>https://shubhamrasal.com/writing/undefined/</link><guid isPermaLink="true">https://shubhamrasal.com/writing/undefined/</guid><description>A blog post by undefined</description><pubDate>Thu, 03 Oct 2024 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;I have always wanted to write technical blogs but I was lazy. But then I recently say few indie hackers publishing what they do on a weekly basis. I felt this writing format is something that I can try and hopefully stick to in the long run.&lt;/p&gt;
&lt;h2&gt;2. General Inference Engine&lt;/h2&gt;
&lt;p&gt;This is a still in stealth mode since we are in the process of developing the pipeline. In the ideal case when it is built, the project can be used for literally any type of media based inference.&lt;/p&gt;
&lt;h2&gt;3. Stock Prediction using News&lt;/h2&gt;
&lt;p&gt;I know this might sound like a cliche project, but I still ended up learning quite a few interesting things.&lt;/p&gt;
&lt;p&gt;The approach I took was to take a bunch of news articles (2018-2021) and performed two major extraction operations on it -&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Sentiment Extraction&lt;/strong&gt; - This is pretty much a standard approach. I did it using a fine-tuned model called FinBERT that is trained on financial news and can understand that lingo.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;LLM based Feature Extraction&lt;/strong&gt; - This was a rather interesting experiment. I did some prompt engineering and got the final prompt which was something like this -&lt;/li&gt;
&lt;/ol&gt;
&lt;pre&gt;&lt;code&gt;&quot;Analyze the following financial news headline: {news}.&quot;

    Based on this headline, extract the following structured information as a tuple, choosing each feature from its predefined categories:

    1. **Company**: Identify the primary company mentioned&quot;
    2. **Event**: Identify the main event or action, choosing from: &quot;Merger,&quot; &quot;New Product,&quot; &quot;Profit/Loss Announcement,&quot; &quot;Partnership/Collaboration,&quot; &quot;Policy Change.&quot;
    3. **Reason**: Identify the reason for the event, choosing from: &quot;Market Demand,&quot; &quot;Regulatory Requirement,&quot; &quot;Internal Strategy,&quot; &quot;External Competition,&quot; &quot;Economic Conditions.&quot;
    4. **Verdict**: Assess the likely impact on stock, choosing from: &quot;UP,&quot; &quot;DOWN,&quot; &quot;NEUTRAL.&quot;

    NOTE: give categories from the categories provided in the prompt. DO NOT EXPLAIN THE CATEGORIES or output. Also, try to reason out the answer based on the headline see if the news might have any impact on the stock price of the company mentioned in the headline. DO NOT OUTPUT ANYTHING ELSE OTHER THEN THE TUPLE. DO NOT SAY - &quot; Here&apos;s the structured information extracted from the headlines:&quot;

    **Return the information in tuple format** only and nothing else using the example format below:

    Example format:
    `(&quot;Company&quot;, &quot;Event&quot;, &quot;Reason&quot;, &quot;Verdict&quot;)`
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Using the Gemini free LLM API, I was able to get the features for 887 news articles. This helped in finding the best predictors of stock movement and what magnitude will it move with.&lt;/p&gt;
&lt;p&gt;That&apos;s all for this devlog. Stay updated for newer editions!!&lt;/p&gt;
</content:encoded><category>devlog</category></item><item><title>Programming is doomed</title><link>https://shubhamrasal.com/writing/undefined/</link><guid isPermaLink="true">https://shubhamrasal.com/writing/undefined/</guid><description>A blog post by undefined</description><pubDate>Fri, 10 Nov 2023 00:00:00 GMT</pubDate><content:encoded>&lt;h2&gt;Introduction&lt;/h2&gt;
&lt;p&gt;Today I had an assignment in a Data structures and Algorithms Lab to implement integer multiplication using following:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Recursion&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://courses.csail.mit.edu/6.006/spring11/exams/notes3-karatsuba&quot;&gt;karatsuba&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;bitwise efficient implementation&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The internet was not allowed and I was not on my usual coding setup (vs code).
I couldn&apos;t complete the assignment in time. But I realized something about my way of programming.&lt;/p&gt;
&lt;h2&gt;My coding methodology&lt;/h2&gt;
&lt;p&gt;I use vs code as my primary editor (with vim bindings, yet to become hardcore vi enthusiast) along with GitHub copilot which is a code completion tool. Also I have a lot of language extensions that assist me with awesome auto completion.&lt;/p&gt;
&lt;p&gt;Before 2021, when I started coding, I used to spend a lot of time going through stack overflow, GitHub issues, docs to figure out something that made the computer do what I needed.&lt;/p&gt;
&lt;p&gt;After I started using copilot, I stopped losing context while coding. I could focus more on what I really cared that was solving the problem I had. I never leave my editor for checking syntax or finding a way to filter an array. Copilot just works. This made me think what is programming all about.&lt;/p&gt;
&lt;h2&gt;What is programming?&lt;/h2&gt;
&lt;p&gt;Computer Science is all about -&lt;/p&gt;
&lt;p&gt;&lt;code&gt;Converting ideas into program through some intermediate steps like algorithms, flowcharts and eventually code. It is to write programs, see that they are understandable and maintainable by humans in future.&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;According to me, I lack at all the described aspects. I am bad at reading someone else&apos;s code (or my own code after 2 weeks), maintaining my own code itself seems like a daunting task. Also, I try to write code that usually works and solves my current problem and I rarely think about it&apos;s understand-ability.&lt;/p&gt;
&lt;p&gt;To go back to the goal of Computer Science is to convert ideas into programs that can be executed by an von Neuman machine. Can you see that there is no mention of humans in this definition. Why should human be the only ones to write programs.&lt;/p&gt;
&lt;p&gt;We started with binary (arranging MOSFETS in a certain structure and passing correct signals through it to get a sum of two 8 bit digits, for example), then we built high level constructs like assembly then Pascal, FORTRAN and C. Then we started building higher order construct using these languages like python and JavaScript. If you observe this is all so that human can focus more on the idea expression side of it and less time coding up the instructions for the computer.&lt;/p&gt;
&lt;h2&gt;If AI written code becomes the norm&lt;/h2&gt;
&lt;p&gt;For now, if we assume that AI written code is as good as an average developer, reviewing it and sending it into production won&apos;t be an issue as long as thoroughly reviewed (which can also be assisted by another specialized model).&lt;/p&gt;
&lt;p&gt;This might give rise to interesting behavioral  changes in programming. For starters, all the design pattern that are currently abundant in most of the codebases (more so in languages like JAVA) are tailored to human understanding and easy readability. AI written code need not be restricted to such arbitrary patterns as long as the code works.&lt;/p&gt;
&lt;p&gt;Just as we have gotten used to probabilistic answering nature of LLMs where no one yet completely understands it&apos;s working but still it&apos;s output can more or less be considered on par with most of junior level coders, we will soon get habituated with having code that you understand less and less but have a high level understanding of what is does.&lt;/p&gt;
&lt;h2&gt;Is programming limited to computers?&lt;/h2&gt;
&lt;p&gt;OpenAI recently launched their new features like pdf chats, custom GPT builder without code (you can just talk with a base model and create a custom GPT) , etc. What really caught my eye was this new Assistant API which can help you develop autonomous agents that can interact with the world with the help of external API and do things for you like booking your tickets deciding you schedule, planning and execution you wedding, figuring out code deployment and al lot more.&lt;/p&gt;
&lt;p&gt;This means that the process of programming and scripting will be completely abstracted away and the only thing that remains for humans to do is problem solving and prompting the ideas in an expressive way.&lt;/p&gt;
&lt;h2&gt;Wild thought?&lt;/h2&gt;
&lt;p&gt;Eventually CS as a field will become a niche like every other engineering field with limited applicability. Models will become so powerful that only a simple prompt will be enough for it to do anything you need to get done.&lt;/p&gt;
</content:encoded><category>ai</category><category>philosophy</category></item><item><title>M# Hackathon Experience</title><link>https://shubhamrasal.com/writing/undefined/</link><guid isPermaLink="true">https://shubhamrasal.com/writing/undefined/</guid><description>A blog post by undefined</description><pubDate>Sat, 28 Oct 2023 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;When we got to know about the hackathon problem statements, we immediately started brainstorming about various PSs. We knew we had to pick a problem statement that complimented with the diverse skillset of our team. We had two members for ML, two for Web and one primarily for app (These roles are flexible and they need to be to make sure to adapt to the changing requirements of the project during the hackathon).&lt;/p&gt;
&lt;p&gt;After going through all the problem statements, we finalized a problem statement related to mental illness onset detection in a college target group. We came up with a elaborate plan and system design which almost included everything that could possibly be put into it (except blockchain, though we got a feedback during the later stage as to why did we not integrate it).&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;../../assets/mindful-ai-system-design.png&quot; alt=&quot;Mindful AI System Design&quot; title=&quot;Mindful AI System Design&quot; /&gt; &lt;em&gt;Mindful AI System Design&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;We then proceeded to make a fabulous PPT with all the buzz words to make it feel innovative. This got us selected in the top 30 teams that qualified to the offline hackathon at MIT Manipal.&lt;/p&gt;
&lt;h3&gt;Day 1&lt;/h3&gt;
&lt;p&gt;I didn&apos;t do much on day one. Two members were working on the ML part of our hack  which needed a lot a big data pre processing and a lot a training time since they were trying to build a custom ml model. The app guy was busy setting up auth for the application and me along with my web member were making a dashboard kind of thing for the admin. I picked up off the shelf ui components (shadcn, tailwind) to quickly get something beautiful as in hackathon like these it&apos;s all about how good your UI/UX is.&lt;/p&gt;
&lt;h3&gt;Day 2&lt;/h3&gt;
&lt;p&gt;Had to finish firebase AUTH integration and making the backend to handle video upload and passing it through the ML models built by then. It was tricky to work with flask as backend tech since it was my first time and using it was a requirement since the ML model dependecies are all in python.&lt;/p&gt;
&lt;h3&gt;Day 3&lt;/h3&gt;
&lt;p&gt;This day as well I didn&apos;t do much as majority of work was done by my teammates. I would always advice you to pick good teammates who are accountable and whose vibe matches with you and clashes are bound to happen and this will help your team to hold together.&lt;/p&gt;
&lt;p&gt;I had a lot of fun joking around and playing TT and carrom. Sleep shouldn&apos;t be your priority since here the main issue for not sleeping would be surprising. The whole place was confined and had a centralised AC. Everytime we tried to sleep someone would always bring down the temperate. this left us sleepless for days which is a common occuring in hackathons.&lt;/p&gt;
&lt;h3&gt;Results&lt;/h3&gt;
&lt;p&gt;At the end we managed to bag a consolation and a spot in the top nine teams with our cool hack.&lt;/p&gt;
&lt;p&gt;Here&apos;s what we built, if your interested - https://github.com/Shubham-Rasal/Mindful-AI&lt;/p&gt;
</content:encoded><category>ai</category></item><item><title>Database choice for toy blockchain in Go</title><link>https://shubhamrasal.com/writing/undefined/</link><guid isPermaLink="true">https://shubhamrasal.com/writing/undefined/</guid><description>A blog post by undefined</description><pubDate>Sat, 17 Jun 2023 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;This blog post is one of the many blog posts in the series of blog posts about my toy blockchain in Go. In order to understand Ethereum, I have decided to build one from scratch. Will use go-ethereum as a reference.&lt;/p&gt;
&lt;p&gt;In order to provide state persistence, the Ethereum spec defines the use of database to store the world state.
the
For storing the world state of the blockchin (which is just a very large merkel patrichia tree), a highly performant and fast key-value store is required. There are many databases which can be used for this purpose.&lt;/p&gt;
&lt;p&gt;In this blog post, I will be discussing the database choice for my toy blockchain in Go. I will be discussing the following databases:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://dgraph.io/docs/badger/&quot;&gt;BadgerDB&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://etcd.io/&quot;&gt;etcd&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/google/leveldb&quot;&gt;LevelDB&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;BadgerDB&lt;/h3&gt;
&lt;p&gt;The database is built in Go and is optimized for SSDs. It is a key-value store and is very fast. It is also ACID compliant. It is also used by &lt;a href=&quot;https://dgraph.io/&quot;&gt;Dgraph&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;There is no issue as such for me to not pick this database. But I want to explore other databases as well. Also, I think this db would be an overkill for my toy blockchain.&lt;/p&gt;
&lt;h3&gt;etcd&lt;/h3&gt;
&lt;p&gt;etcd is a distributed key-value store. It is built in Go and is used by cloud native softwares such as
&lt;a href=&quot;https://kubernetes.io/&quot;&gt;Kubernetes&lt;/a&gt; and &lt;a href=&quot;https://www.docker.com/&quot;&gt;Docker&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The main issue which prevented me from using this db was that it&apos;s installation was not that simple. Some of the dependencies were only complied for 32-bit systems causing problems.&lt;/p&gt;
&lt;h3&gt;LevelDB&lt;/h3&gt;
&lt;p&gt;Built in C++ and used by Google Chrome. It is also a key-value store. It is also very fast. It is also used by &lt;a href=&quot;https://ethereum.org/en/&quot;&gt;Ethereum&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The most popular implementation of ethereum is the go-ethereum or geth. When I was reading the code of geth, I found that they are using LevelDB but since the codebase is in Go, they are using the wrapper of LevelDB in Go - https://github.com/syndtr/goleveldb&lt;/p&gt;
&lt;p&gt;Although this is an old implementation, when I tried it, al its features were working fine. I think I will be using this database for my toy blockchain.&lt;/p&gt;
&lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;Although I have decided to go ahead with LevelDB, I will be exploring other databases as well if the former ends up being a bottleneck. I will be writing a blog post about the implementation of LevelDB in my toy blockchain.&lt;/p&gt;
</content:encoded><category>systems</category></item><item><title>My first blog post</title><link>https://shubhamrasal.com/writing/undefined/</link><guid isPermaLink="true">https://shubhamrasal.com/writing/undefined/</guid><description>A blog post by undefined</description><pubDate>Fri, 16 Jun 2023 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Today I am writing my first blog post. I am writing this blog post to share my experience of learning new things.
Future blogs will mostly be related to the following topics:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Systems&lt;/li&gt;
&lt;li&gt;Programming&lt;/li&gt;
&lt;li&gt;Philosophy&lt;/li&gt;
&lt;li&gt;My side projects&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I am not sure if I will be able to keep up the consistency of writing blogs, but I will try my best to write at least one blog post every month.&lt;/p&gt;
</content:encoded></item></channel></rss>