Skip to content

[codex] stabilize Tiny Stories gameplay feedback loop - #20

Merged
lishehao merged 112 commits into
mainfrom
codex/story-brief-korean-webtoon-agent-chat
Jun 14, 2026
Merged

[codex] stabilize Tiny Stories gameplay feedback loop#20
lishehao merged 112 commits into
mainfrom
codex/story-brief-korean-webtoon-agent-chat

Conversation

@lishehao

Copy link
Copy Markdown
Owner

Summary

  • Adds and stabilizes the Tiny Stories interactive-drama gameplay loop: visible objective/pressure/evidence state, action forecast chips, receipt/reaction feedback, clue/opportunity unlocks, and typed gameplay envelope support.
  • Adds optional live gameplay metadata enrichment and persistence, with backend-derived and UI-derived fallback paths when metadata is missing or rejected.
  • Polishes the live metadata feedback surface so action cards keep short chips while expanded cards show the full validated "Why now" reason.
  • Preserves existing QA routes and player-facing leakage boundaries.

Latest stabilization slice

  • ea4ebf8 fix: stabilize gameplay metadata feedback adds optional chip detail, short Why now chips, per-chip title/ARIA text, and expanded-card reason detail rows.
  • Missing or omitted live metadata remains non-fatal and continues through backend-derived fallback.
  • No new provider call or required schema was added.

Validation

  • python -m py_compile rpg_backend/narrative/contracts.py rpg_backend/narrative/service.py
  • git diff --check
  • git diff --cached --check
  • npm --prefix frontend2 run check
  • npm --prefix frontend2 run build (existing large chunk warning only)
  • /opt/anaconda3/bin/pytest -q tests/test_play_direction_a_editorial_primitives_contract.py tests/test_published_direct_play_contract.py tests/test_navigation_mental_model_contract.py tests/test_narrative_agent_trace.py (47 passed; existing pytest-asyncio deprecation warning only)

Browser Evidence

  • In-app Browser #/qa/play-gameplay-loop: objective, pressure tracks, clue card present; no overflow or technical leakage.
  • In-app Browser #/qa/play-action: idle -> expanded -> pending receipt/reaction -> resolved remained stable.
  • In-app Browser #/qa/play-action?scenario=long-history at 390px: Back-to-move cue scrolled action area into view; no horizontal overflow or leakage.
  • Normal seeded Play #/play/sess_3i_reason_detail: data-gameplay-envelope-source="live_enriched"; chips stayed short; chip titles carried full reasons; expanded selected card showed the full Why now detail row; console warn/error count 0.

Notes / Risks

  • Live metadata acceptance remains optional and provider-dependent; this PR improves readability and fallback behavior rather than forcing metadata every turn.
  • The latest browser validation used persisted accepted metadata instead of spending new live turns, while backend health still showed live text paths configured.

lishehao added 30 commits June 1, 2026 21:55
@lishehao
lishehao marked this pull request as ready for review June 14, 2026 13:37
@lishehao
lishehao merged commit 3f3b604 into main Jun 14, 2026
2 checks passed
@lishehao
lishehao deleted the codex/story-brief-korean-webtoon-agent-chat branch June 14, 2026 13:38

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: aceee3b13d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread rpg_backend/main.py
code="seed_required",
message="Seed must not be empty.",
)
return narrative_service.create_story_brief(payload, owner_user_id=session.user.user_id)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Enforce quotas for story brief LLM calls

When a text gateway is configured, create_story_brief can invoke the live LLM, but this new endpoint returns directly without calling _enforce_llm_quota or accepting the Request needed for the IP key. A signed-in or auto-created guest user can repeatedly POST to /narrative/story-briefs and bypass the daily per-IP/per-user LLM limits that the adjacent story-guide, template creation, turn, and advisor endpoints apply.

Useful? React with 👍 / 👎.

Comment on lines +563 to +567
for entry in self._gateway_trace_since(start_index):
usage = entry.get("usage") if isinstance(entry.get("usage"), dict) else {}
status = _coerce_llm_call_status(entry.get("status"), entry.get("failure_message_bucket"))
source_label: LLMCallSourceLabel = "live_repaired" if status == "repaired" else "live"
self._repo.append_llm_call_event(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Isolate LLM traces per request

Under overlapping live LLM requests, this iterates every entry appended to the shared gateway call_trace after start_index; because narrative_service owns one shared gateway, entries from another user's create/turn request can land in that slice before this request persists it. Those events are then written with this request's user_id/session_id, corrupting reviewer telemetry and potentially exposing another session's response IDs/token data in the wrong runtime inspector.

Useful? React with 👍 / 👎.

Comment thread rpg_backend/config.py
runtime_state_db_path: str = "artifacts/runtime_state.sqlite3"
default_actor_id: str = "local-dev"
agent_trace_reviewer_user_ids: str = ""
agent_trace_reviewer_usernames: str = "portfolio_reviewer"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Require explicit trace reviewers by default

With the current username-only login, leaving portfolio_reviewer in the default allowlist means any visitor can POST /auth/login with that username and immediately receive can_view_agent_trace=true without a password or admin provisioning. In any deployment that does not override APP_AGENT_TRACE_REVIEWER_USERNAMES, the new reviewer/admin gate is effectively public for anyone's own sessions, so this default should be empty or local-only configuration rather than a production setting.

Useful? React with 👍 / 👎.

Comment on lines +410 to +411
const authorReady = await ensureAuthorSession()
if (!authorReady) return

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Restore brief readiness when auth is not ready

If Story Brief planning starts while auth is still loading, or the guest login fails, ensureAuthorSession() returns false after the state has already been changed to analyzing; this early return only clears briefBusy in finally and never restores ready_to_brief. The existing seed then no longer satisfies guideReadyToBrief, so the auto-brief effect will not retry and the user has to add an unrelated extra chat turn to recover.

Useful? React with 👍 / 👎.

Comment thread rpg_backend/main.py
code="guide_message_required",
message="Message must not be empty.",
)
_enforce_llm_quota(request, user_id=session.user.user_id)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Charge both live Story Butler calls

For an accepted Story Butler turn with the text gateway configured, create_story_guide_turn performs two provider operations (create.story_butler_context and create.story_butler_turn), but this route debits the quota with the default cost of 1. A user can therefore run the chat loop and consume roughly twice the intended daily LLM operations before the per-IP/per-user limits trigger.

Useful? React with 👍 / 👎.

opening_fallback_reason: str | None = None
operation_started_at = time.monotonic()
trace_start = self._trace_start()
if request.story_brief is not None and _story_brief_prefers_reliable_opening(request.story_brief):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reject not-fit briefs server-side

When a client posts a story_brief whose advisor result was runtime_fit_status: "not_fit", this branch still proceeds to synthesize a live or fallback opening instead of returning the same revise-first gate enforced in the UI. Direct API callers can bypass the disabled Generate CTA and publish exactly the small-cast/out-of-range briefs that can_generate=false was meant to block.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant