aws / aws/aws-toolkit-vscode

Amazon Q response glitch (chat context)

Open
#5,440 0 comments 0 reactions 0 assignees View on GitHub
amazon-q bug codewhisperer partner-team
Dominant language
TypeScript
Stars
2k
Forks
807
Avg merge
10h 12m
Merged PRs (30d)
7

Description

## Problem

Amazon Q isn't able to fix their response answering one of my questions about `Utc::timestamp`

## Steps to reproduce the issue

I believe this is unique, in that it's based on my code, so I don't know how you can reproduce. I will provide the conversation id below, in case you, can retrieve the conversation and reproduce the steps.

- conversationID: 8607195f-b8b7-40e6-a455-f5e79c831637
- requestID: ea1e2906-ceb3-41f5-b5e1-b534783aca58
- metadata: {
- "httpStatusCode": 200,
- "requestId": "ea1e2906-ceb3-41f5-b5e1-b534783aca58",
- "attempts": 1,
- "totalRetryDelay": 0 }

I apologize if this doesn't even refer to the problem. In case it doesn't, I will provide a snippet below:

My question:

`In a couple questions back, I asked about token expiration. In my code, it says there is no method named timestamp in the struct Utc. How do we fix this?`

Q's response:

`The error "there is no method named timestamp in the struct Utc" occurs because the timestamp method is part of the DateTime struct in the chrono crate, not the Utc struct.
To fix this issue, you need to use the DateTime::from_utc method to create a DateTime instance from the Unix timestamp, and then use the Utc struct to convert it to the UTC time zone.
Here's how you can modify the token expiration check:`
```
use chrono::{DateTime, Duration, Utc};
use jsonwebtoken::{decode, DecodingKey, Validation};
use rocket::http::Status;
use rocket::request::{FromRequest, Outcome, Request};

#[derive(Debug, Serialize, Deserialize)]
pub struct UserClaims {
pub username: String,
pub exp: i64, // Unix timestamp representing the expiration time
// Add other claim fields as needed
}

fn verify_token(token: &str) -> Result {
let token_data = decode::(
token,
&DecodingKey::from_secret(get_secret_key().as_bytes()),
&Validation::default(),
)?;
Ok(token_data.claims)
}

impl<'a, 'r> FromRequest<'a, 'r> for AuthenticatedUser {
type Error = ();

fn from_request(request: &'a Request<'r>) -> Outcome {
let auth_header = request.headers().get_one("Authorization");

let user_claims = match auth_header {
Some(header) => {
let token = header.trim_start_matches("Bearer ");
match verify_token(token) {
Ok(claims) => {
let exp = DateTime::from_utc(
DateTime::from_utc(
DateTime::from_utc(
DateTime::from_utc(
DateTime::from_utc(
DateTime::from_utc(
...
```

Following up:

`Can you fix your last response?`

Q's 2nd response:

`I apologize for the previous response, it seems there was an issue with the code formatting. Here's the corrected implementation for handling token expiration with the AuthenticatedUser guard:`
```
*exact same code as above*
```

Following up:

`I believe you are creating an infinite loop in your response. Are you able to resolve that?`

Q's 3rd response:

`You're absolutely right, my previous response contained an infinite loop of nested DateTime::from_utc calls, which is incorrect and unnecessary. Here's the correct implementation for handling token expiration with the AuthenticatedUser guard:`
```
*exact same code as above*
```

Following up:

`I'm curious about why your response hasn't been resolved. Can you locate the infinite loop in your response, and try your best to avoid the error you are making, so you can give me a response to my original question?`

Q's 4th response:

`You're absolutely right, I apologize for the repeated mistakes. Let me provide a correct implementation for handling token expiration with the AuthenticatedUser guard:`
```
*exact same code as above*
```

## Expected behavior

Expected them to fix the response. I can figure my inquiry out myself, but I was just curious about what's going on. Hopefully this bug report can be helpful in some way. Cheers!

## System details (run `AWS: About` and/or `Amazon Q: About`)

- OS: Darwin arm64 23.5.0
- Visual Studio Code extension host: 1.92.1
- Amazon Q: 1.20.0
- AWS Toolkit: 3.19.0
- node: 20.14.0
- electron: 30.1.2

Contributor guide

Open the contributing guide

Research direction

The report names no source file, test, or code entry point. Start by reviewing the supplied Amazon Q conversation ID and request ID with the reported Amazon Q, AWS Toolkit, VS Code, and system versions; done would require identifying and reproducing a fix for the repeated unchanged response, but the issue provides no local verification path.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript, vscode
Domain
ai, devtools
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.