a digital entity named phi that roams bsky phi.zzstoatzz.io
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

add logfire spans and logging to engagement entry builder

need visibility into whether thread context is actually being fetched
for likes — previous deploys showed no evidence of the code running.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

+42 -21
+42 -21
src/bot/services/message_handler.py
··· 144 144 root_cid = "" 145 145 thread_uri = post_uri 146 146 thread_context = "" 147 - try: 148 - posts_resp = await self.client.get_posts([post_uri]) 149 - if posts_resp.posts: 150 - p = posts_resp.posts[0] 151 - post_text = p.record.text if hasattr(p.record, "text") else "" 152 - cid = p.cid 153 - root_cid = cid 147 + with logfire.span( 148 + "build engagement entry", 149 + post_uri=post_uri, 150 + author=notification.author.handle, 151 + reason=notification.reason, 152 + ): 153 + try: 154 + posts_resp = await self.client.get_posts([post_uri]) 155 + if posts_resp.posts: 156 + p = posts_resp.posts[0] 157 + post_text = p.record.text if hasattr(p.record, "text") else "" 158 + cid = p.cid 159 + root_cid = cid 154 160 155 - # resolve thread refs so phi sees the full conversation 156 - if hasattr(p.record, "reply") and p.record.reply: 157 - root_uri = p.record.reply.root.uri 158 - root_cid = p.record.reply.root.cid 159 - thread_uri = root_uri 161 + has_reply = hasattr(p.record, "reply") and p.record.reply 162 + logger.info( 163 + f"engagement on {post_uri}: has_reply={has_reply}, " 164 + f"text={post_text[:80]}" 165 + ) 166 + 167 + # resolve thread refs so phi sees the full conversation 168 + if has_reply: 169 + root_uri = p.record.reply.root.uri 170 + root_cid = p.record.reply.root.cid 171 + thread_uri = root_uri 172 + logger.info(f"fetching thread context from {thread_uri}") 160 173 161 - try: 162 - thread_data = await self.client.get_thread(thread_uri, depth=100) 163 - thread_context = build_thread_context(thread_data.thread) 164 - except Exception as e: 165 - logger.debug( 166 - f"failed to fetch thread for engaged post {post_uri}: {e}" 167 - ) 168 - except Exception as e: 169 - logger.debug(f"failed to fetch engaged post {post_uri}: {e}") 174 + try: 175 + thread_data = await self.client.get_thread( 176 + thread_uri, depth=100 177 + ) 178 + thread_context = build_thread_context(thread_data.thread) 179 + logger.info( 180 + f"thread context for engagement: " 181 + f"{len(thread_context)} chars" 182 + ) 183 + except Exception as e: 184 + logger.warning( 185 + f"failed to fetch thread for engaged post {post_uri}: {e}" 186 + ) 187 + else: 188 + logger.warning(f"get_posts returned empty for {post_uri}") 189 + except Exception as e: 190 + logger.warning(f"failed to fetch engaged post {post_uri}: {e}") 170 191 171 192 return { 172 193 "uri": post_uri,